Commit d8d314a9 authored by Sebastian Hörl's avatar Sebastian Hörl
Browse files

Improve costs for regional subscriptions

parent 5272ab89
...@@ -2,8 +2,10 @@ package ch.ethz.matsim.projects.astra_2018_002.mode_choice.base; ...@@ -2,8 +2,10 @@ package ch.ethz.matsim.projects.astra_2018_002.mode_choice.base;
import java.util.List; import java.util.List;
import org.matsim.api.core.v01.Coord;
import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.network.Network; import org.matsim.api.core.v01.network.Network;
import org.matsim.api.core.v01.population.Activity;
import org.matsim.api.core.v01.population.Leg; import org.matsim.api.core.v01.population.Leg;
import org.matsim.api.core.v01.population.Person; import org.matsim.api.core.v01.population.Person;
import org.matsim.api.core.v01.population.PlanElement; import org.matsim.api.core.v01.population.PlanElement;
...@@ -79,6 +81,30 @@ public abstract class BaseUtilityEstimator extends AbstractTripRouterEstimator { ...@@ -79,6 +81,30 @@ public abstract class BaseUtilityEstimator extends AbstractTripRouterEstimator {
throw new IllegalStateException(); throw new IllegalStateException();
} }
Double homeX = (Double) person.getAttributes().getAttribute("home_x");
Double homeY = (Double) person.getAttributes().getAttribute("home_y");
if (homeX == null || homeY == null) {
homeX = 0.0;
homeY = 0.0;
for (PlanElement element : person.getSelectedPlan().getPlanElements()) {
if (element instanceof Activity) {
Activity activity = (Activity) element;
if (activity.getType().equals("home")) {
homeX = activity.getCoord().getX();
homeY = activity.getCoord().getY();
}
}
}
person.getAttributes().putAttribute("home_x", homeX);
person.getAttributes().putAttribute("home_y", homeY);
}
personVariables.homeLocation = new Coord(homeX, homeY);
switch (mode) { switch (mode) {
case TransportMode.walk: case TransportMode.walk:
return estimateWalkTrip(personVariables, trip, routedTrip); return estimateWalkTrip(personVariables, trip, routedTrip);
...@@ -226,7 +252,7 @@ public abstract class BaseUtilityEstimator extends AbstractTripRouterEstimator { ...@@ -226,7 +252,7 @@ public abstract class BaseUtilityEstimator extends AbstractTripRouterEstimator {
} }
tripVariables.lineSwitches = Math.max(0, numberOfVehicularTrips - 1); tripVariables.lineSwitches = Math.max(0, numberOfVehicularTrips - 1);
tripVariables.travelCost_CHF = costModel.calculatePtTravelCost(personVariables, inVehicleDistance_km); tripVariables.inVehicleDistance_km = inVehicleDistance_km;
tripVariables.delay_min = calculateDelay(trip, totalTravelTime) / 60.0; tripVariables.delay_min = calculateDelay(trip, totalTravelTime) / 60.0;
tripVariables.travelDistance_km = totalTravelDistance / 1000.0; tripVariables.travelDistance_km = totalTravelDistance / 1000.0;
...@@ -234,6 +260,13 @@ public abstract class BaseUtilityEstimator extends AbstractTripRouterEstimator { ...@@ -234,6 +260,13 @@ public abstract class BaseUtilityEstimator extends AbstractTripRouterEstimator {
tripVariables.crowflyDistance_km = CoordUtils.calcEuclideanDistance(trip.getOriginActivity().getCoord(), tripVariables.crowflyDistance_km = CoordUtils.calcEuclideanDistance(trip.getOriginActivity().getCoord(),
trip.getDestinationActivity().getCoord()); trip.getDestinationActivity().getCoord());
tripVariables.originHomeDistance_km = CoordUtils.calcEuclideanDistance(personVariables.homeLocation,
trip.getOriginActivity().getCoord()) * 1e-3;
tripVariables.destinationHomeDistance_km = CoordUtils.calcEuclideanDistance(personVariables.homeLocation,
trip.getDestinationActivity().getCoord()) * 1e-3;
tripVariables.travelCost_CHF = costModel.calculatePtTravelCost(personVariables, tripVariables);
return estimatePtTrip(trip, personVariables, tripVariables); return estimatePtTrip(trip, personVariables, tripVariables);
} }
......
package ch.ethz.matsim.projects.astra_2018_002.mode_choice.base; package ch.ethz.matsim.projects.astra_2018_002.mode_choice.base;
import org.matsim.api.core.v01.Coord;
public class PersonVariables { public class PersonVariables {
public double age_over18a = 0; public double age_over18a = 0;
public double age_10a = 0; public double age_10a = 0;
public double income_1000CHF = 0.0; public double income_1000CHF = 0.0;
public boolean isMale = false; public boolean isMale = false;
public boolean carAlwaysAvailable = false; public boolean carAlwaysAvailable = false;
public Coord homeLocation = new Coord(0.0, 0.0);
public enum PtSubscription { public enum PtSubscription {
None, Halbtax, Regional, GA None, Halbtax, Regional, GA
......
...@@ -16,9 +16,13 @@ public class TripVariablesPt { ...@@ -16,9 +16,13 @@ public class TripVariablesPt {
} }
public MainMode mainMode = MainMode.Bus; public MainMode mainMode = MainMode.Bus;
public double delay_min = 0.0; public double delay_min = 0.0;
public double travelDistance_km = 0.0; public double travelDistance_km = 0.0;
public double crowflyDistance_km = 0.0; public double crowflyDistance_km = 0.0;
public double inVehicleDistance_km = 0.0;
public double originHomeDistance_km;
public double destinationHomeDistance_km;
} }
package ch.ethz.matsim.projects.astra_2018_002.mode_choice.cost; package ch.ethz.matsim.projects.astra_2018_002.mode_choice.cost;
import ch.ethz.matsim.projects.astra_2018_002.mode_choice.base.PersonVariables; import ch.ethz.matsim.projects.astra_2018_002.mode_choice.base.PersonVariables;
import ch.ethz.matsim.projects.astra_2018_002.mode_choice.base.TripVariablesPt;
public class CostModel { public class CostModel {
private final CostParameters parameters; private final CostParameters parameters;
...@@ -17,23 +18,26 @@ public class CostModel { ...@@ -17,23 +18,26 @@ public class CostModel {
return parameters.avCostPerKm * distance_km; return parameters.avCostPerKm * distance_km;
} }
public double calculatePtTravelCost(PersonVariables personVariables, double distance_km) { public double calculatePtTravelCost(PersonVariables personVariables, TripVariablesPt tripVariables) {
/* /*
* TODO: Later on, we should have a more complex cost model here. * TODO: Later on, we should have a more complex cost model here.
*/ */
switch (personVariables.ptSubscription) { switch (personVariables.ptSubscription) {
case GA: case GA:
return Math.max(parameters.ptCostMinimumGA, parameters.ptCostPerKmGA * distance_km); return Math.max(parameters.ptCostMinimumGA, parameters.ptCostPerKmGA * tripVariables.inVehicleDistance_km);
case Halbtax: case Halbtax:
return Math.max(parameters.ptCostMinimumHalfFare, parameters.ptCostPerKmHalfFare * distance_km); return Math.max(parameters.ptCostMinimumHalfFare,
parameters.ptCostPerKmHalfFare * tripVariables.inVehicleDistance_km);
case None: case None:
return Math.max(parameters.ptCostMinimum, parameters.ptCostPerKm * distance_km); return Math.max(parameters.ptCostMinimum, parameters.ptCostPerKm * tripVariables.inVehicleDistance_km);
case Regional: case Regional:
if (distance_km <= parameters.ptRegionalRadius_km) { if (tripVariables.originHomeDistance_km <= parameters.ptRegionalRadius_km
&& tripVariables.destinationHomeDistance_km <= parameters.ptRegionalRadius_km) {
return 0.0; return 0.0;
} else { } else {
return Math.max(parameters.ptCostMinimumRegional, parameters.ptCostPerKmRegional * distance_km); return Math.max(parameters.ptCostMinimumRegional,
parameters.ptCostPerKmRegional * tripVariables.inVehicleDistance_km);
} }
default: default:
throw new IllegalStateException(); throw new IllegalStateException();
......
...@@ -13,6 +13,6 @@ public class CostParameters { ...@@ -13,6 +13,6 @@ public class CostParameters {
public double ptCostMinimumHalfFare = 2.7 * 0.5; public double ptCostMinimumHalfFare = 2.7 * 0.5;
public double ptCostMinimumGA = 0.0; public double ptCostMinimumGA = 0.0;
public double ptCostMinimumRegional = 2.7; public double ptCostMinimumRegional = 2.7;
public double ptRegionalRadius_km = 30.0; public double ptRegionalRadius_km = 15.0;
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment