Skip to content

Commit

Permalink
Generalize transit trips per month accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
zptro committed Sep 19, 2022
1 parent 3da8555 commit fe0270c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
18 changes: 9 additions & 9 deletions Scripts/datatypes/tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import parameters.car as param
import parameters.zone as zone_param
from parameters.assignment import assignment_classes, vot_inv
from parameters.impedance_transformation import divided_classes, trips_month
from parameters.impedance_transformation import divided_classes, transit_trips_per_month


class Tour:
Expand Down Expand Up @@ -200,14 +200,12 @@ def calc_cost(self, impedance):

def _get_cost(self, impedance, mtx_type):
"""Get cost and time components from tour dest choice."""
if self.mode in divided_classes:
ass_class = "{}_{}".format(
self.mode, assignment_classes[self.purpose.name])
else:
ass_class = self.mode
demand_type = assignment_classes[self.purpose.name]
ass_class = ("{}_{}".format(self.mode, demand_type)
if self.mode in divided_classes else self.mode)
cost = 0
try:
if assignment_classes[self.purpose_name] == "work":
if demand_type == "work":
departure_imp = impedance["aht"][mtx_type][ass_class]
sec_dest_imp = impedance["iht"][mtx_type][ass_class]
return_imp = impedance["iht"][mtx_type][ass_class]
Expand All @@ -229,8 +227,10 @@ def _get_cost(self, impedance, mtx_type):
pass
# scale transit costs from month to day
if self.mode == "transit" and mtx_type == "cost":
idx = int(self.position[0] > self.purpose.zone_data.first_surrounding_zone)
cost /= trips_month[ass_class][idx]
idx = numpy.searchsorted(
[bounds.stop for bounds in self.purpose.sub_bounds],
self.position[0], side="right")
cost /= transit_trips_per_month[self.purpose.area][demand_type][idx]
return cost

def __str__(self):
Expand Down
16 changes: 13 additions & 3 deletions Scripts/parameters/impedance_transformation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
### IMPEDANCE TRANSFORMATION PARAMETERS ###

trips_month = {
"transit_work": (60.0, 44.0),
"transit_leisure": (30.0, 30.0),
transit_trips_per_month = {
"metropolitan": {
"work": (60.0, 44.0),
"leisure": (30.0, 30.0),
},
"peripheral": {
"work": (44.0,),
"leisure": (30.0,),
},
"all": {
"work": (60.0, 44.0),
"leisure": (30.0, 30.0),
},
}

impedance_share = {
Expand Down
13 changes: 8 additions & 5 deletions Scripts/transform/impedance_transformer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import defaultdict
import numpy

from parameters.impedance_transformation import impedance_share, divided_classes, trips_month
import parameters.impedance_transformation as param
from parameters.assignment import assignment_classes


Expand Down Expand Up @@ -32,9 +32,10 @@ def transform(self, purpose, impedance):
cols = (purpose.bounds if purpose.name == "hoo"
else slice(0, purpose.zone_data.nr_zones))
day_imp = {}
impedance_share = param.impedance_share
for mode in impedance_share[purpose.name]:
day_imp[mode] = defaultdict(float)
if mode in divided_classes:
if mode in param.divided_classes:
ass_class = "{}_{}".format(
mode, assignment_classes[purpose.name])
else:
Expand All @@ -47,9 +48,11 @@ def transform(self, purpose, impedance):
day_imp[mode][mtx_type] += share[0] * imp[rows, cols]
day_imp[mode][mtx_type] += share[1] * imp[cols, rows].T
# transit cost to eur per day
transit_class = "{}_{}".format("transit", assignment_classes[purpose.name])
trips_month = (param.transit_trips_per_month
[purpose.area][assignment_classes[purpose.name]])
trips_per_month = numpy.full_like(
day_imp["transit"]["cost"], trips_month[transit_class][0])
trips_per_month[purpose.sub_bounds[-1], :] = trips_month[transit_class][1]
day_imp["transit"]["cost"], trips_month[0])
for i in range(1, len(purpose.sub_bounds)):
trips_per_month[purpose.sub_bounds[i], :] = trips_month[i]
day_imp["transit"]["cost"] /= trips_per_month
return day_imp

0 comments on commit fe0270c

Please sign in to comment.