-
Notifications
You must be signed in to change notification settings - Fork 17
/
scripts_i210.py
197 lines (162 loc) · 6.72 KB
/
scripts_i210.py
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
from process_data import extract_features, process_links, geojson_link, \
process_net
from frank_wolfe import solver_3
import numpy as np
from metrics import cost_ratio, cost, save_metrics
# from heterogeneous_solver import gauss_seidel, jacobi
from multi_types_solver import parametric_study
from utils import multiply_cognitive_cost
def load_I210():
net = np.loadtxt('data/I210_net.csv', delimiter=',', skiprows=1)
demand = np.loadtxt('data/I210_od.csv', delimiter=',', skiprows=1)
node = np.loadtxt('data/I210_node.csv', delimiter=',', skiprows=1)
geometry = extract_features('data/I210Sketch_net.csv')
demand = np.reshape(demand, (1, 3))
return net, demand, node, geometry
def process_I210_net():
process_net('data/I210Sketch_net.csv', 'data/I210_net.csv')
def frank_wolfe_on_I210():
'''
Frank-Wolfe on I210
'''
graph = np.loadtxt('data/I210_net.csv', delimiter=',', skiprows=1)
demand = np.loadtxt('data/I210_od.csv', delimiter=',', skiprows=1)
demand[:, 2] = 1. * demand[:, 2] / 4000
# run solver
f = solver_3(graph, demand, max_iter=1000, q=50, display=1, stop=1e-2)
# display cost
for a, b in zip(cost(f, graph), f * 4000):
print a, b
# visualization
node = np.loadtxt('data/I210_node.csv', delimiter=',', skiprows=1)
# extract features: 'capacity', 'length', 'fftt'
feat = extract_features('data/I210Sketch_net.csv')
ratio = cost_ratio(f, graph)
# merge features with the cost ratios
features = np.zeros((feat.shape[0], 4))
features[:, :3] = feat
features[:, 3] = ratio
# join features with (lat1,lon1,lat2,lon2)
links = process_links(graph, node, features)
color = features[:, 3] # we choose the costs
names = ['capacity', 'length', 'fftt', 'tt_over_fftt']
geojson_link(links, names, color)
def I210_ratio_r_total():
'''
study the test_*.csv files generated by I210_parametric_study()
in particular, visualize the ratio each type of users on each link
'''
fs = np.loadtxt('data/test_50.csv', delimiter=',', skiprows=0)
ratio = np.divide(fs[:, 1], np.maximum(np.sum(fs, axis=1), 1e-8))
net = np.loadtxt('data/I210_net.csv', delimiter=',', skiprows=1)
node = np.loadtxt('data/I210_node.csv', delimiter=',', skiprows=1)
geometry = extract_features('data/I210Sketch_net.csv')
features = np.zeros((fs.shape[0], 4))
features[:, :3] = geometry
features[:, 3] = ratio
links = process_links(net, node, features)
color = 2 * ratio # we choose the ratios of nr over r+nr
geojson_link(links, ['capacity', 'length', 'fftt', 'r_routed'], color)
# print(fs)
# for a,b in zip(cost(f, graph), f*4000): print a,b
def I210_parametric_study(alphas):
g, d, node, geom = load_I210()
d[:, 2] = d[:, 2] / 4000.
parametric_study(alphas, g, d, node, geom, 3000., 100.,
'data/I210/test_{}.csv', stop=1e-3, stop_cycle=1e-3)
def I210_metrics(alphas):
net, d, node, features = load_I210()
d[:, 2] = d[:, 2] / 4000.
net2, small_capacity = multiply_cognitive_cost(net, features, 3000., 100.)
save_metrics(alphas, net, net2, d, features, small_capacity,
'data/I210/test_{}.csv', 'data/I210/out.csv', skiprows=1)
def I210_path_choices(alphas):
out = np.zeros((len(alphas), 4))
for i, alpha in enumerate(alphas):
f_r = np.loadtxt('data/I210/test_{}.csv'.format(int(alpha * 100)),
delimiter=',',
skiprows=1)[:, 1]
out[i, 0] = alpha
if f_r[12] > 0.:
out[i, 3] = f_r[12] * 4000. # flow middle path
if f_r[0] > 0.:
out[i, 2] = f_r[0] * 4000. # flow up path
if f_r[13] > 0.:
out[i, 1] = f_r[13] * 4000. # flow low path
np.savetxt('data/I210/path_flows_routed.csv', out, delimiter=',',
header='ratio_routed,low_path,hi_path,mid_path', comments='')
def check_results():
# check highest ration of tt / fftt (should be less than 5)
net, d, node, features = load_I210()
f = np.loadtxt('data/I210/test_0.csv', delimiter=',')
print np.max(cost_ratio(f, net))
def I210_ratio_r_nr(alpha):
'''
study the test_*.csv files generated by chicago_parametric_study()
in particular, visualize the ratio each type of users on each link
#ratio of non-routed over total for each link
'''
fs = np.loadtxt(
'data/I210/test_{}.csv'.format(int(alpha * 100)),
delimiter=',', skiprows=0)
ratio = np.divide(fs[:, 1], np.maximum(np.sum(fs, axis=1), 1e-8))
net, demand, node, geometry = load_I210()
features = np.zeros((fs.shape[0], 4))
features[:, :3] = geometry
features[:, 3] = ratio
links = process_links(net, node, features, in_order=True)
color = 5. * ratio # we choose the ratios of nr over r+nr
geojson_link(links, ['capacity', 'length', 'fftt', 'r_non_routed'], color)
def visual(alpha):
'''
study the test_*.csv files generated by chicago_parametric_study()
in particular, visualize the ratio each type of users on each link
ratio of non-routed over total for each link
'''
fs = np.loadtxt(
'data/I210/test_{}.csv'.format(int(alpha * 100)),
delimiter=',', skiprows=0)
f_total = 4000 * np.sum(fs, axis=1)
color = np.zeros(len(f_total))
# v_max = 30000
v_thres = 6000
for i in range(len(f_total)):
if f_total[i] <= v_thres:
color[i] = 1
# elif f_total[i]<=2*v_thres:
# color[i]=2
# elif f_total[i]<=3*v_thres:
# color[i]=3
# elif f_total[i]<=4*v_thres:
# color[i]=4
else:
color[i] = 5
print(np.mean(color))
net, demand, node, geometry = load_I210()
features = np.zeros((fs.shape[0], 4))
features[:, :3] = geometry
features[:, 3] = f_total
links = process_links(net, node, features, in_order=True)
# color = 5. * ratio # we choose the ratios of nr over r+nr
geojson_link(links, ['capacity', 'length', 'fftt', 'r_non_routed'], color)
def I210_capacities():
net, demand, node, features = load_I210()
links = process_links(net, node, features)
color = 2. * (features[:, 0] <= 3000.) + 5. * (features[:, 0] > 3000.)
weight = (features[:, 0] <= 3000.) + 2. * (features[:, 0] > 3000.)
geojson_link(links, ['capacity', 'length', 'fftt'], color, 2. * weight)
def main():
# process_I210_net()
# frank_wolfe_on_I210()
# I210_parametric_study()
# I210_ratio_r_total()
# I210_parametric_study_2()
I210_parametric_study(np.linspace(0, .25, 26))
I210_metrics(np.linspace(0, .25, 26))
# 210_ratio_r_nr(0.9)
# visual(0.5)
# check_results()
# I210_path_choices(np.linspace(0,.25,26))
# I210_capacities()
if __name__ == '__main__':
main()