-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathLineStationRepository.java
More file actions
36 lines (29 loc) · 1.38 KB
/
Copy pathLineStationRepository.java
File metadata and controls
36 lines (29 loc) · 1.38 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
package subway.domain;
import org.jgrapht.GraphPath;
import org.jgrapht.alg.shortestpath.DijkstraShortestPath;
import org.jgrapht.graph.DefaultWeightedEdge;
import org.jgrapht.graph.WeightedMultigraph;
import static subway.domain.SubwayPathFactory.creatPathFirstGraph;
import static subway.domain.SubwayPathFactory.creatTimeFirstGraph;
public class LineStationRepository {
private static WeightedMultigraph<String, DefaultWeightedEdge> lineStation
= new WeightedMultigraph<>(DefaultWeightedEdge.class);
public static void addLineStationOfSection(String startStation, String endStation, int weight) {
lineStation.setEdgeWeight(lineStation.addEdge(startStation, endStation), weight);
}
public static void addVertex(String startStation) {
lineStation.addVertex(startStation);
}
public static GraphPath findShortestPath(String start, String end) {
SubwayPathFactory.init();
creatPathFirstGraph();
DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(lineStation);
return dijkstraShortestPath.getPath(start, end);
}
public static GraphPath findShortestTime(String start, String end) {
SubwayPathFactory.init();
creatTimeFirstGraph();
DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(lineStation);
return dijkstraShortestPath.getPath(start, end);
}
}