Package org.graph4j
Class GraphBuilder
java.lang.Object
org.graph4j.GraphBuilder
Support class for creating a graph of any type.
- Author:
- Cristian Frăsinaru
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected Integerprotected final List<int[]> protected final List<int[]> protected Doubleprotected booleanprotected intprotected Integerprotected Stringprotected Longprotected final List<int[]> protected intprotected int[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddClique(int... clique) Adds a clique to the graph, specified by its vertex numbers.addCycle(int... cycle) Adds a cycle to the graph, specified by its vertex numbers.addEdge(int v, int u) Adds an edge to the graph, specified using its vertex numbers.Adds an edge to the graph.<V> GraphBuilderaddEdge(V vLabel, V uLabel) Adds an edge to the graph, specified using its vertex labels.Adds to the graph a set of edges represented as a string, for example: "1-2, 2-3, 3-1", "a-b, b-c, c-d", etcaddPath(int... path) Adds a path to the graph, specified by its vertex numbers.adjList(int[][] a) Builds the graph from the adjacency list.protected intBuilds a directed graph, without multiple edges or self loops.Builds a directed graph, without self loops, allowing multiple edges between two vertices.Builds a directed graph, allowing both multiple edges between two vertices and self loops.Builds an undirected graph, without multiple edges or self loops.Builds an undirected graph, without self loops, allowing multiple edges between two vertices.Builds an undirected graph, allowing both multiple edges between two vertices and self loops.edgeDataSize(int edgeDataSize) static GraphBuilderCreates a new graph based on the string representation of its edge set, for example: "1-2, 2-3, 3-1", "a-b, b-c, c-d", etc. "0-1,0-2-0-3" may be written as "0-1,2,3".static GraphBuilderempty()Creates an empty graph (with no vertices).estimatedAvgDegree(int avgDegree) Sets an estimation of the graph average vertex degree, in order to optimize memory allocation.estimatedDensity(double density) Sets an estimation of the graph density, in order to optimize memory allocation.estimatedNumEdges(long numEdges) Sets an estimation of the number of edges in the graph, in order to optimize memory allocation.estimatedNumVertices(int numVertices) Sets an estimation of the number of vertices in the graph, in order to optimize memory allocation.protected intfindVertexWithLabel(String strLabel) protected intgetVertex(int v) protected intstatic <V> GraphBuilderlabeledVertices(Collection vertexObjects) Creates a new graph having the specified vertex labels.static <V> GraphBuilderlabeledVertices(V... vertexObjects) Creates a new graph having the specified vertex labels.Sets the name of the graph.protected intstatic GraphBuildernumVertices(int numVertices) Creates a graph having as vertices the numbers from0tonumVertices - 1.protected voidvalidate()vertexDataSize(int vertexDataSize) static GraphBuildervertexRange(int firstVertex, int lastVertex) Creates a new graph having as vertices the numbers in the specified range.static GraphBuildervertices(int... vertices) Creates a new graph having the specified vertex numbers.static GraphBuilderverticesFrom(Graph graph) Creates a new graph having the same vertex numbers as the specified graph.
-
Field Details
-
vertices
protected int[] vertices -
dynamicVertices
-
vertexLabelMap
-
vertexWeightMap
-
maxVertices
-
numEdges
-
avgDegree
-
density
-
directed
protected boolean directed -
allowingSelfLoops
protected boolean allowingSelfLoops -
allowingMultiEdges
protected boolean allowingMultiEdges -
vertexDataSize
protected int vertexDataSize -
edgeDataSize
protected int edgeDataSize -
name
-
edges
-
paths
-
cycles
-
cliques
-
-
Constructor Details
-
GraphBuilder
protected GraphBuilder()
-
-
Method Details
-
empty
Creates an empty graph (with no vertices).- Returns:
- a new a
GraphBuilder.
-
numVertices
Creates a graph having as vertices the numbers from0tonumVertices - 1.- Parameters:
numVertices- the actual number of vertices in the graph.- Returns:
- a new a
GraphBuilder.
-
vertexRange
Creates a new graph having as vertices the numbers in the specified range.- Parameters:
firstVertex- The number of the first vertex.lastVertex- The number of the last vertex.- Returns:
- a new a
GraphBuilder.
-
vertices
Creates a new graph having the specified vertex numbers.- Parameters:
vertices- the vertices of the graph.- Returns:
- a new a
GraphBuilder.
-
labeledVertices
Creates a new graph having the specified vertex labels. The vertex numbers will be assigned in the order of the collection, starting with 0.- Type Parameters:
V- the type of vertex labels.- Parameters:
vertexObjects- a collection of objects, representing the labeled vertices of the graph.- Returns:
- a new a
GraphBuilder.
-
labeledVertices
Creates a new graph having the specified vertex labels. The vertex numbers will be the indices in the array of labels.- Type Parameters:
V- the type of vertex labels.- Parameters:
vertexObjects- a list of objects, representing the labeled vertices of the graph.- Returns:
- a new a
GraphBuilder.
-
verticesFrom
Creates a new graph having the same vertex numbers as the specified graph.- Parameters:
graph- a graph of any type.- Returns:
- a new a
GraphBuilder.
-
edges
Creates a new graph based on the string representation of its edge set, for example: "1-2, 2-3, 3-1", "a-b, b-c, c-d", etc. "0-1,0-2-0-3" may be written as "0-1,2,3". Useful for creating small graphs for testing purposes.- Parameters:
edges- a text representation of the edges of the graph.- Returns:
- a new a
GraphBuilder.
-
named
Sets the name of the graph.- Parameters:
name- the name to be set for the graph.- Returns:
- a reference to this object.
-
estimatedDensity
Sets an estimation of the graph density, in order to optimize memory allocation.- Parameters:
density- the estimated density of the graph.- Returns:
- a reference to this object.
-
estimatedAvgDegree
Sets an estimation of the graph average vertex degree, in order to optimize memory allocation.- Parameters:
avgDegree- the estimated average degree of the vertices.- Returns:
- a reference to this object.
-
estimatedNumEdges
Sets an estimation of the number of edges in the graph, in order to optimize memory allocation.- Parameters:
numEdges- the estimated maximum number of edges.- Returns:
- a reference to this object.
-
estimatedNumVertices
Sets an estimation of the number of vertices in the graph, in order to optimize memory allocation. No vertex will be added to the graph as a result of this invocation.- Parameters:
numVertices- the estimated maximum number of vertices.- Returns:
- a reference to this object.
-
vertexDataSize
-
edgeDataSize
-
addEdge
Adds an edge to the graph.- Parameters:
e- an object containing the endpoints of the edge, eventually its weight and label.- Returns:
- a reference to this object.
-
addPath
Adds a path to the graph, specified by its vertex numbers.- Parameters:
path- an array of vertex numbers.- Returns:
- a reference to this object.
-
addCycle
Adds a cycle to the graph, specified by its vertex numbers.- Parameters:
cycle- an array of vertex numbers.- Returns:
- a reference to this object.
-
addClique
Adds a clique to the graph, specified by its vertex numbers.- Parameters:
clique- an array of vertex numbers.- Returns:
- a reference to this object.
-
adjList
Builds the graph from the adjacency list. The number of rows is the number of vertices, for the row with the index i, a[i] represents the neighbors (successors) of the vertex with the index i in the graph.- Parameters:
a- the adjacency list.- Returns:
- a reference to this object.
-
addEdges
Adds to the graph a set of edges represented as a string, for example: "1-2, 2-3, 3-1", "a-b, b-c, c-d", etc. "0-1,0-2-0-3" may be written as "0-1,2,3".- Parameters:
edges- a text representation of the edges to be added.- Returns:
- a reference to this object.
-
addEdge
Adds an edge to the graph, specified using its vertex labels.- Type Parameters:
V- the type of vertex labels.- Parameters:
vLabel- a labeled vertex.uLabel- a labeled vertex.- Returns:
- a reference to this object.
-
addEdge
Adds an edge to the graph, specified using its vertex numbers.- Parameters:
v- a vertex number.u- a vertex number.- Returns:
- a reference to this object.
-
buildGraph
Builds an undirected graph, without multiple edges or self loops.- Returns:
- a simple undirected graph.
-
buildDigraph
Builds a directed graph, without multiple edges or self loops.- Returns:
- a simple directed graph.
-
buildMultigraph
Builds an undirected graph, without self loops, allowing multiple edges between two vertices.- Returns:
- an undirected multigraph.
-
buildDirectedMultigraph
Builds a directed graph, without self loops, allowing multiple edges between two vertices.- Returns:
- a directed multigraph.
-
buildPseudograph
Builds an undirected graph, allowing both multiple edges between two vertices and self loops.- Returns:
- an undirected pseudograph.
-
buildDirectedPseudograph
Builds a directed graph, allowing both multiple edges between two vertices and self loops.- Returns:
- a directed pseudograph.
-
getVertex
protected int getVertex(int v) -
getVertex
-
findVertexWithLabel
-
nextVertexNumber
protected int nextVertexNumber() -
validate
protected void validate() -
avgDegree
protected int avgDegree()
-