Skip to content

Commit b5a204b

Browse files
committed
continue optimizing column generation module
- rename _update_column_travel_time() to _update_column_attributes(); - move toll and travel time update for each column from _update_column_gradient_cost_and_flow() to _update_column_attributes() as they are not needed for column update at each iteration, which significantly improves the overall run time of the column generation module.
1 parent 18c8c7d commit b5a204b

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

path4gmns/colgen.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,12 @@ def _update_column_gradient_cost_and_flow(column_pool,
107107
least_gradient_cost_path_id = -1
108108

109109
for col in cv.get_columns():
110-
path_toll = 0
111110
path_gradient_cost = 0
112-
path_travel_time = 0
113111
# i is link sequence no
114-
for i in col.get_links():
115-
# 04/10/22, code optimization,
116-
# we only need to compute two of them
117-
# as generalized cost = toll + route choice cost + travel time
118-
# and route choice cost is always zero in the current implementation
119-
path_toll += links[i].get_toll()
120-
path_travel_time += (
121-
links[i].travel_time_by_period[tau]
122-
)
123-
path_gradient_cost += (
124-
links[i].get_generalized_cost(tau, vot)
125-
)
112+
path_gradient_cost = sum(
113+
links[i].get_generalized_cost(tau, vot) for i in col.links
114+
)
126115

127-
col.set_toll(path_toll)
128-
col.set_travel_time(path_travel_time)
129116
col.set_gradient_cost(path_gradient_cost)
130117

131118
if column_num == 1:
@@ -276,7 +263,8 @@ def _backtrace_shortest_path_tree(orig_node_no,
276263
cv.add_new_column(col)
277264

278265

279-
def _update_column_travel_time(column_pool, links):
266+
def _update_column_attributes(column_pool, links):
267+
""" update toll and travel time for each column """
280268
for k, cv in column_pool.items():
281269
# k = (at, dp, oz, dz)
282270
dp = k[1]
@@ -287,6 +275,11 @@ def _update_column_travel_time(column_pool, links):
287275
)
288276
col.set_travel_time(travel_time)
289277

278+
path_toll = sum(
279+
links[j].get_toll() for j in col.links
280+
)
281+
col.set_toll(path_toll)
282+
290283

291284
def _generate(spn, column_pool, iter_num):
292285
for node_id in spn.get_orig_nodes():
@@ -382,7 +375,7 @@ def perform_column_generation(column_gen_num, column_update_num, ui):
382375

383376
_update_link_travel_time_and_cost(links)
384377

385-
_update_column_travel_time(column_pool, links)
378+
_update_column_attributes(column_pool, links)
386379

387380

388381
def update_links_using_columns(network):

0 commit comments

Comments
 (0)