Class SparseIntUndirectedGraph

  • All Implemented Interfaces:
    Graph<Integer,​Integer>
    Direct Known Subclasses:
    SparseIntUndirectedWeightedGraph

    public class SparseIntUndirectedGraph
    extends org.jgrapht.opt.graph.sparse.specifics.AbstractSparseSpecificsGraph<org.jgrapht.opt.graph.sparse.specifics.SparseGraphSpecifics>
    Sparse undirected 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 the boolean incidence matrix of the graph (rows are vertices and columns are edges) as Compressed Sparse Rows (CSR). In order to also support constant time source and target lookups from an edge identifier we also store the transposed of the incidence matrix again in compressed sparse rows format. This is a classic format for write-once read-many use cases. Thus, the graph is unmodifiable.

    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.
    Author:
    Dimitrios Michail
    • Constructor Detail

      • SparseIntUndirectedGraph

        public SparseIntUndirectedGraph​(int numVertices,
                                        List<Pair<Integer,​Integer>> edges)
        Create a new graph from an edge list
        Parameters:
        numVertices - number of vertices
        edges - edge list
      • SparseIntUndirectedGraph

        public SparseIntUndirectedGraph​(int numVertices,
                                        int numEdges,
                                        Supplier<Stream<Pair<Integer,​Integer>>> edges)
        Create a new graph from an edge stream
        Parameters:
        numVertices - number of vertices
        numEdges - number of edges
        edges - supplier of an edge stream