Skip to content

Commit 741e09d

Browse files
committed
Add bidirectional networks for exporting simulator solutions
1 parent c04c8aa commit 741e09d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3596
-48
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
./build/apps/rail_vss_generation_timetable_simulator_genetic_parameter_testing ./test/example-networks-unidirec/SimpleNetwork .
1+
./build/apps/rail_vss_generation_timetable_simulator_genetic_parameter_testing ./test/example-networks-sim-unidirec/SimpleNetwork .
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
./build/apps/rail_vss_generation_timetable_simulator_greedy_parameter_testing ./test/example-networks-unidirec/SimpleNetwork .
1+
./build/apps/rail_vss_generation_timetable_simulator_greedy_parameter_testing ./test/example-networks-sim-unidirec/SimpleNetwork .
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
./build/apps/rail_vss_generation_timetable_simulator_local_parameter_testing ./test/example-networks-unidirec/SimpleNetwork .
1+
./build/apps/rail_vss_generation_timetable_simulator_local_parameter_testing ./test/example-networks-sim-unidirec/SimpleNetwork .

dev_scripts/launch_method_compare.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
./build/apps/rail_vss_generation_timetable_simulator_search_methods_testing ./test/example-networks-unidirec/Overtake .
2-
./build/apps/rail_vss_generation_timetable_simulator_search_methods_testing ./test/example-networks-unidirec/SimpleNetwork .
3-
./build/apps/rail_vss_generation_timetable_simulator_search_methods_testing ./test/example-networks-unidirec/Stammstrecke16Trains .
1+
./build/apps/rail_vss_generation_timetable_simulator_search_methods_testing ./test/example-networks-sim-unidirec/Overtake .
2+
./build/apps/rail_vss_generation_timetable_simulator_search_methods_testing ./test/example-networks-sim-unidirec/SimpleNetwork .
3+
./build/apps/rail_vss_generation_timetable_simulator_search_methods_testing ./test/example-networks-sim-unidirec/Stammstrecke16Trains .
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
./build/apps/rail_vss_generation_timetable_simulator_search_methods_testing ./test/example-networks-unidirec/Overtake .
2-
./build/apps/rail_vss_generation_timetable_simulator_search_methods_testing ./test/example-networks-unidirec/SimpleNetwork .
3-
./build/apps/rail_vss_generation_timetable_simulator_search_methods_testing ./test/example-networks-unidirec/Stammstrecke16Trains .
1+
./build/apps/rail_vss_generation_timetable_simulator_search_methods_testing ./test/example-networks-sim-unidirec/Overtake .
2+
./build/apps/rail_vss_generation_timetable_simulator_search_methods_testing ./test/example-networks-sim-unidirec/SimpleNetwork .
3+
./build/apps/rail_vss_generation_timetable_simulator_search_methods_testing ./test/example-networks-sim-unidirec/Stammstrecke16Trains .

dev_scripts/launch_solver.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
./build/apps/rail_vss_generation_timetable_simulator ./test/example-networks-unidirec/Overtake .
1+
./build/apps/rail_vss_generation_timetable_simulator ./test/example-networks-sim-unidirec/Overtake .

