From 91c5e6c6c957641f34c32615f305b127b62bba59 Mon Sep 17 00:00:00 2001 From: "jdlph@MBP" Date: Tue, 15 Aug 2023 20:24:35 -0400 Subject: [PATCH] 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. --- path4gmns/utils.py | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/path4gmns/utils.py b/path4gmns/utils.py index d91cbe5..961dcde 100644 --- a/path4gmns/utils.py +++ b/path4gmns/utils.py @@ -681,25 +681,17 @@ def read_demand_matrix(input_dir, agent_type_id, demand_period_id, at = agent_type_id dp = demand_period_id - total_agents = 0 + total_vol = 0 reader = csv.DictReader(fp) for line in reader: - try: - oz_id = _convert_str_to_int(line['od']) - except InvalidRecord: + oz_id = line['od'] + # o_zone_id does not exist in node.csv, discard it + if oz_id not in zone_to_node_dict.keys(): continue for dz_str, vol_str in line: - try: - dz_id = _convert_str_to_int(dz_str) - except InvalidRecord: - continue - - if oz_id == dz_id: - continue - - # o_zone_id does not exist in node.csv, discard it - if oz_id not in zone_to_node_dict.keys(): + dz_id = _convert_str_to_int(dz_str) + if dz_id == oz_id: continue # 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, f'DUPLICATE OD pair found between {oz_id} and {dz_id}' ) - total_agents += int(vol + 1) + total_vol += vol - print(f'the number of agents is {total_agents}') + print(f'the number of agents is {total_vol}') - if total_agents == 0: + if total_vol == 0: raise Exception( 'NO VALID OD VOLUME!! DOUBLE CHECK YOUR input_matrix.csv' )