Skip to content

Commit

Permalink
Rename assignment events
Browse files Browse the repository at this point in the history
  • Loading branch information
samakinen committed Feb 6, 2025
1 parent 50d033c commit 9ccada3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
20 changes: 10 additions & 10 deletions Scripts/assignment/assignment_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self, name: str, emme_scenario: int,
self._separate_emme_scenarios = separate_emme_scenarios
self.emme_matrices = emme_matrices
self.dist_unit_cost = param.dist_unit_cost
self.on_emme_assignment_period_initialized(self)
self.event_handler.on_assignment_period_initialized(self)

def extra(self, attr: str) -> str:
"""Add prefix "@" and time-period suffix.
Expand Down Expand Up @@ -118,7 +118,7 @@ def assign(self, matrices: dict, iteration: Union[int,str]) -> Dict:
Type (time/cost/dist) : dict
Assignment class (car_work/transit/...) : numpy 2-d matrix
"""
self.event_handler.on_emme_assignment_started(self, iteration, matrices, self.emme_scenario)
self.event_handler.on_assignment_started(self, iteration, matrices, self.emme_scenario)
self._set_emmebank_matrices(matrices, iteration=="last")
if iteration=="init":
self._assign_pedestrians()
Expand Down Expand Up @@ -189,7 +189,7 @@ def assign(self, matrices: dict, iteration: Union[int,str]) -> Dict:
if iteration != "last":
for ass_cl in ("car_work", "car_leisure"):
mtxs["cost"][ass_cl] += self.dist_unit_cost * mtxs["dist"][ass_cl]
self.event_handler.on_emme_assignment_complete(self, iteration, matrices, mtxs, self.emme_scenario)
self.event_handler.on_assignment_complete(self, iteration, matrices, mtxs, self.emme_scenario)
return mtxs