test/convertToBidirec.py

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Add any missing reciprocal edges to graph and adjust successor_list
2+
3+
# Solutions from the Simulator can be exported only to bidirectional networks generated from the same base as the unidirectional network
4+
5+
#
6+
# Usage:
7+
# python convertToBidirec.py NETWORK_NAME_IN_DIRECTORY_STRUCTURE
8+
#
9+
10+
import sys
11+
import os
12+
import json
13+
import networkx as nx
14+
import shutil
15+
import ast
16+
17+
def parse_tuple(string):
18+
try:
19+
s = ast.literal_eval(str(string))
20+
if type(s) == tuple:
21+
return s
22+
return
23+
except:
24+
return
25+
26+
27+
def readJson(path):
28+
with open(path,"r") as f:
29+
data = f.read()
30+
31+
jsonObj = json.loads(data)
32+
return jsonObj
33+
34+
def writeJson(obj, path):
35+
with open(path, 'w') as g:
36+
json.dump(obj, g, indent=4)
37+
38+
origin_p = "./example-networks/" + sys.argv[1]
39+
destination_p = "./example-networks-sim-bidirec/" + sys.argv[1]
40+
41+
print("Opening files ...")
42+
old_graph = nx.read_graphml(origin_p + "/network/tracks.graphml")
43+
graph = old_graph.copy()
44+
45+
succ = readJson(origin_p + "/network/successors_cpp.json")
46+
stations = readJson(origin_p + "/timetable/stations.json")
47+
routes = readJson(origin_p + "/routes/routes.json")
48+
49+
attb_mbl = nx.get_edge_attributes(graph, "min_block_length")
50+
attb_sp = nx.get_edge_attributes(graph, "max_speed")
51+
attb_le = nx.get_edge_attributes(graph, "length")
52+
attb_br = nx.get_edge_attributes(graph, "breakable")
53+
54+
for (u, v) in old_graph.edges:
55+
# Add reciprocal
56+
if graph.has_edge(u, v) and not(graph.has_edge(v, u)):
57+
print("Graph: Adding reciprocal edge to ", [u, v], "because", [v, u], " does not exist")
58+
graph.add_edge(v, u, min_block_length=attb_mbl[u,v], max_speed=attb_sp[u,v], length=attb_le[u,v], breakable=attb_br[u,v])
59+
60+
## Edit successor list
61+
key_old = "('"+ u + "', '" + v + "')"
62+
key_new = "('"+ v + "', '" + u + "')"
63+
64+
# For each successor of the old edge
65+
for [o,d] in succ[key_old]:
66+
# The new edge is a successor of the reciprocal
67+
print("Successors: Adding new edge ", [v, u]," as a successor of ", [d, o])
68+
key_succ_recip = "('"+ d + "', '" + o + "')"
69+
if key_succ_recip in succ:
70+
succ[key_succ_recip].append([v,u])
71+
else:
72+
succ[key_succ_recip] = [[v,u]]
73+
74+
succ_iter = succ.copy()
75+
for edge in succ_iter:
76+
edge_p = parse_tuple(edge)
77+
o = edge_p[0]
78+
d = edge_p[1]
79+
# For each predicessor of the old edge
80+
if [u, v] in succ_iter[edge]:
81+
# The new edge can reach the reciprocal
82+
print("Successors: Adding new edge ", [v, u]," as a predicessor of", [d, o])
83+
key_pred_recip = "('"+ d + "', '" + o + "')"
84+
if key_new in succ:
85+
succ[key_new].append([d,o])
86+
else:
87+
succ[key_new] = [[d,o]]
88+
89+
os.makedirs(destination_p + "/network", exist_ok=True)
90+
os.makedirs(destination_p + "/routes", exist_ok=True)
91+
os.makedirs(destination_p + "/timetable", exist_ok=True)
92+
93+
print("Saving modified files ...")
94+
nx.write_graphml(graph, destination_p + "/network/tracks.graphml")
95+
writeJson(succ, destination_p + "/network/successors_cpp.json")
96+
writeJson(stations, destination_p + "/timetable/stations.json")
97+
writeJson(routes, destination_p + "/routes/routes.json")
98+
99+
shutil.copyfile(origin_p + "/timetable/schedules.json", destination_p + "/timetable/schedules.json")
100+
shutil.copyfile(origin_p + "/timetable/trains.json", destination_p + "/timetable/trains.json")

test/convertToUnidirec.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def writeJson(obj, path):
3030
json.dump(obj, g, indent=4)
3131

3232
origin_p = "./example-networks/" + sys.argv[1]
33-
destination_p = "./example-networks-unidirec/" + sys.argv[1]
33+
destination_p = "./example-networks-sim-unidirec/" + sys.argv[1]
3434

3535
print("Opening files ...")
3636
old_graph = nx.read_graphml(origin_p + "/network/tracks.graphml")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"('switch_center', 'v6')": [["v6", "v7"]],
3+
"('v1', 'v2')": [["v2", "v3"]],
4+
"('v10', 'v11')": [],
5+
"('v2', 'v3')": [
6+
["v3", "v4"],
7+
["v3", "v4b"]
8+
],
9+
"('v3', 'v4')": [["v4", "v5"]],
10+
"('v3', 'v4b')": [["v4b", "v5b"]],
11+
"('v4', 'v5')": [["v5", "v6"]],
12+
"('v4b', 'v5b')": [["v5b", "v6b"]],
13+
"('v5', 'v6')": [["v6", "v7"]],
14+
"('v5b', 'v6b')": [
15+
["v6b", "v7b"],
16+
["v6b", "switch_center"]
17+
],
18+
"('v6', 'v7')": [["v7", "v8"]],
19+
"('v6b', 'switch_center')": [["switch_center", "v6"]],
20+
"('v6b', 'v7b')": [["v7b", "v8b"]],
21+
"('v7', 'v8')": [["v8", "v9"]],
22+
"('v7b', 'v8b')": [["v8b", "v9"]],
23+
"('v8', 'v9')": [["v9", "v10"]],
24+
"('v8b', 'v9')": [["v9", "v10"]],
25+
"('v9', 'v10')": [["v10", "v11"]],
26+
"('v3', 'v2')": [
27+
["v2", "v1"],
28+
["v2", "v1"]
29+
],
30+
"('v4', 'v3')": [
31+
["v3", "v2"],
32+
["v3", "v2"]
33+
],
34+
"('v4b', 'v3')": [
35+
["v3", "v2"],
36+
["v3", "v2"]
37+
],
38+
"('v5', 'v4')": [
39+
["v4", "v3"],
40+
["v4", "v3"]
41+
],
42+
"('v5b', 'v4b')": [
43+
["v4b", "v3"],
44+
["v4b", "v3"]
45+
],
46+
"('v6', 'v5')": [
47+
["v5", "v4"],
48+
["v5", "v4"]
49+
],
50+
"('v7', 'v6')": [
51+
["v6", "v5"],
52+
["v6", "switch_center"],
53+
["v6", "v5"],
54+
["v6", "switch_center"]
55+
],
56+
"('v8', 'v7')": [
57+
["v7", "v6"],
58+
["v7", "v6"]
59+
],
60+
"('v9', 'v8')": [
61+
["v8", "v7"],
62+
["v8", "v7"]
63+
],
64+
"('v10', 'v9')": [
65+
["v9", "v8"],
66+
["v9", "v8"],
67+
["v9", "v8b"],
68+
["v9", "v8b"]
69+
],
70+
"('v11', 'v10')": [
71+
["v10", "v9"],
72+
["v10", "v9"]
73+
],
74+
"('v6b', 'v5b')": [
75+
["v5b", "v4b"],
76+
["v5b", "v4b"]
77+
],
78+
"('v7b', 'v6b')": [
79+
["v6b", "v5b"],
80+
["v6b", "v5b"]
81+
],
82+
"('switch_center', 'v6b')": [
83+
["v6b", "v5b"],
84+
["v6b", "v5b"]
85+
],
86+
"('v8b', 'v7b')": [
87+
["v7b", "v6b"],
88+
["v7b", "v6b"]
89+
],
90+
"('v6', 'switch_center')": [
91+
["switch_center", "v6b"],
92+
["switch_center", "v6b"]
93+
],
94+
"('v9', 'v8b')": [
95+
["v8b", "v7b"],
96+
["v8b", "v7b"]
97+
]
98+
}

0 commit comments

Comments
 (0)