public class External extends Object implements Path<String>
Path
interface by calling an external
program.
This program must take four arguments:
If a shortest path is found, then the program must produce output in the following format:
If no shortest path is found, then the program must produce output in a format that cannot be confused with the format given above.
Constructor and Description |
---|
External(List<BStop> stops,
List<BLineTable> lines)
Creates an instance of this class for the program
Lab3 (or, if the use of Lab3 fails
in certain ways, Lab3.bat ) in the current
directory and the transport network defined by
stops and lines . |
External(String program,
List<BStop> stops,
List<BLineTable> lines)
Creates an instance of this class for the program
program (or, if the use of program
fails in certain ways, program + ".bat" ) and the
transport network defined by stops and
lines . |
Modifier and Type | Method and Description |
---|---|
void |
computePath(String from,
String to)
Computes the path from
from to to (if any). |
Iterator<String> |
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.
|
public External(String program, List<BStop> stops, List<BLineTable> lines)
program
(or, if the use of program
fails in certain ways, program + ".bat"
) and the
transport network defined by stops
and
lines
.
Preconditions: The program must accept input and produce
output in a certain format (see External
). All stop
names must be unique. All stop names in lines
must also exist in stops
.
public External(List<BStop> stops, List<BLineTable> lines)
Lab3
(or, if the use of Lab3
fails
in certain ways, Lab3.bat
) in the current
directory and the transport network defined by
stops
and lines
.
Preconditions: The program must accept input and produce
output in a certain format (see External
). All stop
names must be unique. All stop names in lines
must also exist in stops
.
public void computePath(String from, String to)
Path
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.
computePath
in interface Path<String>
public Iterator<String> getPath()
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.
public int getPathLength()
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.
getPathLength
in interface Path<String>