Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSA method for car impedance #177

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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 Scripts/modelsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def assign_base_demand(self, use_fixed_transit_cost=False):
impedance[tp] = self.ass_model.get_impedance()
if tp == "aht":
self._update_ratios(impedance, tp)

self.imptrans.average_car_impedance(impedance)
return impedance

def run_iteration(self, previous_iter_impedance, is_last_iteration=False):
Expand Down Expand Up @@ -177,6 +179,7 @@ def run_iteration(self, previous_iter_impedance, is_last_iteration=False):
cost_data = impedance[tp][mtx_type][ass_class]
mtx[ass_class] = cost_data

self.imptrans.average_car_impedance(impedance)
if is_last_iteration:
self.ass_model.print_vehicle_kms(self.resultdata)

Expand Down
42 changes: 41 additions & 1 deletion Scripts/transform/impedance_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,47 @@

class ImpedanceTransformer:
def __init__(self):
pass
self.iteration_counter = 0
self.averaged_impedance = dict.fromkeys(
["aht", "pt", "iht"])
for time_period in self.averaged_impedance:
self.averaged_impedance[time_period] = dict.fromkeys(
["time", "cost", "dist"])
for mtx_type in self.averaged_impedance[time_period]:
self.averaged_impedance[time_period][mtx_type] = dict.fromkeys(
["car_work", "car_leisure"])

def average_car_impedance(self, impedance):
"""Perform averaging of car impedance matrices.
Parameters
----------
impedance: dict
Time period (aht/pt/iht) : dict
Type (time/cost/dist) : dict
Assignment class (car_work/transit/...) : numpy 2d matrix
Return
------
dict
Time period (aht/pt/iht) : dict
Type (time/cost/dist) : dict
Assignment class (car_work/transit/...) : numpy 2d matrix
"""
self.iteration_counter += 1
n = self.iteration_counter
for time_period in impedance:
for mtx_type in impedance[time_period]:
average_imp = self.averaged_impedance[time_period][mtx_type]
for ass_class in average_imp:
imp = impedance[time_period][mtx_type][ass_class]
if n == 1:
average_imp[ass_class] = imp
else:
old_average = average_imp[ass_class]
# Method of successive averages
new_average = ((n-1)*old_average + imp) / n
average_imp[ass_class] = new_average
impedance[time_period][mtx_type][ass_class] = new_average
return impedance

def transform(self, purpose, impedance):
"""Perform transformation from time period dependent matrices
Expand Down