-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRailNet.java
More file actions
86 lines (73 loc) · 2.73 KB
/
RailNet.java
File metadata and controls
86 lines (73 loc) · 2.73 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package traintransfer;
import java.io.IOException;
public class RailNet extends Graph {
String stationsPath, trainsPath;
public RailNet(String stationsPath, String trainsPath, String sameStPath) throws IOException {
this.stationsPath = stationsPath;
this.trainsPath = trainsPath;
v = ReadStations.readStations(stationsPath, sameStPath);
super.Nv = v.length;
Trains.readSchedules(trainsPath);
Trains.addTrains(this);
this.setInOrOutAdjList(true);
}
public void addEdge(Trains newT) {
super.addEdge(newT);
}
public void avoidStations(String[] stNameToAvoid) {
if (stNameToAvoid[0].contains("#"))
return;
for (int i = 0; i < stNameToAvoid.length; i++) {
this.v[Stations.stationNameDic.get(stNameToAvoid[i])].saveHeadNode();
this.v[Stations.stationNameDic.get(stNameToAvoid[i])].E = null;
}
}
public void restoreAvoidStations(String[] stNameToAvoid) {
if (stNameToAvoid[0].contains("#"))
return;
for (int i = 0; i < stNameToAvoid.length; i++) {
this.v[Stations.stationNameDic.get(stNameToAvoid[i])].restoreHeadNode();
}
}
public static boolean isTheTypeOfTrainSuitable(Trains aTrain, String avoidTrainType) {
if (avoidTrainType != null && aTrain.trainCodeId >= 0 && Trains.schedules[aTrain.trainCodeId].lines != null) {
char trainCodeFirstChar = Trains.schedules[aTrain.trainCodeId].lines[0].station_train_code.charAt(0);
if (trainCodeFirstChar >= '0' && trainCodeFirstChar <= '9')
trainCodeFirstChar = '0';
boolean flag = false;
for (int i = 0; i < avoidTrainType.length(); i++) {
if (avoidTrainType.charAt(i) == trainCodeFirstChar)
flag = true;
} /* 筛选车次 */
if (flag)
return false;
}
/* Trains.schedules[aTrain.trainCodeId].lines != null 貌似永真,为验证猜想,设置以下测试代码*/
if (avoidTrainType != null && aTrain.trainCodeId >= 0 && Trains.schedules[aTrain.trainCodeId].lines == null) {
System.out.println(aTrain.trainCodeId);
System.out.println(aTrain.depStName);
System.out.println(aTrain.arrStName);
}
return true;
}
public Trains getTrainsBetweenTwoStas(int startV, int arrV, String avoidTrainType) {
Trains headTrains = null;
Trains aTrain = null;
for (aTrain = (Trains) this.v[startV].E; aTrain != null; aTrain = (Trains) aTrain.nextEdge) {
if(aTrain.arrStId!=arrV)continue;
if(!isTheTypeOfTrainSuitable(aTrain, avoidTrainType)) {continue;}
if(headTrains==null) {
headTrains=(Trains) aTrain.clone();
headTrains.nextEdge=null;
continue;
}
Edge tmp=(Edge) aTrain.clone();
tmp.nextEdge=headTrains.nextEdge;
headTrains.nextEdge=tmp;
}
return headTrains;
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
}
}