Skip to content

Commit

Permalink
avoid circular dependency for predictor
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhoerl committed Oct 7, 2024
1 parent a666bbb commit 84a5e96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import org.eqasim.core.simulation.mode_choice.cost.CostModel;
import org.eqasim.core.simulation.mode_choice.utilities.UtilityEstimator;
import org.eqasim.core.simulation.mode_choice.utilities.estimators.EstimatorUtils;
import org.eqasim.ile_de_france.mode_choice.parameters.IDFModeParameters;
Expand All @@ -14,18 +15,21 @@
import org.matsim.contribs.discrete_mode_choice.model.DiscreteModeChoiceTrip;

import com.google.inject.Inject;
import com.google.inject.name.Named;

public class IDFPtUtilityEstimator implements UtilityEstimator {
private final IDFModeParameters parameters;
private final IDFPersonPredictor personPredictor;
private final IDFPtPredictor idfPtPredictor;
private final CostModel costModel;

@Inject
public IDFPtUtilityEstimator(IDFModeParameters parameters, IDFPtPredictor idfPtPredictor,
IDFPersonPredictor personPredictor) {
IDFPersonPredictor personPredictor, @Named("pt") CostModel costModel) {
this.personPredictor = personPredictor;
this.idfPtPredictor = idfPtPredictor;
this.parameters = parameters;
this.costModel = costModel;
}

protected double estimateConstantUtility() {
Expand All @@ -48,9 +52,9 @@ protected double estimateLineSwitchUtility(IDFPtVariables variables) {
return parameters.pt.betaLineSwitch_u * variables.numberOfLineSwitches;
}

protected double estimateMonetaryCostUtility(IDFPtVariables variables) {
protected double estimateMonetaryCostUtility(IDFPtVariables variables, double cost_EUR) {
return parameters.betaCost_u_MU * EstimatorUtils.interaction(variables.euclideanDistance_km,
parameters.referenceEuclideanDistance_km, parameters.lambdaCostEuclideanDistance) * variables.cost_MU;
parameters.referenceEuclideanDistance_km, parameters.lambdaCostEuclideanDistance) * cost_EUR;
}

protected double estimateDrivingPermitUtility(IDFPersonVariables variables) {
Expand All @@ -66,14 +70,16 @@ public double estimateUtility(Person person, DiscreteModeChoiceTrip trip, List<?
IDFPersonVariables personVariables = personPredictor.predictVariables(person, trip, elements);
IDFPtVariables ptVariables = idfPtPredictor.predictVariables(person, trip, elements);

double cost_EUR = costModel.calculateCost_MU(person, trip, elements);

double utility = 0.0;

utility += estimateConstantUtility();
utility += estimateAccessEgressTimeUtility(ptVariables);
utility += estimateInVehicleTimeUtility(ptVariables);
utility += estimateWaitingTimeUtility(ptVariables);
utility += estimateLineSwitchUtility(ptVariables);
utility += estimateMonetaryCostUtility(ptVariables);
utility += estimateMonetaryCostUtility(ptVariables, cost_EUR);

utility += estimateDrivingPermitUtility(personVariables);
utility += estimateOnlyBus(ptVariables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,19 @@
import org.matsim.pt.transitSchedule.api.TransitStopFacility;

import com.google.inject.Inject;
import com.google.inject.name.Named;

public class IDFPtPredictor extends CachedVariablePredictor<IDFPtVariables> {
static public final String PARIS_ATTRIBUTE = "isParis";

private final TransitSchedule schedule;
private final CostModel costModel;

@Inject
public IDFPtPredictor(TransitSchedule schedule, @Named("pt") CostModel costModel) {
public IDFPtPredictor(TransitSchedule schedule) {
this.schedule = schedule;
this.costModel = costModel;
}

protected CostModel getCostModel() {
return this.costModel;
return null;
}

@Override
Expand Down Expand Up @@ -108,9 +105,6 @@ public IDFPtVariables predict(Person person, DiscreteModeChoiceTrip trip, List<?

int numberOfLineSwitches = Math.max(0, numberOfVehicularTrips - 1);

// Calculate cost
double cost_CHF = costModel.calculateCost_MU(person, trip, elements);

double euclideanDistance_km = PredictorUtils.calculateEuclideanDistance_km(trip);

boolean isOnlyBus = busCount > 0 && subwayCount == 0 && otherCount == 0;
Expand All @@ -129,6 +123,6 @@ public IDFPtVariables predict(Person person, DiscreteModeChoiceTrip trip, List<?
}

return new IDFPtVariables(inVehicleTime_min, waitingTime_min, accessEgressTime_min, numberOfLineSwitches,
cost_CHF, euclideanDistance_km, isOnlyBus, hasOnlySubwayAndBus, isWithinParis);
euclideanDistance_km, isOnlyBus, hasOnlySubwayAndBus, isWithinParis);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@ public class IDFPtVariables implements BaseVariables {
public final double waitingTime_min;
public final double accessEgressTime_min;
public final int numberOfLineSwitches;
public final double cost_MU;
public final double euclideanDistance_km;

public final boolean isOnlyBus;
public final boolean hasOnlySubwayAndBus;
public final boolean isWithinParis;

public IDFPtVariables(double inVehicleTime_min, double waitingTime_min, double accessEgressTime_min,
int numberOfLineSwitches, double cost_MU, double euclideanDistance_km, boolean isOnlyBus,
int numberOfLineSwitches, double euclideanDistance_km, boolean isOnlyBus,
boolean hasOnlySubwayAndBus, boolean isWithinParis) {
this.inVehicleTime_min = inVehicleTime_min;
this.waitingTime_min = waitingTime_min;
this.accessEgressTime_min = accessEgressTime_min;
this.numberOfLineSwitches = numberOfLineSwitches;
this.cost_MU = cost_MU;
this.euclideanDistance_km = euclideanDistance_km;

this.isOnlyBus = isOnlyBus;
Expand Down

0 comments on commit 84a5e96

Please sign in to comment.