Skip to content

Commit 2be00cd

Browse files
committed
fix bugs in load_columns() and total_travel_time
- node path and link path shall be reversed in the loading process; - check if a loaded column is existing following the same logic in colgen.py; - fix bug in computing the total system travel time in _update_column_gradient_cost_and_flow(), where total_travel_time shall be updated before shifting flow.
1 parent 01227b8 commit 2be00cd

File tree

3 files changed

+40
-45
lines changed

3 files changed

+40
-45
lines changed

path4gmns/colgen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def _update_column_gradient_cost_and_flow(column_pool, links, agent_types, iter_
113113

114114
if least_gradient_cost_path_id != -1:
115115
col = cv.get_column(least_gradient_cost_path_id)
116-
col.increase_volume(total_switched_out_path_vol)
117116
total_travel_time += col.get_sys_travel_time()
117+
col.increase_volume(total_switched_out_path_vol)
118118

119119
rel_gap = total_gap / max(total_travel_time, SMALL_DIVISOR)
120120

path4gmns/utils.py

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,63 +1052,56 @@ def load_columns(ui, input_dir='.'):
10521052
continue
10531053

10541054
cv = A.get_column_vec(at, dp, oz_id, dz_id)
1055+
path_id = cv.get_column_num()
1056+
col = Column(path_id)
10551057

1056-
node_path = None
10571058
try:
1058-
# "if x" check is only needed for columns generated from DTALite,
1059+
col.nodes = [A.get_node_no(int(x)) for x in reversed(node_seq.split(';')) if x]
1060+
except KeyError:
1061+
raise Exception(
1062+
'Invalid node found on column!!'
1063+
'Did you use agent.csv from a different network?'
1064+
)
1065+
1066+
try:
1067+
# if x is only needed for columns generated from DTALite,
10591068
# which have the trailing ';' and leads to '' after split
1060-
node_path = [int(x) for x in node_seq.split(';') if x]
1069+
col.links = [
1070+
A.get_link_seq_no(x) for x in reversed(link_seq.split(';')) if x
1071+
]
1072+
except KeyError:
1073+
raise Exception(
1074+
'INVALID link found on column!!'
1075+
'Did you use agent.csv from a different network?'
1076+
)
10611077
except ValueError:
10621078
raise Exception(
1063-
f'INVALID NODE PATH found for agent id: {agent_id}'
1079+
f'INVALID LINK PATH found for agent id: {agent_id}'
10641080
)
10651081

1082+
# the following four are non-critical info
1083+
col.set_volume(vol)
1084+
col.set_toll(toll)
1085+
col.set_travel_time(tt)
1086+
col.set_geometry(geo)
1087+
10661088
# deprecate node_sum and adopt the same implementation in colgen.py
10671089
existing = False
1068-
for col in cv.get_columns():
1069-
if col.get_nodes() == node_path:
1070-
col.increase_volume(vol)
1071-
existing = True
1072-
break
10731090

1074-
if not existing:
1075-
path_id = cv.get_column_num()
1076-
col = Column(path_id)
1091+
if dist == 0:
1092+
sum(A.get_link(x).get_length() for x in col.links)
10771093

1078-
try:
1079-
col.nodes = [A.get_node_no(x) for x in node_path]
1080-
except KeyError:
1081-
raise Exception(
1082-
'Invalid node found on column!!'
1083-
'Did you use agent.csv from a different network?'
1084-
)
1085-
1086-
try:
1087-
# if x is only needed for columns generated from DTALite,
1088-
# which have the trailing ';' and leads to '' after split
1089-
col.links = [
1090-
A.get_link_seq_no(x) for x in link_seq.split(';') if x
1091-
]
1092-
except KeyError:
1093-
raise Exception(
1094-
'INVALID link found on column!!'
1095-
'Did you use agent.csv from a different network?'
1096-
)
1097-
except ValueError:
1098-
raise Exception(
1099-
f'INVALID LINK PATH found for agent id: {agent_id}'
1100-
)
1094+
for col_ in cv.get_columns():
1095+
if col_.get_distance() != dist:
1096+
continue
11011097

1102-
# the following four are non-critical info
1103-
col.set_volume(vol)
1104-
col.set_toll(toll)
1105-
col.set_travel_time(tt)
1106-
col.set_geometry(geo)
1098+
if col_.get_links() == col.links:
1099+
col_.increase_volume(vol)
1100+
existing = True
1101+
break
11071102

1108-
if dist == 0:
1109-
sum(A.get_link(x).get_length() for x in col.links)
1103+
if not existing:
11101104
col.set_distance(dist)
1111-
11121105
cv.add_new_column(col)
11131106

11141107
update_links_using_columns(ui)

tests/demo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ def test_simulation():
225225
column_gen_num = 10
226226
column_update_num = 10
227227
pg.perform_column_generation(column_gen_num, column_update_num, network)
228+
229+
# pg.load_columns(network)
228230
pg.perform_simple_simulation(network, 'uniform')
229231
print('complete simple simulation.\n')
230232

@@ -279,4 +281,4 @@ def demo_mode(mode):
279281

280282
if __name__=="__main__":
281283

282-
demo_mode(3)
284+
demo_mode(10)

0 commit comments

Comments
 (0)