V
- the type of the verticespublic class Trail<V extends Vertex> extends Walk<V>
Graph
.
Walk
that does not pass over the same edge twice. A trail might visit the same vertex twice, but only if it
comes and goes from a different edge each time.
cast()
to convert this trail using concrete Vertex
s in a TrailByID
using vertex identifiers.
TrailByID
.Constructor and Description |
---|
Trail(Graph<V,? extends Edge> graph)
Creates an empty trail.
|
Trail(Graph<V,? extends Edge> graph,
java.util.List<V> trail)
Creates a trail based on a predefined trail.
|
Trail(Graph<V,? extends Edge> graph,
V[] trail)
Creates a trail based on a predefined trail.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
V vertex)
Adds a new vertex to the trail.
|
void |
add(V vertex)
Adds a new vertex to the trail.
|
void |
add(V vertex,
Edge edge)
Adds a new vertex to the trail using the specified edge.
|
protected void |
addImpl(int index,
V vertex)
Adds a new vertex to the trail at a specified index.
|
TrailByID<V> |
cast()
|
Trail<V> |
clone()
Gets a shallow copy of this trail (the vertices in the trail are not cloned).
|
boolean |
contains(Edge e)
Indicates whether the trail contains the specified edge.
|
boolean |
equals(java.lang.Object o)
Indicates whether this trail equals the specified one.
|
boolean |
equals(Trail<V> t)
Indicates whether this trail equals the specified one.
|
Edge |
getEdge(int index)
Gets the edge of the trail at the specified index.
|
void |
insert(Walk<V> w,
boolean back)
Inserts a closed trail at the first occurrence of the starting vertex.
|
void |
insert(Walk<V> w,
int index)
Inserts a closed trail at the first occurrence of the starting vertex.
|
protected void |
insertImpl(int index,
Walk<V> w)
The implementation of insert a walk in this walk.
|
boolean |
isClosed()
Indicates whether this trail is a circuit meaning that the trail begins and ends on the same vertex.
|
void |
removeLast()
Removes the last vertex of the trail.
|
public Trail(Graph<V,? extends Edge> graph) throws java.lang.IllegalArgumentException
graph
- the graph its vertices can be part of this trailjava.lang.IllegalArgumentException
- public Trail(Graph<V,? extends Edge> graph, V[] trail) throws java.lang.IllegalArgumentException
graph
- the graph its vertices can be part of this trailtrail
- the predefined trail or null
java.lang.IllegalArgumentException
- public Trail(Graph<V,? extends Edge> graph, java.util.List<V> trail) throws java.lang.IllegalArgumentException
graph
- the graph its vertices can be part of this trailtrail
- the predefined trail or null
java.lang.IllegalArgumentException
- public void add(V vertex) throws java.lang.IllegalArgumentException
public void add(int index, V vertex) throws java.lang.IllegalArgumentException, java.lang.IndexOutOfBoundsException
public void add(V vertex, Edge edge) throws java.lang.IllegalArgumentException
vertex
- the vertexedge
- the edge the trail should take when traversing from the last vertex of the trail to the new one or null
to take an edge that is currently not visitedjava.lang.IllegalArgumentException
- Trail
)Trail
)public void insert(Walk<V> w, boolean back) throws java.lang.IllegalArgumentException
Trail
instance, is closed and does not contain edges that already exist in this trail.insert
in class Walk<V extends Vertex>
w
- a trailback
- true
if the trail should be inserted at the last occurrence of the starting vertex or false
for the first occurrencejava.lang.IllegalArgumentException
- Trail
instancepublic void insert(Walk<V> w, int index) throws java.lang.IllegalArgumentException
Trail
instance, is closed and does not contain edges that already exist in this trail.insert
in class Walk<V extends Vertex>
w
- a trailindex
- the index of the starting vertex of w in this trail at which the trail 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
- Trail
instance< 1
or > the number of occurrences of the starting vertex of w
public void removeLast()
removeLast
in class Walk<V extends Vertex>
public Edge getEdge(int index) throws java.lang.IndexOutOfBoundsException
index
- the indexnull
if there is no edge (a reason for that might be that the graph is modified)java.lang.IndexOutOfBoundsException
- index < 0 || index > length()
)Walk.length()
public boolean contains(Edge e)
public boolean isClosed()
public boolean equals(java.lang.Object o)
public boolean equals(Trail<V> t)
t
- another trail that should be compared with this trailtrue
if the trails are equal otherwise false
public Trail<V> clone()
protected void addImpl(int index, V vertex) throws java.lang.IllegalArgumentException
addImpl
in class Walk<V extends Vertex>
index
- the index at which the vertex should be addedvertex
- the vertexjava.lang.IllegalArgumentException
- Trail
)Trail
)protected void insertImpl(int index, Walk<V> w) throws java.lang.IllegalArgumentException
Walk
Walk.updateWeight()
.insertImpl
in class Walk<V extends Vertex>
index
- the index at which the walk has to be inserted (rembember that the first vertex is already in this walk)w
- the walkjava.lang.IllegalArgumentException