graphvertex.h
Go to the documentation of this file.
1 /***************************************************************************
2  SocNetV: Social Network Visualizer
3  version: 3.1
4  Written in Qt
5 
6  graphvertex.h - description
7  -------------------
8  copyright : (C) 2005-2023 by Dimitris B. Kalamaras
9  project site : https://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 <QMultiHash>
36 #include <QList>
37 #include <QPointF>
38 #include <QPair>
39 
40 #include <map>
41 
42 using namespace std;
43 
44 class Graph;
45 
46 
47 typedef QList<int> L_int;
48 
49 typedef QHash<int,QString> H_IntToStr;
50 typedef QHash <QString, int> H_StrToInt;
51 
52 typedef QPair <qreal, bool> pair_f_b;
53 typedef QPair <int, pair_f_b > pair_i_fb;
54 typedef QMultiHash < int, pair_i_fb > H_edges;
55 
56 typedef QPair <int, qreal > pair_i_f;
57 typedef QHash < int, pair_i_f > H_distance;
58 
59 typedef QPair <int, int> pair_i_i;
60 typedef QHash < int, pair_i_i > H_shortestPaths;
61 
62 
63 class GraphVertex : public QObject{
64  Q_OBJECT
65 
66 public:
67 
68  GraphVertex(Graph* parentGraph,
69  const int &name,
70  const int &val,
71  const int &relation,
72  const int &size,
73  const QString &color,
74  const QString &numColor,
75  const int &numSize,
76  const QString &label,
77  const QString &labelColor,
78  const int &labelSize,
79  const QPointF &p,
80  const QString &shape,
81  const QString &iconPath,
82  const int &edgesEstimate = 2000);
83 
84  GraphVertex(const int &name);
85 
86  ~GraphVertex();
87 
88  int number() const;
89  void setNumber(const int &number);
90 
91  void setEnabled(const bool &status);
92  bool isEnabled () const;
93 
94  void setSize(const int &size );
95  int size() const;
96 
97  void setShape(const QString &shape, const QString &iconPath = QString());
98  QString shape() const;
99  QString shapeIconPath();
100 
101  void setColor(const QString &color);
102  QString color() const;
103  QString colorToPajek();
104 
105  void setNumberColor (const QString &color);
106  QString numberColor() const;
107 
108  void setNumberSize (const int &size);
109  int numberSize() const;
110 
111  void setNumberDistance (const int &distance);
112  int numberDistance() const;
113 
114  void setLabel (const QString &label);
115  QString label() const;
116 
117  void setLabelColor (const QString &labelColor);
118  QString labelColor() const;
119 
120  void setLabelSize(const int &size);
121  int labelSize() const;
122 
123  void setLabelDistance (const int &distance);
124  int labelDistance() const;
125 
126  void setX(const qreal &x);
127  qreal x() const;
128 
129  void setY(const qreal &y);
130  qreal y() const;
131 
132  void setPos (QPointF &p);
133  QPointF pos () const;
134 
135  void set_dispX (qreal x);
136  void set_dispY (qreal y);
137  QPointF & disp();
138 
139  void setRelation(int newRel) ;
140 
141  void addOutEdge (const int &v2, const qreal &weight, const QString &color=QString(), const QString &label=QString());
142  qreal hasEdgeTo(const int &v, const bool &allRelations=false);
143  void removeOutEdge (const int target);
144  void setOutEdgeWeight (const int &target, const qreal &weight);
145  void setOutEdgeEnabled (const int &target, bool);
146  void setOutLinkColor(const int &v2, const QString &color);
147  QString outLinkColor(const int &v2);
148  void setOutEdgeLabel(const int &v2, const QString &label);
149  QString outEdgeLabel(const int &v2) const;
150 
151  void addInEdge(const int &v1, const qreal &weight);
152  qreal hasEdgeFrom (const int &v, const bool &allRelations=false);
153  void removeInEdge(const int source);
154  void setInEdgeWeight (const int &source, const qreal &weight);
155  void setInEdgeEnabled (const int &source, bool);
156 
157  int outEdgesCount();
158  int outEdgesCountConst() const ;
159 
160  int inEdgesCount();
161  int inEdgesCountConst() const ;
162 
163  bool isOutLinked();
164  bool isInLinked();
165 
166  void setIsolated(bool isolated);
167  bool isIsolated();
168 
169  QHash<int, qreal> outEdgesEnabledHash(const bool &allRelations=false);
170  QHash<int,qreal>* outEdgesAllRelationsUniqueHash();
171  QHash<int,qreal>* inEdgesEnabledHash();
172  QHash<int,qreal> reciprocalEdgesHash();
173  QList<int> neighborhoodList();
174 
175  int degreeOut();
176  int outDegreeConst();
177  int degreeIn();
178  int inDegreeConst();
179  int localDegree();
180 
181  void setEnabledEdgesByRelation(const int relation, const bool status);
182  void setEnabledUnilateralEdges(const bool &status=false);
183 
184  qreal distance(const int &v1) ;
185  void setDistance (const int &v1, const qreal &d) ;
186  void reserveDistance(const int &N);
187  void clearDistance();
188 
189  int shortestPaths(const int &v1) ;
190  void setShortestPaths(const int &v1, const int &sp) ;
191  void reserveShortestPaths(const int &N);
192  void clearShortestPaths();
193 
194  void setEccentricity(const qreal &c);
195  qreal eccentricity();
196 
197  void setDelta(const qreal &c);
198  qreal delta();
199 
200  void clearPs() ;
201 
202  void appendToPs(const int &vertex ) ;
203  L_int Ps(void);
204 
205  //used in reciprocity report
206  void setOutEdgesReciprocated(int outEdgesSym=-1) { m_outEdgesSym = (outEdgesSym!=-1) ? outEdgesSym : m_outEdgesSym+1; }
207  int outEdgesReciprocated() { return m_outEdgesSym; }
208 
209  void setOutEdgesNonSym(int outEdgesNonSym=-1) { m_outEdgesNonSym = (outEdgesNonSym!=-1) ? outEdgesNonSym : m_outEdgesNonSym+1; }
210  int outEdgesNonSym() { return m_outEdgesNonSym; }
211 
212  void setInEdgesNonSym(int inEdgesNonSym=-1) { m_inEdgesNonSym = (inEdgesNonSym!=-1) ? inEdgesNonSym : m_inEdgesNonSym+1; }
213  int inEdgesNonSym() { return m_inEdgesNonSym; }
214 
215  void setDC (const qreal &c){ m_DC=c;} /* Sets vertex Degree Centrality*/
216  void setSDC (const qreal &c ) { m_SDC=c;} /* Sets standard vertex Degree Centrality*/
217  qreal DC() { return m_DC;} /* Returns vertex Degree Centrality*/
218  qreal SDC() { return m_SDC;} /* Returns standard vertex Degree Centrality*/
219 
220  void setDistanceSum (const qreal &c) { m_distanceSum = c; }
221  qreal distanceSum () { return m_distanceSum; }
222  void setCC (const qreal &c){ m_CC=c;} /* sets vertex Closeness Centrality*/
223  void setSCC (const qreal &c ) { m_SCC=c;} /* sets standard vertex Closeness Centrality*/
224  qreal CC() { return m_CC;} /* Returns vertex Closeness Centrality*/
225  qreal SCC() { return m_SCC; } /* Returns standard vertex Closeness Centrality*/
226 
227  void setIRCC (const qreal &c){ m_IRCC=c;} /* sets vertex IRCC */
228  void setSIRCC (const qreal &c ) { m_SIRCC=c;} /* sets standard vertex IRCC */
229  qreal IRCC() { return m_IRCC;} /* Returns vertex IRCC */
230  qreal SIRCC() { return m_SIRCC; } /* Returns standard vertex IRCC*/
231 
232  void setBC(const qreal &c){ m_BC=c;} /* sets s vertex Betweenness Centrality*/
233  void setSBC (const qreal &c ) { m_SBC=c;} /* sets standard vertex Betweenness Centrality*/
234  qreal BC() { return m_BC;} /* Returns vertex Betweenness Centrality*/
235  qreal SBC() { return m_SBC; } /* Returns standard vertex Betweenness Centrality*/
236 
237  void setSC (const qreal &c){ m_SC=c;} /* sets vertex Stress Centrality*/
238  void setSSC (const qreal &c ) { m_SSC=c;} /* sets standard vertex Stress Centrality*/
239  qreal SC() { return m_SC;} /* Returns vertex Stress Centrality*/
240  qreal SSC() { return m_SSC; } /* Returns standard vertex Stress Centrality*/
241 
242  void setEC(const qreal &dist) { m_EC=dist;} /* Sets max Geodesic Distance to all other vertices*/
243  void setSEC(const qreal &c) {m_SEC=c;}
244  qreal EC() { return m_EC;} /* Returns max Geodesic Distance to all other vertices*/
245  qreal SEC() { return m_SEC;}
246 
247  void setPC (const qreal &c){ m_PC=c;} /* sets vertex Power Centrality*/
248  void setSPC (const qreal &c ) { m_SPC=c;} /* sets standard vertex Power Centrality*/
249  qreal PC() { return m_PC;} /* Returns vertex Power Centrality*/
250  qreal SPC() { return m_SPC; } /* Returns standard vertex Power Centrality*/
251 
252  void setIC (const qreal &c){ m_IC=c;} /* sets vertex Information Centrality*/
253  void setSIC (const qreal &c ) { m_SIC=c;} /* sets standard vertex Information Centrality*/
254  qreal IC() { return m_IC;} /* Returns vertex Information Centrality*/
255  qreal SIC() { return m_SIC; } /* Returns standard vertex Information Centrality*/
256 
257  void setDP (const qreal &c){ m_DP=c;} /* Sets vertex Degree Prestige */
258  void setSDP (const qreal &c ) { m_SDP=c;} /* Sets standard vertex Degree Prestige */
259  qreal DP() { return m_DP;} /* Returns vertex Degree Prestige */
260  qreal SDP() { return m_SDP;} /* Returns standard vertex Degree Prestige */
261 
262  void setPRP (const qreal &c){ m_PRC=c;} /* sets vertex PageRank*/
263  void setSPRP (const qreal &c ) { m_SPRC=c;} /* sets standard vertex PageRank*/
264  qreal PRP() { return m_PRC;} /* Returns vertex PageRank */
265  qreal SPRP() { return m_SPRC; } /* Returns standard vertex PageRank*/
266 
267  void setPP (const qreal &c){ m_PP=c;} /* sets vertex Proximity Prestige */
268  void setSPP (const qreal &c ) { m_SPP=c;} /* sets standard vertex Proximity Prestige */
269  qreal PP() { return m_PP;} /* Returns vertex Proximity Prestige */
270  qreal SPP() { return m_SPP; } /* Returns standard vertex Proximity Prestige */
271 
272  qreal CLC() { return m_CLC; }
273  void setCLC(const qreal &clucof) { m_CLC=clucof; m_hasCLC=true; }
274  bool hasCLC() { return m_hasCLC; }
275 
276  void setEVC (const qreal &c){ m_EVC=c;} /* Sets vertex Degree Centrality*/
277  void setSEVC (const qreal &c ) { m_SEVC=c;} /* Sets standard vertex Degree Centrality*/
278  qreal EVC() { return m_EVC;} /* Returns vertex Degree Centrality*/
279  qreal SEVC() { return m_SEVC;} /* Returns standard vertex Degree Centrality*/
280 
281 
282  int cliques (const int &ofSize);
283 
284  void cliqueAdd (const QList<int> &clique);
285 
286  void clearCliques() { m_cliques.clear(); }
287 
288  //Hashes of all outbound and inbound edges of this vertex.
289  H_edges m_outEdges, m_inEdges;
290 
291  //Hash dictionary of this vertex pair-wise distances to all other vertices for each relationship
292  //The key is the relationship
293  //The value is a QPair < int target, qreal weight >
295 
297 
298 signals:
299  void signalSetEdgeVisibility (const int &relation,
300  const int &name,
301  const int &target,
302  const bool &visible,
303  const bool &preserveReverseEdge=false,
304  const int &edgeWeight=1,
305  const int &reverseEdgeWeight=1
306  );
307 
308 protected:
309 
310 private:
312  int m_number, m_outEdgesCounter, m_inEdgesCounter, m_outDegree, m_inDegree, m_localDegree;
313  int m_outEdgesNonSym, m_inEdgesNonSym, m_outEdgesSym;
314  int m_value, m_size, m_labelSize, m_numberSize, m_numberDistance, m_labelDistance;
316  bool m_reciprocalLinked, m_enabled, m_hasCLC, m_isolated;
317  double m_x, m_y;
318  qreal m_Eccentricity, m_CLC;
319  qreal m_delta, m_EC, m_SEC;
320  qreal m_DC, m_SDC, m_DP, m_SDP, m_CC, m_SCC, m_BC, m_SBC, m_IRCC, m_SIRCC, m_SC, m_SSC;
321  qreal m_PC, m_SPC, m_SIC, m_IC, m_SPRC, m_PRC;
322  qreal m_PP, m_SPP, m_EVC, m_SEVC;
324 
325  QString m_color, m_numberColor, m_label, m_labelColor, m_shape, m_iconPath;
326  QPointF m_disp;
327 
328  QHash<int,qreal> m_reciprocalEdges;
330  QMultiHash <int, L_int> m_cliques;
332  H_IntToStr m_outLinkColors, m_outEdgeLabels;
333 
334  //FIXME vertex coords
335 
336 
337 
338 };
339 
340 #endif
Definition: graphvertex.h:63
qreal DP()
Definition: graphvertex.h:259
int m_inEdgesNonSym
Definition: graphvertex.h:313
qreal IRCC()
Definition: graphvertex.h:229
qreal BC()
Definition: graphvertex.h:234
qreal SPRP()
Definition: graphvertex.h:265
qreal m_BC
Definition: graphvertex.h:320
qreal CC()
Definition: graphvertex.h:224
QString m_color
Definition: graphvertex.h:325
qreal EC()
Definition: graphvertex.h:244
L_int myPs
Definition: graphvertex.h:329
void setEC(const qreal &dist)
Definition: graphvertex.h:242
void setInEdgesNonSym(int inEdgesNonSym=-1)
Definition: graphvertex.h:212
void setSEVC(const qreal &c)
Definition: graphvertex.h:277
qreal m_delta
Definition: graphvertex.h:319
void setSDP(const qreal &c)
Definition: graphvertex.h:258
void setPC(const qreal &c)
Definition: graphvertex.h:247
double m_x
Definition: graphvertex.h:317
qreal m_IC
Definition: graphvertex.h:321
void setSCC(const qreal &c)
Definition: graphvertex.h:223
qreal SDC()
Definition: graphvertex.h:218
void setEVC(const qreal &c)
Definition: graphvertex.h:276
void setSPP(const qreal &c)
Definition: graphvertex.h:268
L_int m_neighborhoodList
Definition: graphvertex.h:331
void setSDC(const qreal &c)
Definition: graphvertex.h:216
void setDistanceSum(const qreal &c)
Definition: graphvertex.h:220
void setSIRCC(const qreal &c)
Definition: graphvertex.h:228
void setIC(const qreal &c)
Definition: graphvertex.h:252
void setSPC(const qreal &c)
Definition: graphvertex.h:248
void setSEC(const qreal &c)
Definition: graphvertex.h:243
QMultiHash< int, L_int > m_cliques
Definition: graphvertex.h:330
int m_labelDistance
Definition: graphvertex.h:314
QPointF m_disp
Definition: graphvertex.h:326
H_distance m_distance
Definition: graphvertex.h:294
void setCLC(const qreal &clucof)
Definition: graphvertex.h:273
qreal SIC()
Definition: graphvertex.h:255
qreal SEC()
Definition: graphvertex.h:245
void setSC(const qreal &c)
Definition: graphvertex.h:237
qreal m_CLC
Definition: graphvertex.h:318
qreal SBC()
Definition: graphvertex.h:235
QHash< int, qreal > m_reciprocalEdges
Definition: graphvertex.h:328
int m_curRelation
Definition: graphvertex.h:315
void setSPRP(const qreal &c)
Definition: graphvertex.h:263
H_IntToStr m_outEdgeLabels
Definition: graphvertex.h:332
void setSBC(const qreal &c)
Definition: graphvertex.h:233
void signalSetEdgeVisibility(const int &relation, const int &name, const int &target, const bool &visible, const bool &preserveReverseEdge=false, const int &edgeWeight=1, const int &reverseEdgeWeight=1)
qreal m_distanceSum
Definition: graphvertex.h:323
qreal SPC()
Definition: graphvertex.h:250
qreal SEVC()
Definition: graphvertex.h:279
int inEdgesNonSym()
Definition: graphvertex.h:213
qreal SDP()
Definition: graphvertex.h:260
H_shortestPaths m_shortestPaths
Definition: graphvertex.h:296
void setCC(const qreal &c)
Definition: graphvertex.h:222
void setPRP(const qreal &c)
Definition: graphvertex.h:262
int outEdgesReciprocated()
Definition: graphvertex.h:207
void setSIC(const qreal &c)
Definition: graphvertex.h:253
qreal PC()
Definition: graphvertex.h:249
H_edges m_inEdges
Definition: graphvertex.h:289
qreal m_EVC
Definition: graphvertex.h:322
void setIRCC(const qreal &c)
Definition: graphvertex.h:227
qreal CLC()
Definition: graphvertex.h:272
void setOutEdgesNonSym(int outEdgesNonSym=-1)
Definition: graphvertex.h:209
qreal SSC()
Definition: graphvertex.h:240
void clearCliques()
Definition: graphvertex.h:286
qreal SIRCC()
Definition: graphvertex.h:230
void setDP(const qreal &c)
Definition: graphvertex.h:257
qreal distanceSum()
Definition: graphvertex.h:221
qreal DC()
Definition: graphvertex.h:217
qreal PRP()
Definition: graphvertex.h:264
qreal PP()
Definition: graphvertex.h:269
int m_inDegree
Definition: graphvertex.h:312
qreal EVC()
Definition: graphvertex.h:278
qreal SCC()
Definition: graphvertex.h:225
qreal IC()
Definition: graphvertex.h:254
void setDC(const qreal &c)
Definition: graphvertex.h:215
void setPP(const qreal &c)
Definition: graphvertex.h:267
bool m_enabled
Definition: graphvertex.h:316
void setBC(const qreal &c)
Definition: graphvertex.h:232
void setOutEdgesReciprocated(int outEdgesSym=-1)
Definition: graphvertex.h:206
int outEdgesNonSym()
Definition: graphvertex.h:210
qreal SPP()
Definition: graphvertex.h:270
void setSSC(const qreal &c)
Definition: graphvertex.h:238
qreal SC()
Definition: graphvertex.h:239
bool hasCLC()
Definition: graphvertex.h:274
Graph * m_graph
Definition: graphvertex.h:311
The Graph class This is the main class for a Graph, used in conjuction with GraphVertex,...
Definition: graph.h:111
QList< int > L_int
Definition: graph.h:85
QMultiHash< int, pair_i_fb > H_edges
Definition: graph.h:83
QHash< int, QString > H_IntToStr
Definition: graphvertex.h:49
QPair< int, int > pair_i_i
Definition: graphvertex.h:59
QList< int > L_int
Definition: graphvertex.h:44
QHash< int, pair_i_i > H_shortestPaths
Definition: graphvertex.h:60
QHash< int, pair_i_f > H_distance
Definition: graphvertex.h:57
QPair< int, qreal > pair_i_f
Definition: graphvertex.h:56
QMultiHash< int, pair_i_fb > H_edges
Definition: graphvertex.h:54
QPair< qreal, bool > pair_f_b
Definition: graphvertex.h:52
QHash< QString, int > H_StrToInt
Definition: graphvertex.h:50
QPair< int, pair_f_b > pair_i_fb
Definition: graphvertex.h:53