|
6 | 6 | import org.eqasim.core.simulation.mode_choice.utilities.predictors.CachedVariablePredictor;
|
7 | 7 | import org.eqasim.core.simulation.mode_choice.utilities.predictors.PredictorUtils;
|
8 | 8 | import org.eqasim.sao_paulo.mode_choice.utilities.variables.TaxiVariables;
|
| 9 | +import org.matsim.api.core.v01.TransportMode; |
9 | 10 | import org.matsim.api.core.v01.population.Leg;
|
10 | 11 | import org.matsim.api.core.v01.population.Person;
|
11 | 12 | import org.matsim.api.core.v01.population.PlanElement;
|
12 | 13 | import org.matsim.contribs.discrete_mode_choice.model.DiscreteModeChoiceTrip;
|
| 14 | +import org.matsim.core.router.TripStructureUtils; |
13 | 15 |
|
| 16 | +import com.google.common.base.Verify; |
14 | 17 | import com.google.inject.Inject;
|
15 | 18 | import com.google.inject.name.Named;
|
16 | 19 |
|
17 | 20 | public class SaoPauloTaxiPredictor extends CachedVariablePredictor<TaxiVariables> {
|
18 | 21 | private final CostModel costModel;
|
| 22 | + |
19 | 23 |
|
20 | 24 | @Inject
|
21 | 25 | public SaoPauloTaxiPredictor(@Named("taxi") CostModel costModel) {
|
22 | 26 | this.costModel = costModel;
|
| 27 | + |
23 | 28 | }
|
24 | 29 |
|
25 | 30 | @Override
|
26 | 31 | public TaxiVariables predict(Person person, DiscreteModeChoiceTrip trip, List<? extends PlanElement> elements) {
|
27 |
| - if (elements.size() > 1) { |
28 |
| - throw new IllegalStateException("We do not support multi-stage taxi trips yet."); |
| 32 | + |
| 33 | + double taxiTravelTime_min = 0; |
| 34 | + double accessEgressTime_min = 0; |
| 35 | + |
| 36 | + boolean foundTaxi = false; |
| 37 | + |
| 38 | + for (Leg leg : TripStructureUtils.getLegs(elements)) { |
| 39 | + if (leg.getMode().equals(TransportMode.taxi)) { |
| 40 | + Verify.verify(!foundTaxi); |
| 41 | + taxiTravelTime_min += leg.getTravelTime().seconds() / 60.0; |
| 42 | + } else if (leg.getMode().equals(TransportMode.walk)) { |
| 43 | + accessEgressTime_min += leg.getTravelTime().seconds() / 60.0; |
| 44 | + } else { |
| 45 | + throw new IllegalStateException("Unexpected mode in taxi chain: " + leg.getMode()); |
| 46 | + } |
29 | 47 | }
|
30 | 48 |
|
31 |
| - Leg leg = (Leg) elements.get(0); |
32 |
| - |
33 |
| - double travelTime_min = leg.getTravelTime().seconds() / 60.0; |
| 49 | + |
34 | 50 | double cost_MU = costModel.calculateCost_MU(person, trip, elements);
|
35 |
| - |
36 | 51 | double euclideanDistance_km = PredictorUtils.calculateEuclideanDistance_km(trip);
|
37 |
| - double accessEgressTime_min = 0;// parameters.car.constantAccessEgressWalkTime_min; |
| 52 | + |
38 | 53 |
|
39 |
| - return new TaxiVariables(travelTime_min, cost_MU, euclideanDistance_km, accessEgressTime_min); |
| 54 | + return new TaxiVariables(taxiTravelTime_min, cost_MU, euclideanDistance_km, accessEgressTime_min); |
40 | 55 | }
|
41 | 56 | }
|
0 commit comments