Skip to content

Commit

Permalink
Add option to use congested transit assignment every iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
samakinen committed Oct 28, 2024
1 parent 0f50606 commit 2eb5906
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
16 changes: 8 additions & 8 deletions Scripts/assignment/assignment_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,30 +124,30 @@ def assign(self, matrices: dict, iteration: Union[int,str]) -> Dict:
self._calc_background_traffic()
self._assign_cars(param.stopping_criteria_coarse)
self._calc_extra_wait_time()
self._assign_transit()
self._assign_congested_transit() if param.always_congested else self._assign_transit()
elif iteration==0:
self._set_car_and_transit_vdfs()
if not self._separate_emme_scenarios:
self._calc_background_traffic()
self._assign_cars(param.stopping_criteria_coarse)
self._calc_extra_wait_time()
self._assign_transit()
self._assign_congested_transit() if param.always_congested else self._assign_transit()
elif iteration==1:
if not self._separate_emme_scenarios:
self._set_car_and_transit_vdfs()
self._calc_background_traffic()
self._assign_cars(param.stopping_criteria_coarse)
self._calc_extra_wait_time()
self._assign_transit()
self._calc_background_traffic(include_trucks=True)
self._assign_congested_transit()
self._assign_congested_transit() if param.always_congested else self._assign_transit()
elif isinstance(iteration, int) and iteration>1:
if not self._separate_emme_scenarios:
self._set_car_and_transit_vdfs()
self._calc_background_traffic(include_trucks=True)
self._assign_cars(
param.stopping_criteria_coarse, lightweight=True)
self._calc_extra_wait_time()
self._assign_transit()
self._assign_congested_transit() if param.always_congested else self._assign_transit()
elif iteration=="last":
self._set_bike_vdfs()
self._assign_bikes(self.emme_matrices["bike"]["dist"], "all")
Expand Down Expand Up @@ -424,7 +424,7 @@ def _set_emmebank_matrices(self,
tmp_mtx = {
"bike": 0,
}
if not is_last_iteration:
if not (param.always_congested or is_last_iteration):
tmp_mtx["transit"] = 0
for mtx in matrices:
mode = mtx.split('_')[0]
Expand Down Expand Up @@ -474,15 +474,15 @@ def _get_matrices(self,
matrices = {}
for ass_class, mtx_types in self.emme_matrices.items():
if (mtx_type in mtx_types and
(is_last_iteration or ass_class not in last_iter_classes)):
(param.always_congested or is_last_iteration or ass_class not in last_iter_classes)):
if mtx_type == "time" and ass_class in param.assignment_modes:
mtx = self._extract_timecost_from_gcost(ass_class)
elif mtx_type == "time" and ass_class in param.transit_classes:
mtx = self._damp_travel_time(ass_class)
else:
mtx = self._get_matrix(ass_class, mtx_type)
matrices[ass_class] = mtx
if not is_last_iteration:
if not (param.always_congested or is_last_iteration):
matrices["transit_leisure"] = matrices["transit_work"]
return matrices

Expand Down
7 changes: 4 additions & 3 deletions Scripts/modelsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _add_internal_demand(self, previous_iter_impedance, is_last_iteration):
purpose_impedance = self.imptrans.transform(
purpose, previous_iter_impedance)
purpose.generate_tours()
if is_last_iteration:
if param.always_congested or is_last_iteration:
for mode in purpose.model.dest_choice_param:
self._distribute_sec_dests(
purpose, mode, purpose_impedance)
Expand Down Expand Up @@ -322,7 +322,8 @@ def run_iteration(self, previous_iter_impedance, iteration=None):
impedance[tp] = ap.assign(self.dtm.demand[tp], iteration)
if tp == "aht":
self._update_ratios(impedance[tp], tp)
if iteration=="last":
if iteration=="last": # TODO: Get uncongested time from assignment results
log.warn('TODO: Get uncongested transit time from the assignment results')
impedance[tp]["time"]["transit_uncongested"] = previous_iter_impedance[tp]["time"]["transit_work"]
self._save_to_omx(impedance[tp], tp)
if iteration=="last":
Expand Down Expand Up @@ -594,7 +595,7 @@ def _add_internal_demand(self, previous_iter_impedance, is_last_iteration):
elif nr_threads <= 0:
nr_threads = 1
bounds = next(iter(purpose.sources)).bounds
modes = purpose.modes if is_last_iteration else ["car"]
modes = purpose.modes if param.always_congested or is_last_iteration else ["car"]
for mode in modes:
threads = []
for i in range(nr_threads):
Expand Down

0 comments on commit 2eb5906

Please sign in to comment.