Package org.graph4j
Class NetworkBuilder
java.lang.Object
org.graph4j.NetworkBuilder
Support class for creating transportation (flow) networks.
- 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 TypeMethodDescriptionorg.graph4j.GraphBuilderBaseaddClique(int... clique) Adds a clique to the graph, specified by its vertex numbers.org.graph4j.GraphBuilderBaseaddCycle(int... cycle) Adds a cycle to the graph, specified by its vertex numbers.org.graph4j.GraphBuilderBaseaddEdge(int v, int u) Adds an edge to the graph, specified using its vertex numbers.Adds an edge to the graph.<V> org.graph4j.GraphBuilderBaseaddEdge(V vLabel, V uLabel) Adds an edge to the graph, specified using its vertex labels.org.graph4j.GraphBuilderBaseAdds 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", etcorg.graph4j.GraphBuilderBaseaddPath(int... path) Adds a path to the graph, specified by its vertex numbers.org.graph4j.GraphBuilderBaseadjList(int[][] a) Builds the graph from the adjacency list.protected intBuilds a transportation (flow) network.edgeDataSize(int edgeDataSize) static NetworkBuilderCreates a new network 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 NetworkBuilderempty()Creates an empty network (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> NetworkBuilderlabeledVertices(Collection vertexObjects) Creates a new network having the specified vertex labels.static <V> NetworkBuilderlabeledVertices(V... vertexObjects) Creates a new network having the specified vertex labels.Sets the name of the graph.protected intstatic NetworkBuildernumVertices(int numVertices) Creates a network having as vertices the numbers from0tonumVertices - 1.sink(int sink) source(int source) protected voidvalidate()vertexDataSize(int vertexDataSize) static NetworkBuildervertexRange(int firstVertex, int lastVertex) Creates a new network having as vertices the numbers in the specified range.static NetworkBuildervertices(int... vertices) Creates a new network having the specified vertex numbers.static NetworkBuilderverticesFrom(Graph graph) Creates a new network 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
-
NetworkBuilder
protected NetworkBuilder()
-
-
Method Details
-
empty
Creates an empty network (with no vertices).- Returns:
- a new a
NetworkBuilder.
-
numVertices
Creates a network having as vertices the numbers from0tonumVertices - 1.- Parameters:
numVertices- the actual number of vertices in the graph.- Returns:
- a new a
NetworkBuilder.
-
vertexRange
Creates a new network 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
NetworkBuilder.
-
vertices
Creates a new network having the specified vertex numbers.- Parameters:
vertices- the vertices of the graph.- Returns:
- a new a
NetworkBuilder.
-
labeledVertices
Creates a new network 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
NetworkBuilder.
-
labeledVertices
Creates a new network 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
NetworkBuilder.
-
verticesFrom
Creates a new network having the same vertex numbers as the specified graph.- Parameters:
graph- a graph of any type.- Returns:
- a new a
NetworkBuilder.
-
edges
Creates a new network 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
NetworkBuilder.
-
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.
-
source
-
sink
-
buildNetwork
Builds a transportation (flow) network.- Returns:
- a network.
-
addEdge
public org.graph4j.GraphBuilderBase addEdge(int v, int u) 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.
-
addEdge
public <V> org.graph4j.GraphBuilderBase addEdge(V vLabel, V uLabel) 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.
-
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.
-
adjList
public org.graph4j.GraphBuilderBase adjList(int[][] a) 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.
-
getVertex
protected int getVertex(int v) -
getVertex
-
findVertexWithLabel
-
nextVertexNumber
protected int nextVertexNumber() -
addPath
public org.graph4j.GraphBuilderBase addPath(int... path) 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
public org.graph4j.GraphBuilderBase addCycle(int... cycle) 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
public org.graph4j.GraphBuilderBase addClique(int... clique) Adds a clique to the graph, specified by its vertex numbers.- Parameters:
clique- an array of vertex numbers.- Returns:
- a reference to this object.
-
validate
protected void validate() -
avgDegree
protected int avgDegree()
-