org.graphstream.algorithm

## Class Toolkit

• java.lang.Object
• org.graphstream.ui.graphicGraph.GraphPosLengthUtils
• org.graphstream.algorithm.Toolkit

• ```public class Toolkit
extends org.graphstream.ui.graphicGraph.GraphPosLengthUtils```
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.

## Usage

### Degrees

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.

*

### Density

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).

### Diameter

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.

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 if the second argument is non-null. The second argument is the weight attribute name. The third argument indicates if the graph must be considered as directed or not.

Note that this operation can be quite costly, the algorithm used depends on the fact the graph is weighted or not. If unweighted, the algorithm is in O(n*(n+m)). If weighted the algorithm is the Floyd-Warshall algorithm whose complexity is at worst of O(n^3).

### Clustering coefficient

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.

### Random nodes and edges

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)`.

### Nodes position

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 `GraphPosLengthUtils.nodePosition(Node)` which returns an array of three doubles, containing the position of the node. You can also use `GraphPosLengthUtils.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 `GraphPosLengthUtils.nodePosition(Node, double[])` that will store the position in the passed array. You can as well use `GraphPosLengthUtils.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 `GraphPosLengthUtils.nodePointPosition(Graph, String)` and `GraphPosLengthUtils.nodePointPosition(Node)`.

### Cliques

A clique C is a subset of the node set of a graph, such that there exists an edge between each pair of nodes in C. In other words, the subgraph induced by C is complete. A maximal clique is a clique that cannot be extended by adding more nodes, that is, there is no node outside the clique connected to all the clique nodes.

This class provides several methods for dealing with cliques. Use `isClique(Collection)` or `isMaximalClique(Collection, Graph)` to check if a set of nodes is a clique or a maximal clique.

The methods `getMaximalCliqueIterator(Graph)` and `getMaximalCliques(Graph)` enumerate all the maximal cliques in a graph. Iterating on all the maximal cliques of a graph can take much time, because their number can grow exponentially with the size of the graph. For example, the following naive method to find the maximum clique (that is, the largest possible clique) in a graph, is practical only for small and sparse graphs.

``` List<Node> maximumClique = new ArrayList<Node>();
for (List<Node> clique : Toolkit.getMaximalCliques(g))
if (clique.size() > maximumClique.size())
maximumClique = clique;
```

## Example

You can use this class with a static import for example:

``` import static org.graphstream.algorithm.Toolkit.*;
```
• ### Constructor Summary

Constructors
Constructor and Description
`Toolkit()`
• ### Method Summary

Methods
Modifier and Type Method and Description
`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 void` `computeLayout(org.graphstream.graph.Graph g)`
Compute coordinates of nodes using default layout algorithm and default stabilization limit.
`static void` ```computeLayout(org.graphstream.graph.Graph g, double stab)```
Compute coordinates of nodes using default layout algorithm (SpringBox).
`static void` ```computeLayout(org.graphstream.graph.Graph g, org.graphstream.ui.layout.Layout layout, double stab)```
Compute coordinates of nodes using a layout algorithm.
`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` ```enteringWeightedDegree(org.graphstream.graph.Node node, String weightAttribute)```
Compute the weighted entering degree of a given node.
`static double` ```enteringWeightedDegree(org.graphstream.graph.Node node, String weightAttribute, double defaultWeightValue)```
Compute the weighted entering degree of a given node.
`static void` ```fillAdjacencyMatrix(org.graphstream.graph.Graph graph, int[][] matrix)```
Fills an array with the adjacency matrix of a graph.
`static void` ```fillIncidenceMatrix(org.graphstream.graph.Graph graph, byte[][] matrix)```
Fills an array with the incidence matrix of a graph.
`static int[][]` `getAdjacencyMatrix(org.graphstream.graph.Graph graph)`
Returns the adjacency matrix of a graph.
`static <T extends org.graphstream.graph.Node> int` ```getDegeneracy(org.graphstream.graph.Graph graph, List<T> ordering)```
This method computes the gedeneracy and the degeneracy ordering of a graph.
`static byte[][]` `getIncidenceMatrix(org.graphstream.graph.Graph graph)`
Returns the incidence matrix of a graph.
`static <T extends org.graphstream.graph.Node> Iterator<List<T>>` `getMaximalCliqueIterator(org.graphstream.graph.Graph graph)`
This iterator traverses all the maximal cliques in a graph.
`static <T extends org.graphstream.graph.Node> Iterable<List<T>>` `getMaximalCliques(org.graphstream.graph.Graph graph)`
An iterable view of the set of all the maximal cliques in a graph.
`static boolean` `isClique(Collection<? extends org.graphstream.graph.Node> nodes)`
Checks if a set of nodes is a clique.
`static boolean` `isConnected(org.graphstream.graph.Graph graph)`
Determines if a graph is (weakly) connected.
`static boolean` ```isMaximalClique(Collection<? extends org.graphstream.graph.Node> nodes, org.graphstream.graph.Graph graph)```
Checks if a set of nodes is a maximal clique.
`static double` ```leavingWeightedDegree(org.graphstream.graph.Node node, String weightAttribute)```
Compute the weighted leaving degree of a given node.
`static double` ```leavingWeightedDegree(org.graphstream.graph.Node node, String weightAttribute, double defaultWeightValue)```
Compute the weighted leaving degree of a given node.
`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.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 <T extends org.graphstream.graph.Edge> List<T>` ```randomEdgeSet(org.graphstream.graph.Graph graph, double p)```
Returns a random subset of edges.
`static <T extends org.graphstream.graph.Edge> List<T>` ```randomEdgeSet(org.graphstream.graph.Graph graph, double p, Random random)```
Returns a random subset of edges.
`static <T extends org.graphstream.graph.Edge> List<T>` ```randomEdgeSet(org.graphstream.graph.Graph graph, int k)```
Returns a random subset of edges of fixed size.
`static <T extends org.graphstream.graph.Edge> List<T>` ```randomEdgeSet(org.graphstream.graph.Graph graph, int k, Random random)```
Returns a random subset of edges of fixed size.
`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 <T extends org.graphstream.graph.Node> List<T>` ```randomNodeSet(org.graphstream.graph.Graph graph, double p)```
Returns a random subset of nodes.
`static <T extends org.graphstream.graph.Node> List<T>` ```randomNodeSet(org.graphstream.graph.Graph graph, double p, Random random)```
Returns a random subset of nodes.
`static <T extends org.graphstream.graph.Node> List<T>` ```randomNodeSet(org.graphstream.graph.Graph graph, int k)```
Returns a random subset of nodes of fixed size.
`static <T extends org.graphstream.graph.Node> List<T>` ```randomNodeSet(org.graphstream.graph.Graph graph, int k, Random random)```
Returns a random subset of nodes of fixed size.
`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.
`static int` ```unweightedEccentricity(org.graphstream.graph.Node node, boolean directed)```
Eccentricity of a node not considering edge weights.
`static double` ```weightedDegree(org.graphstream.graph.Node node, String weightAttribute)```
Compute the weighted degree of a given node.
`static double` ```weightedDegree(org.graphstream.graph.Node node, String weightAttribute, double defaultWeightValue)```
Compute the weighted degree of a given node.
`static ArrayList<org.graphstream.graph.Node>` ```weightedDegreeMap(org.graphstream.graph.Graph graph, String weightAttribute)```
Return a list of nodes sorted by their weighted degree, the larger first.
`static ArrayList<org.graphstream.graph.Node>` ```weightedDegreeMap(org.graphstream.graph.Graph graph, String weightAttribute, double defaultWeightValue)```
Return a list of nodes sorted by their weighted degree, the larger first.
• ### Methods inherited from class org.graphstream.ui.graphicGraph.GraphPosLengthUtils

`edgeLength, edgeLength, nodePointPosition, nodePointPosition, nodePosition, nodePosition, nodePosition, nodePosition, nodePosition, nodePosition, positionFromObject, positionFromObject`
• ### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Constructor Detail

• #### Toolkit

`public Toolkit()`
• ### Method Detail

• #### weightedDegree

```public static double weightedDegree(org.graphstream.graph.Node node,
String weightAttribute)```
Compute the weighted degree of a given node. For each entering and leaving edge the value contained by the 'weightAttribute' is considered. If the edge does not have such an attribute, the value one is used instead, resolving to a normal degree. Loop edges are counted twice. The 'weightAttribute' must contain a number or the default value is used.
Parameters:
`node` - The node to consider.
`weightAttribute` - The name of the attribute to look for weights on edges, it must be a number.
Returns:
The weighted degree.
• #### weightedDegree

```public static double weightedDegree(org.graphstream.graph.Node node,
String weightAttribute,
double defaultWeightValue)```
Compute the weighted degree of a given node. For each entering and leaving edge the value contained by the 'weightAttribute' is considered. If the edge does not have such an attribute, the value `defaultWeightValue` is used instead. Loop edges are counted twice. The 'weightAttribute' must contain a number or the default value is used.
Parameters:
`node` - The node to consider.
`weightAttribute` - The name of the attribute to look for weights on edges, it must be a number.
`defaultWeightValue` - The default weight value to use if edges do not have the 'weightAttribute'.
Returns:
The weighted degree.
• #### enteringWeightedDegree

```public static double enteringWeightedDegree(org.graphstream.graph.Node node,
String weightAttribute)```
Compute the weighted entering degree of a given node. For each entering edge the value contained by the 'weightAttribute' is considered. If the edge does not have such an attribute, the value one is used instead, resolving to a normal degree. Loop edges are counted once if directed, but twice if undirected. The 'weightAttribute' must contain a number or the default value is used.
Parameters:
`node` - The node to consider.
`weightAttribute` - The name of the attribute to look on edges, it must be a number.
`defaultWeightValue` - The default weight value to use if edges do not have the 'weightAttribute'.
Returns:
The entering weighted degree.
• #### enteringWeightedDegree

```public static double enteringWeightedDegree(org.graphstream.graph.Node node,
String weightAttribute,
double defaultWeightValue)```
Compute the weighted entering degree of a given node. For each entering edge the value contained by the 'weightAttribute' is considered. If the edge does not have such an attribute, the value 'defaultWeightValue' is used instead. Loop edges are counted once if directed, but twice if undirected. The 'weightAttribute' must contain a number or the default value is used.
Parameters:
`node` - The node to consider.
`weightAttribute` - The name of the attribute to look on edges, it must be a number.
`defaultWeightValue` - The default weight value to use if edges do not have the 'weightAttribute'.
Returns:
The entering weighted degree.
• #### leavingWeightedDegree

```public static double leavingWeightedDegree(org.graphstream.graph.Node node,
String weightAttribute)```
Compute the weighted leaving degree of a given node. For each leaving edge the value contained by the 'weightAttribute' is considered. If the edge does not have such an attribute, the value one is used instead, resolving to a normal degree. Loop edges are counted once if directed, but twice if undirected. The 'weightAttribute' must contain a number or the default value is used.
Parameters:
`node` - The node to consider.
`weightAttribute` - The name of the attribute to look on edges, it must be a number.
`defaultWeightValue` - The default weight value to use if edges do not have the 'weightAttribute'.
Returns:
The leaving weighted degree.
• #### leavingWeightedDegree

```public static double leavingWeightedDegree(org.graphstream.graph.Node node,
String weightAttribute,
double defaultWeightValue)```
Compute the weighted leaving degree of a given node. For each leaving edge the value contained by the 'weightAttribute' is considered. If the edge does not have such an attribute, the value 'defaultWeightValue' is used instead. Loop edges are counted once if directed, but twice if undirected. The 'weightAttribute' must contain a number or the default value is used.
Parameters:
`node` - The node to consider.
`weightAttribute` - The name of the attribute to look on edges, it must be a number.
`defaultWeightValue` - The default weight value to use if edges do not have the 'weightAttribute'.
Returns:
The leaving weighted degree.
• #### degreeDistribution

`public static int[] degreeDistribution(org.graphstream.graph.Graph graph)`
Compute the degree distribution of this graph. Each cell of the returned array contains the number of nodes having degree n where n is the index of the cell. For example cell 0 counts how many nodes have zero edges, cell 5 counts how many nodes have five edges. The last index indicates the maximum degree.
Computational Complexity :
O(n) where n is the number of nodes.
• #### degreeMap

`public static ArrayList<org.graphstream.graph.Node> degreeMap(org.graphstream.graph.Graph graph)`
Return a list of nodes sorted by degree, the larger first.
Returns:
The degree map.
Computational Complexity :
O(n log(n)) where n is the number of nodes.
• #### weightedDegreeMap

```public static ArrayList<org.graphstream.graph.Node> weightedDegreeMap(org.graphstream.graph.Graph graph,
String weightAttribute,
double defaultWeightValue)```
Return a list of nodes sorted by their weighted degree, the larger first.
Parameters:
`graph` - The graph to consider.
`weightAttribute` - The name of the attribute to look for weights on edges, it must be a number, or the default value is used.
`defaultWeightValue` - The value to use if the weight attribute is not found on edges.
Returns:
The degree map.
`weightedDegree(Node, String, double)`
Computational Complexity :
O(n log(n)) where n is the number of nodes.
• #### weightedDegreeMap

```public static ArrayList<org.graphstream.graph.Node> weightedDegreeMap(org.graphstream.graph.Graph graph,
String weightAttribute)```
Return a list of nodes sorted by their weighted degree, the larger first.
Parameters:
`graph` - The graph to consider.
`weightAttribute` - The name of the attribute to look for weights on edges, it must be a number, or the default value of one is used.
Returns:
The degree map.
`weightedDegree(Node, String, double)`
Computational Complexity :
O(n log(n)) where n is the number of nodes.
• #### averageDegree

`public static double averageDegree(org.graphstream.graph.Graph graph)`
Returns the value of the average degree of the graph. A node with a loop edge has degree two.
Returns:
The average degree of the graph.
Computational Complexity :
O(1).
• #### degreeAverageDeviation

`public static double degreeAverageDeviation(org.graphstream.graph.Graph graph)`
Returns the value of the degree average deviation of the graph.
Returns:
The degree average deviation.
Computational Complexity :
O(n) where n is the number of nodes.
• #### density

`public 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.
Returns:
The density of the graph.
Computational Complexity :
O(1)
• #### clusteringCoefficients

`public static double[] clusteringCoefficients(org.graphstream.graph.Graph graph)`
Clustering coefficient for each node of the graph.
Returns:
An array whose size correspond to the number of nodes, where each element is the clustering coefficient of a node.
Computational Complexity :
at worse O(n d^2) where n is the number of nodes and d the average or maximum degree of nodes.
• #### averageClusteringCoefficient

`public static double averageClusteringCoefficient(org.graphstream.graph.Graph graph)`
Average clustering coefficient of the whole graph. Average of each node individual clustering coefficient.
Returns:
The average clustering coefficient.
Computational Complexity :
at worse O(n d^2) where n is the number of nodes and d the average or maximum degree of nodes.
• #### clusteringCoefficient

`public static double clusteringCoefficient(org.graphstream.graph.Node node)`
Clustering coefficient for one node of the graph. For a node i with degree k, if Ni is the neighborhood of i (a set of nodes), clustering coefficient of i is defined as the count of edge e_uv with u,v in Ni divided by the maximum possible count, ie. k * (k-1) / 2. This method only works with undirected graphs.
Parameters:
`node` - The node to compute the clustering coefficient for.
Returns:
The clustering coefficient for this node.
Computational Complexity :
O(d^2) where d is the degree of the given node.
Scientific Reference :
D. J. Watts and Steven Strogatz (June 1998). "Collective dynamics of 'small-world' networks" . Nature 393 (6684): 440â€“442
• #### randomNode

`public static org.graphstream.graph.Node randomNode(org.graphstream.graph.Graph graph)`
Choose a node at random.
Returns:
A node chosen at random, null if the graph is empty.
Computational Complexity :
O(1).
• #### randomNode

```public static org.graphstream.graph.Node randomNode(org.graphstream.graph.Graph graph,
Random random)```
Choose a node at random.
Parameters:
`random` - The random number generator to use.
Returns:
A node chosen at random, null if the graph is empty.
Computational Complexity :
O(1).
• #### randomEdge

`public static org.graphstream.graph.Edge randomEdge(org.graphstream.graph.Graph graph)`
Choose an edge at random.
Returns:
An edge chosen at random.
Computational Complexity :
O(1).
• #### randomEdge

```public static org.graphstream.graph.Edge randomEdge(org.graphstream.graph.Graph graph,
Random random)```
Choose an edge at random.
Parameters:
`random` - The random number generator to use.
Returns:
O(1).
• #### randomEdge

`public static org.graphstream.graph.Edge randomEdge(org.graphstream.graph.Node node)`
Choose an edge at random from the edges connected to the given node.
Returns:
O(1).
• #### randomInEdge

`public 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.
Returns:
O(1).
• #### randomOutEdge

