Package org.jgrapht.graph
Class AsUnweightedGraph<V,E>
- java.lang.Object
-
- org.jgrapht.graph.AbstractGraph<V,E>
-
- org.jgrapht.graph.GraphDelegator<V,E>
-
- org.jgrapht.graph.AsUnweightedGraph<V,E>
-
- Type Parameters:
V
- the graph vertex typeE
- the graph edge type
- All Implemented Interfaces:
java.io.Serializable
,Graph<V,E>
public class AsUnweightedGraph<V,E> extends GraphDelegator<V,E> implements java.io.Serializable, Graph<V,E>
Provides an unweighted view on a graph. Algorithms designed for unweighted graphs should also work on weighted graphs. This class emulates an unweighted graph based on a weighted one by returningGraph.DEFAULT_EDGE_WEIGHT
for each edge weight. The underlying weighted graph is provided at the constructor. Modifying operations (adding/removing vertexes/edges) are also passed through to the underlying weighted graph. As edge weight, Graph.DEFAULT_EDGE_WEIGHT is used. Setting an edge weight is not supported. The edges are not modified. So, if an edge is asked for, the one from the underlying weighted graph is returned. In case the underlying graph is serializable, this one is serializable, too.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface org.jgrapht.Graph
DEFAULT_EDGE_WEIGHT
-
-
Constructor Summary
Constructors Constructor Description AsUnweightedGraph(Graph<V,E> g)
Constructor for AsUnweightedGraph.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
getEdgeWeight(E e)
Returns the weight assigned to a given edge.GraphType
getType()
Get the graph type.void
setEdgeWeight(E e, double weight)
Assigns a weight to an edge.-
Methods inherited from class org.jgrapht.graph.GraphDelegator
addEdge, addEdge, addVertex, addVertex, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getDelegate, getEdge, getEdgeSource, getEdgeSupplier, getEdgeTarget, getVertexSupplier, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, toString, vertexSet
-
Methods inherited from class org.jgrapht.graph.AbstractGraph
assertVertexExist, containsEdge, equals, hashCode, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toStringFromSets
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jgrapht.Graph
addEdge, addEdge, addVertex, addVertex, containsEdge, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeSource, getEdgeSupplier, getEdgeTarget, getVertexSupplier, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf, removeAllEdges, removeAllEdges, removeAllVertices, removeEdge, removeEdge, removeVertex, setEdgeWeight, vertexSet
-
-
-
-
Method Detail
-
getEdgeWeight
public double getEdgeWeight(E e)
Description copied from class:GraphDelegator
Returns the weight assigned to a given edge. Unweighted graphs return 1.0 (as defined byGraph.DEFAULT_EDGE_WEIGHT
), allowing weighted-graph algorithms to apply to them when meaningful.- Specified by:
getEdgeWeight
in interfaceGraph<V,E>
- Overrides:
getEdgeWeight
in classGraphDelegator<V,E>
- Parameters:
e
- edge of interest- Returns:
- edge weight
-
setEdgeWeight
public void setEdgeWeight(E e, double weight)
Description copied from class:GraphDelegator
Assigns a weight to an edge.- Specified by:
setEdgeWeight
in interfaceGraph<V,E>
- Overrides:
setEdgeWeight
in classGraphDelegator<V,E>
- Parameters:
e
- edge on which to set weightweight
- new weight for edge
-
getType
public GraphType getType()
Description copied from class:GraphDelegator
Get the graph type. The graph type can be used to query for additional metadata such as whether the graph supports directed or undirected edges, self-loops, multiple (parallel) edges, weights, etc.
-
-