-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathTimeWeightedGraph.java
More file actions
31 lines (22 loc) · 1.01 KB
/
Copy pathTimeWeightedGraph.java
File metadata and controls
31 lines (22 loc) · 1.01 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
package subway.graph;
import org.jgrapht.alg.shortestpath.DijkstraShortestPath;
import org.jgrapht.graph.DefaultWeightedEdge;
import org.jgrapht.graph.WeightedMultigraph;
import java.util.List;
public class TimeWeightedGraph {
private static final WeightedMultigraph<String, DefaultWeightedEdge> graph = new WeightedMultigraph(DefaultWeightedEdge.class);
public static void addVertex(String vertex) {
graph.addVertex(vertex);
}
public static DefaultWeightedEdge addEdge(String source, String destination) {
return graph.addEdge(source, destination);
}
public static void setEdgeWeight(DefaultWeightedEdge DWE, double weight) {
graph.setEdgeWeight(DWE, weight);
}
public static List<String> getOptimalGraph(String source, String destination) {
DijkstraShortestPath dijkstraShortestPath = new DijkstraShortestPath(graph);
List<String> optimalGraph = dijkstraShortestPath.getPath(source, destination).getVertexList();
return optimalGraph;
}
}