`public 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.
Returns:
An edge chosen at random, null if the node has no leaving edges.
Computational Complexity :
O(1).
• #### randomEdge

```public 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.
Parameters:
`random` - The random number generator to use.
Returns:
An edge chosen at random, null if the node has no edges.
Computational Complexity :
O(1).
• #### randomInEdge

```public 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.
Parameters:
`random` - The random number generator to use.
Returns:
An edge chosen at random, null if the node has no entering edges.
Computational Complexity :
O(1).
• #### randomOutEdge

```public 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.
Parameters:
`random` - The random number generator to use.
Returns:
An edge chosen at random, null if the node has no leaving edges.
Computational Complexity :
O(1).
• #### communities

```public 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). For example, if the marker is "color" and in the graph there are nodes whose "color" attribute value is "red" and others with value "blue", this method will return two sets, one containing all nodes corresponding to the nodes whose "color" attribute is red, the other with blue nodes. If some nodes do not have the "color" attribute, a third set is returned. The returned sets are stored in a hash map whose keys are the values of the marker attribute (in our example, the keys would be "red" and "blue", and if there are nodes that do not have the "color" attribute, the third set will have key "NULL_COMMUNITY").
Parameters:
`marker` - The attribute that allows to group nodes.
Returns:
The communities indexed by the value of the marker.
Computational Complexity :
O(n) with n the number of nodes.
• #### modularityMatrix

```public static double[][] modularityMatrix(org.graphstream.graph.Graph graph,
HashMap<Object,HashSet<org.graphstream.graph.Node>> communities)```
Create the modularity matrix E from the communities. The given communities are set of nodes forming the communities as produced by the `communities(Graph,String)` method.
Parameters:
`graph` - Graph to which the computation will be applied
`communities` - Set of nodes.
Returns:
The E matrix as defined by Newman and Girvan.
Computational Complexity :
O(m!k) with m the number of communities and k the average number of nodes per community.
• #### modularityMatrix

```public 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. The given communities are set of nodes forming the communities as produced by the `communities(Graph,String)` method.
Parameters:
`graph` - Graph to which the computation will be applied
`communities` - Set of nodes.
`weightMarker` - The marker used to store the weight of each edge
Returns:
The E matrix as defined by Newman and Girvan.
Computational Complexity :
O(m!k) with m the number of communities and k the average number of nodes per community.
• #### modularity

`public static double modularity(double[][] E)`
Compute the modularity of the graph from the E matrix.
Parameters:
`E` - The E matrix given by `modularityMatrix(Graph,HashMap)` .
Returns:
The modularity of the graph.
Computational Complexity :
O(m!) with m the number of communities.
• #### modularity

```public 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". This algorithm traverses the graph to count nodes in communities. For this to work, there must exist an attribute on each node whose value define the community the node pertains to (see `communities(Graph,String)`). This method is an utility method that call: in order to produce the modularity value.
Parameters:
`marker` - The community attribute stored on nodes.
Returns:
The graph modularity.
`Modularity`
Computational Complexity :
0(n + m! + m!k) with n the number of nodes, m the number of communities and k the average number of nodes per communities.
• #### modularity

```public static double modularity(org.graphstream.graph.Graph graph,
String marker,
String weightMarker)```
Computes the weighted modularity. This algorithm traverses the graph to count nodes in communities. For this to work, there must exist an attribute on each node whose value define the community the node pertains to (see `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.
Parameters:
`marker` - The community attribute stored on nodes.
`weightMarker` - The marker used to store the weight of each edge.
Returns:
The graph modularity.
`Modularity`
Computational Complexity :
0(n + m! + m!k) with n the number of nodes, m the number of communities and k the average number of nodes per communities.
• #### diameter

`public static double diameter(org.graphstream.graph.Graph graph)`
Compute 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. The graph is considered non weighted.

Note that this operation can be quite costly, O(n*(n+m)).

The returned diameter is not an integer since some graphs have non-integer weights on edges. Although this version of the diameter algorithm will return an integer.

Parameters:
`graph` - The graph to use.
Returns:
The diameter.
• #### diameter

