public class SparseWeightedGraph extends AbstractGraph<WeightedEdge,SparseWeightedEdgeSet> implements WeightedGraph<WeightedEdge>
DirectedGraph that uses a sparse backing
representation. This implementation assumes that the total number of edges
is less than the n2 possible, where n is the
number of vertices.
This class supports all optional Graph and DirectedGraph
methods. All returned DirectedEdge-based collections will reflect
the state of the graph and may be modified to change the graph; i.e., adding
an edge to the adjacency list of a vertex or edge list of the graph will add
that edge in the backing graph. Adding vertices by adding to the AbstractGraph.vertices() set is supported. Adding edges by adding a vertex to the set of
adjacent vertex is not supported.
AbstractGraph.Subgraph| Constructor and Description |
|---|
SparseWeightedGraph()
Creates an empty directed graph
|
SparseWeightedGraph(Graph<? extends WeightedEdge> g)
Creates a directed graph with a copy of all the vertices and edges in
g. |
SparseWeightedGraph(Set<Integer> vertices)
Creates a directed graph with the provided vertices
|
| Modifier and Type | Method and Description |
|---|---|
WeightedGraph<WeightedEdge> |
copy(Set<Integer> toCopy)
Creates a copy of this graph containing only the specified number of
vertices and all edges between those vertices.
|
protected SparseWeightedEdgeSet |
createEdgeSet(int vertex)
Creates an
EdgeSet for storing WeightedEdge instances for
the specified vertex. |
double |
strength(int vertex)
Returns the sum of the weights for all edges connected to this vertex.
|
WeightedGraph |
subgraph(Set<Integer> vertices)
Returns a view of this graph containing only the specified vertices where
the returned graph's vertinces are renamed (0, ..., n).
|
add, add, clear, clearEdges, contains, contains, contains, degree, edges, equals, getAdjacencyList, getEdges, getEdgeSet, getNeighbors, hasCycles, hashCode, iterator, order, remove, remove, size, toString, verticesclone, finalize, getClass, notify, notifyAll, wait, wait, waitadd, edges, getAdjacencyList, getEdgespublic SparseWeightedGraph()
public SparseWeightedGraph(Set<Integer> vertices)
public SparseWeightedGraph(Graph<? extends WeightedEdge> g)
g.public WeightedGraph<WeightedEdge> copy(Set<Integer> toCopy)
vertices is
empty a new, empty graph of this instance's type is returned. Any
changes made to this graph will not be reflected in returned copy or
vice-versa.copy in interface Graph<WeightedEdge>copy in interface WeightedGraph<WeightedEdge>copy in class AbstractGraph<WeightedEdge,SparseWeightedEdgeSet>protected SparseWeightedEdgeSet createEdgeSet(int vertex)
EdgeSet for storing WeightedEdge instances for
the specified vertex.createEdgeSet in class AbstractGraph<WeightedEdge,SparseWeightedEdgeSet>public double strength(int vertex)
0 is returned.strength in interface WeightedGraph<WeightedEdge>public WeightedGraph subgraph(Set<Integer> vertices)
Only edges connecting two vertices in the provided set will be viewable in the subgraph. Any changes to the subgraph will be reflected in this graph and vice versa.
This view allows for direct manipulation of a part of the graph. For example, clearing this subgraph will remove all of its corresponding vertices and edges from the backing graph.
subgraph in interface Graph<WeightedEdge>subgraph in interface WeightedGraph<WeightedEdge>subgraph in class AbstractGraph<WeightedEdge,SparseWeightedEdgeSet>vertices - the vertices to include in the subgraphCopyright © 2012. All Rights Reserved.