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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package edu.caltech.cs2.datastructures;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import edu.caltech.cs2.interfaces.IDeque;
import edu.caltech.cs2.interfaces.IDictionary;
import edu.caltech.cs2.interfaces.ISet;
import java.io.FileReader;
import java.io.IOException;
public class BeaverMapsGraph extends Graph<Long, Double> {
private IDictionary<Long, Location> ids;
private ISet<Location> buildings;
public BeaverMapsGraph() {
super();
this.buildings = new ChainingHashSet<>();
this.ids = new ChainingHashDictionary<>(MoveToFrontDictionary::new);
}
/**
* Reads in buildings, waypoinnts, and roads file into this graph.
* Populates the ids, buildings, vertices, and edges of the graph
* @param buildingsFileName the buildings filename
* @param waypointsFileName the waypoints filename
* @param roadsFileName the roads filename
*/
public BeaverMapsGraph(String buildingsFileName, String waypointsFileName, String roadsFileName) {
this();
// TODO (student): Write This
}
/**
* Returns a deque of all the locations with the name locName.
* @param locName the name of the locations to return
* @return a deque of all location with the name locName
*/
public IDeque<Location> getLocationByName(String locName) {
// TODO (student): Write This
return null;
}
/**
* Returns the Location object corresponding to the provided id
* @param id the id of the object to return
* @return the location identified by id
*/
public Location getLocationByID(long id) {
// TODO (student): Write This
return null;
}
/**
* Adds the provided location to this map.
* @param n the location to add
* @return true if n is a new location and false otherwise
*/
public boolean addVertex(Location n) {
// TODO (student): Write This
return false;
}
/**
* Returns the closest building to the location (lat, lon)
* @param lat the latitude of the location to search near
* @param lon the longitute of the location to search near
* @return the building closest to (lat, lon)
*/
public Location getClosestBuilding(double lat, double lon) {
// TODO (student): Write This
return null;
}
/**
* Returns a set of locations which are reachable along a path that goes no further than `threshold` feet from start
* @param start the location to search around
* @param threshold the number of feet in the search radius
* @return
*/
public ISet<Location> dfs(Location start, double threshold) {
// TODO (student): Write This
return null;
}
/**
* Returns a list of Locations corresponding to
* buildings in the current map.
* @return a list of all building locations
*/
public ISet<Location> getBuildings() {
return this.buildings;
}
/**
* Returns a shortest path (i.e., a deque of vertices) between the start
* and target locations (including the start and target locations).
* @param start the location to start the path from
* @param target the location to end the path at
* @return a shortest path between start and target
*/
public IDeque<Location> dijkstra(Location start, Location target) {
// TODO (student): Write This
return null;
}
/**
* Returns a JsonElement corresponding to the data in the file
* with the filename filename
* @param filename the name of the file to return the data from
* @return the JSON data from filename
*/
private static JsonElement fromFile(String filename) {
try (FileReader reader = new FileReader(filename)) {
return JsonParser.parseReader(reader);
} catch (IOException e) {
return null;
}
}
}