File tree Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -451,14 +451,22 @@ def joint_tour_participation(
451451 PARTICIPANT_COLS = ["tour_id" , "household_id" , "person_id" ]
452452 participants = candidates [participate ][PARTICIPANT_COLS ].copy ()
453453
454- # assign participant_num
455- # FIXME do we want something smarter than the participant with the lowest person_id?
456- participants ["participant_num" ] = (
457- participants .sort_values (by = ["tour_id" , "person_id" ])
458- .groupby ("tour_id" )
459- .cumcount ()
460- + 1
461- )
454+ if estimator :
455+ # In estimation mode, use participant_num from survey data to preserve consistency
456+ # with the original survey data. ActivitySim treats participant_num=1 as the tour
457+ # leader, so the joint tour in the tour table will be associated with the tour
458+ # leader's person_id. We merge participant_num from survey data using the
459+ # participant_id as the join key to ensure the correct tour leader is identified.
460+ participants ["participant_num" ] = survey_participants_df .reindex (participants .index )["participant_num" ]
461+ else :
462+ # assign participant_num
463+ # FIXME do we want something smarter than the participant with the lowest person_id?
464+ participants ["participant_num" ] = (
465+ participants .sort_values (by = ["tour_id" , "person_id" ])
466+ .groupby ("tour_id" )
467+ .cumcount ()
468+ + 1
469+ )
462470
463471 state .add_table ("joint_tour_participants" , participants )
464472
You can’t perform that action at this time.
0 commit comments