def calc_transit_cost(self,
Expand Down Expand Up @@ -376,7 +376,7 @@ def _set_car_and_transit_vdfs(self):
link.modes |= {main_mode}
elif main_mode in link.modes:
link.modes -= {main_mode}
self.event_handler.on_emme_car_and_transit_vdfs_set(self, network)
self.event_handler.on_car_and_transit_vdfs_set(self, network)
self.emme_scenario.publish_network(network)

def _set_bike_vdfs(self):
Expand Down Expand Up @@ -419,7 +419,7 @@ def _set_bike_vdfs(self):
link.modes |= {main_mode}
elif main_mode in link.modes:
link.modes -= {main_mode}
self.event_handler.on_emme_bike_vdfs_set(self, network)
self.event_handler.on_bike_vdfs_set(self, network)
self.emme_scenario.publish_network(network)

def _set_emmebank_matrices(self,
Expand Down Expand Up @@ -574,7 +574,7 @@ def _calc_background_traffic(self, include_trucks: bool=False):
if include_trucks:
for ass_class in heavy:
link[background_traffic] += link[ass_class]
self.event_handler.on_emme_background_traffic_calculated(self, network)
self.event_handler.on_background_traffic_calculated(self, network)
self.emme_scenario.publish_network(network)

def _calc_road_cost(self):
Expand All @@ -586,7 +586,7 @@ def _calc_road_cost(self):
dist_cost = self.dist_unit_cost * link.length
link[self.extra("toll_cost")] = toll_cost
link[self.extra("total_cost")] = toll_cost + dist_cost
self.event_handler.on_emme_road_cost_calculated(self, network)
self.event_handler.on_road_cost_calculated(self, network)
self.emme_scenario.publish_network(network)

def _calc_boarding_penalties(self,
Expand All @@ -609,7 +609,7 @@ def _calc_boarding_penalties(self,
if missing_penalties:
missing_penalties_str: str = ", ".join(missing_penalties)
log.warn("No boarding penalty found for transit modes " + missing_penalties_str)
self.event_handler.on_emme_boarding_penalties_calculated(self, network)
self.event_handler.on_boarding_penalties_calculated(self, network)
self.emme_scenario.publish_network(network)

def _specify(self):
Expand Down Expand Up @@ -748,7 +748,7 @@ def _assign_pedestrians(self):
log.info("Pedestrian assignment started...")
self.emme_project.pedestrian_assignment(
specification=self.walk_spec, scenario=self.emme_scenario)
self.event_handler.on_emme_pedestrian_assignment_complete(self, self.emme_scenario)
self.event_handler.on_pedestrian_assignment_complete(self, self.emme_scenario)
log.info("Pedestrian assignment performed for scenario " + str(self.emme_scenario.id))

def _calc_extra_wait_time(self):
Expand Down Expand Up @@ -809,7 +809,7 @@ def _calc_extra_wait_time(self):
+ b["cspeed"]*cumulative_speed)
# Estimated waiting time addition caused by headway deviation
segment["@wait_time_dev"] = headway_sd**2 / (2.0*line[headway_attr])
self.event_handler.on_emme_transit_wait_time_calculated(self, network)
self.event_handler.on_transit_wait_time_calculated(self, network)
self.emme_scenario.publish_network(network)

def _assign_transit(self):
Expand Down
4 changes: 2 additions & 2 deletions Scripts/assignment/emme_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class EmmeAssignmentModel(AssignmentModel):
def __init__(self,
emme_context: EmmeProject,
first_scenario_id: int,
event_handler: EventHandler=None,
event_handler: EventHandler,
separate_emme_scenarios: bool=False,
save_matrices: bool=False,
time_periods: List[str]=param.time_periods,
Expand Down Expand Up @@ -100,7 +100,7 @@ def prepare_network(self,
tp, i*hundred + self.first_matrix_id, id_ten)
self.assignment_periods.append(AssignmentPeriod(
tp, scen_id, self.emme_project, emme_matrices,
separate_emme_scenarios=self.separate_emme_scenarios))
self._event_handler, separate_emme_scenarios=self.separate_emme_scenarios))
self._create_attributes(self.day_scenario, self._extra)
for ap in self.assignment_periods:
if car_dist_unit_cost is not None:
Expand Down
20 changes: 10 additions & 10 deletions Scripts/events/model_system_event_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ def on_iteration_complete(self, iteration: Union[int, str], impedance: Dict[str,
"""
pass

def on_emme_assignment_period_initialized(self, assignment_period: 'AssignmentPeriod'):
def on_assignment_period_initialized(self, assignment_period: 'AssignmentPeriod'):
"""
Event handler for when an EMME assignment period is initialized.
Args:
assignment_period (AssignmentPeriod): The assignment period that has been initialized.
"""
pass

def on_emme_pedestrian_assignment_complete(self, assignment_period: 'AssignmentPeriod', emme_scenario: 'Scenario') -> None:
def on_pedestrian_assignment_complete(self, assignment_period: 'AssignmentPeriod', emme_scenario: 'Scenario') -> None:
"""
Event handler for when an EMME pedestrian assignment is complete.
Args:
Expand All @@ -162,7 +162,7 @@ def on_emme_pedestrian_assignment_complete(self, assignment_period: 'AssignmentP
"""
pass

def on_emme_transit_wait_time_calculated(self, assignment_period: 'AssignmentPeriod' ,network: 'Network') -> None:
def on_transit_wait_time_calculated(self, assignment_period: 'AssignmentPeriod' ,network: 'Network') -> None:
"""
Event handler for when the extra transit wait time has been calculated.
Args:
Expand All @@ -171,7 +171,7 @@ def on_emme_transit_wait_time_calculated(self, assignment_period: 'AssignmentPer
"""
pass

def on_emme_background_traffic_calculated(self, assignment_period: 'AssignmentPeriod' ,network: 'Network') -> None:
def on_background_traffic_calculated(self, assignment_period: 'AssignmentPeriod' ,network: 'Network') -> None:
"""
Event handler for when background traffic has been calculated.
Args:
Expand All @@ -180,7 +180,7 @@ def on_emme_background_traffic_calculated(self, assignment_period: 'AssignmentPe
"""
pass

def on_emme_assignment_started(self,
def on_assignment_started(self,
assignment_period: 'AssignmentPeriod',
iteration: Union[int, str],
demand: Dict[str, np.ndarray]) -> None:
Expand All @@ -193,7 +193,7 @@ def on_emme_assignment_started(self,
"""
pass

def on_emme_assignment_complete(self,
def on_assignment_complete(self,
assignment_period: 'AssignmentPeriod',
iteration: Union[int, str],
demand: Dict[str, np.ndarray],
Expand All @@ -211,7 +211,7 @@ def on_emme_assignment_complete(self,
"""
pass

def on_emme_car_and_transit_vdfs_set(self, assignment_period: 'AssignmentPeriod', network: 'Network') -> None:
def on_car_and_transit_vdfs_set(self, assignment_period: 'AssignmentPeriod', network: 'Network') -> None:
"""
Event handler for when car and transit VDFs have been set.
Args:
Expand All @@ -220,7 +220,7 @@ def on_emme_car_and_transit_vdfs_set(self, assignment_period: 'AssignmentPeriod'
"""
pass

def on_emme_bike_vdfs_set(self, assignment_period: 'AssignmentPeriod', network: 'Network') -> None:
def on_bike_vdfs_set(self, assignment_period: 'AssignmentPeriod', network: 'Network') -> None:
"""
Event handler for when bike VDFs have been set.
Args:
Expand All @@ -229,7 +229,7 @@ def on_emme_bike_vdfs_set(self, assignment_period: 'AssignmentPeriod', network:
"""
pass

def on_emme_road_cost_calculated(self, assignment_period: 'AssignmentPeriod', network: 'Network') -> None:
def on_road_cost_calculated(self, assignment_period: 'AssignmentPeriod', network: 'Network') -> None:
"""
Event handler for when road costs have been calculated.
Args:
Expand All @@ -238,7 +238,7 @@ def on_emme_road_cost_calculated(self, assignment_period: 'AssignmentPeriod', ne
"""
pass

def on_emme_boarding_penalties_calculated(self, assignment_period: 'AssignmentPeriod', network: 'Network') -> None:
def on_boarding_penalties_calculated(self, assignment_period: 'AssignmentPeriod', network: 'Network') -> None:
"""
Event handler for when boarding penalties have been calculated.
Args:
Expand Down

0 comments on commit 9ccada3

Please sign in to comment.