Skip to content

Commit 91c5e6c

Browse files
committed
parse zone id as string in read_demand_matrix()
- rename total_agents to total_vol and drop the problematic way to update total_agents as total_agents += int(vol + 1), which will always lead to positive number even there is no OD demand from the input file.
1 parent f8c1bdd commit 91c5e6c

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

path4gmns/utils.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -681,25 +681,17 @@ def read_demand_matrix(input_dir, agent_type_id, demand_period_id,
681681
at = agent_type_id
682682
dp = demand_period_id
683683

684-
total_agents = 0
684+
total_vol = 0
685685
reader = csv.DictReader(fp)
686686
for line in reader:
687-
try:
688-
oz_id = _convert_str_to_int(line['od'])
689-
except InvalidRecord:
687+
oz_id = line['od']
688+
# o_zone_id does not exist in node.csv, discard it
689+
if oz_id not in zone_to_node_dict.keys():
690690
continue
691691

692692
for dz_str, vol_str in line:
693-
try:
694-
dz_id = _convert_str_to_int(dz_str)
695-
except InvalidRecord:
696-
continue
697-
698-
if oz_id == dz_id:
699-
continue
700-
701-
# o_zone_id does not exist in node.csv, discard it
702-
if oz_id not in zone_to_node_dict.keys():
693+
dz_id = _convert_str_to_int(dz_str)
694+
if dz_id == oz_id:
703695
continue
704696

705697
# d_zone_id does not exist in node.csv, discard it
@@ -725,11 +717,11 @@ def read_demand_matrix(input_dir, agent_type_id, demand_period_id,
725717
f'DUPLICATE OD pair found between {oz_id} and {dz_id}'
726718
)
727719

728-
total_agents += int(vol + 1)
720+
total_vol += vol
729721

730-
print(f'the number of agents is {total_agents}')
722+
print(f'the number of agents is {total_vol}')
731723

732-
if total_agents == 0:
724+
if total_vol == 0:
733725
raise Exception(
734726
'NO VALID OD VOLUME!! DOUBLE CHECK YOUR input_matrix.csv'
735727
)

0 commit comments

Comments
 (0)