Skip to content

Commit

Permalink
add multi-stage taxi trip to SaoPauloTaxiPredictor (#194)
Browse files Browse the repository at this point in the history
* add multi-stage taxi trip

* fix wrong parameters

* update changelog
  • Loading branch information
MayuriAnn authored Feb 20, 2024
1 parent a8a73b5 commit 9fab628
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ included in the (note yet determined) next version number.

**Development version**

- Add support for multi-stage taxi trips in Sao Paulo
- fix: make compatible with downstream population pipelines
- Ensure outside activity id doesn't already exist
- Network-based (car) routing now generates access and egress walk legs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,51 @@
import org.eqasim.core.simulation.mode_choice.utilities.predictors.CachedVariablePredictor;
import org.eqasim.core.simulation.mode_choice.utilities.predictors.PredictorUtils;
import org.eqasim.sao_paulo.mode_choice.utilities.variables.TaxiVariables;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.population.Leg;
import org.matsim.api.core.v01.population.Person;
import org.matsim.api.core.v01.population.PlanElement;
import org.matsim.contribs.discrete_mode_choice.model.DiscreteModeChoiceTrip;
import org.matsim.core.router.TripStructureUtils;

import com.google.common.base.Verify;
import com.google.inject.Inject;
import com.google.inject.name.Named;

public class SaoPauloTaxiPredictor extends CachedVariablePredictor<TaxiVariables> {
private final CostModel costModel;


@Inject
public SaoPauloTaxiPredictor(@Named("taxi") CostModel costModel) {
this.costModel = costModel;

}

@Override
public TaxiVariables predict(Person person, DiscreteModeChoiceTrip trip, List<? extends PlanElement> elements) {
if (elements.size() > 1) {
throw new IllegalStateException("We do not support multi-stage taxi trips yet.");

double taxiTravelTime_min = 0;
double accessEgressTime_min = 0;

boolean foundTaxi = false;

for (Leg leg : TripStructureUtils.getLegs(elements)) {
if (leg.getMode().equals(TransportMode.taxi)) {
Verify.verify(!foundTaxi);
taxiTravelTime_min += leg.getTravelTime().seconds() / 60.0;
} else if (leg.getMode().equals(TransportMode.walk)) {
accessEgressTime_min += leg.getTravelTime().seconds() / 60.0;
} else {
throw new IllegalStateException("Unexpected mode in taxi chain: " + leg.getMode());
}
}

Leg leg = (Leg) elements.get(0);

double travelTime_min = leg.getTravelTime().seconds() / 60.0;

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

double euclideanDistance_km = PredictorUtils.calculateEuclideanDistance_km(trip);
double accessEgressTime_min = 0;// parameters.car.constantAccessEgressWalkTime_min;


return new TaxiVariables(travelTime_min, cost_MU, euclideanDistance_km, accessEgressTime_min);
return new TaxiVariables(taxiTravelTime_min, cost_MU, euclideanDistance_km, accessEgressTime_min);
}
}

0 comments on commit 9fab628

Please sign in to comment.