|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.graphstream.algorithm.Toolkit
public class Toolkit
Lots of small often used algorithms on graphs.
This class contains a lot of very small algorithms that could be often useful with a graph. Most methods take a graph as first argument.
The degreeDistribution(Graph)
method allows to obtain an array where
each cell index represents the degree, and the value of the cell the number
of nodes having this degree. Its complexity is O(n) with n the number of nodes.
The degreeMap(Graph)
returns an array of nodes sorted by degree
in descending order. The complexity is O(n log(n)) with n the number of nodes.
The averageDegree(Graph)
returns the average degree. The complexity
is O(1).
The degreeAverageDeviation(Graph)
returns the deviation of the average
degree. The complexity is O(n) with n the number of nodes.
The density(Graph)
method returns the number of links in the graph
divided by the total number of possible links. The complexity is O(1).
The diameter(Graph)
method computes the diameter of the graph.
The diameter of the graph is the largest of all the shortest paths from any node to
any other node.
Note that this operation can be quite costly, the algorithm used to compute all shortest paths is the Floyd-Warshall algorithm whose complexity is at worst of O(n^3).
The returned diameter is not an integer since some graphs have non-integer weights on edges.
The diameter(Graph, String, boolean)
method does the same thing, but
considers that the graph is weighted. The second argument is the weight attribute
name. The third argument indicates if the graph must be considered as directed
or not.
The clusteringCoefficient(Node)
method return the clustering
coefficient for the given node. The complexity if O(d^2) where d is the
degree of the node.
The clusteringCoefficients(Graph)
method return the clustering
coefficient of each node of the graph as an array.
The averageClusteringCoefficient(Graph)
method return the average
clustering coefficient for the graph.
The randomNode(Graph)
returns a node chosen at random in the graph. You can
alternatively pass a ``Random`` instance as parameter with randomNode(Graph, Random)
.
The complexity depends on the kind of graph.
The randomEdge(Graph)
returns an edge chosen at random in the graph. You can
alternatively pass a ``Random`` instance as parameter with randomEdge(Graph, Random)
.
The randomEdge(Node)
returns an edge chosen at random within the edge set of
the given node. You can also use randomEdge(Node, Random)
. To chose a random
edge of a node inside the entering or leaving edge sets only, you can use randomInEdge(Node)
or randomInEdge(Node, Random)
, or randomOutEdge(Node)
or finally
randomOutEdge(Node, Random)
.
Extracting nodes position from attributes can be tricky due to the face the positions can be stored either as separate ``x``, ``y`` and ``z`` attributes or inside ``xy`` or ``xyz`` attributes.
To simplify things you can use nodePosition(Node)
which returns an array of three
doubles, containing the position of the node. You can also use nodePosition(Graph, String)
with a graph and a node identifier.
If you already have an array of doubles with at least three cells you can also use
nodePosition(Node, double[])
that will store the position in the passed array.
You can as well use nodePosition(Graph, String, double[])
.
All these methods can also handle the ``org.graphstream.ui.geom.Point3`` class instead
of arrays of doubles. Methods that use such an array as argument are the same. Methods
that return a ``Point3`` instead of an array are nodePointPosition(Graph, String)
and nodePointPosition(Node)
.
You can use this class with a static import for example:
import static org.graphstream.algorithm.Toolkit.*;
Constructor Summary | |
---|---|
Toolkit()
|
Method Summary | |
---|---|
static double |
averageClusteringCoefficient(org.graphstream.graph.Graph graph)
Average clustering coefficient of the whole graph. |
static double |
averageDegree(org.graphstream.graph.Graph graph)
Returns the value of the average degree of the graph. |
static double |
clusteringCoefficient(org.graphstream.graph.Node node)
Clustering coefficient for one node of the graph. |
static double[] |
clusteringCoefficients(org.graphstream.graph.Graph graph)
Clustering coefficient for each node of the graph. |
static HashMap<Object,HashSet<org.graphstream.graph.Node>> |
communities(org.graphstream.graph.Graph graph,
String marker)
Return set of nodes grouped by the value of one attribute (the marker). |
static double |
degreeAverageDeviation(org.graphstream.graph.Graph graph)
Returns the value of the degree average deviation of the graph. |
static int[] |
degreeDistribution(org.graphstream.graph.Graph graph)
Compute the degree distribution of this graph. |
static ArrayList<org.graphstream.graph.Node> |
degreeMap(org.graphstream.graph.Graph graph)
Return a list of nodes sorted by degree, the larger first. |
static double |
density(org.graphstream.graph.Graph graph)
The density is the number of links in the graph divided by the total number of possible links. |
static double |
diameter(org.graphstream.graph.Graph graph)
Compute the diameter of the graph. |
static double |
diameter(org.graphstream.graph.Graph graph,
String weightAttributeName,
boolean directed)
Compute the diameter of the graph. |
static double |
edgeLength(org.graphstream.graph.Edge edge)
Like edgeLength(Graph,String) but use an existing edge as
argument. |
static double |
edgeLength(org.graphstream.graph.Graph graph,
String id)
Compute the edge length of the given edge according to its two nodes positions. |
static double |
modularity(double[][] E)
Compute the modularity of the graph from the E matrix. |
static double |
modularity(org.graphstream.graph.Graph graph,
String marker)
Computes the modularity as defined by Newman and Girvan in "Finding and evaluating community structure in networks". |
static double |
modularity(org.graphstream.graph.Graph graph,
String marker,
String weightMarker)
Computes the weighted modularity. |
static double[][] |
modularityMatrix(org.graphstream.graph.Graph graph,
HashMap<Object,HashSet<org.graphstream.graph.Node>> communities)
Create the modularity matrix E from the communities. |
static double[][] |
modularityMatrix(org.graphstream.graph.Graph graph,
HashMap<Object,HashSet<org.graphstream.graph.Node>> communities,
String weightMarker)
Create the weighted modularity matrix E from the communities. |
static org.graphstream.ui.geom.Point3 |
nodePointPosition(org.graphstream.graph.Graph graph,
String id)
Retrieve a node position from its attributes ("x", "y", "z", or "xy", or "xyz"). |
static org.graphstream.ui.geom.Point3 |
nodePointPosition(org.graphstream.graph.Node node)
Like nodePointPosition(Graph,String) but use an existing node as
argument. |
static double[] |
nodePosition(org.graphstream.graph.Graph graph,
String id)
Retrieve a node position from its attributes ("x", "y", "z", or "xy", or "xyz"). |
static void |
nodePosition(org.graphstream.graph.Graph graph,
String id,
double[] xyz)
Like nodePosition(Graph,String) , but instead of returning a
newly allocated array, fill up the array given as parameter. |
static void |
nodePosition(org.graphstream.graph.Graph graph,
String id,
org.graphstream.ui.geom.Point3 pos)
Like nodePointPosition(Graph,String) , but instead of returning a
newly allocated array, fill up the array given as parameter. |
static double[] |
nodePosition(org.graphstream.graph.Node node)
Like nodePosition(Graph,String) but use an existing node as
argument. |
static void |
nodePosition(org.graphstream.graph.Node node,
double[] xyz)
Like nodePosition(Graph,String,double[]) but use an existing node
as argument. |
static void |
nodePosition(org.graphstream.graph.Node node,
org.graphstream.ui.geom.Point3 pos)
Like nodePosition(Graph,String,Point3) but use an existing node
as argument. |
static org.graphstream.graph.Edge |
randomEdge(org.graphstream.graph.Graph graph)
Choose an edge at random. |
static org.graphstream.graph.Edge |
randomEdge(org.graphstream.graph.Graph graph,
Random random)
Choose an edge at random. |
static org.graphstream.graph.Edge |
randomEdge(org.graphstream.graph.Node node)
Choose an edge at random from the edges connected to the given node. |
static org.graphstream.graph.Edge |
randomEdge(org.graphstream.graph.Node node,
Random random)
Choose an edge at random from the edges connected to the given node. |
static org.graphstream.graph.Edge |
randomInEdge(org.graphstream.graph.Node node)
Choose an edge at random from the entering edges connected to the given node. |
static org.graphstream.graph.Edge |
randomInEdge(org.graphstream.graph.Node node,
Random random)
Choose an edge at random from the entering edges connected to the given node. |
static org.graphstream.graph.Node |
randomNode(org.graphstream.graph.Graph graph)
Choose a node at random. |
static org.graphstream.graph.Node |
randomNode(org.graphstream.graph.Graph graph,
Random random)
Choose a node at random. |
static org.graphstream.graph.Edge |
randomOutEdge(org.graphstream.graph.Node node)
Choose an edge at random from the leaving edges connected to the given node. |
static org.graphstream.graph.Edge |
randomOutEdge(org.graphstream.graph.Node node,
Random random)
Choose an edge at random from the leaving edges connected to the given node. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Toolkit()
Method Detail |
---|
public static int[] degreeDistribution(org.graphstream.graph.Graph graph)
public static ArrayList<org.graphstream.graph.Node> degreeMap(org.graphstream.graph.Graph graph)
public static double averageDegree(org.graphstream.graph.Graph graph)
public static double degreeAverageDeviation(org.graphstream.graph.Graph graph)
public static double density(org.graphstream.graph.Graph graph)
public static double[] clusteringCoefficients(org.graphstream.graph.Graph graph)
public static double averageClusteringCoefficient(org.graphstream.graph.Graph graph)
public static double clusteringCoefficient(org.graphstream.graph.Node node)
node
- The node to compute the clustering coefficient for.
public static org.graphstream.graph.Node randomNode(org.graphstream.graph.Graph graph)
public static org.graphstream.graph.Node randomNode(org.graphstream.graph.Graph graph, Random random)
random
- The random number generator to use.
public static org.graphstream.graph.Edge randomEdge(org.graphstream.graph.Graph graph)
public static org.graphstream.graph.Edge randomEdge(org.graphstream.graph.Graph graph, Random random)
random
- The random number generator to use.
public static org.graphstream.graph.Edge randomEdge(org.graphstream.graph.Node node)
public static org.graphstream.graph.Edge randomInEdge(org.graphstream.graph.Node node)
public static org.graphstream.graph.Edge randomOutEdge(org.graphstream.graph.Node node)
public static org.graphstream.graph.Edge randomEdge(org.graphstream.graph.Node node, Random random)
random
- The random number generator to use.
public static org.graphstream.graph.Edge randomInEdge(org.graphstream.graph.Node node, Random random)
random
- The random number generator to use.
public static org.graphstream.graph.Edge randomOutEdge(org.graphstream.graph.Node node, Random random)
random
- The random number generator to use.
public static HashMap<Object,HashSet<org.graphstream.graph.Node>> communities(org.graphstream.graph.Graph graph, String marker)
marker
- The attribute that allows to group nodes.
public static double[][] modularityMatrix(org.graphstream.graph.Graph graph, HashMap<Object,HashSet<org.graphstream.graph.Node>> communities)
communities(Graph,String)
method.
graph
- Graph to which the computation will be appliedcommunities
- Set of nodes.
public static double[][] modularityMatrix(org.graphstream.graph.Graph graph, HashMap<Object,HashSet<org.graphstream.graph.Node>> communities, String weightMarker)
communities(Graph,String)
method.
graph
- Graph to which the computation will be appliedcommunities
- Set of nodes.weightMarker
- The marker used to store the weight of each edge
public static double modularity(double[][] E)
E
- The E matrix given by modularityMatrix(Graph,HashMap)
.
public static double modularity(org.graphstream.graph.Graph graph, String marker)
communities(Graph,String)
).
This method is an utility method that call:
in order to produce the modularity value.
marker
- The community attribute stored on nodes.
Modularity
public static double modularity(org.graphstream.graph.Graph graph, String marker, String weightMarker)
communities(Graph,String)
) and a attribute on each edge
storing their weight (all edges without this attribute will be ignored in
the computation).
This method is an utility method that call:
in order to produce the modularity value.
marker
- The community attribute stored on nodes.weightMarker
- The marker used to store the weight of each edge.
Modularity
public static double[] nodePosition(org.graphstream.graph.Graph graph, String id)
id
- The node identifier.
public static org.graphstream.ui.geom.Point3 nodePointPosition(org.graphstream.graph.Graph graph, String id)
id
- The node identifier.
public static double[] nodePosition(org.graphstream.graph.Node node)
nodePosition(Graph,String)
but use an existing node as
argument.
node
- The node to consider.
public static org.graphstream.ui.geom.Point3 nodePointPosition(org.graphstream.graph.Node node)
nodePointPosition(Graph,String)
but use an existing node as
argument.
node
- The node to consider.
public static void nodePosition(org.graphstream.graph.Graph graph, String id, double[] xyz)
nodePosition(Graph,String)
, but instead of returning a
newly allocated array, fill up the array given as parameter. This array
must have at least three cells.
id
- The node identifier.xyz
- An array of at least three cells.
RuntimeException
- If the node with the given identifier does not exist.public static void nodePosition(org.graphstream.graph.Graph graph, String id, org.graphstream.ui.geom.Point3 pos)
nodePointPosition(Graph,String)
, but instead of returning a
newly allocated array, fill up the array given as parameter. This array
must have at least three cells.
id
- The node identifier.pos
- A point that will receive the node position.
RuntimeException
- If the node with the given identifier does not exist.public static void nodePosition(org.graphstream.graph.Node node, double[] xyz)
nodePosition(Graph,String,double[])
but use an existing node
as argument.
node
- The node to consider.xyz
- An array of at least three cells.public static void nodePosition(org.graphstream.graph.Node node, org.graphstream.ui.geom.Point3 pos)
nodePosition(Graph,String,Point3)
but use an existing node
as argument.
node
- The node to consider.pos
- A point that will receive the node position.public static double edgeLength(org.graphstream.graph.Graph graph, String id)
id
- The identifier of the edge.
RuntimeException
- If the edge cannot be found.public static double edgeLength(org.graphstream.graph.Edge edge)
edgeLength(Graph,String)
but use an existing edge as
argument.
edge
-
public static double diameter(org.graphstream.graph.Graph graph)
The diameter of the graph is the largest of all the shortest paths from any node to any other node.
Note that this operation can be quite costly, the algorithm used to compute all shortest paths is the Floyd-Warshall algorithm whose complexity is at worst of O(n^3).
The returned diameter is not an integer since some graphs have non-integer weights on edges.
graph
- The graph to use.
public static double diameter(org.graphstream.graph.Graph graph, String weightAttributeName, boolean directed)
The diameter of the graph is the largest of all the shortest paths from any node to any other node.
Note that this operation can be quite costly, the algorithm used to compute all shortest paths is the Floyd-Warshall algorithm whose complexity is at worst of O(n^3).
The returned diameter is not an integer since some graphs have non-integer weights on edges.
graph
- The graph to use.weightAttributeName
- The name used to store weights on the edges (must be a Number).directed
- Does
The edge direction should be considered ?.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |