public class Toolkit
extends org.graphstream.ui.graphicGraph.GraphPosLengthUtils
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.
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).
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 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)
.
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;
You can use this class with a static import for example:
import static org.graphstream.algorithm.Toolkit.*;
Constructor and Description |
---|
Toolkit() |
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> |
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> |
getMaximalCliqueIterator(org.graphstream.graph.Graph graph)
This iterator traverses all the maximal cliques in a graph.
|
static <T extends org.graphstream.graph.Node> |
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> |
randomEdgeSet(org.graphstream.graph.Graph graph,
double p)
Returns a random subset of edges.
|
static <T extends org.graphstream.graph.Edge> |
randomEdgeSet(org.graphstream.graph.Graph graph,
double p,
Random random)
Returns a random subset of edges.
|
static <T extends org.graphstream.graph.Edge> |
randomEdgeSet(org.graphstream.graph.Graph graph,
int k)
Returns a random subset of edges of fixed size.
|
static <T extends org.graphstream.graph.Edge> |
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> |
randomNodeSet(org.graphstream.graph.Graph graph,
double p)
Returns a random subset of nodes.
|
static <T extends org.graphstream.graph.Node> |
randomNodeSet(org.graphstream.graph.Graph graph,
double p,
Random random)
Returns a random subset of nodes.
|
static <T extends org.graphstream.graph.Node> |
randomNodeSet(org.graphstream.graph.Graph graph,
int k)
Returns a random subset of nodes of fixed size.
|
static <T extends org.graphstream.graph.Node> |
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.
|
public static double weightedDegree(org.graphstream.graph.Node node, String weightAttribute)
node
- The node to consider.weightAttribute
- The name of the attribute to look for weights on edges, it must be a number.public static double weightedDegree(org.graphstream.graph.Node node, String weightAttribute, double defaultWeightValue)
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'.public static double enteringWeightedDegree(org.graphstream.graph.Node node, String weightAttribute)
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'.public static double enteringWeightedDegree(org.graphstream.graph.Node node, String weightAttribute, double defaultWeightValue)
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'.public static double leavingWeightedDegree(org.graphstream.graph.Node node, String weightAttribute)
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'.public static double leavingWeightedDegree(org.graphstream.graph.Node node, String weightAttribute, double defaultWeightValue)
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'.public static int[] degreeDistribution(org.graphstream.graph.Graph graph)
public static ArrayList<org.graphstream.graph.Node> degreeMap(org.graphstream.graph.Graph graph)
public static ArrayList<org.graphstream.graph.Node> weightedDegreeMap(org.graphstream.graph.Graph graph, String weightAttribute, double defaultWeightValue)
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.weightedDegree(Node, String, double)
public static ArrayList<org.graphstream.graph.Node> weightedDegreeMap(org.graphstream.graph.Graph graph, String weightAttribute)
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.weightedDegree(Node, String, double)
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 edgepublic 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 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. 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.
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. 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.
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 ?.public static int unweightedEccentricity(org.graphstream.graph.Node node, boolean directed)
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.
node
- The node for which the eccentricity is to be computed.directed
- If true, the computation will respect edges direction, if any.public static boolean isClique(Collection<? extends org.graphstream.graph.Node> nodes)
nodes
- a set of nodestrue
if nodes
form a cliquenodes
public static boolean isMaximalClique(Collection<? extends org.graphstream.graph.Node> nodes, org.graphstream.graph.Graph graph)
nodes
- a set of nodestrue
if form a maximal cliquenodes
public static <T extends org.graphstream.graph.Node> Iterator<List<T>> getMaximalCliqueIterator(org.graphstream.graph.Graph graph)
Iterator.next()
returns a maximal clique in the form of
list of nodes. This iterator does not support remove.graph
- a graph, must not have loop edgesgraph
IllegalArgumentException
- if graph
has loop edgesIterator.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.public static <T extends org.graphstream.graph.Node> Iterable<List<T>> getMaximalCliques(org.graphstream.graph.Graph graph)
getMaximalCliqueIterator(Graph)
.graph
- a graphgraph
.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.
graph
- a graphordering
- a list of nodes. If not null
, this list is first
cleared and then filled with the nodes of the graph in
degeneracy order.graph
public static void fillAdjacencyMatrix(org.graphstream.graph.Graph graph, int[][] 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]
.graph
- A graph.matrix
- The array where the adjacency matrix is stored. Must be of
size at least n times nIndexOutOfBoundsException
- if the size of the matrix is insufficient.getAdjacencyMatrix(Graph)
public static int[][] getAdjacencyMatrix(org.graphstream.graph.Graph graph)
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]
.graph
- A graphfillAdjacencyMatrix(Graph, int[][])
public static void fillIncidenceMatrix(org.graphstream.graph.Graph graph, byte[][] 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:
graph.getEdge(j)
is directed and
graph.getNode(i)
is its source.graph.getEdge(j)
is undirected and
graph.getNode(i)
is its source.graph.getNode(i)
is the target of
graph.getEdge(j)
.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.graph
- A graphmatrix
- The array where the incidence matrix is stored. Must be at
least of size n times mIndexOutOfBoundsException
- if the size of the matrix is insufficientgetIncidenceMatrix(Graph)
public static byte[][] getIncidenceMatrix(org.graphstream.graph.Graph graph)
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:
graph.getEdge(j)
is directed and
graph.getNode(i)
is its source.graph.getEdge(j)
is undirected and
graph.getNode(i)
is its source.graph.getNode(i)
is the target of
graph.getEdge(j)
.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.graph
- A graphfillIncidenceMatrix(Graph, byte[][])
public static void computeLayout(org.graphstream.graph.Graph g, org.graphstream.ui.layout.Layout layout, double stab)
g
- the graphlayout
- layout algorithm to use for computing coordinatesstab
- stabilization limitpublic static void computeLayout(org.graphstream.graph.Graph g, double stab)
g
- the graphstab
- stabilization limitpublic static void computeLayout(org.graphstream.graph.Graph g)
g
- the graphpublic static <T extends org.graphstream.graph.Node> List<T> randomNodeSet(org.graphstream.graph.Graph graph, int k)
graph
- A graph.k
- The size of the subset.k
.IllegalArgumentException
- If k
is negative or greater than the number of
nodes.k
)public static <T extends org.graphstream.graph.Node> List<T> randomNodeSet(org.graphstream.graph.Graph graph, int k, Random random)
graph
- A graph.k
- The size of the subset.random
- A source of randomness.k
.IllegalArgumentException
- If k
is negative or greater than the number of
nodes.k
)public static <T extends org.graphstream.graph.Node> List<T> randomNodeSet(org.graphstream.graph.Graph graph, double p)
graph
- A graph.p
- The probability to choose each node.IllegalArgumentException
- If p
is negative or greater than one.n * p), where n
is the
number of nodes.
public static <T extends org.graphstream.graph.Node> List<T> randomNodeSet(org.graphstream.graph.Graph graph, double p, Random random)
graph
- A graph.p
- The probability to choose each node.random
- A source of randomness.IllegalArgumentException
- If p
is negative or greater than one.n * p), where n
is the
number of nodes.
public static <T extends org.graphstream.graph.Edge> List<T> randomEdgeSet(org.graphstream.graph.Graph graph, int k)
graph
- A graph.k
- The size of the subset.k
.IllegalArgumentException
- If k
is negative or greater than the number of
edges.k
)public static <T extends org.graphstream.graph.Edge> List<T> randomEdgeSet(org.graphstream.graph.Graph graph, int k, Random random)
graph
- A graph.k
- The size of the subset.random
- A source of randomness.k
.IllegalArgumentException
- If k
is negative or greater than the number of
edges.k
)public static <T extends org.graphstream.graph.Edge> List<T> randomEdgeSet(org.graphstream.graph.Graph graph, double p)
graph
- A graph.p
- The probability to choose each edge.IllegalArgumentException
- If p
is negative or greater than one.m * p), where m
is the
number of edges.
public static <T extends org.graphstream.graph.Edge> List<T> randomEdgeSet(org.graphstream.graph.Graph graph, double p, Random random)
graph
- A graph.p
- The probability to choose each edge.random
- A source of randomness.IllegalArgumentException
- If p
is negative or greater than one.m * p), where m
is the
number of edges.
public static boolean isConnected(org.graphstream.graph.Graph graph)
graph
- A graph.true
if the graph is connected.m + n
) where m
is the number of edges and n
is the number of nodes.Copyright © 2015. All rights reserved.