public interface Path<E>
String
). A node cannot occur more than once in a single path.
The path is initialized by a call to computePath()
after
which the relevant information can be retrieved using the methods
getPath()
and getPathLength()
.
A class implementing Path
could perhaps be used as follows:
Lab3File f = new Lab3File(); List<BStop> stops = f.readStops("stops-gbg.txt"); List<BLineTable> lines = f.readLines("lines-gbg.txt"); Path<String> p = new MyPath(stops, lines); p.computePath("Chalmers","Angered"); System.out.println("Distance: " + p.getPathLength()); p.computePath("Chalmers","GuldHeden"); System.out.println("Distance: " + p.getPathLength());
Modifier and Type | Method and Description |
---|---|
void |
computePath(E from,
E to)
Computes the path from
from to to (if any). |
Iterator<E> |
getPath()
Returns an iterator over the nodes in the path.
|
int |
getPathLength()
Returns the length of the computed path, that is, the sum of the
weights of each arc on the path.
|
void computePath(E from, E to)
from
to to
(if any). Path
information can be retrieved by subsequent calls to
getPath()
and getPathLength()
. It must be
possible to call this method any number of times.
Precondition: The underlying graph must not contain any negative edge weights.
Iterator<E> getPath()
If a path has been found the first node in the iterator is the
argument from
passed to computePath
and
the last node is to
.
If no path was found or if no call to computePath has been made the iterator is empty.
int getPathLength()
If no path was found the return value is an arbitrary integer. It is appropriate but not required to return a special value such as -1 in this case.