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

Merge branch 'car_passenger' into 'master'

Add car_passenger mode

See merge request !11
parents ef4bd25f 813c3f3a
...@@ -13,7 +13,7 @@ public class ASTRAConfigurator { ...@@ -13,7 +13,7 @@ public class ASTRAConfigurator {
Set<String> allowedModes = new HashSet<>(link.getAllowedModes()); Set<String> allowedModes = new HashSet<>(link.getAllowedModes());
if (allowedModes.contains("car")) { if (allowedModes.contains("car")) {
allowedModes.addAll(Arrays.asList("av", "prav3", "prav4", "prav5")); allowedModes.addAll(Arrays.asList("av", "prav3", "prav4", "prav5", "car_passenger"));
} }
link.setAllowedModes(allowedModes); link.setAllowedModes(allowedModes);
......
...@@ -2,8 +2,10 @@ package ch.ethz.matsim.projects.astra_2018_002.flow_efficiency; ...@@ -2,8 +2,10 @@ package ch.ethz.matsim.projects.astra_2018_002.flow_efficiency;
import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.population.Person;
import org.matsim.core.config.Config; import org.matsim.core.config.Config;
import org.matsim.core.config.groups.QSimConfigGroup.VehiclesSource; import org.matsim.core.config.groups.QSimConfigGroup.VehiclesSource;
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleType; import org.matsim.vehicles.VehicleType;
import org.matsim.vehicles.VehicleUtils; import org.matsim.vehicles.VehicleUtils;
...@@ -17,6 +19,7 @@ public class FlowEfficiencyConfigurator { ...@@ -17,6 +19,7 @@ public class FlowEfficiencyConfigurator {
static final public Id<VehicleType> PRAV3_ID = Id.create("prav3", VehicleType.class); static final public Id<VehicleType> PRAV3_ID = Id.create("prav3", VehicleType.class);
static final public Id<VehicleType> PRAV4_ID = Id.create("prav4", VehicleType.class); static final public Id<VehicleType> PRAV4_ID = Id.create("prav4", VehicleType.class);
static final public Id<VehicleType> PRAV5_ID = Id.create("prav5", VehicleType.class); static final public Id<VehicleType> PRAV5_ID = Id.create("prav5", VehicleType.class);
static final public Id<VehicleType> PASSENGER_VEHICLE_TYPE_ID = Id.create("car_passenger", VehicleType.class);
static public void configure(Config config) { static public void configure(Config config) {
// Load vehicles by vehicle type // Load vehicles by vehicle type
...@@ -44,6 +47,10 @@ public class FlowEfficiencyConfigurator { ...@@ -44,6 +47,10 @@ public class FlowEfficiencyConfigurator {
.createVehicleType(CONVENTIONAL_VEHICLE_TYPE_ID); .createVehicleType(CONVENTIONAL_VEHICLE_TYPE_ID);
scenario.getVehicles().addVehicleType(carVehicleType); scenario.getVehicles().addVehicleType(carVehicleType);
VehicleType passengerVehicleType = VehicleUtils.getFactory() //
.createVehicleType(PASSENGER_VEHICLE_TYPE_ID);
scenario.getVehicles().addVehicleType(passengerVehicleType);
VehicleType privateAvVehicleType = VehicleUtils.getFactory() // VehicleType privateAvVehicleType = VehicleUtils.getFactory() //
.createVehicleType(PRIVATE_AV_VEHICLE_TYPE_ID); .createVehicleType(PRIVATE_AV_VEHICLE_TYPE_ID);
scenario.getVehicles().addVehicleType(privateAvVehicleType); scenario.getVehicles().addVehicleType(privateAvVehicleType);
...@@ -63,5 +70,11 @@ public class FlowEfficiencyConfigurator { ...@@ -63,5 +70,11 @@ public class FlowEfficiencyConfigurator {
VehicleType prav5VehicleType = VehicleUtils.getFactory() // VehicleType prav5VehicleType = VehicleUtils.getFactory() //
.createVehicleType(PRAV5_ID); .createVehicleType(PRAV5_ID);
scenario.getVehicles().addVehicleType(prav5VehicleType); scenario.getVehicles().addVehicleType(prav5VehicleType);
for (Person person : scenario.getPopulation().getPersons().values()) {
Id<Vehicle> vehicleId = Id.createVehicleId(person.getId().toString() + "_car_passenger");
Vehicle vehicle = scenario.getVehicles().getFactory().createVehicle(vehicleId, passengerVehicleType);
scenario.getVehicles().addVehicle(vehicle);
}
} }
} }
package ch.ethz.matsim.projects.astra_2018_002.mode_choice;
import java.util.Collection;
import java.util.List;
import org.matsim.api.core.v01.population.Person;
import ch.ethz.matsim.discrete_mode_choice.model.DiscreteModeChoiceTrip;
import ch.ethz.matsim.discrete_mode_choice.model.constraints.AbstractTripConstraint;
import ch.ethz.matsim.discrete_mode_choice.model.trip_based.TripConstraint;
import ch.ethz.matsim.discrete_mode_choice.model.trip_based.TripConstraintFactory;
public class PassengerConstraint extends AbstractTripConstraint {
public static final String PASSENGER_MODE = "car_passenger";
@Override
public boolean validateBeforeEstimation(DiscreteModeChoiceTrip trip, String mode, List<String> previousModes) {
if (trip.getInitialMode().equals(PASSENGER_MODE)) {
if (!mode.equals(PASSENGER_MODE)) {
return false;
}
}
if (mode.equals(PASSENGER_MODE)) {
if (!trip.getInitialMode().equals(PASSENGER_MODE)) {
return false;
}
}
return true;
}
static public class Factory implements TripConstraintFactory {
@Override
public TripConstraint createConstraint(Person person, List<DiscreteModeChoiceTrip> planTrips,
Collection<String> availableModes) {
return new PassengerConstraint();
}
}
}
...@@ -33,6 +33,7 @@ public class SwissDiscreteModeChoiceModule extends AbstractDiscreteModeChoiceExt ...@@ -33,6 +33,7 @@ public class SwissDiscreteModeChoiceModule extends AbstractDiscreteModeChoiceExt
public static final String SWISS_MODE_AVAILABILITY_NAME = "SwissModeAvailability"; public static final String SWISS_MODE_AVAILABILITY_NAME = "SwissModeAvailability";
public static final String SWISS_TOUR_FINDER_NAME = "SwissTourFinder"; public static final String SWISS_TOUR_FINDER_NAME = "SwissTourFinder";
public static final String OUTSIDE_CONSTRAINT_NAME = "OutsideConstraint"; public static final String OUTSIDE_CONSTRAINT_NAME = "OutsideConstraint";
public static final String PASSENGER_CONSTRAINT_NAME = "PassengerConstraint";
private final UtilitySet utilitySet; private final UtilitySet utilitySet;
private final boolean useRouteChoice; private final boolean useRouteChoice;
...@@ -54,6 +55,7 @@ public class SwissDiscreteModeChoiceModule extends AbstractDiscreteModeChoiceExt ...@@ -54,6 +55,7 @@ public class SwissDiscreteModeChoiceModule extends AbstractDiscreteModeChoiceExt
bindModeAvailability(SWISS_MODE_AVAILABILITY_NAME).to(SwissModeAvailability.class); bindModeAvailability(SWISS_MODE_AVAILABILITY_NAME).to(SwissModeAvailability.class);
bindTourFinder(SWISS_TOUR_FINDER_NAME).to(SwissTourFinder.class); bindTourFinder(SWISS_TOUR_FINDER_NAME).to(SwissTourFinder.class);
bindTripConstraintFactory(OUTSIDE_CONSTRAINT_NAME).to(OutsideConstraint.Factory.class); bindTripConstraintFactory(OUTSIDE_CONSTRAINT_NAME).to(OutsideConstraint.Factory.class);
bindTripConstraintFactory(PASSENGER_CONSTRAINT_NAME).to(PassengerConstraint.Factory.class);
} }
@Provides @Provides
...@@ -122,4 +124,10 @@ public class SwissDiscreteModeChoiceModule extends AbstractDiscreteModeChoiceExt ...@@ -122,4 +124,10 @@ public class SwissDiscreteModeChoiceModule extends AbstractDiscreteModeChoiceExt
public HomeFinder provideHomeFinder() { public HomeFinder provideHomeFinder() {
return new SwissHomeFinder(); return new SwissHomeFinder();
} }
@Provides
@Singleton
public PassengerConstraint.Factory providePassengerConstraintFactory() {
return new PassengerConstraint.Factory();
}
} }
...@@ -44,6 +44,12 @@ public class SwissModeAvailability extends CarModeAvailability { ...@@ -44,6 +44,12 @@ public class SwissModeAvailability extends CarModeAvailability {
modes.add("outside"); modes.add("outside");
} }
Boolean isCarPassenger = (Boolean) person.getAttributes().getAttribute("isCarPassenger");
if (isCarPassenger != null && isCarPassenger) {
modes.add("car_passenger");
}
return modes; return modes;
} }
} }
...@@ -46,7 +46,8 @@ public class SwissModeChoiceConfigurator { ...@@ -46,7 +46,8 @@ public class SwissModeChoiceConfigurator {
dmcConfig.setTourConstraints( dmcConfig.setTourConstraints(
Arrays.asList(ConstraintModule.VEHICLE_CONTINUITY, ConstraintModule.FROM_TRIP_BASED)); Arrays.asList(ConstraintModule.VEHICLE_CONTINUITY, ConstraintModule.FROM_TRIP_BASED));
dmcConfig.setTripConstraints( dmcConfig.setTripConstraints(
Arrays.asList(ConstraintModule.TRANSIT_WALK, SwissDiscreteModeChoiceModule.OUTSIDE_CONSTRAINT_NAME)); Arrays.asList(ConstraintModule.TRANSIT_WALK, SwissDiscreteModeChoiceModule.OUTSIDE_CONSTRAINT_NAME,
SwissDiscreteModeChoiceModule.PASSENGER_CONSTRAINT_NAME));
dmcConfig.getVehicleTourConstraintConfig().setHomeType(HomeType.USE_ACTIVITY_TYPE); dmcConfig.getVehicleTourConstraintConfig().setHomeType(HomeType.USE_ACTIVITY_TYPE);
dmcConfig.getVehicleTourConstraintConfig().setRestrictedModes(Arrays.asList("car", "bike")); dmcConfig.getVehicleTourConstraintConfig().setRestrictedModes(Arrays.asList("car", "bike"));
...@@ -64,6 +65,8 @@ public class SwissModeChoiceConfigurator { ...@@ -64,6 +65,8 @@ public class SwissModeChoiceConfigurator {
scoringConfig.setMarginalUtilityOfMoney(0.0); scoringConfig.setMarginalUtilityOfMoney(0.0);
scoringConfig.setMarginalUtlOfWaitingPt_utils_hr(0.0); scoringConfig.setMarginalUtlOfWaitingPt_utils_hr(0.0);
scoringConfig.getOrCreateModeParams("car_passenger");
// Some additional settings // Some additional settings
config.controler().setRoutingAlgorithmType(RoutingAlgorithmType.FastAStarLandmarks); config.controler().setRoutingAlgorithmType(RoutingAlgorithmType.FastAStarLandmarks);
......
...@@ -120,6 +120,8 @@ public abstract class BaseUtilityEstimator extends AbstractTripRouterEstimator { ...@@ -120,6 +120,8 @@ public abstract class BaseUtilityEstimator extends AbstractTripRouterEstimator {
return estimatePrivateAVTrip(personVariables, trip, routedTrip) + outsideOffset; return estimatePrivateAVTrip(personVariables, trip, routedTrip) + outsideOffset;
case TransportMode.car: case TransportMode.car:
return estimateCarTrip(personVariables, trip, routedTrip) + outsideOffset; return estimateCarTrip(personVariables, trip, routedTrip) + outsideOffset;
case "car_passenger":
return 0.0;
case TransportMode.pt: case TransportMode.pt:
return estimatePtTrip(personVariables, trip, routedTrip) + outsideOffset; return estimatePtTrip(personVariables, trip, routedTrip) + outsideOffset;
case SharedAVModule.AV_POOL: case SharedAVModule.AV_POOL:
......
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