graphvertex.h
Go to the documentation of this file.
1 /***************************************************************************
2  SocNetV: Social Network Visualizer
3  version: 2.5
4  Written in Qt
5 
6  graphvertex.h - description
7  -------------------
8  copyright : (C) 2005-2018 by Dimitris B. Kalamaras
9  project site : http://socnetv.org
10 
11  ***************************************************************************/
12 
13 /*******************************************************************************
14 * This program is free software: you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation, either version 3 of the License, or *
17 * (at your option) any later version. *
18 * *
19 * This program is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 * GNU General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU General Public License *
25 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
26 ********************************************************************************/
27 
28 #ifndef GRAPHVERTEX_H
29 #define GRAPHVERTEX_H
30 
31 #include <QObject>
32 #include <QString>
33 #include <QStringList>
34 #include <QHash>
35 #include <QList>
36 #include <QPointF>
37 #include <map>
38 
39 using namespace std;
40 
41 class QPointF;
42 class Graph;
43 
44 
45 typedef QList<int> L_int;
46 
47 typedef QHash<int,QString> H_IntToStr;
48 typedef QHash <QString, int> H_StrToInt;
49 
50 
51 typedef QPair <float, bool> pair_f_b;
52 typedef QPair <int, pair_f_b > pair_i_fb;
53 typedef QHash < int, pair_i_fb > H_edges;
54 
55 typedef QPair <int, float > pair_i_f;
56 typedef QHash < int, pair_i_f > H_distance;
57 
58 typedef QPair <int, int> pair_i_i;
59 typedef QHash < int, pair_i_i > H_shortestPaths;
60 
61 
62 class GraphVertex : public QObject{
63  Q_OBJECT
64 
65 public:
66 
67  GraphVertex(Graph* parent,
68  const long int &name,
69  const int &val,
70  const int &relation,
71  const int &size,
72  const QString &color,
73  const QString &numColor,
74  const int &numSize,
75  const QString &label,
76  const QString &labelColor,
77  const int &labelSize,
78  const QPointF &p,
79  const QString &shape);
80 
81  GraphVertex(const long int &name);
82 
83  ~GraphVertex();
84 
85  long int name() const { return m_name; }
86 
87  void setName (const long int &name) { m_name=name; }
88 
89  void setEnabled (const bool &flag ) { m_enabled=flag; }
90  bool isEnabled () const { return m_enabled; }
91 
92  void relationSet(int newRel) ;
93 
94  void edgeAddTo (const long int &v2, const float &weight);
95  void edgeAddFrom(const long int &v1, const float &weight);
96 
97  void changeOutEdgeWeight (long int target, float weight);
98 
99  void setOutEdgeEnabled (long int, bool);
100 
101  void edgeRemoveTo (long int target);
102  void edgeRemoveFrom(long int source);
103 
104  QHash<int, float> outEdgesEnabledHash(const bool &allRelations=false);
105  QHash<int,float>* outEdgesAllRelationsUniqueHash();
106  QHash<int,float>* inEdgesEnabledHash();
107  QHash<int,float> reciprocalEdgesHash();
108  QList<int> neighborhoodList();
109 
110  long int outEdges();
111  long int outEdgesConst() const ;
112 
113  long int inEdges();
114  long int inEdgesConst() const ;
115 
116  long int degreeOut();
117  long int outDegreeConst();
118  long int degreeIn();
119  long int inDegreeConst();
120  long int localDegree();
121 
122  float distance(const long int &v1) ;
123  void setDistance (const long int &v1, const float &d) ;
124  void reserveDistance(const int &N);
125  void clearDistance();
126 
127  int shortestPaths(const long int &v1) ;
128  void setShortestPaths(const long int &v1, const int &sp) ;
129  void reserveShortestPaths(const int &N);
130  void clearShortestPaths();
131 
132 
133  /* sets eccentricity */
134  void setEccentricity (float c){ m_Eccentricity=c;}
135  float eccentricity() { return m_Eccentricity;}
136 
137  /* Returns true if there is an outLink from this vertex */
138  bool isOutLinked() { return (outEdges() > 0) ? true:false;}
139  float hasEdgeTo(const long int &v, const bool &allRelations=false);
140 
141  /* Returns true if there is an outLink from this vertex */
142  bool isInLinked() { return (inEdges() > 0) ? true:false;}
143  float hasEdgeFrom (const long int &v, const bool &allRelations=false);
144 
145  bool isIsolated() { return !(isOutLinked() | isInLinked()) ; }
146  void setIsolated(bool isolated) {m_isolated = isolated; }
147 
148  void edgeFilterByWeight(float m_threshold, bool overThreshold);
149  // void filterEdgesByColor(float m_threshold, bool overThreshold);
150  void edgeFilterByRelation(int relation, bool status);
151  void edgeFilterUnilateral(const bool &toggle=false);
152 
153  void setSize(const int &size ) { m_size=size; }
154  int size() const { return m_size; }
155 
156  void setShape(const QString &shape) { m_shape=shape; }
157  QString shape() const { return m_shape; }
158 
159  void setColor(const QString &color) { m_color=color; }
160  QString color() const { return m_color; }
161  QString colorToPajek();
162 
163  void setNumberColor (const QString &color) { m_numberColor = color; }
164  QString numberColor() const { return m_numberColor; }
165 
166  void setNumberSize (const int &size) { m_numberSize=size; }
167  int numberSize() const { return m_numberSize; }
168 
169  void setNumberDistance (const int &distance) { m_numberDistance=distance; }
170  int numberDistance() const { return m_numberDistance; }
171 
172  void setLabel (const QString &label) { m_label=label; }
173  QString label() const { return m_label; }
174 
175  void setLabelColor (const QString &labelColor) { m_labelColor=labelColor; }
176  QString labelColor() const { return m_labelColor; }
177 
178  void setLabelSize(const int &size) { m_labelSize=size; }
179  int labelSize() const { return m_labelSize; }
180 
181  void setLabelDistance (const int &distance) { m_labelDistance=distance; }
182  int labelDistance() const { return m_labelDistance; }
183 
184  void setX(const float &x) { m_x=x; }
185  float x() const { return m_x; }
186 
187  void setY(const float &y) { m_y=y; }
188  float y() const { return m_y; }
189 
190  QPointF pos () const { return QPointF ( x(), y() ); }
191  void setPos (QPointF &p) { m_x=p.x(); m_y=p.y(); }
192 
193  //returns displacement vector
194  QPointF & disp() { return m_disp; }
195 
196  void set_dispX (float x) { m_disp.rx() = x ; }
197  void set_dispY (float y) { m_disp.ry() = y ; }
198 
199 
200  void setOutLinkColor(const long int &v2,
201  const QString &color) { m_outLinkColors[v2]=color; }
202  QString outLinkColor(const long int &v2) {
203  return ( m_outLinkColors.contains(v2) ) ? m_outLinkColors.value(v2) : "black";
204  }
205 
206 
207  void setOutEdgeLabel(const long int &v2,
208  const QString &label) { m_outEdgeLabels[v2]=label; }
209  QString outEdgeLabel(const long int &v2) const {
210  return ( m_outEdgeLabels.contains(v2) ) ? m_outEdgeLabels.value(v2) : QString::null;
211  }
212 
213 
214  void setDelta (float c){ m_delta=c;} /* Sets vertex pair dependancy */
215  float delta() { return m_delta;} /* Returns vertex pair dependancy */
216 
217  void clearPs() ;
218 
219  void appendToPs(long int vertex ) ;
220  L_int Ps(void);
221 
222  //used in reciprocity report
223  void setOutEdgesReciprocated(int outEdgesSym=-1) { m_outEdgesSym = (outEdgesSym!=-1) ? outEdgesSym : m_outEdgesSym+1; }
224  int outEdgesReciprocated() { return m_outEdgesSym; }
225 
226  void setOutEdgesNonSym(int outEdgesNonSym=-1) { m_outEdgesNonSym = (outEdgesNonSym!=-1) ? outEdgesNonSym : m_outEdgesNonSym+1; }
227  int outEdgesNonSym() { return m_outEdgesNonSym; }
228 
229  void setInEdgesNonSym(int inEdgesNonSym=-1) { m_inEdgesNonSym = (inEdgesNonSym!=-1) ? inEdgesNonSym : m_inEdgesNonSym+1; }
230  int inEdgesNonSym() { return m_inEdgesNonSym; }
231 
232  void setDC (float c){ m_DC=c;} /* Sets vertex Degree Centrality*/
233  void setSDC (float c ) { m_SDC=c;} /* Sets standard vertex Degree Centrality*/
234  float DC() { return m_DC;} /* Returns vertex Degree Centrality*/
235  float SDC() { return m_SDC;} /* Returns standard vertex Degree Centrality*/
236 
237  void setCC (float c){ m_CC=c;} /* sets vertex Closeness Centrality*/
238  void setSCC (float c ) { m_SCC=c;} /* sets standard vertex Closeness Centrality*/
239  float CC() { return m_CC;} /* Returns vertex Closeness Centrality*/
240  float SCC() { return m_SCC; } /* Returns standard vertex Closeness Centrality*/
241 
242  void setIRCC (float c){ m_IRCC=c;} /* sets vertex IRCC */
243  void setSIRCC (float c ) { m_SIRCC=c;} /* sets standard vertex IRCC */
244  float IRCC() { return m_IRCC;} /* Returns vertex IRCC */
245  float SIRCC() { return m_SIRCC; } /* Returns standard vertex IRCC*/
246 
247  void setBC(float c){ m_BC=c;} /* sets s vertex Betweenness Centrality*/
248  void setSBC (float c ) { m_SBC=c;} /* sets standard vertex Betweenness Centrality*/
249  float BC() { return m_BC;} /* Returns vertex Betweenness Centrality*/
250  float SBC() { return m_SBC; } /* Returns standard vertex Betweenness Centrality*/
251 
252  void setSC (float c){ m_SC=c;} /* sets vertex Stress Centrality*/
253  void setSSC (float c ) { m_SSC=c;} /* sets standard vertex Stress Centrality*/
254  float SC() { return m_SC;} /* Returns vertex Stress Centrality*/
255  float SSC() { return m_SSC; } /* Returns standard vertex Stress Centrality*/
256 
257  void setEC(float dist) { m_EC=dist;} /* Sets max Geodesic Distance to all other vertices*/
258  void setSEC(float c) {m_SEC=c;}
259  float EC() { return m_EC;} /* Returns max Geodesic Distance to all other vertices*/
260  float SEC() { return m_SEC;}
261 
262  void setPC (float c){ m_PC=c;} /* sets vertex Power Centrality*/
263  void setSPC (float c ) { m_SPC=c;} /* sets standard vertex Power Centrality*/
264  float PC() { return m_PC;} /* Returns vertex Power Centrality*/
265  float SPC() { return m_SPC; } /* Returns standard vertex Power Centrality*/
266 
267  void setIC (float c){ m_IC=c;} /* sets vertex Information Centrality*/
268  void setSIC (float c ) { m_SIC=c;} /* sets standard vertex Information Centrality*/
269  float IC() { return m_IC;} /* Returns vertex Information Centrality*/
270  float SIC() { return m_SIC; } /* Returns standard vertex Information Centrality*/
271 
272  void setDP (float c){ m_DP=c;} /* Sets vertex Degree Prestige */
273  void setSDP (float c ) { m_SDP=c;} /* Sets standard vertex Degree Prestige */
274  float DP() { return m_DP;} /* Returns vertex Degree Prestige */
275  float SDP() { return m_SDP;} /* Returns standard vertex Degree Prestige */
276 
277  void setPRP (float c){ m_PRC=c;} /* sets vertex PageRank*/
278  void setSPRP (float c ) { m_SPRC=c;} /* sets standard vertex PageRank*/
279  float PRP() { return m_PRC;} /* Returns vertex PageRank */
280  float SPRP() { return m_SPRC; } /* Returns standard vertex PageRank*/
281 
282  void setPP (float c){ m_PP=c;} /* sets vertex Proximity Prestige */
283  void setSPP (float c ) { m_SPP=c;} /* sets standard vertex Proximity Prestige */
284  float PP() { return m_PP;} /* Returns vertex Proximity Prestige */
285  float SPP() { return m_SPP; } /* Returns standard vertex Proximity Prestige */
286 
287  float CLC() { return m_CLC; }
288  void setCLC(float clucof) { m_CLC=clucof; m_hasCLC=true; }
289  bool hasCLC() { return m_hasCLC; }
290 
291  void setEVC (float c){ m_EVC=c;} /* Sets vertex Degree Centrality*/
292  void setSEVC (float c ) { m_SEVC=c;} /* Sets standard vertex Degree Centrality*/
293  float EVC() { return m_EVC;} /* Returns vertex Degree Centrality*/
294  float SEVC() { return m_SEVC;} /* Returns standard vertex Degree Centrality*/
295 
296 
297  int cliques (const int &ofSize);
298 
299  void cliqueAdd (const QList<int> &clique);
300 
301  void clearCliques() { m_cliques.clear(); }
302 
303  //hold all outbound and inbound edges of this vertex.
304  H_edges m_outEdges, m_inEdges;
307 
308 signals:
309  void setEdgeVisibility (int, int, int, bool);
310 
311 protected:
312 
313 private:
315  long int m_name, m_outEdgesCounter, m_inEdgesCounter, m_outDegree, m_inDegree, m_localDegree;
316  long int m_outEdgesNonSym, m_inEdgesNonSym, m_outEdgesSym;
317  int m_value, m_size, m_labelSize, m_numberSize, m_numberDistance, m_labelDistance;
319  bool m_reciprocalLinked, m_enabled, m_hasCLC, m_isolated;
320  double m_x, m_y;
321  float m_Eccentricity, m_CLC;
322  float m_delta, m_EC, m_SEC;
323  float m_DC, m_SDC, m_DP, m_SDP, m_CC, m_SCC, m_BC, m_SBC, m_IRCC, m_SIRCC, m_SC, m_SSC;
324  float m_PC, m_SPC, m_SIC, m_IC, m_SPRC, m_PRC;
325  float m_PP, m_SPP, m_EVC, m_SEVC;
326 
327  QString m_color, m_numberColor, m_label, m_labelColor, m_shape;
328  QPointF m_disp;
329 
330  QHash<int,float> m_reciprocalEdges;
332  QHash <int, L_int> m_cliques;
334  H_IntToStr m_outLinkColors, m_outEdgeLabels;
335 
336  //FIXME vertex coords
337 
338 
339 
340 };
341 
342 #endif
int numberSize() const
Definition: graphvertex.h:167
void setSize(const int &size)
Definition: graphvertex.h:153
float SSC()
Definition: graphvertex.h:255
long int m_outEdgesSym
Definition: graphvertex.h:316
float SPRP()
Definition: graphvertex.h:280
float m_SSC
Definition: graphvertex.h:323
QString color() const
Definition: graphvertex.h:160
QPair< float, bool > pair_f_b
Definition: graphvertex.h:51
void setSDC(float c)
Definition: graphvertex.h:233
void setColor(const QString &color)
Definition: graphvertex.h:159
QPair< int, int > pair_i_i
Definition: graphvertex.h:58
H_IntToStr m_outLinkColors
Definition: graphvertex.h:334
int labelSize() const
Definition: graphvertex.h:179
void setSPC(float c)
Definition: graphvertex.h:263
QHash< int, pair_i_f > H_distance
Definition: graphvertex.h:56
void setSIC(float c)
Definition: graphvertex.h:268
void setNumberDistance(const int &distance)
Definition: graphvertex.h:169
void setOutEdgesReciprocated(int outEdgesSym=-1)
Definition: graphvertex.h:223
The Graph class This is the main class for a Graph, used in conjuction with GraphVertex, Parser and Matrix objects. Graph class methods are the interface to various analysis algorithms GraphVertex class holds each vertex data (colors, strings, statistics, etc) Matrix class holds the adjacency matrix of the network. Parser class loads files of networks.
Definition: graph.h:208
void setSPP(float c)
Definition: graphvertex.h:283
void setDP(float c)
Definition: graphvertex.h:272
float CC()
Definition: graphvertex.h:239
float SCC()
Definition: graphvertex.h:240
void setEccentricity(float c)
Definition: graphvertex.h:134
float IRCC()
Definition: graphvertex.h:244
QString m_shape
Definition: graphvertex.h:327
float SEC()
Definition: graphvertex.h:260
void clearCliques()
Definition: graphvertex.h:301
int outEdgesReciprocated()
Definition: graphvertex.h:224
float SBC()
Definition: graphvertex.h:250
void setLabel(const QString &label)
Definition: graphvertex.h:172
bool isIsolated()
Definition: graphvertex.h:145
void set_dispX(float x)
Definition: graphvertex.h:196
float EVC()
Definition: graphvertex.h:293
void setY(const float &y)
Definition: graphvertex.h:187
QHash< int, pair_i_fb > H_edges
Definition: graph.h:123
void setSCC(float c)
Definition: graphvertex.h:238
float PP()
Definition: graphvertex.h:284
void setEVC(float c)
Definition: graphvertex.h:291
H_distance m_distance
Definition: graphvertex.h:305
H_edges m_outEdges
Definition: graphvertex.h:304
float SPC()
Definition: graphvertex.h:265
float m_SEC
Definition: graphvertex.h:322
void setPRP(float c)
Definition: graphvertex.h:277
float SDP()
Definition: graphvertex.h:275
QHash< int, QString > H_IntToStr
Definition: graphvertex.h:47
float CLC()
Definition: graphvertex.h:287
Graph * parentGraph
Definition: graphvertex.h:314
L_int myPs
Definition: graphvertex.h:331
float SDC()
Definition: graphvertex.h:235
float m_SPRC
Definition: graphvertex.h:324
int m_curRelation
Definition: graphvertex.h:318
void setSIRCC(float c)
Definition: graphvertex.h:243
double m_y
Definition: graphvertex.h:320
void setIsolated(bool isolated)
Definition: graphvertex.h:146
QString numberColor() const
Definition: graphvertex.h:164
void setPC(float c)
Definition: graphvertex.h:262
void setSDP(float c)
Definition: graphvertex.h:273
bool hasCLC()
Definition: graphvertex.h:289
QHash< int, L_int > m_cliques
Definition: graphvertex.h:332
QPair< int, pair_f_b > pair_i_fb
Definition: graphvertex.h:52
void setNumberColor(const QString &color)
Definition: graphvertex.h:163
void setPos(QPointF &p)
Definition: graphvertex.h:191
float BC()
Definition: graphvertex.h:249
int outEdgesNonSym()
Definition: graphvertex.h:227
void setCC(float c)
Definition: graphvertex.h:237
float SIRCC()
Definition: graphvertex.h:245
QPointF & disp()
Definition: graphvertex.h:194
H_shortestPaths m_shortestPaths
Definition: graphvertex.h:306
void setLabelSize(const int &size)
Definition: graphvertex.h:178
int inEdgesNonSym()
Definition: graphvertex.h:230
L_int m_neighborhoodList
Definition: graphvertex.h:333
void setDelta(float c)
Definition: graphvertex.h:214
float DP()
Definition: graphvertex.h:274
QList< int > L_int
Definition: graph.h:125
int labelDistance() const
Definition: graphvertex.h:182
void setPP(float c)
Definition: graphvertex.h:282
QString outEdgeLabel(const long int &v2) const
Definition: graphvertex.h:209
QString shape() const
Definition: graphvertex.h:157
float SC()
Definition: graphvertex.h:254
long int name() const
Definition: graphvertex.h:85
void setX(const float &x)
Definition: graphvertex.h:184
void setIC(float c)
Definition: graphvertex.h:267
void setEC(float dist)
Definition: graphvertex.h:257
void setCLC(float clucof)
Definition: graphvertex.h:288
void setSPRP(float c)
Definition: graphvertex.h:278
void setShape(const QString &shape)
Definition: graphvertex.h:156
float m_SPP
Definition: graphvertex.h:325
float PC()
Definition: graphvertex.h:264
void setNumberSize(const int &size)
Definition: graphvertex.h:166
float SPP()
Definition: graphvertex.h:285
QPointF m_disp
Definition: graphvertex.h:328
int numberDistance() const
Definition: graphvertex.h:170
QPointF pos() const
Definition: graphvertex.h:190
float y() const
Definition: graphvertex.h:188
void setDC(float c)
Definition: graphvertex.h:232
bool isInLinked()
Definition: graphvertex.h:142
void setOutEdgesNonSym(int outEdgesNonSym=-1)
Definition: graphvertex.h:226
float eccentricity()
Definition: graphvertex.h:135
void setSEC(float c)
Definition: graphvertex.h:258
float m_Eccentricity
Definition: graphvertex.h:321
QHash< int, float > m_reciprocalEdges
Definition: graphvertex.h:330
float EC()
Definition: graphvertex.h:259
int size() const
Definition: graphvertex.h:154
void setBC(float c)
Definition: graphvertex.h:247
void setLabelDistance(const int &distance)
Definition: graphvertex.h:181
bool m_reciprocalLinked
Definition: graphvertex.h:319
float delta()
Definition: graphvertex.h:215
QString outLinkColor(const long int &v2)
Definition: graphvertex.h:202
void setIRCC(float c)
Definition: graphvertex.h:242
void setSBC(float c)
Definition: graphvertex.h:248
void setSSC(float c)
Definition: graphvertex.h:253
void setSEVC(float c)
Definition: graphvertex.h:292
void setName(const long int &name)
Definition: graphvertex.h:87
int m_value
Definition: graphvertex.h:317
QString labelColor() const
Definition: graphvertex.h:176
long int m_outEdgesCounter
Definition: graphvertex.h:315
float DC()
Definition: graphvertex.h:234
void setOutEdgeLabel(const long int &v2, const QString &label)
Definition: graphvertex.h:207
QHash< QString, int > H_StrToInt
Definition: graphvertex.h:48
QString label() const
Definition: graphvertex.h:173
void set_dispY(float y)
Definition: graphvertex.h:197
float IC()
Definition: graphvertex.h:269
void setEnabled(const bool &flag)
Definition: graphvertex.h:89
void setSC(float c)
Definition: graphvertex.h:252
bool isOutLinked()
Definition: graphvertex.h:138
float x() const
Definition: graphvertex.h:185
QList< int > L_int
Definition: graphvertex.h:42
void setLabelColor(const QString &labelColor)
Definition: graphvertex.h:175
float SIC()
Definition: graphvertex.h:270
bool isEnabled() const
Definition: graphvertex.h:90
float SEVC()
Definition: graphvertex.h:294
void setInEdgesNonSym(int inEdgesNonSym=-1)
Definition: graphvertex.h:229
void setOutLinkColor(const long int &v2, const QString &color)
Definition: graphvertex.h:200
float PRP()
Definition: graphvertex.h:279
Definition: graphvertex.h:62
QPair< int, float > pair_i_f
Definition: graphvertex.h:55
QHash< int, pair_i_fb > H_edges
Definition: graphvertex.h:53
QHash< int, pair_i_i > H_shortestPaths
Definition: graphvertex.h:59