Class SparseDirectedWeightedGraph

java.lang.Object
org.jgrapht.graph.AbstractGraph<SWCPoint,SWCWeightedEdge>
org.jgrapht.graph.AbstractBaseGraph<SWCPoint,SWCWeightedEdge>
All Implemented Interfaces:
Serializable, Cloneable, org.jgrapht.Graph<SWCPoint,SWCWeightedEdge>

public class SparseDirectedWeightedGraph extends DirectedWeightedGraph
Memory-efficient variant of DirectedWeightedGraph backed by a compressed sparse-row (CSR) adjacency representation (CsrDirectedSpecifics). Public surface is identical to DirectedWeightedGraph

Intended for the post-Fast-Marching forest produced by the disk-backed GWDT tracer, where the dense object-based specifics jgrapht uses by default can run to multi-gigabyte heaps for 10⁷+-vertex graphs. Per-vertex overhead with this class is on the order of 30 bytes vs ≈400 bytes for the efault FastLookupDirectedSpecifics.

Trade-off: getEdge(v1, v2) degrades from O(1) to O(out-degree of v1) because the per-pair edge index is gone.

Author:
Tiago Ferreira
See Also:
  • Constructor Details

    • SparseDirectedWeightedGraph

      public SparseDirectedWeightedGraph()
      Creates an empty sparse directed-weighted graph. Edges are unweighted until AbstractBaseGraph.setEdgeWeight(E, double) or DirectedWeightedGraph.assignEdgeWeightsEuclidean() is called, matching DirectedWeightedGraph's default behavior.
    • SparseDirectedWeightedGraph

      public SparseDirectedWeightedGraph(Tree tree)
      Builds a CSR-backed graph from a Tree. Edge weights are set to inter-node Euclidean distances. Mirrors DirectedWeightedGraph(Tree) but uses ~20x less per-vertex memory. Useful when batching many StrahlerAnalyzer / TreeStatistics instances against large neuron collections.
      Parameters:
      tree - the source tree
      Throws:
      IllegalArgumentException - if tree contains multiple roots
    • SparseDirectedWeightedGraph

      public SparseDirectedWeightedGraph(Tree tree, boolean assignDistancesToWeight)
      Builds a CSR-backed graph from a Tree, with an option to skip Euclidean edge-weight assignment.
      Parameters:
      tree - the source tree
      assignDistancesToWeight - if true, edge weights are set to inter-node Euclidean distances
      Throws:
      IllegalArgumentException - if tree contains multiple roots
    • SparseDirectedWeightedGraph

      public SparseDirectedWeightedGraph(Collection<SWCPoint> nodes, boolean assignDistancesToWeight)
      Builds a CSR-backed graph from a collection of SWC nodes. Mirrors DirectedWeightedGraph(Collection, boolean).
      Parameters:
      nodes - the SWC nodes
      assignDistancesToWeight - if true, edge weights are set to inter-node Euclidean distances