Class SparseIntUndirectedWeightedGraph
- java.lang.Object
-
- org.jgrapht.graph.AbstractGraph<java.lang.Integer,java.lang.Integer>
-
- org.jgrapht.opt.graph.sparse.SparseIntUndirectedGraph
-
- org.jgrapht.opt.graph.sparse.SparseIntUndirectedWeightedGraph
-
- All Implemented Interfaces:
java.io.Serializable,org.jgrapht.Graph<java.lang.Integer,java.lang.Integer>
public class SparseIntUndirectedWeightedGraph extends SparseIntUndirectedGraph implements java.io.Serializable
Sparse undirected 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 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 row format. 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.
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.
- Author:
- Dimitrios Michail
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected double[]weightsThe edge weights-
Fields inherited from class org.jgrapht.opt.graph.sparse.SparseIntUndirectedGraph
incidenceMatrix, incidenceMatrixT, UNMODIFIABLE
-
-
Constructor Summary
Constructors Constructor Description SparseIntUndirectedWeightedGraph(int numVertices, java.util.List<org.jgrapht.alg.util.Triple<java.lang.Integer,java.lang.Integer,java.lang.Double>> edges)Create a new graph from an edge list
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doublegetEdgeWeight(java.lang.Integer e)org.jgrapht.GraphTypegetType()voidsetEdgeWeight(java.lang.Integer e, double weight)-
Methods inherited from class org.jgrapht.opt.graph.sparse.SparseIntUndirectedGraph
addEdge, addEdge, addVertex, addVertex, assertEdgeExist, assertVertexExist, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeSource, getEdgeSupplier, getEdgeTarget, getVertexSupplier, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, vertexSet
-
Methods inherited from class org.jgrapht.graph.AbstractGraph
containsEdge, equals, hashCode, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
-
-
-
-
Constructor Detail
-
SparseIntUndirectedWeightedGraph
public SparseIntUndirectedWeightedGraph(int numVertices, java.util.List<org.jgrapht.alg.util.Triple<java.lang.Integer,java.lang.Integer,java.lang.Double>> edges)Create a new graph from an edge list- Parameters:
numVertices- number of verticesedges- edge list with weights
-
-
Method Detail
-
getType
public org.jgrapht.GraphType getType()
- Specified by:
getTypein interfaceorg.jgrapht.Graph<java.lang.Integer,java.lang.Integer>- Overrides:
getTypein classSparseIntUndirectedGraph
-
getEdgeWeight
public double getEdgeWeight(java.lang.Integer e)
- Specified by:
getEdgeWeightin interfaceorg.jgrapht.Graph<java.lang.Integer,java.lang.Integer>- Overrides:
getEdgeWeightin classSparseIntUndirectedGraph
-
setEdgeWeight
public void setEdgeWeight(java.lang.Integer e, double weight)- Specified by:
setEdgeWeightin interfaceorg.jgrapht.Graph<java.lang.Integer,java.lang.Integer>- Overrides:
setEdgeWeightin classSparseIntUndirectedGraph
-
-