Package org.graph4j.util
Class Walk
java.lang.Object
org.graph4j.util.VertexCollection
org.graph4j.util.VertexList
org.graph4j.util.Walk
- Direct Known Subclasses:
Trail
A walk is a sequence of graph vertices such that any two consecutive
vertices form an edge of the graph. Vertices can repeat. Edges can repeat.
In order to ensure these properties are respected, call
validate.
A walk is closed if the last vertex equals the first one.
The length of a walk is its number of edges.- Author:
- Cristian Frăsinaru
- See Also:
-
Field Summary
FieldsFields inherited from class org.graph4j.util.VertexCollection
bitset, DEFAULT_CAPACITY, first, graph, numVertices, vertices -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(int v) Adds the vertex at the end of the walk, trail or path.protected voidprotected final voiddoublebooleaninthashCode()booleanisClosed()booleanbooleanisValid()intlength()The length of the walk, trail, path or cycle (number of edges).voidreverse()Reverses the walk. 1-2-3 becomes 3-2-1.toString()protected Stringtype()Methods inherited from class org.graph4j.util.VertexList
addAll, get, indexOf, indexOf, insert, remove, removeFromPos, set, union, unionMethods inherited from class org.graph4j.util.VertexCollection
clear, computeVerticesWeight, contains, getGraph, grow, isClique, isEmpty, isStableSet, iterator, numVertices, removeAll, removeLast, retainAll, size, union, vertexToString, verticesMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
numEdges
protected int numEdges
-
-
Constructor Details
-
Walk
-
Walk
-
Walk
-
-
Method Details
-
type
-
checkEdge
-
checkEdges
protected final void checkEdges() -
isValid
public boolean isValid()- Returns:
falseif the vertices do not represent the intendended structure.
-
add
public boolean add(int v) Adds the vertex at the end of the walk, trail or path.- Overrides:
addin classVertexList- Parameters:
v- a vertex number- Returns:
trueif the walk was modified as a result of this invocation.
-
isDirected
public boolean isDirected()- Returns:
true, if it belongs to a directed graph.
-
isClosed
public boolean isClosed()- Returns:
true, if the first vertex equals the last one.
-
length
public int length()The length of the walk, trail, path or cycle (number of edges).- Returns:
- the number of edges.
-
computeEdgesWeight
public double computeEdgesWeight()- Returns:
- the sum of the edge weights.
-
reverse
public void reverse()Reverses the walk. 1-2-3 becomes 3-2-1. In case of directed graphs we have to check the reversed walk is valid. -
toString
- Overrides:
toStringin classVertexCollection
-
hashCode
public int hashCode()- Overrides:
hashCodein classVertexCollection
-
equals
- Overrides:
equalsin classVertexCollection
-