Interface Path


public interface Path

A path is a sequence of nodes describing how to get from one node to another in a graph. A node is represented by its name (a String). A node can not 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().

All implementations of a Path must support two constructors both taking two arguments; one takes the name of a stop file and the name of a line file, and the other takes two lists with the stops and lines (i.e List<BStop> and List<BLineTable>).

A class implementing Path could be used as follows:

  Lab3File lab3file = new Lab3File();
  List stops = lab3file.readStops("stops-gbg.txt");
  List lines = lab3file.readLines("lines-gbg.txt");
  Path 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());


Method Summary
 void computePath(String from, String to)
          Computes the path from from to to.
 Iterator<String> getPath()
          Return an iterator over (the names of) 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.
 

Method Detail

computePath

void computePath(String from,
                 String to)
Computes the path from from to to. Path information can be retrieved by subsequent calls to getPath() and getPathLength(). Must be possible to call this method any number of times.


getPath

Iterator<String> getPath()
Return an iterator over (the names of) the nodes in the path.

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.

Returns:
An iterator over the computed path.

getPathLength

int getPathLength()
Returns the length of the computed path, that is, the sum of the weights of each arc on the path.

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.

Returns:
The length of the computed path.