Skip to content

Commit 8f13299

Browse files
committed
fix(jtp): Correct the participant_num assignment logic for estimation mode in joint tour participation
1 parent 335111b commit 8f13299

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

activitysim/abm/models/joint_tour_participation.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)