@@ -273,12 +273,14 @@ def destination_sample(
273273 return choices
274274
275275
276- def aggregate_size_term_matrix (maz_size_term_matrix , network_los ):
276+ def aggregate_size_term_matrix (maz_size_term_matrix , network_los , all_tazs = None ):
277277 df = maz_size_term_matrix .df
278278 assert ALT_DEST_TAZ not in df
279279
280280 dest_taz = network_los .map_maz_to_taz (df .index )
281281 taz_size_term_matrix = df .groupby (dest_taz ).sum ()
282+ if all_tazs is not None :
283+ taz_size_term_matrix = taz_size_term_matrix .reindex (all_tazs , fill_value = 0 ).rename_axis (taz_size_term_matrix .index .name , axis = 0 )
282284
283285 taz_size_term_matrix = DataFrameMatrix (taz_size_term_matrix )
284286
@@ -612,7 +614,14 @@ def destination_presample(
612614
613615 alt_dest_col_name = model_settings .ALT_DEST_COL_NAME
614616
615- TAZ_size_term_matrix = aggregate_size_term_matrix (size_term_matrix , network_los )
617+ if state .settings .sharrow :
618+ # when using sharrow, we use the skim_dataset structure, and need to ensure
619+ # that all TAZs are represented in the size_term_matrix, even those with no MAZs
620+ all_tazs = state .get_dataframe ("land_use_taz" ).index
621+ else :
622+ all_tazs = None
623+
624+ TAZ_size_term_matrix = aggregate_size_term_matrix (size_term_matrix , network_los , all_tazs )
616625
617626 TRIP_ORIGIN = model_settings .TRIP_ORIGIN
618627 PRIMARY_DEST = model_settings .PRIMARY_DEST
@@ -627,6 +636,15 @@ def destination_presample(
627636 network_los .map_maz_to_taz (alternatives .index )
628637 ).sum ()
629638
639+ # We now have aggregated alternatives indexed by TAZ instead of MAZ.
640+ # For sharrow, we need the TAZ indexing to be "complete", i.e. include all TAZ ids,
641+ # even those that had no MAZs (and so were missing from the aggregation result).
642+ # this is needed because we are going to taking the entire set of TAZ alternatives
643+ # as a vector which will need to align with the TAZ skims.
644+ if state .settings .sharrow :
645+ all_tazs = state .get_dataframe ("land_use_taz" ).index
646+ alternatives = alternatives .reindex (all_tazs , fill_value = 0 ).rename_axis (alternatives .index .name , axis = 0 )
647+
630648 # # i did this but after changing alt_dest_col_name to 'trip_dest' it
631649 # # shouldn't be needed anymore
632650 # alternatives.index.name = ALT_DEST_TAZ
0 commit comments