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

add multi-stage taxi trip to SaoPauloTaxiPredictor #194

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 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);
}
}
Loading