Skip to content

Commit

Permalink
Generalize sub-bound handling
Browse files Browse the repository at this point in the history
  • Loading branch information
zptro committed Sep 26, 2022
1 parent ac46d6e commit 2d841e2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions Scripts/datatypes/purpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, specification, zone_data, resultdata=None):
sub_intervals = zone_numbers[self.bounds].searchsorted(zone_intervals)
self.sub_bounds = [slice(sub_intervals[i-1], sub_intervals[i])
for i in range(1, len(sub_intervals))]
self.sub_intervals = sub_intervals[1:]
self.zone_data = zone_data
self.resultdata = resultdata
self.model = None
Expand Down
5 changes: 2 additions & 3 deletions Scripts/datatypes/tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,9 @@ def _get_cost(self, impedance, mtx_type):
pass
# scale transit costs from month to day
if self.mode == "transit" and mtx_type == "cost":
idx = numpy.searchsorted(
[bounds.stop for bounds in self.purpose.sub_bounds],
i = self.purpose.sub_intervals.searchsorted(
self.position[0], side="right")
cost /= transit_trips_per_month[self.purpose.area][demand_type][idx]
cost /= transit_trips_per_month[self.purpose.area][demand_type][i]
return cost

def __str__(self):
Expand Down
12 changes: 6 additions & 6 deletions Scripts/models/logit.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,10 @@ def calc_individual_mode_prob(self, is_car_user, zone):
try:
mode_exps[mode] *= math.exp(b["car_users"])
except TypeError:
if zone < self.zone_data.first_surrounding_zone:
mode_exps[mode] *= math.exp(b["car_users"][0])
else:
mode_exps[mode] *= math.exp(b["car_users"][1])
# Separate sub-region parameters
i = self.purpose.sub_intervals.searchsorted(
zone, side="right")
mode_exps[mode] *= math.exp(b["car_users"][i])
mode_expsum += mode_exps[mode]
probs = numpy.empty(len(modes))
for i, mode in enumerate(modes):
Expand All @@ -395,8 +395,8 @@ def calc_individual_mode_prob(self, is_car_user, zone):
money_utility = 1 / b
except TypeError:
# Separate sub-region parameters
money_utility = (1 / b[0] if self.sub_bounds[0].stop < zone
else 1 / b[1])
i = self.purpose.sub_intervals.searchsorted(zone, side="right")
money_utility = 1 / b[i]
money_utility /= self.mode_choice_param["car"]["log"]["logsum"]
accessibility = -money_utility * logsum
return probs, accessibility
Expand Down

0 comments on commit 2d841e2

Please sign in to comment.