```public static double diameter(org.graphstream.graph.Graph graph,
String weightAttributeName,
boolean directed)```
Compute 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. Two algorithms are used here. If the graph is not weighted (the weightAttributeName parameter is null), the algorithm use breath first search from all the nodes to find the max depth (or eccentricity) of each node. The diameter is then the maximum of these maximum depths. The complexity of this algorithm is O(n*(n+m)), with n the number of nodes and m the number of edges.

If the graph is weighted, 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 weighted graphs have non-integer weights on edges.

Parameters:
`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 ?.
Returns:
The diameter.
• #### unweightedEccentricity

```public static int unweightedEccentricity(org.graphstream.graph.Node node,
boolean directed)```
Eccentricity of a node not considering edge weights.

The eccentricity is the largest shortest path between the given node and any other. It is here computed on number of edges crossed, not considering the eventual weights of edges.

This is computed using a breath first search and looking at the maximum depth of the search.

Parameters:
`node` - The node for which the eccentricity is to be computed.
`directed` - If true, the computation will respect edges direction, if any.
Returns:
The eccentricity.
Computational Complexity :
O(n+m) with n the number of nodes and m the number of edges.
• #### isClique

`public static boolean isClique(Collection<? extends org.graphstream.graph.Node> nodes)`
Checks if a set of nodes is a clique.
Parameters:
`nodes` - a set of nodes
Returns:
`true` if `nodes` form a clique
Computational Complexity :
O(k), where k is the size of `nodes`
• #### isMaximalClique

```public static boolean isMaximalClique(Collection<? extends org.graphstream.graph.Node> nodes,
org.graphstream.graph.Graph graph)```
Checks if a set of nodes is a maximal clique.
Parameters:
`nodes` - a set of nodes
Returns:
`true` if form a maximal clique
Computational Complexity :
O(kn), where n is the number of nodes in the graph and k is the size of `nodes`
• #### getMaximalCliqueIterator

`public static <T extends org.graphstream.graph.Node> Iterator<List<T>> getMaximalCliqueIterator(org.graphstream.graph.Graph graph)`
This iterator traverses all the maximal cliques in a graph. Each call to `Iterator.next()` returns a maximal clique in the form of list of nodes. This iterator does not support remove.
Parameters:
`graph` - a graph, must not have loop edges
Returns:
an iterator on the maximal cliques of `graph`
Throws:
`IllegalArgumentException` - if `graph` has loop edges
Computational Complexity :
This iterator implements the Bronâ€“Kerbosch algorithm. There is no guarantee that each call to `Iterator.next()` will run in polynomial time. However, iterating over all the maximal cliques is efficient in worst case sense. The whole iteration takes O(3n/3) time in the worst case and it is known that a n-node graph has at most 3n/3 maximal cliques.
• #### getMaximalCliques

`public static <T extends org.graphstream.graph.Node> Iterable<List<T>> getMaximalCliques(org.graphstream.graph.Graph graph)`
An iterable view of the set of all the maximal cliques in a graph. Uses `getMaximalCliqueIterator(Graph)`.
Parameters:
`graph` - a graph
Returns:
An iterable view of the maximal cliques in `graph`.
• #### getDegeneracy

```public static <T extends org.graphstream.graph.Node> int getDegeneracy(org.graphstream.graph.Graph graph,
List<T> ordering)```

This method computes the gedeneracy and the degeneracy ordering of a graph.

The degeneracy of a graph is the smallest number d such that every subgraph has a node with degree d or less. The degeneracy is a measure of sparseness of graphs. A degeneracy ordering is an ordering of the nodes such that each node has at most d neighbors following it in the ordering. The degeneracy ordering is used, among others, in greedy coloring algorithms.

Parameters:
`graph` - a graph
`ordering` - a list of nodes. If not `null`, this list is first cleared and then filled with the nodes of the graph in degeneracy order.
Returns:
the degeneracy of `graph`
Computational Complexity :
O(m) where m is the number of edges in the graph

```public static void fillAdjacencyMatrix(org.graphstream.graph.Graph graph,
int[][] matrix)```
Fills an array with the adjacency matrix of a graph. The adjacency matrix of a graph is a n times n matrix `a`, where n is the number of nodes of the graph. The element `a[i][j]` of this matrix is equal to the number of edges from the node `graph.getNode(i)` to the node `graph.getNode(j)`. An undirected edge between i-th and j-th node is counted twice: in `a[i][j]` and in `a[j][i]`.
Parameters:
`graph` - A graph.
`matrix` - The array where the adjacency matrix is stored. Must be of size at least n times n
Throws:
`IndexOutOfBoundsException` - if the size of the matrix is insufficient.
`getAdjacencyMatrix(Graph)`
Computational Complexity :
O(n2), where n is the number of nodes.

`public static int[][] getAdjacencyMatrix(org.graphstream.graph.Graph graph)`
Returns the adjacency matrix of a graph. The adjacency matrix of a graph is a n times n matrix `a`, where n is the number of nodes of the graph. The element `a[i][j]` of this matrix is equal to the number of edges from the node `graph.getNode(i)` to the node `graph.getNode(j)`. An undirected edge between i-th and j-th node is counted twice: in `a[i][j]` and in `a[j][i]`.
Parameters:
`graph` - A graph
Returns:
The adjacency matrix of the graph.
`fillAdjacencyMatrix(Graph, int[][])`
Computational Complexity :
O(n2), where n is the number of nodes.
• #### fillIncidenceMatrix

```public static void fillIncidenceMatrix(org.graphstream.graph.Graph graph,
byte[][] matrix)```
Fills an array with the incidence matrix of a graph. The incidence matrix of a graph is a n times m matrix `a`, where n is the number of nodes and m is the number of edges of the graph. The coefficients `a[i][j]` of this matrix have the following values:
• -1 if `graph.getEdge(j)` is directed and `graph.getNode(i)` is its source.
• 1 if `graph.getEdge(j)` is undirected and `graph.getNode(i)` is its source.
• 1 if `graph.getNode(i)` is the target of `graph.getEdge(j)`.
• 0 otherwise.
In the special case when the j-th edge is a loop connecting the i-th node to itself, the coefficient `a[i][j]` is 0 if the loop is directed and 2 if the loop is undirected. All the other coefficients in the j-th column are 0.
Parameters:
`graph` - A graph
`matrix` - The array where the incidence matrix is stored. Must be at least of size n times m
Throws:
`IndexOutOfBoundsException` - if the size of the matrix is insufficient
`getIncidenceMatrix(Graph)`
Computational Complexity :
O(mn), where n is the number of nodes and m is the number of edges.
• #### getIncidenceMatrix

`public static byte[][] getIncidenceMatrix(org.graphstream.graph.Graph graph)`
Returns the incidence matrix of a graph. The incidence matrix of a graph is a n times m matrix `a`, where n is the number of nodes and m is the number of edges of the graph. The coefficients `a[i][j]` of this matrix have the following values:
• -1 if `graph.getEdge(j)` is directed and `graph.getNode(i)` is its source.
• 1 if `graph.getEdge(j)` is undirected and `graph.getNode(i)` is its source.
• 1 if `graph.getNode(i)` is the target of `graph.getEdge(j)`.
• 0 otherwise.
In the special case when the j-th edge is a loop connecting the i-th node to itself, the coefficient `a[i][j]` is 0 if the loop is directed and 2 if the loop is undirected. All the other coefficients in the j-th column are 0.
Parameters:
`graph` - A graph
Returns:
The incidence matrix of the graph.
`fillIncidenceMatrix(Graph, byte[][])`
Computational Complexity :
O(mn), where n is the number of nodes and m is the number of edges.
• #### computeLayout

```public static void computeLayout(org.graphstream.graph.Graph g,
org.graphstream.ui.layout.Layout layout,
double stab)```
Compute coordinates of nodes using a layout algorithm.
Parameters:
`g` - the graph
`layout` - layout algorithm to use for computing coordinates
`stab` - stabilization limit
• #### computeLayout

```public static void computeLayout(org.graphstream.graph.Graph g,
double stab)```
Compute coordinates of nodes using default layout algorithm (SpringBox).
Parameters:
`g` - the graph
`stab` - stabilization limit
• #### computeLayout

`public static void computeLayout(org.graphstream.graph.Graph g)`
Compute coordinates of nodes using default layout algorithm and default stabilization limit.
Parameters:
`g` - the graph
• #### randomNodeSet

```public static <T extends org.graphstream.graph.Node> List<T> randomNodeSet(org.graphstream.graph.Graph graph,
int k)```
Returns a random subset of nodes of fixed size. Each node has the same chance to be chosen.
Parameters:
`graph` - A graph.
`k` - The size of the subset.
Returns:
A random subset of nodes of size `k`.
Throws:
`IllegalArgumentException` - If `k` is negative or greater than the number of nodes.
Computational Complexity :
O(`k`)
• #### randomNodeSet

```public static <T extends org.graphstream.graph.Node> List<T> randomNodeSet(org.graphstream.graph.Graph graph,
int k,
Random random)```
Returns a random subset of nodes of fixed size. Each node has the same chance to be chosen.
Parameters:
`graph` - A graph.
`k` - The size of the subset.
`random` - A source of randomness.
Returns:
A random subset of nodes of size `k`.
Throws:
`IllegalArgumentException` - If `k` is negative or greater than the number of nodes.
Computational Complexity :
O(`k`)
• #### randomNodeSet

```public static <T extends org.graphstream.graph.Node> List<T> randomNodeSet(org.graphstream.graph.Graph graph,
double p)```
Returns a random subset of nodes. Each node is chosen with given probability.
Parameters:
`graph` - A graph.
`p` - The probability to choose each node.
Returns:
A random subset of nodes.
Throws:
`IllegalArgumentException` - If `p` is negative or greater than one.
Computational Complexity :
In average O(```n * p), where n is the number of nodes.```
``` ```
• ``` ```
``` randomNodeSet public static <T extends org.graphstream.graph.Node> List<T> randomNodeSet(org.graphstream.graph.Graph graph, double p, Random random) Returns a random subset of nodes. Each node is chosen with given probability. Parameters:graph - A graph.p - The probability to choose each node.random - A source of randomness. Returns:A random subset of nodes. Throws: IllegalArgumentException - If p is negative or greater than one.Computational Complexity : In average O(n * p), where n is the number of nodes. randomEdgeSet public static <T extends org.graphstream.graph.Edge> List<T> randomEdgeSet(org.graphstream.graph.Graph graph, int k) Returns a random subset of edges of fixed size. Each edge has the same chance to be chosen. Parameters:graph - A graph.k - The size of the subset. Returns:A random subset of edges of size k. Throws: IllegalArgumentException - If k is negative or greater than the number of edges.Computational Complexity : O(k) randomEdgeSet public static <T extends org.graphstream.graph.Edge> List<T> randomEdgeSet(org.graphstream.graph.Graph graph, int k, Random random) Returns a random subset of edges of fixed size. Each edge has the same chance to be chosen. Parameters:graph - A graph.k - The size of the subset.random - A source of randomness. Returns:A random subset of edges of size k. Throws: IllegalArgumentException - If k is negative or greater than the number of edges.Computational Complexity : O(k) randomEdgeSet public static <T extends org.graphstream.graph.Edge> List<T> randomEdgeSet(org.graphstream.graph.Graph graph, double p) Returns a random subset of edges. Each edge is chosen with given probability. Parameters:graph - A graph.p - The probability to choose each edge. Returns:A random subset of edges. Throws: IllegalArgumentException - If p is negative or greater than one.Computational Complexity : In average O(m * p), where m is the number of edges. randomEdgeSet public static <T extends org.graphstream.graph.Edge> List<T> randomEdgeSet(org.graphstream.graph.Graph graph, double p, Random random) Returns a random subset of edges. Each edge is chosen with given probability. Parameters:graph - A graph.p - The probability to choose each edge.random - A source of randomness. Returns:A random subset of edges. Throws: IllegalArgumentException - If p is negative or greater than one.Computational Complexity : In average O(m * p), where m is the number of edges. isConnected public static boolean isConnected(org.graphstream.graph.Graph graph) Determines if a graph is (weakly) connected. Parameters:graph - A graph. Returns:true if the graph is connected.Computational Complexity : O(m + n) where m is the number of edges and n is the number of nodes. ```
• ``` ```
``` ```
• ``` ```
``` ```
``` ```
``` Overview Package Class Use Tree Deprecated Index Help Prev Class Next Class Frames No Frames All Classes <!-- allClassesLink = document.getElementById("allclasses_navbar_bottom"); if(window==top) { allClassesLink.style.display = "block"; } else { allClassesLink.style.display = "none"; } //--> Summary:  Nested |  Field |  Constr |  Method Detail:  Field |  Constr |  Method Copyright © 2015. All rights reserved. ```