From 78c849415ead0b72e6bc13b16973a720e7d4e31f Mon Sep 17 00:00:00 2001 From: Tobias Kohl Date: Thu, 6 Jun 2024 13:27:49 +0200 Subject: [PATCH] remove some confusing or unimplemented functionality --- .../LinearPenaltyFunctionWithCap.java | 6 +- .../parkingproxy/ParkingProxyModule.java | 72 +++++++------------ .../config/ParkingProxyConfigGroup.java | 28 +------- 3 files changed, 31 insertions(+), 75 deletions(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/LinearPenaltyFunctionWithCap.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/LinearPenaltyFunctionWithCap.java index 810f7de6f35..af9b2fbb758 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/LinearPenaltyFunctionWithCap.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/LinearPenaltyFunctionWithCap.java @@ -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); } } diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/ParkingProxyModule.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/ParkingProxyModule.java index 8f83c20d126..f356f0911e8 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/ParkingProxyModule.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/ParkingProxyModule.java @@ -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) { @@ -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())); } } diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/config/ParkingProxyConfigGroup.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/config/ParkingProxyConfigGroup.java index 060b072ecdc..0d0d0fec3af 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/config/ParkingProxyConfigGroup.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/config/ParkingProxyConfigGroup.java @@ -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() { @@ -58,22 +53,12 @@ public Map 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; @@ -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;