Skip to content

Commit

Permalink
Cost coefficient calculation to separate function
Browse files Browse the repository at this point in the history
* Same code used in two places in 'logit.py', so similar function created to base class
  • Loading branch information
Supponen committed Apr 1, 2021
1 parent 52da639 commit 3aa1bd3
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions Scripts/models/logit.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ def _calc_mode_util(self, impedance):
self.resultdata.print_data(
pandas.Series(logsum, self.purpose.zone_numbers),
"sustainable_accessibility.txt", self.purpose.name)
try:
b = self.dest_choice_param["car"]["impedance"]["cost"]
except KeyError:
# School tours do not have a constant cost parameter
# Use value of time conversion from CBA guidelines instead
b = -0.31690253
b = self._get_cost_util_coefficient()
try:
# Convert utility into euros
money_utility = 1 / b
Expand Down Expand Up @@ -270,6 +265,14 @@ def _add_log_zone_util(self, exps, b, generation=False):
zdata.get_data(i, self.bounds, generation) + 1, b[i])
return exps

def _get_cost_util_coefficient(self):
try:
b = self.dest_choice_param["car"]["impedance"]["cost"]
except KeyError:
# School tours do not have a constant cost parameter
# Use value of time conversion from CBA guidelines instead
b = -0.31690253
return b

class ModeDestModel(LogitModel):
"""Nested logit model with mode choice in upper level.
Expand Down Expand Up @@ -449,12 +452,7 @@ def calc_individual_mode_prob(self, is_car_user, zone):
logsum = numpy.log(mode_expsum)
sust_logsum = numpy.log(sust_expsum)
car_logsum = numpy.log(car_expsum)
try:
b = self.dest_choice_param["car"]["impedance"]["cost"]
except KeyError:
# School tours do not have a constant cost parameter
# Use value of time conversion from CBA guidelines instead
b = -0.31690253
b = self._get_cost_util_coefficient()
if isinstance(b, tuple):
# Separate params for cap region and surrounding
# Choose based location
Expand Down

0 comments on commit 3aa1bd3

Please sign in to comment.