-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCampusModel.java
More file actions
67 lines (59 loc) · 2.12 KB
/
Copy pathCampusModel.java
File metadata and controls
67 lines (59 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package hw9;
import java.util.*;
import hw5.Edge;
import hw5.Graph;
import hw8.Buildings;
import hw8.CampusMain;
import hw8.PathParser;
/**
* CampusModel represents the model of the program and has functions like
* finding the path between two buildings and returning a list of buildings.
*
* @author RibhavHora
*/
public class CampusModel {
// This class does not represent an ADT.
/**
* @param startNode
* the starting building from who you want the path to begin
* @param endNode
* the ending building where you want the path to end
* @requires both startNode and endNode are in the graph
* @returns a list of edges that show the shortest path between startNode
* and endNode, returns null if path was not found or buildings are
* not in the graph
*/
public static List<Edge<Buildings, Double>> findPath(String startNode, String endNode) {
Graph<Buildings, Double> graph = new Graph<Buildings, Double>();
try {
graph = PathParser.parsePathData("src/hw8/data/campus_buildings.dat", "src/hw8/data/campus_paths.dat");
} catch (Exception e) {
System.err.println("Caught Exception: " + e.toString());
}
Buildings start = CampusMain.fullBuilding(startNode, "src/hw8/data/campus_buildings.dat");
Buildings end = CampusMain.fullBuilding(endNode, "src/hw8/data/campus_buildings.dat");
return CampusMain.findPath(start, end, graph);
}
/**
* @returns an array that contains the abbreviated names of all the
* buildings and an extra place holder string for convenience.
*/
public static String[] returnBuildings() {
Set<Buildings> nameBuildings = new HashSet<Buildings>();
Map<String, Buildings> shorts = new HashMap<String, Buildings>();
try {
PathParser.parseBuildingData("src/hw8/data/campus_buildings.dat", nameBuildings, shorts);
} catch (Exception e) {
System.err.println(e.toString());
e.printStackTrace(System.err);
}
String[] shortNames = new String[shorts.size() + 1];
shortNames[0] = "Select Building"; // place holder
int i = 1;
for (String s : shorts.keySet()) {
shortNames[i] = s;
i++;
}
return shortNames;
}
}