Skip to content

Commit

Permalink
added more options to trip choice model
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Jul 22, 2024
1 parent 7d4f2c2 commit 315fab3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public Integer call() throws Exception {
header.add(mode + "_km");
header.add(mode + "_hours");
header.add(mode + "_walking_km");
header.add(mode + "_switches");
header.add(mode + "_valid");
}

Expand Down Expand Up @@ -233,6 +234,9 @@ private List<Object> computeAlternatives(TripRouter router, Network network, Per
}
}

// This is mainly used for PT, to count the number of switches
long switches = route.stream().filter(r -> r instanceof Leg l && l.getMode().equals(mode)).count() - 1;

if (!PersonUtils.canUseCar(person) && mode.equals(TransportMode.car)) {
valid = false;
}
Expand All @@ -242,7 +246,7 @@ private List<Object> computeAlternatives(TripRouter router, Network network, Per
return null;
}

row.addAll(List.of(travelDistance / 1000, travelTime / 3600, walkDistance / 1000, valid));
row.addAll(List.of(travelDistance / 1000, travelTime / 3600, walkDistance / 1000, switches, valid));
}

return row;
Expand Down
28 changes: 22 additions & 6 deletions src/main/python/choicemodels/estimate_biogeme_trip_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
parser.add_argument("--mxl-modes", help="Modes to use mixed logit for", nargs="+", type=set,
default=["pt", "bike", "ride"])
parser.add_argument("--est-performing", help="Estimate the beta for performing", action="store_true")
parser.add_argument("--est-exp-income", help="Estimate exponent for income", action="store_true")
parser.add_argument("--est-util-money", help="Estimate utility of money", action="store_true")
parser.add_argument("--no-income", help="Don't consider the income", action="store_true")

args = parser.parse_args()
Expand Down Expand Up @@ -48,16 +50,19 @@
U = {}
AV = {}

B_TIME = Beta('B_TIME', 6.88, None, None, ESTIMATE if args.est_performing else FIXED)
UTIL_MONEY = 1
EXP_INCOME = 1
EXP_INCOME = Beta('EXP_INCOME', 1, 0, 1.5, ESTIMATE if args.est_exp_income else FIXED)
UTIL_MONEY = Beta('UTIL_MONEY', 1, 0, 2, ESTIMATE if args.est_util_money else FIXED)
BETA_PERFORMING = Beta('BETA_PERFORMING', 6.88, 1, 15, ESTIMATE if args.est_performing else FIXED)

for i, mode in enumerate(ds.modes, 1):
u = ASC[mode] - B_TIME * v[f"{mode}_hours"]
u = ASC[mode] - BETA_PERFORMING * v[f"{mode}_hours"] * (2 if mode == "ride" else 1)

price = km_costs[mode] * v[f"{mode}_km"]
u += price * UTIL_MONEY * (1 if args.no_income else (ds.global_income / v["income"]) ** EXP_INCOME)

if mode == "pt":
u -= v[f"{mode}_switches"]

U[i] = u
AV[i] = v[f"{mode}_valid"]

Expand All @@ -71,15 +76,26 @@

biogeme = bio.BIOGEME(database, logprob)

biogeme.modelName = "trip_choice"
modelName = "trip_choice"
if args.est_performing:
modelName += "_performing"
if args.est_exp_income:
modelName += "_exp_income"
if args.est_util_money:
modelName += "_util_money"

biogeme.modelName = modelName
biogeme.weight = v["weight"]

biogeme.calculateNullLoglikelihood(AV)

results = biogeme.estimate()
print(results.short_summary())

pandas_results = results.getEstimatedParameters()
print(pandas_results)

sim_results = biogeme.simulate(results.getBetaValues())
# sim_results = biogeme.simulate(results.getBetaValues())

# print(sim_results)
#
Expand Down

0 comments on commit 315fab3

Please sign in to comment.