cc.redberry.core.graph
Class GraphUtils
- java.lang.Object
-
- cc.redberry.core.graph.GraphUtils
-
public class GraphUtils extends java.lang.ObjectThis class implements useful graph algorithms.- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor and Description GraphUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static int[]calculateConnectedComponents(int[] _from, int[] _to, int vertices)Calculates connected components of the graph from its list of edges.static intcomponentSize(int vertex, int[] components)Returns the number of vertices belonging to the connected component containing specifiedvertex.
-
-
-
Method Detail
-
calculateConnectedComponents
public static int[] calculateConnectedComponents(int[] _from, int[] _to, int vertices)Calculates connected components of the graph from its list of edges. The list of edges is provided as two arrays (_from, which contains 'from' vertices indices, and array_to, which contains vertices indices connected with corresponding 'from' vertices). Vertices are indexed from zero tovertexes - 1, wherevertexesis the total number of vertices of the graph. All indices in arrays_fromand_toshould be in the range [ 0 .. (vertices -1) ].The resulting array have length equal to the total number of vertices plus one. Two vertices A and B belongs to the same connected component if the resulting array have equal values at positions A and B. The last element in the resulting array represents the total number of connected components.
- Parameters:
_from- array of 'from' vertices_to- array of 'to' verticesvertices- total number of vertices in graph- Returns:
- array of connected components and the total number of connected components at the last position
- Throws:
java.lang.IllegalArgumentException- if_from.length() != _to.lengthjava.lang.IllegalArgumentException- if any element of_fromor_toequal or greater thenvertices- Since:
- 1.0
-
componentSize
public static int componentSize(int vertex, int[] components)Returns the number of vertices belonging to the connected component containing specifiedvertex.- Parameters:
vertex- vertex of the graphcomponents- the array, produced bycalculateConnectedComponents(int[], int[], int)- Returns:
- number of vertices belonging to the same connected component as specified
vertex - Since:
- 1.0
-
-
DataMelt 3.0 © DataMelt by jWork.ORG