V
- the type of the verticespublic class Walk<V extends Vertex>
extends java.lang.Object
implements java.lang.Cloneable
Graph
.
cast()
to convert this walk using concrete Vertex
s in a WalkByID
using vertex identifiers.
WalkByID
.Modifier and Type | Field and Description |
---|---|
protected Graph<V,? extends Edge> |
graph
the associated graph
|
protected java.util.List<V> |
vertices
the list of vertices of the walk
|
Constructor and Description |
---|
Walk(Graph<V,? extends Edge> graph)
Creates an empty walk.
|
Walk(Graph<V,? extends Edge> graph,
java.util.List<V> walk)
Creates a walk based on a predefined walk.
|
Walk(Graph<V,? extends Edge> graph,
V[] walk)
Creates a walk based on a predefined walk.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
V vertex)
Adds a new vertex to the walk.
|
void |
add(V vertex)
Adds a new vertex to the walk.
|
protected void |
addImpl(int index,
V vertex)
Adds a new vertex to the walk at a given index.
|
java.util.List<V> |
asList()
Gets the walk as a list.
|
WalkByID<V> |
cast()
|
Walk<V> |
clone()
Gets a shallow copy of this walk (the vertices in the walk are not cloned).
|
boolean |
contains(Edge edge)
Indicates whether the walk contains the specified edge or more precisely whether the walk contains
the predecessor and the successor of the edge regarding the direction of the edge.
|
boolean |
contains(V vertex)
Indicates whether the specified vertex is on this walk.
|
boolean |
equals(java.lang.Object o)
Indicates whether this walk equals the specified one.
|
boolean |
equals(Walk<V> w)
Indicates whether this walk equals the specified one.
|
V |
get(int index)
Gets a vertex at the specified index.
|
float |
getWeight()
Gets the weight (or cost) of the walk which is the sum of the weights of the traversed edges.
|
void |
insert(Walk<V> w,
boolean back)
Inserts a closed walk.
|
void |
insert(Walk<V> w,
int index)
Inserts a closed walk.
|
protected void |
insertImpl(int index,
Walk<V> w)
The implementation of insert a walk in this walk.
|
boolean |
isClosed()
Indicates whether the walk is closed meaning the walk ends on the same vertex on which it began.
|
int |
length()
The length of the walk meaning the number of edges.
|
void |
removeLast()
Removes the last vertex of the walk.
|
protected static <V extends Vertex> |
toList(V[] array)
Converts the given array to a list.
|
java.lang.String |
toString() |
protected void |
updateWeight()
Updates the weight of the walk.
|
public Walk(Graph<V,? extends Edge> graph) throws java.lang.IllegalArgumentException
graph
- the graph its vertices can be part of this walkjava.lang.IllegalArgumentException
- public Walk(Graph<V,? extends Edge> graph, V[] walk) throws java.lang.IllegalArgumentException
graph
- the graph its vertices can be part of this walkwalk
- the predefined walk or null
java.lang.IllegalArgumentException
- public Walk(Graph<V,? extends Edge> graph, java.util.List<V> walk) throws java.lang.IllegalArgumentException
graph
- the graph its vertices can be part of this walkwalk
- the predefined walk or null
java.lang.IllegalArgumentException
- public void add(V vertex) throws java.lang.IllegalArgumentException
vertex
- the vertexjava.lang.IllegalArgumentException
- Walk
)public void add(int index, V vertex) throws java.lang.IllegalArgumentException, java.lang.IndexOutOfBoundsException
index
- the index at which the vertex should be insertedvertex
- the vertexjava.lang.IllegalArgumentException
- Walk
)java.lang.IndexOutOfBoundsException
- public void insert(Walk<V> w, boolean back) throws java.lang.IllegalArgumentException
w
- the walk to insertback
- true
if the walk should be inserted at the last occurrence of the starting vertex or false
for the first occurrencejava.lang.IllegalArgumentException
- public void insert(Walk<V> w, int index) throws java.lang.IllegalArgumentException
w
- the walk to insertindex
- the index of the starting vertex of w in this walk at which the walk w should be inserted (example this = v1,v2,v3,v2,v4,v1
, w = v2,v5,v2
, so w can be inserted at occurrence 1 or 2 of v2)java.lang.IllegalArgumentException
- < 1
or > the number of occurrences of the starting vertex of w
public void removeLast()
public int length()
public V get(int index) throws java.lang.IndexOutOfBoundsException
length()
returns the number of edges meaning that get(length())
is the last vertex of the walk.index
- the indexjava.lang.IndexOutOfBoundsException
- index < 0 || index > length()
)public boolean contains(V vertex)
vertex
- the vertextrue
if the vertex is on this walk otherwise false
public boolean contains(Edge edge)
edge
- the edgetrue
if the walk contains the specified edge otherwise false
public boolean isClosed()
true
if the walk is closed otherwise false
public float getWeight()
public WalkByID<V> cast() throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- public java.util.List<V> asList()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- another walk of the same vertex type that should be compared with this walktrue
if the walks are equal otherwise false
public boolean equals(Walk<V> w)
w
- another walk that should be compared with this walktrue
if the walks are equal otherwise false
public Walk<V> clone()
clone
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
protected void addImpl(int index, V vertex) throws java.lang.IllegalArgumentException, java.lang.IndexOutOfBoundsException
updateWeight()
.index
- the index at which the vertex should be addedvertex
- the vertexjava.lang.IllegalArgumentException
- Walk
)java.lang.IndexOutOfBoundsException
- protected void insertImpl(int index, Walk<V> w)
updateWeight()
.index
- the index at which the walk has to be inserted (rembember that the first vertex is already in this walk)w
- the walkprotected static <V extends Vertex> java.util.List<V> toList(V[] array)
array
- the arrayprotected void updateWeight()