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

Generalize sub-bound handling #469

Merged
merged 3 commits into from
Oct 27, 2022
Merged
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
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