Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "vitm"]
path = vitm
url = https://github.com/VictoriaTransport/activitysim-vitm.git
19 changes: 19 additions & 0 deletions activitysim/abm/models/mandatory_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging

import numpy as np
import pandas as pd

from activitysim.abm.models.util.tour_scheduling import run_tour_scheduling
Expand Down Expand Up @@ -53,6 +54,24 @@ def mandatory_tour_scheduling(
~is_university_tour, "univ"
)

# split work purpose into work_white_collar and work_blue_collar which have different coefficients
mandatory_tours[tour_segment_col] = np.where((mandatory_tours.tour_type == 'work') &
(reindex(persons_merged['work_segment'].isin([1,2,3,4]), mandatory_tours.person_id)),
'work_white_collar', mandatory_tours[tour_segment_col])

mandatory_tours[tour_segment_col] = np.where((mandatory_tours.tour_type == 'work') &
(reindex((persons_merged['work_segment'] == 5), mandatory_tours.person_id)),
'work_blue_collar', mandatory_tours[tour_segment_col])

# split school purpose into school_primary and school_secondary which have different coefficients
mandatory_tours[tour_segment_col] = np.where((mandatory_tours.tour_type == 'school') &
(reindex(persons_merged.is_primary_student, mandatory_tours.person_id)),
'school_primary', mandatory_tours[tour_segment_col])

mandatory_tours[tour_segment_col] = np.where((mandatory_tours.tour_type == 'school') &
(reindex(persons_merged.is_secondary_student, mandatory_tours.person_id)),
'school_secondary', mandatory_tours[tour_segment_col])

choices = run_tour_scheduling(
state,
model_name,
Expand Down
14 changes: 14 additions & 0 deletions activitysim/abm/models/tour_mode_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,20 @@ def tour_mode_choice_simulate(
not_university, "univ"
)

# split work purpose into work_white_collar and work_blue_collar which have different coefficients
primary_tours_merged['tour_purpose'] = np.where((primary_tours_merged['tour_purpose'] == 'work') &
(primary_tours_merged['work_segment'].isin([1,2,3,4])), 'work_white_collar', primary_tours_merged['tour_purpose'])

primary_tours_merged['tour_purpose'] = np.where((primary_tours_merged['tour_purpose'] == 'work') &
(primary_tours_merged['work_segment'] == 5), 'work_blue_collar', primary_tours_merged['tour_purpose'])

# split school purpose into school_primary and school_secondary which have different coefficients
primary_tours_merged['tour_purpose'] = np.where((primary_tours_merged['tour_purpose'] == 'school') &
(primary_tours_merged.is_primary_student), 'school_primary', primary_tours_merged['tour_purpose'])

primary_tours_merged['tour_purpose'] = np.where((primary_tours_merged['tour_purpose'] == 'school') &
(primary_tours_merged.is_secondary_student), 'school_secondary', primary_tours_merged['tour_purpose'])

# if trip logsums are used, run trip mode choice and append the logsums
if model_settings.COMPUTE_TRIP_MODE_CHOICE_LOGSUMS:
primary_tours_merged = get_trip_mc_logsums_for_all_modes(
Expand Down
5 changes: 4 additions & 1 deletion activitysim/abm/models/util/canonical_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ def determine_mandatory_tour_flavors(mtf_settings, model_spec, default_flavors):
# hard code work and school tours
"work": parse_tour_flavor_from_columns(model_spec.columns, "work"),
"school": parse_tour_flavor_from_columns(model_spec.columns, "school"),
"business": parse_tour_flavor_from_columns(model_spec.columns, "business"),
}

valid_flavors = (mandatory_tour_flavors["work"] >= 1) & (
mandatory_tour_flavors["school"] >= 1
) & (
mandatory_tour_flavors["business"] >= 1
)

if provided_flavors is not None:
Expand Down Expand Up @@ -264,7 +267,7 @@ def canonical_tours(state: workflow.State):
)
mtf_spec = mtf_model_settings.get("SPEC", "mandatory_tour_frequency.csv")
mtf_model_spec = read_alts_file(state, file_name=mtf_spec)
default_mandatory_tour_flavors = {"work": 2, "school": 2}
default_mandatory_tour_flavors = {"work": 2, "school": 2, "business": 2}

mandatory_tour_flavors = determine_mandatory_tour_flavors(
mtf_model_settings, mtf_model_spec, default_mandatory_tour_flavors
Expand Down
17 changes: 14 additions & 3 deletions activitysim/abm/models/util/tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def process_mandatory_tours(
"workplace_zone_id",
"home_zone_id",
"household_id",
"business_zone_id",
]
assert not persons.mandatory_tour_frequency.isnull().any()

Expand Down Expand Up @@ -249,10 +250,20 @@ def process_mandatory_tours(
)

# work tours destination is workplace_zone_id, school tours destination is school_zone_id
tours["destination"] = tours_merged.workplace_zone_id.where(
(tours_merged.tour_type == "work"), tours_merged.school_zone_id
)
conditions = [
tours_merged.tour_type == "work",
tours_merged.tour_type == "school",
tours_merged.tour_type == "business"
]

choices = [
tours_merged.workplace_zone_id,
tours_merged.school_zone_id,
tours_merged.business_zone_id
]

tours["destination"] = np.select(conditions, choices, default=-1)

tours["origin"] = tours_merged.home_zone_id

tours["household_id"] = tours_merged.household_id
Expand Down
8 changes: 1 addition & 7 deletions activitysim/abm/tables/shadow_pricing.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,7 @@
default_segment_to_name_dict = {
# model_selector : persons_segment_name
"school": "school_segment",
"workplace": "income_segment",
}

default_segment_to_name_dict = {
# model_selector : persons_segment_name
"school": "school_segment",
"workplace": "income_segment",
"workplace": "work_segment",
}


Expand Down
4 changes: 3 additions & 1 deletion activitysim/core/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ def get_segment_coefficients(
coefficients_df = filesystem.read_model_coefficients(model_settings)
template_df = read_model_coefficient_template(filesystem, model_settings)
coefficients_col = (
template_df[segment_name].map(coefficients_df.value).astype(float)
template_df[segment_name].replace(coefficients_df.value).astype(float)
)

if coefficients_col.isnull().any():
Expand All @@ -430,6 +430,8 @@ def get_segment_coefficients(
assert not coefficients_col.isnull().any()

coefficients_dict = coefficients_col.to_dict()

coefficients_dict['SEGMENT_NAME'] = segment_name

return coefficients_dict

Expand Down
2 changes: 1 addition & 1 deletion conda-environments/activitysim-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies:
- ipykernel # so this env will appear in jupyter as a selection
- isort
- jupyterlab
- larch = 5.7.*
# - larch = 5.7.*
- matplotlib
- multimethod <2.0
- myst-parser # allows markdown in sphinx
Expand Down
1 change: 1 addition & 0 deletions vitm
Submodule vitm added at 5e80bf
Loading