Class SparseIntDirectedWeightedGraph

All Implemented Interfaces:
Serializable, Graph<Integer,Integer>

public class SparseIntDirectedWeightedGraph extends SparseIntDirectedGraph implements Serializable
Sparse directed weighted graph.

Assuming the graph has $n$ vertices, the vertices are numbered from $0$ to $n-1$. Similarly, edges are numbered from $0$ to $m-1$ where $m$ is the total number of edges.

It stores two boolean incidence matrix of the graph (rows are vertices and columns are edges) as Compressed Sparse Rows (CSR). Constant time source and target lookups are provided by storing the edge lists in arrays. This is a classic format for write-once read-many use cases. Thus, the graph is unmodifiable. The edge weights are maintained in an array indexed by the edge identifier. If the user does not require support for incoming edges, then the second incidence matrix can be either completely avoided or constructed lazily. See SparseIntDirectedWeightedGraph(int, List, IncomingEdgesSupport) for more details.

The graph is weighted. While unmodifiable with respect to the structure of the graph, the edge weights can be changed even after the graph is constructed.

The question of whether a sparse or dense representation is more appropriate is highly dependent on various factors such as the graph, the machine running the algorithm and the algorithm itself. Wilkinson defined a matrix as "sparse" if it has enough zeros that it pays to take advantage of them. For more details see

  • Wilkinson, J. H. 1971. Linear algebra; part II: the algebraic eigenvalue problem. In Handbook for Automatic Computation, J. H. Wilkinson and C. Reinsch, Eds. Vol. 2. Springer-Verlag, Berlin, New York.
Additional information about sparse representations can be found in the wikipedia.
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • weights

      protected double[] weights
      The edge weights
  • Constructor Details

    • SparseIntDirectedWeightedGraph

      public SparseIntDirectedWeightedGraph(int numVertices, List<Triple<Integer,Integer,Double>> edges)
      Create a new graph from an edge list.
      Parameters:
      numVertices - the number of vertices
      edges - the edge list with additional weights
    • SparseIntDirectedWeightedGraph

      public SparseIntDirectedWeightedGraph(int numVertices, List<Triple<Integer,Integer,Double>> edges, IncomingEdgesSupport incomingEdgeSupport)
      Create a new graph from an edge list.
      Parameters:
      numVertices - the number of vertices
      edges - the edge list with additional weights
      incomingEdgeSupport - the kind of incoming edges support needed
    • SparseIntDirectedWeightedGraph

      public SparseIntDirectedWeightedGraph(int numVertices, int numEdges, Supplier<Stream<Triple<Integer,Integer,Double>>> edges, IncomingEdgesSupport incomingEdgeSupport)
      Create a new graph from an edge stream.
      Parameters:
      numVertices - the number of vertices
      numEdges - the number of edges
      edges - a supplier of an edge stream with additional weights
      incomingEdgeSupport - the kind of incoming edges support needed
  • Method Details