Skip to content

Commit

Permalink
Merge pull request #161 from BayAreaMetro/warmstart-options
Browse files Browse the repository at this point in the history
Use warmstart skim or warmstart demand
  • Loading branch information
i-am-sijia authored Jul 30, 2024
2 parents d4735bf + 77676e6 commit 975368e
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 274 deletions.
6 changes: 3 additions & 3 deletions tm2py/components/demand/prepare_demand.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,12 +677,12 @@ def _read_demand(self, file_config, time_period, skim_set, num_zones):
# Load demand from cross-referenced source file,
# the named demand model component under the key highway_demand_file
if (
self.controller.config.run.warmstart.warmstart
self.controller.config.warmstart.warmstart
and self.controller.iteration == 0
):
source = self.controller.config.run.warmstart
source = file_config["source"]
path = self.controller.get_abs_path(
source.household_transit_demand_file
self.controller.config[source].transit_demand_file
).__str__()
else:
source = file_config["source"]
Expand Down
28 changes: 21 additions & 7 deletions tm2py/components/network/highway/highway_assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,22 @@ def validate_inputs(self):
def run(self):
"""Run highway assignment."""
demand = PrepareHighwayDemand(self.controller)
if self.controller.iteration >= 0:
demand.run()
else:
if self.controller.iteration == 0:
self.highway_emmebank.zero_matrix
if self.controller.config.warmstart.warmstart:
if self.controller.config.warmstart.use_warmstart_demand:
demand.run()
else:
demand.run()

for time in self.time_period_names:
scenario = self.highway_emmebank.scenario(time)
with self._setup(scenario, time):
iteration = self.controller.iteration
warmstart = self.controller.config.warmstart.warmstart
assign_classes = [
AssignmentClass(c, time, iteration) for c in self.config.classes
AssignmentClass(c, time, iteration, warmstart)
for c in self.config.classes
]
if iteration > 0:
self._copy_maz_flow(scenario)
Expand Down Expand Up @@ -424,17 +430,19 @@ def _log_debug_report(self, scenario: EmmeScenario, time_period: str):
class AssignmentClass:
"""Highway assignment class, represents data from config and conversion to Emme specs."""

def __init__(self, class_config, time_period, iteration):
def __init__(self, class_config, time_period, iteration, warmstart):
"""Constructor of Highway Assignment class.
Args:
class_config (_type_): _description_
time_period (_type_): _description_
iteration (_type_): _description_
warmstart (bool): True if assigning warmstart demand
"""
self.class_config = class_config
self.time_period = time_period
self.iteration = iteration
self.warmstart = warmstart
self.name = class_config["name"].lower()
self.skims = class_config.get("skims", [])

Expand All @@ -451,7 +459,10 @@ def emme_highway_class_spec(self) -> EmmeHighwayClassSpec:
class specification used in the SOLA assignment.
"""
if self.iteration == 0:
demand_matrix = 'ms"zero"'
if not self.warmstart:
demand_matrix = 'ms"zero"'
else:
demand_matrix = f'mf"{self.time_period}_{self.name}"'
else:
demand_matrix = f'mf"{self.time_period}_{self.name}"'
class_spec = {
Expand Down Expand Up @@ -485,7 +496,10 @@ def emme_highway_class_spec_wo_pa(self) -> EmmeHighwayClassSpec:
class specification used in the SOLA assignment.
"""
if self.iteration == 0:
demand_matrix = 'ms"zero"'
if not self.warmstart:
demand_matrix = 'ms"zero"'
else:
demand_matrix = f'mf"{self.time_period}_{self.name}"'
else:
demand_matrix = f'mf"{self.time_period}_{self.name}"'
class_spec = {
Expand Down
Loading

0 comments on commit 975368e

Please sign in to comment.