GraphImplementation
public abstract class GraphAbstract
extends java.lang.Object
Modifier and Type | Class | Description |
---|---|---|
class |
GraphAbstract.GraphEdge |
|
class |
GraphAbstract.GraphNode |
Modifier and Type | Field | Description |
---|---|---|
static java.util.ArrayList<GraphAbstract.GraphNode> |
cities |
|
static java.util.ArrayList<GraphAbstract.GraphEdge> |
mileages |
Constructor | Description |
---|---|
GraphAbstract() |
Modifier and Type | Method | Description |
---|---|---|
abstract void |
breadthFirst(java.lang.String startCity) |
|
abstract void |
depthFirst(java.lang.String startCity) |
|
abstract void |
readGraph(java.lang.String filename) |
Reads mileage chart from CSV file and builds lists of nodes (cities) and edges (distances).
|
abstract void |
shortestPath(java.lang.String fromCity,
java.lang.String toCity) |
|
abstract void |
writeGraph(java.lang.String filename) |
Writes mileage graph to DOT file.
|
public static java.util.ArrayList<GraphAbstract.GraphNode> cities
public static java.util.ArrayList<GraphAbstract.GraphEdge> mileages
public abstract void readGraph(java.lang.String filename)
The first line contains all the cities which should be represented as GraphAbstract.GraphNode
s
The successive lines start with a city, followed by a list of mileages to other cities.
To avoid redundancy, not all the values are filled in, ignore empty entries.
When you read a mileage, for example from Fort Collins to Denver, create only one
entry in the mileages array, but add the edge to both cities.
First extract all the edges, then sort the edges by mileage, then add the edges associated with each node.
filename
- the CSV filepublic abstract void writeGraph(java.lang.String filename)
Traverses the data structures created above and writes nodes and edges in GraphViz format.
You will build the GraphViz format into an ArrayList
, which will then be written to file
using the GraphImplementation.writeFile(String, ArrayList)
method.
Use the provided example and the following directions to implement this method:
\u2264100 miles
, blue for \u2264200
miles,
magenta for \u2264300 miles
, and red otherwise.
HINT: Match the file format exactly as provided in order to pass automated grading!
filename
- the output file namepublic abstract void depthFirst(java.lang.String startCity)
public abstract void breadthFirst(java.lang.String startCity)
public abstract void shortestPath(java.lang.String fromCity, java.lang.String toCity)