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

parkingProxy cleanup #3310

Merged
merged 3 commits into from
Jun 7, 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
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,15 @@ class LinearPenaltyFunctionWithCap implements PenaltyFunction {

private final double penaltyPerCar;
private final double maxPenalty;
private final double areaFactor;

public LinearPenaltyFunctionWithCap(double gridSize, double penaltyPerCar, double maxPenalty) {
public LinearPenaltyFunctionWithCap(double penaltyPerCar, double maxPenalty) {
this.penaltyPerCar = penaltyPerCar;
this.maxPenalty = maxPenalty;
this.areaFactor = gridSize * gridSize / 2500.;
}

@Override
public double calculatePenalty(int numberOfCars) {
return Math.max(Math.min(numberOfCars * penaltyPerCar / areaFactor, maxPenalty), 0);
return Math.max(Math.min(numberOfCars * penaltyPerCar, maxPenalty), 0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
*/
public /*deliberately non-final*/ class ParkingProxyModule extends AbstractModule {

private final static int GRIDSIZE = 500;
private final Scenario scenario;

public ParkingProxyModule(Scenario scenario) {
Expand All @@ -60,57 +61,38 @@ public void install() {
initialLoad,
parkingConfig.getTimeBinSize(),
qsimEndTime,
parkingConfig.getGridSize()
GRIDSIZE
);
PenaltyFunction penaltyFunction = new LinearPenaltyFunctionWithCap(parkingConfig.getGridSize(), parkingConfig.getDelayPerCar(), parkingConfig.getMaxDelay());
PenaltyFunction penaltyFunction = new LinearPenaltyFunctionWithCap(parkingConfig.getDelayPerCar(), parkingConfig.getMaxDelay());
//PenaltyFunction penaltyFunction = new ExponentialPenaltyFunctionWithCap(10, parkingConfig.getGridSize(), parkingConfig.getMaxDelay(), 360);

switch(parkingConfig.getCalculationMethod()) {
case none:
ParkingVehiclesCountEventHandler parkingHandler = new ParkingVehiclesCountEventHandler(carCounter, scenario.getNetwork(), parkingConfig.getScenarioScaleFactor());
super.addEventHandlerBinding().toInstance(parkingHandler);

CarEgressWalkObserver walkObserver;
switch (parkingConfig.getIter0Method()) {
case hourPenalty:
walkObserver = new CarEgressWalkObserver(parkingHandler, penaltyFunction, PenaltyCalculator.getDummyHourCalculator());
break;
case noPenalty:
walkObserver = new CarEgressWalkObserver(parkingHandler, penaltyFunction, PenaltyCalculator.getDummyZeroCalculator());
break;
case events:
ParkingVehiclesCountEventHandler parkingHandler = new ParkingVehiclesCountEventHandler(carCounter, scenario.getNetwork(), parkingConfig.getScenarioScaleFactor());
super.addEventHandlerBinding().toInstance(parkingHandler);

CarEgressWalkObserver walkObserver;
switch (parkingConfig.getIter0Method()) {
case hourPenalty:
walkObserver = new CarEgressWalkObserver(parkingHandler, penaltyFunction, PenaltyCalculator.getDummyHourCalculator());
break;
case noPenalty:
walkObserver = new CarEgressWalkObserver(parkingHandler, penaltyFunction, PenaltyCalculator.getDummyZeroCalculator());
break;
case takeFromAttributes:
// CarEgressWalkChanger will handle this, we don't want to also change egress walks. Note that if it is observeOnly, the first iteration will put out zeros.
walkObserver = new CarEgressWalkObserver(parkingHandler, penaltyFunction, PenaltyCalculator.getDummyZeroCalculator());
break;
case estimateFromPlans:
ParkingCounterByPlans plansCounter = new ParkingCounterByPlans(carCounter, parkingConfig.getScenarioScaleFactor());
plansCounter.calculateByPopulation(scenario.getPopulation(), scenario.getNetwork());
walkObserver = new CarEgressWalkObserver(parkingHandler, penaltyFunction, plansCounter.generatePenaltyCalculator());
break;
default:
throw new RuntimeException("Unknown iter0 mode");
}
if (parkingConfig.getObserveOnly()) {
super.addControlerListenerBinding().toInstance(walkObserver);
} else {
super.addControlerListenerBinding().toInstance(new CarEgressWalkChanger(parkingHandler, penaltyFunction, walkObserver, parkingConfig.getIter0Method()));
}
case takeFromAttributes:
// CarEgressWalkChanger will handle this, we don't want to also change egress walks. Note that if it is observeOnly, the first iteration will put out zeros.
walkObserver = new CarEgressWalkObserver(parkingHandler, penaltyFunction, PenaltyCalculator.getDummyZeroCalculator());
break;
case estimateFromPlans:
ParkingCounterByPlans plansCounter = new ParkingCounterByPlans(carCounter, parkingConfig.getScenarioScaleFactor());
plansCounter.calculateByPopulation(scenario.getPopulation(), scenario.getNetwork());
walkObserver = new CarEgressWalkObserver(parkingHandler, penaltyFunction, plansCounter.generatePenaltyCalculator());
break;
case plans:
throw new RuntimeException("Mode \"plans\" is not working yet. Use \"events\" instead.");
/*
ParkingCounterByPlans planCounter = new ParkingCounterByPlans(carCounter, parkingConfig.getScenarioScaleFactor());
super.addControlerListenerBinding().toInstance(planCounter);
if (parkingConfig.getObserveOnly()) {
super.addControlerListenerBinding().toInstance(new CarEgressWalkObserver(planCounter, penaltyFunction));
} else {
super.addControlerListenerBinding().toInstance(new CarEgressWalkChanger(planCounter, penaltyFunction));
}
break;*/
default:
throw new RuntimeException("Unsupported calculation method " + parkingConfig.getCalculationMethod());
throw new RuntimeException("Unknown iter0 mode");
}
if (parkingConfig.getObserveOnly()) {
super.addControlerListenerBinding().toInstance(walkObserver);
} else {
super.addControlerListenerBinding().toInstance(new CarEgressWalkChanger(parkingHandler, penaltyFunction, walkObserver, parkingConfig.getIter0Method()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,23 @@

public class ParkingProxyConfigGroup extends ReflectiveConfigGroup {

public static enum CalculationMethod {none, events, plans};
public static enum Iter0Method {noPenalty, hourPenalty, takeFromAttributes, estimateFromPlans}

public static final String GROUP_NAME = "parkingProxy";
public static final String METHOD = "method";
public static final String ITER0 = "iter0";
public static final String OBSERVE_ONLY = "observeOnly";
public static final String DELAY_PER_CAR = "delayPerCar";
public static final String MAX_DELAY = "maxDelay";
public static final String SCALE_FACTOR = "scenarioScaleFactor";
public static final String TIME_BIN_SIZE = "timeBinSize";
public static final String GRID_SIZE = "gridSize";
public static final String CARS_PER_1000_PERSONS = "carsPer1000Persons";

private CalculationMethod method = CalculationMethod.events;
private Iter0Method iter0Method = Iter0Method.hourPenalty;
private boolean observeOnly = false;
private double delayPerCar = 2.5;
private double maxDelay = 900;
private int scenarioScaleFactor = 100;
private int timeBinSize = 900;
private int gridSize = 500;
private int carsPer1000Persons = 500;

public ParkingProxyConfigGroup() {
Expand All @@ -58,22 +53,12 @@ public Map<String, String> getComments() {
comments.put(SCALE_FACTOR, "The inverse of the scenario perentage, i.e. the number with which to multiply the"
+ " number of agents to get the real life population, e.g. 4 in a 25% scenario. Needs to be an Intger,"
+ " so in case of weird percentages (e.g. 1/3) please round.");
comments.put(DELAY_PER_CAR, "in seconds. Note that this should be scaled MANUALLY with the gridsize!");
comments.put(MAX_DELAY, "in seconds. Note that this should be scaled MANUALLY with the gridsize!");
comments.put(DELAY_PER_CAR, "in seconds");
comments.put(MAX_DELAY, "in seconds");
comments.put(TIME_BIN_SIZE, "in seconds");
comments.put(GRID_SIZE, "in CRS units, usually meters");
return comments;
}

@StringGetter(METHOD)
public CalculationMethod getCalculationMethod() {
return this.method;
}
@StringSetter(METHOD)
public void setCalculationMethod(CalculationMethod method) {
this.method = method;
}

@StringGetter(ITER0)
public Iter0Method getIter0Method() {
return this.iter0Method;
Expand Down Expand Up @@ -110,15 +95,6 @@ public void setMaxDelay(double maxDelay) {
this.maxDelay = maxDelay;
}

@StringGetter(GRID_SIZE)
public int getGridSize() {
return gridSize;
}
@StringSetter(GRID_SIZE)
public void setGridSize(int gridSize) {
this.gridSize = gridSize;
}

@StringGetter(TIME_BIN_SIZE)
public int getTimeBinSize() {
return timeBinSize;
Expand Down
Loading