Package org.graph4j

Class NetworkBuilder

java.lang.Object
org.graph4j.NetworkBuilder

public class NetworkBuilder extends Object
Support class for creating transportation (flow) networks.
Author:
Cristian Frăsinaru
  • Field Details

    • vertices

      protected int[] vertices
    • dynamicVertices

      protected final List<Integer> dynamicVertices
    • vertexLabelMap

      protected final Map<Object,Integer> vertexLabelMap
    • vertexWeightMap

      protected final Map<Integer,Double> vertexWeightMap
    • maxVertices

      protected Integer maxVertices
    • numEdges

      protected Long numEdges
    • avgDegree

      protected Integer avgDegree
    • density

      protected Double density
    • directed

      protected boolean directed
    • allowingSelfLoops

      protected boolean allowingSelfLoops
    • allowingMultiEdges

      protected boolean allowingMultiEdges
    • vertexDataSize

      protected int vertexDataSize
    • edgeDataSize

      protected int edgeDataSize
    • name

      protected String name
    • edges

      protected final List<Edge> edges
    • paths

      protected final List<int[]> paths
    • cycles

      protected final List<int[]> cycles
    • cliques

      protected final List<int[]> cliques
  • Constructor Details

    • NetworkBuilder

      protected NetworkBuilder()
  • Method Details

    • empty

      public static NetworkBuilder empty()
      Creates an empty network (with no vertices).
      Returns:
      a new a NetworkBuilder.
    • numVertices

      public static NetworkBuilder numVertices(int numVertices)
      Creates a network having as vertices the numbers from 0 to numVertices - 1.
      Parameters:
      numVertices - the actual number of vertices in the graph.
      Returns:
      a new a NetworkBuilder.
    • vertexRange

      public static NetworkBuilder vertexRange(int firstVertex, int lastVertex)
      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

      public static NetworkBuilder vertices(int... vertices)
      Creates a new network having the specified vertex numbers.
      Parameters:
      vertices - the vertices of the graph.
      Returns:
      a new a NetworkBuilder.
    • labeledVertices

      public static <V> NetworkBuilder labeledVertices(Collection vertexObjects)
      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

      public static <V> NetworkBuilder labeledVertices(V... vertexObjects)
      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

      public static NetworkBuilder verticesFrom(Graph graph)
      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

      public static NetworkBuilder edges(String 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

      public NetworkBuilder named(String name)
      Sets the name of the graph.
      Parameters:
      name - the name to be set for the graph.
      Returns:
      a reference to this object.
    • estimatedDensity

      public NetworkBuilder estimatedDensity(double density)
      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

      public NetworkBuilder estimatedAvgDegree(int avgDegree)
      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

      public NetworkBuilder estimatedNumEdges(long numEdges)
      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

      public NetworkBuilder estimatedNumVertices(int numVertices)
      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

      public NetworkBuilder vertexDataSize(int vertexDataSize)
    • edgeDataSize

      public NetworkBuilder edgeDataSize(int edgeDataSize)
    • addEdge

      public NetworkBuilder addEdge(Edge e)
      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

      public NetworkBuilder source(int source)
    • sink

      public NetworkBuilder sink(int sink)
    • buildNetwork

      public Network 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

      public org.graph4j.GraphBuilderBase addEdges(String edges)
      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

      protected int getVertex(String vstr)
    • findVertexWithLabel

      protected int findVertexWithLabel(String strLabel)
    • 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()