Skip to content

Commit

Permalink
Merge pull request #635 from camsys/develop
Browse files Browse the repository at this point in the history
Composite - Disaggregate Accessibility
  • Loading branch information
jpn-- authored Jan 28, 2023
2 parents 71d3e91 + 5eebf18 commit 28ff447
Show file tree
Hide file tree
Showing 117 changed files with 14,677 additions and 623 deletions.
4 changes: 4 additions & 0 deletions activitysim/abm/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# flake8: noqa
# ActivitySim
# See full license in LICENSE.txt.

from . import (
accessibility,
atwork_subtour_destination,
Expand All @@ -8,6 +10,7 @@
atwork_subtour_scheduling,
auto_ownership,
cdap,
disaggregate_accessibility,
free_parking,
initialize,
initialize_los,
Expand All @@ -24,6 +27,7 @@
non_mandatory_scheduling,
non_mandatory_tour_frequency,
parking_location_choice,
school_escorting,
stop_frequency,
summarize,
telecommute_frequency,
Expand Down
763 changes: 763 additions & 0 deletions activitysim/abm/models/disaggregate_accessibility.py

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions activitysim/abm/models/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pandas as pd

from activitysim.abm.tables import shadow_pricing
from activitysim.abm.tables import shadow_pricing, disaggregate_accessibility
from activitysim.core import chunk, config, expressions, inject, mem, pipeline, tracing
from activitysim.core.steps.output import (
track_skim_usage,
Expand Down Expand Up @@ -141,7 +141,8 @@ def initialize_households():
add_size_tables = model_settings.get("add_size_tables", True)
if add_size_tables:
# warnings.warn(f"Calling add_size_tables from initialize will be removed in the future.", FutureWarning)
shadow_pricing.add_size_tables()
suffixes = inject.get_injectable("disaggregate_suffixes")
shadow_pricing.add_size_tables(suffixes)

# - preload person_windows
person_windows = inject.get_table("person_windows").to_frame()
Expand Down
5 changes: 5 additions & 0 deletions activitysim/abm/models/location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def aggregate_size_terms(dest_size_terms, network_los, model_settings):
"size_term": "sum",
"shadow_price_size_term_adjustment": "sum",
"shadow_price_utility_adjustment": "sum",
"avail_MAZ": "sum",
}
)

Expand Down Expand Up @@ -552,6 +553,7 @@ def run_location_simulate(
chunk_size,
chunk_tag,
trace_label,
skip_choice=False,
):
"""
run location model on location_sample annotated with mode_choice logsum
Expand Down Expand Up @@ -628,6 +630,7 @@ def run_location_simulate(
trace_label=trace_label,
trace_choice_name=model_settings["DEST_CHOICE_COLUMN_NAME"],
estimator=estimator,
skip_choice=skip_choice,
)

if not want_logsums:
Expand All @@ -652,6 +655,7 @@ def run_location_choice(
chunk_tag,
trace_hh_id,
trace_label,
skip_choice=False,
):
"""
Run the three-part location choice algorithm to generate a location choice for each chooser
Expand Down Expand Up @@ -750,6 +754,7 @@ def run_location_choice(
trace_label=tracing.extend_trace_label(
trace_label, "simulate.%s" % segment_name
),
skip_choice=skip_choice,
)

if estimator:
Expand Down
29 changes: 27 additions & 2 deletions activitysim/abm/models/non_mandatory_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from activitysim.core import config, inject, pipeline, simulate, tracing
from activitysim.core.util import assign_in_place

from .util import estimation, tour_destination
from .util import estimation, tour_destination, annotate


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -43,7 +44,18 @@ def non_mandatory_tour_destination(
# choosers are tours - in a sense tours are choosing their destination
non_mandatory_tours = tours[tours.tour_category == "non_mandatory"]

# - if no mandatory_tours
# separating out pure escort school tours
# they already have their destination set
if pipeline.is_table("school_escort_tours"):
nm_tour_index = non_mandatory_tours.index
pure_school_escort_tours = non_mandatory_tours[
(non_mandatory_tours["school_esc_outbound"] == "pure_escort")
| (non_mandatory_tours["school_esc_inbound"] == "pure_escort")
]
non_mandatory_tours = non_mandatory_tours[
~non_mandatory_tours.index.isin(pure_school_escort_tours.index)
]

if non_mandatory_tours.shape[0] == 0:
tracing.no_results(trace_label)
return
Expand Down Expand Up @@ -85,14 +97,27 @@ def non_mandatory_tour_destination(

non_mandatory_tours["destination"] = choices_df.choice

# merging back in school escort tours and preserving index
if pipeline.is_table("school_escort_tours"):
non_mandatory_tours = pd.concat(
[pure_school_escort_tours, non_mandatory_tours]
).set_index(nm_tour_index)

assign_in_place(tours, non_mandatory_tours[["destination"]])

if want_logsums:
non_mandatory_tours[logsum_column_name] = choices_df["logsum"]
assign_in_place(tours, non_mandatory_tours[[logsum_column_name]])

assert all(
~tours["destination"].isna()
), f"Tours are missing destination: {tours[tours['destination'].isna()]}"

pipeline.replace_table("tours", tours)

if model_settings.get("annotate_tours"):
annotate.annotate_tours(model_settings, trace_label)

if want_sample_table:
assert len(save_sample_df.index.get_level_values(0).unique()) == len(choices_df)
# save_sample_df.set_index(model_settings['ALT_DEST_COL_NAME'], append=True, inplace=True)
Expand Down
3 changes: 0 additions & 3 deletions activitysim/abm/models/non_mandatory_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
from activitysim.core import timetable as tt
from activitysim.core import tracing
from activitysim.core.util import assign_in_place

from .util import estimation
from .util.tour_scheduling import run_tour_scheduling
from .util.vectorize_tour_scheduling import vectorize_tour_scheduling

logger = logging.getLogger(__name__)
DUMP = False
Expand Down
10 changes: 10 additions & 0 deletions activitysim/abm/models/non_mandatory_tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
from activitysim.core.interaction_simulate import interaction_simulate

from .util import estimation
from .util import annotate
from .util.school_escort_tours_trips import recompute_tour_count_statistics

from .util.overlap import person_max_window
from .util.tour_frequency import process_non_mandatory_tours

Expand Down Expand Up @@ -376,6 +379,13 @@ def non_mandatory_tour_frequency(persons, persons_merged, chunk_size, trace_hh_i
tracing.register_traceable_table("tours", non_mandatory_tours)
pipeline.get_rn_generator().add_channel("tours", non_mandatory_tours)

if pipeline.is_table("school_escort_tours"):
# need to re-compute tour frequency statistics to account for school escort tours
recompute_tour_count_statistics()

if model_settings.get("annotate_tours"):
annotate.annotate_tours(model_settings, trace_label)

expressions.assign_columns(
df=persons,
model_settings=model_settings.get("annotate_persons"),
Expand Down
Loading

0 comments on commit 28ff447

Please sign in to comment.