V
- the graph vertex typeE
- the graph edge typepublic class GraphWalk<V,E> extends Object implements GraphPath<V,E>, Serializable
See http://mathworld.wolfram.com/Walk.html
GraphWalk is the default implementation of GraphPath
.
Two special cases exist:
This class is implemented as a light-weight data structure; this class does not verify whether the sequence of edges or the sequence of vertices provided during construction forms an actual walk. It is the responsibility of the invoking class to provide correct input data.
Note: Serialization of a GraphWalk implies the serialization of the entire underlying graph.
Modifier and Type | Field and Description |
---|---|
protected List<E> |
edgeList |
protected V |
endVertex |
protected Graph<V,E> |
graph |
protected V |
startVertex |
protected List<V> |
vertexList |
protected double |
weight |
Constructor and Description |
---|
GraphWalk(Graph<V,E> graph,
List<V> vertexList,
double weight)
Creates a walk defined by a sequence of vertices.
|
GraphWalk(Graph<V,E> graph,
V startVertex,
V endVertex,
List<E> edgeList,
double weight)
Creates a walk defined by a sequence of edges.
|
GraphWalk(Graph<V,E> graph,
V startVertex,
V endVertex,
List<V> vertexList,
List<E> edgeList,
double weight)
Creates a walk defined by both a sequence of edges and a sequence of vertices.
|
Modifier and Type | Method and Description |
---|---|
GraphWalk<V,E> |
concat(GraphWalk<V,E> extension,
Function<GraphWalk<V,E>,Double> walkWeightCalculator)
Concatenates the specified GraphWalk to the end of this GraphWalk.
|
static <V,E> GraphWalk<V,E> |
emptyWalk(Graph<V,E> graph)
Convenience method which creates an empty walk.
|
boolean |
equals(Object o) |
List<E> |
getEdgeList()
Returns the edges making up the path.
|
V |
getEndVertex()
Returns the end vertex in the path.
|
Graph<V,E> |
getGraph()
Returns the graph over which this path is defined.
|
int |
getLength()
Returns the length of the path, measured in the number of edges.
|
V |
getStartVertex()
Returns the start vertex in the path.
|
List<V> |
getVertexList()
Returns the path as a sequence of vertices.
|
double |
getWeight()
Returns the weight assigned to the path.
|
int |
hashCode() |
boolean |
isEmpty()
Returns true if the path is an empty path, that is, a path with startVertex=endVertex=null
and with an empty vertex and edge list.
|
GraphWalk<V,E> |
reverse()
Reverses the direction of the walk.
|
GraphWalk<V,E> |
reverse(Function<GraphWalk<V,E>,Double> walkWeightCalculator)
Reverses the direction of the walk.
|
void |
setWeight(double weight)
Updates the weight of this walk
|
static <V,E> GraphWalk<V,E> |
singletonWalk(Graph<V,E> graph,
V v)
Convenience method which creates a walk consisting of a single vertex with weight 0.0.
|
static <V,E> GraphWalk<V,E> |
singletonWalk(Graph<V,E> graph,
V v,
double weight)
Convenience method which creates a walk consisting of a single vertex.
|
String |
toString() |
void |
verify()
Convenience method which verifies whether the given path is feasible wrt the input graph and
forms an actual path.
|
protected V startVertex
protected V endVertex
protected double weight
public GraphWalk(Graph<V,E> graph, V startVertex, V endVertex, List<E> edgeList, double weight)
graph
- the graphstartVertex
- the starting vertexendVertex
- the last vertex of the pathedgeList
- the list of edges of the pathweight
- the total weight of the pathpublic GraphWalk(Graph<V,E> graph, List<V> vertexList, double weight)
graph
- the graphvertexList
- the list of vertices of the pathweight
- the total weight of the pathpublic GraphWalk(Graph<V,E> graph, V startVertex, V endVertex, List<V> vertexList, List<E> edgeList, double weight)
graph
- the graphstartVertex
- the starting vertexendVertex
- the last vertex of the pathvertexList
- the list of vertices of the pathedgeList
- the list of edges of the pathweight
- the total weight of the pathpublic Graph<V,E> getGraph()
GraphPath
public V getStartVertex()
GraphPath
getStartVertex
in interface GraphPath<V,E>
public V getEndVertex()
GraphPath
getEndVertex
in interface GraphPath<V,E>
public List<E> getEdgeList()
GraphPath
GraphPath.getVertexList()
.
Whether or not the returned edge list is modifiable depends on the path implementation.
getEdgeList
in interface GraphPath<V,E>
public List<V> getVertexList()
GraphPath
getVertexList
in interface GraphPath<V,E>
public double getWeight()
GraphPath
public void setWeight(double weight)
weight
- weight of the walkpublic int getLength()
GraphPath
public GraphWalk<V,E> reverse()
org.jgrapht.graph.InvalidGraphWalkException
- if the path is invalidpublic GraphWalk<V,E> reverse(Function<GraphWalk<V,E>,Double> walkWeightCalculator)
walkWeightCalculator
- Function used to calculate the weight of the reversed GraphWalkorg.jgrapht.graph.InvalidGraphWalkException
- if the path is invalidpublic GraphWalk<V,E> concat(GraphWalk<V,E> extension, Function<GraphWalk<V,E>,Double> walkWeightCalculator)
extension
- GraphPath used for the concatenation.walkWeightCalculator
- Function used to calculate the weight of the GraphWalk obtained
after the concatenation.public boolean isEmpty()
public void verify()
org.jgrapht.graph.InvalidGraphWalkException
- if the path is invalidpublic static <V,E> GraphWalk<V,E> emptyWalk(Graph<V,E> graph)
V
- vertex typeE
- edge typegraph
- input graphpublic static <V,E> GraphWalk<V,E> singletonWalk(Graph<V,E> graph, V v)
V
- vertex typeE
- edge typegraph
- input graphv
- single vertexpublic static <V,E> GraphWalk<V,E> singletonWalk(Graph<V,E> graph, V v, double weight)
V
- vertex typeE
- edge typegraph
- input graphv
- single vertexweight
- weight of the pathCopyright © 2019. All rights reserved.