|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--lu.cs.co.graph.Path
A class for simple paths in a graph. A path is a sequence of adjecent vertices in a graph (or digraph) without repeated vertices, except maybe the first and last (in which case the path is a cycle). The number of vertices is given by the method size, which is the same as the method numVertices specified by the Subgraph interface.
The vertices are ordered 0..numVertices-1. The edges are ordered 0..numEdges-1. If the path is simple then numVertices = numEdges+1. If the path is closed then numVertices=numEdges.
The path's length (in the field len) is the total length of the edges joining the path's vertices in the underlying graph.
| Field Summary | |
int |
len
The total length of the path. |
| Constructor Summary | |
Path(Graph G)
Constructs an empty path. |
|
Path(Graph G,
int[] pi,
boolean closed)
Constructs a path from an array of vertex indices. |
|
Path(Graph G,
Vertex v)
Constructs a path consisting of one vertex only. |
|
Path(Graph G,
Vertices V)
Constructs a path consisting of the given vertices. |
|
| Method Summary | |
Object |
clone()
Returns a clone of this path. |
boolean |
contains(Edge e)
|
boolean |
contains(Vertex u)
Check if the path contains a given vertex. |
Edges |
edges()
Creates an iterator over the edges on this path |
void |
exchange(int i,
int j)
Exchange the two vertices on a closed path. |
Edge |
getEdge(int i)
Gets the edge with given index on this path. |
Vertex |
getVertex(int i)
Gets the vertex with given index on this path. |
Vertex |
head()
The last vertex on this path. |
void |
insert(Edge e)
Extends the path with a new edge. |
boolean |
isClosed()
Returns true iff this path is a cycle. |
boolean |
isExtendedBy(Edge e)
Checks if an edge can be added to the path. |
boolean |
isHamiltonian()
Check if the path is Hamiltonian, that is, it contains every vertex in the underlying graph precisely once. |
int |
numEdges()
The number of edges on this path. |
int |
numVertices()
The number of vertices on this path. |
int |
size()
The number of vertices on this path. |
Vertex |
tail()
The first vertex on this path. |
String |
toString()
|
Graph |
underlying()
|
Vertices |
vertices()
Creates an iterator over the vertices on this path. |
| Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
| Field Detail |
public int len
| Constructor Detail |
public Path(Graph G)
G - the underlying graph
public Path(Graph G,
Vertex v)
G - the underlying graphv - the (only) vertex in the path
public Path(Graph G,
int[] pi,
boolean closed)
G - the underlying graphpi - an array of vertex indicesclosed - if true, connects the last vertex to the first,
forming a cycle
public Path(Graph G,
Vertices V)
| Method Detail |
public int numVertices()
public int numEdges()
public Vertex tail()
public Vertex head()
public int size()
public String toString()
public boolean contains(Vertex u)
u - a vertex in the underlying graphpublic boolean contains(Edge e)
public Graph underlying()
public Edges edges()
public Vertices vertices()
public Vertex getVertex(int i)
i - the index, must be in the range 0..numVertices-1.public Edge getEdge(int i)
i - the index, must be in the range 0..numEdges-1.public void insert(Edge e)
e - the new edgepublic boolean isClosed()
public boolean isHamiltonian()
public boolean isExtendedBy(Edge e)
The implementation is inefficient.
e - the edge to be added
public void exchange(int i,
int j)
i - the index of one of the vertices to be exchangedj - the index of the other vertex to be exchangedpublic Object clone()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||