Tulip  5.1.0
Large graphs analysis and drawing
GraphMeasure.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 ///@cond DOXYGEN_HIDDEN
20 
21 #ifndef _TLPGRAPHMEASEURE_H
22 #define _TLPGRAPHMEASEURE_H
23 
24 #include <set>
25 
26 #include <tulip/Node.h>
27 #include <tulip/MutableContainer.h>
28 #include <tulip/DoubleProperty.h>
29 #include <tulip/StaticProperty.h>
30 
31 namespace tlp {
32 
33 class Graph;
34 class PluginProgress;
35 enum EDGE_TYPE {UNDIRECTED = 0, INV_DIRECTED = 1, DIRECTED = 2};
36 #define IN_EDGE INV_DIRECTED
37 #define OUT_EDGE DIRECTED
38 #define INOUT_EDGE UNDIRECTED
39 /**
40  * returns the average path lengh of a graph, that is the sum
41  * of the shortest distances for all pair of distinct nodes in that graph
42  * divided by the number of those pairs. For a pair of non connected nodes,
43  * the shorted distance is set to 0.
44  * see http://en.wikipedia.org/wiki/Average_path_length for more details
45  */
46 TLP_SCOPE double averagePathLength(const Graph* g, PluginProgress* = NULL);
47 /*
48  * return the clustering coefficient of a graph
49  * as the average of the local clustering coefficients
50  * (see clusteringCoefficient function) of all the nodes.
51  * see http://en.wikipedia.org/wiki/Clustering_coefficient for more details.
52  */
53 TLP_SCOPE double averageClusteringCoefficient(const Graph *, PluginProgress * = NULL);
54 /*
55  * assign to each node its local clustering coefficient
56  * that is the proportion of edges between the nodes within its neighbourhood
57  * divided by the number of edges that could possibly exist between them.
58  * This quantifies how close its neighbors are to being a clique.
59  * see http://en.wikipedia.org/wiki/Clustering_coefficient for more details
60  * WARNING: this function is deprecated
61  */
62 TLP_SCOPE _DEPRECATED void clusteringCoefficient(const Graph *g, MutableContainer<double> &result, unsigned int maxDepth = 1, PluginProgress* = NULL);
63 /*
64  * assign to each node its local clustering coefficient
65  * that is the proportion of edges between the nodes within its neighbourhood
66  * divided by the number of edges that could possibly exist between them.
67  * This quantifies how close its neighbors are to being a clique.
68  * see http://en.wikipedia.org/wiki/Clustering_coefficient for more details
69  */
70 TLP_SCOPE void clusteringCoefficient(const Graph *g, tlp::NodeStaticProperty<double> &result, unsigned int maxDepth = 1, PluginProgress* = NULL);
71 /*
72  * assign to each node of a Directed Acyclic Graph a level such that
73  * if the edge e(u,v) exists level(u) < level(v) the algorithm ensure that
74  * the number of level used is minimal.
75  * WARNING: this function is deprecated
76  */
77 TLP_SCOPE _DEPRECATED void dagLevel(const Graph *graph, MutableContainer<unsigned int> &level, PluginProgress* = NULL);
78 /*
79  * assign to each node of a graph its (in/ou/inout) degree.
80  * The weighted degree of a node is the sum of weights of
81  * all its in/out/inout edges."
82  * If no metric is specified, using a uniform metric value of 1 for all edges
83  * it assigns the usual degree of nodes (number of neighbors).",
84  * If norm is true, the measure is normalized in the following way:
85  * unweighted case => m(n) = deg(n) / (#V - 1)
86  * weighted case => m(n) = deg_w(n) / [(sum(e_w)/#E)(#V - 1)]
87  */
88 TLP_SCOPE void degree(const Graph *graph, tlp::NodeStaticProperty<double> &deg,
89  EDGE_TYPE direction = UNDIRECTED,
90  NumericProperty* weights = NULL, bool norm = false);
91 /*
92  * assign to each node of a Directed Acyclic Graph a level such that
93  * if the edge e(u,v) exists level(u) < level(v) the algorithm ensure that
94  * the number of level used is minimal.
95  *
96  * Warning: the graph must be acyclic (no self loops).
97  */
98 TLP_SCOPE void dagLevel(const Graph *graph, tlp::NodeStaticProperty<unsigned int> &level, PluginProgress* = NULL);
99 // return the maximum value of the degree of the graph's nodes
100 TLP_SCOPE unsigned int maxDegree(const Graph *);
101 // return the minimum value of the degree of the graph's nodes
102 TLP_SCOPE unsigned int minDegree(const Graph *);
103 /*
104  * compute the maximum distance from n to all the other nodes of graph
105  * and store it into distance, (stored value is UINT_MAX for non connected nodes),
106  * if direction is set to UNDIRECTED use undirected graph, DIRECTED use directed graph
107  * and INV_DIRECTED use reverse directed graph (ie. all edges are reversed)
108  * all the edge's weight is set to 1. (it uses a bfs thus the complexity is o(m), m = |E|).
109  */
110 TLP_SCOPE _DEPRECATED unsigned int maxDistance(const Graph *graph, const node n, MutableContainer<unsigned int> &distance, EDGE_TYPE direction = UNDIRECTED);
111 /*
112  * compute the maximum distance from n to all the other nodes of graph
113  * and store it into distance, (stored value is UINT_MAX for non connected nodes),
114  * if direction is set to UNDIRECTED use undirected graph, DIRECTED use directed graph
115  * and INV_DIRECTED use reverse directed graph (ie. all edges are reversed)
116  * all the edge's weight is set to 1. (it uses a bfs thus the complexity is o(m), m = |E|).
117  */
118 TLP_SCOPE unsigned int maxDistance(const Graph *graph, const unsigned int nPos, tlp::NodeStaticProperty<unsigned int> &distance, EDGE_TYPE direction = UNDIRECTED);
119 /*
120  * add to a result set, all the nodes, according to direction,
121  * at distance less or equal to maxDistance of startNode.
122  * If direction is set to UNDIRECTED use undirected graph, DIRECTED use directed graph
123  * and INV_DIRECTED use reverse directed graph (ie. all edges are reversed)
124  * WARNING: this function is deprecated use markReachableNodes instead
125  */
126 TLP_SCOPE _DEPRECATED void reachableNodes(const Graph *graph, const node startNode, std::set<node> &result, unsigned int maxDistance, EDGE_TYPE direction = UNDIRECTED);
127 /*
128  * mark as reachable (set value in "reachables" hash map to true),
129  * all the nodes, according to direction,
130  * at distance less or equal to maxDistance of startNode.
131  * If direction is set to UNDIRECTED use undirected graph,
132  * DIRECTED use directed graph
133  * and INV_DIRECTED use reverse directed graph (ie. all edges are reversed)
134  */
135 TLP_SCOPE void markReachableNodes(const Graph *graph, const node startNode, TLP_HASH_MAP<node, bool> &reachables, unsigned int maxDistance, EDGE_TYPE direction = UNDIRECTED);
136 }
137 #endif
138 ///@endcond