Skip to content

Commit 40450ff

Browse files
committed
feat: implement work segment
1 parent 1781014 commit 40450ff

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

activitysim/abm/models/mandatory_scheduling.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import logging
66

7+
import numpy as np
78
import pandas as pd
89

910
from activitysim.abm.models.util.tour_scheduling import run_tour_scheduling
@@ -53,6 +54,24 @@ def mandatory_tour_scheduling(
5354
~is_university_tour, "univ"
5455
)
5556

57+
# split work purpose into work_white_collar and work_blue_collar which have different coefficients
58+
mandatory_tours[tour_segment_col] = np.where((mandatory_tours.tour_type == 'work') &
59+
(reindex(persons_merged['work_segment'].isin([1,2,3,4]), mandatory_tours.person_id)),
60+
'work_white_collar', mandatory_tours[tour_segment_col])
61+
62+
mandatory_tours[tour_segment_col] = np.where((mandatory_tours.tour_type == 'work') &
63+
(reindex((persons_merged['work_segment'] == 5), mandatory_tours.person_id)),
64+
'work_blue_collar', mandatory_tours[tour_segment_col])
65+
66+
# split school purpose into school_primary and school_secondary which have different coefficients
67+
mandatory_tours[tour_segment_col] = np.where((mandatory_tours.tour_type == 'school') &
68+
(reindex(persons_merged.is_primary_student, mandatory_tours.person_id)),
69+
'school_primary', mandatory_tours[tour_segment_col])
70+
71+
mandatory_tours[tour_segment_col] = np.where((mandatory_tours.tour_type == 'school') &
72+
(reindex(persons_merged.is_secondary_student, mandatory_tours.person_id)),
73+
'school_secondary', mandatory_tours[tour_segment_col])
74+
5675
choices = run_tour_scheduling(
5776
state,
5877
model_name,

activitysim/abm/models/tour_mode_choice.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,20 @@ def tour_mode_choice_simulate(
325325
not_university, "univ"
326326
)
327327

328+
# split work purpose into work_white_collar and work_blue_collar which have different coefficients
329+
primary_tours_merged['tour_purpose'] = np.where((primary_tours_merged['tour_purpose'] == 'work') &
330+
(primary_tours_merged['work_segment'].isin([1,2,3,4])), 'work_white_collar', primary_tours_merged['tour_purpose'])
331+
332+
primary_tours_merged['tour_purpose'] = np.where((primary_tours_merged['tour_purpose'] == 'work') &
333+
(primary_tours_merged['work_segment'] == 5), 'work_blue_collar', primary_tours_merged['tour_purpose'])
334+
335+
# split school purpose into school_primary and school_secondary which have different coefficients
336+
primary_tours_merged['tour_purpose'] = np.where((primary_tours_merged['tour_purpose'] == 'school') &
337+
(primary_tours_merged.is_primary_student), 'school_primary', primary_tours_merged['tour_purpose'])
338+
339+
primary_tours_merged['tour_purpose'] = np.where((primary_tours_merged['tour_purpose'] == 'school') &
340+
(primary_tours_merged.is_secondary_student), 'school_secondary', primary_tours_merged['tour_purpose'])
341+
328342
# if trip logsums are used, run trip mode choice and append the logsums
329343
if model_settings.COMPUTE_TRIP_MODE_CHOICE_LOGSUMS:
330344
primary_tours_merged = get_trip_mc_logsums_for_all_modes(

activitysim/core/simulate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def get_segment_coefficients(
418418
coefficients_df = filesystem.read_model_coefficients(model_settings)
419419
template_df = read_model_coefficient_template(filesystem, model_settings)
420420
coefficients_col = (
421-
template_df[segment_name].map(coefficients_df.value).astype(float)
421+
template_df[segment_name].replace(coefficients_df.value).astype(float)
422422
)
423423

424424
if coefficients_col.isnull().any():
@@ -430,6 +430,8 @@ def get_segment_coefficients(
430430
assert not coefficients_col.isnull().any()
431431

432432
coefficients_dict = coefficients_col.to_dict()
433+
434+
coefficients_dict['SEGMENT_NAME'] = segment_name
433435

434436
return coefficients_dict
435437

conda-environments/activitysim-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ dependencies:
2727
- ipykernel # so this env will appear in jupyter as a selection
2828
- isort
2929
- jupyterlab
30-
- larch = 5.7.*
30+
# - larch = 5.7.*
3131
- matplotlib
3232
- multimethod <2.0
3333
- myst-parser # allows markdown in sphinx

0 commit comments

Comments
 (0)