-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathPathTimeWeight.java
More file actions
35 lines (28 loc) · 1.02 KB
/
Copy pathPathTimeWeight.java
File metadata and controls
35 lines (28 loc) · 1.02 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
package subway.domain;
import org.jgrapht.graph.DefaultWeightedEdge;
import org.jgrapht.graph.WeightedMultigraph;
import java.util.List;
public class PathTimeWeight {
private WeightedMultigraph<Station, DefaultWeightedEdge> pathTime =
new WeightedMultigraph(DefaultWeightedEdge.class);
public PathTimeWeight(List<Station> stations, List<Integer> times) {
addStation(stations);
addStationDistance(stations, times);
}
private void addStation(List<Station> stations) {
for (Station station : stations) {
pathTime.addVertex(station);
}
}
private void addStationDistance(List<Station> stations, List<Integer> times) {
for (int i = 0; i < stations.size() - 1; i++) {
pathTime.setEdgeWeight(
pathTime.addEdge(stations.get(i), stations.get(i + 1)),
times.get(i)
);
}
}
public WeightedMultigraph<Station, DefaultWeightedEdge> getPathDistance() {
return pathTime;
}
}