From 6ba48ca65ecdf5a220685b561c011414acd02daa Mon Sep 17 00:00:00 2001 From: Paul Heinrich Date: Thu, 28 Nov 2024 14:43:45 +0100 Subject: [PATCH] left some comments --- .../org/matsim/contrib/dynagent/DynAgent.java | 26 ++-- .../DynAgent/BenensonDynLeg.java | 119 ++++++++++-------- .../DynAgent/NearestParkingDynLeg.java | 34 +++-- .../agentLogic/ParkingAgentLogic.java | 77 +++++++----- .../manager/FacilityBasedParkingManager.java | 6 + .../manager/ZoneParkingManager.java | 3 + .../sim/ParkingSearchConfigGroup.java | 4 +- .../AbstractParkingTest.java | 8 -- 8 files changed, 158 insertions(+), 119 deletions(-) diff --git a/contribs/dvrp/src/main/java/org/matsim/contrib/dynagent/DynAgent.java b/contribs/dvrp/src/main/java/org/matsim/contrib/dynagent/DynAgent.java index 8915326d992..d7c15d7552f 100644 --- a/contribs/dvrp/src/main/java/org/matsim/contrib/dynagent/DynAgent.java +++ b/contribs/dvrp/src/main/java/org/matsim/contrib/dynagent/DynAgent.java @@ -19,8 +19,6 @@ package org.matsim.contrib.dynagent; -import java.util.List; - import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.events.ActivityEndEvent; import org.matsim.api.core.v01.events.ActivityStartEvent; @@ -40,6 +38,8 @@ import org.matsim.pt.transitSchedule.api.TransitStopFacility; import org.matsim.vehicles.Vehicle; +import java.util.List; + public final class DynAgent implements MobsimDriverPassengerAgent { private final DynAgentLogic agentLogic; @@ -83,11 +83,11 @@ private void computeNextAction(DynAction oldDynAction, double now) { DynAction nextDynAction = agentLogic.computeNextAction(oldDynAction, now); if (nextDynAction instanceof DynActivity) { - dynActivity = (DynActivity)nextDynAction; + dynActivity = (DynActivity) nextDynAction; state = MobsimAgent.State.ACTIVITY; events.processEvent(new ActivityStartEvent(now, id, currentLinkId, null, dynActivity.getActivityType())); } else { - dynLeg = (DynLeg)nextDynAction; + dynLeg = (DynLeg) nextDynAction; state = MobsimAgent.State.LEG; } } @@ -145,7 +145,7 @@ public String getMode() { // VehicleUsingAgent @Override public final Id getPlannedVehicleId() { - Id vehId = ((DriverDynLeg)dynLeg).getPlannedVehicleId(); + Id vehId = ((DriverDynLeg) dynLeg).getPlannedVehicleId(); // according to BasicPlanAgentImpl return vehId != null ? vehId : Id.create(id, Vehicle.class); } @@ -177,13 +177,13 @@ public Id getDestinationLinkId() { // DriverAgent @Override public Id chooseNextLinkId() { - return ((DriverDynLeg)dynLeg).getNextLinkId(); + return ((DriverDynLeg) dynLeg).getNextLinkId(); } // DriverAgent @Override public void notifyMoveOverNode(Id newLinkId) { - ((DriverDynLeg)dynLeg).movedOverNode(newLinkId); + ((DriverDynLeg) dynLeg).movedOverNode(newLinkId); currentLinkId = newLinkId; } @@ -226,26 +226,28 @@ public boolean isWantingToArriveOnCurrentLink() { // PTPassengerAgent @Override public boolean getEnterTransitRoute(TransitLine line, TransitRoute transitRoute, List stopsToCome, - TransitVehicle transitVehicle) { - return ((PTPassengerDynLeg)dynLeg).getEnterTransitRoute(line, transitRoute, stopsToCome, transitVehicle); + TransitVehicle transitVehicle) { + return ((PTPassengerDynLeg) dynLeg).getEnterTransitRoute(line, transitRoute, stopsToCome, transitVehicle); } // PTPassengerAgent + // yyyy seems a bit odd, that this and the following methods are implemented for DynAgent as not every DynAgent is a PTPassengerAgent. paul, + // nov'24 @Override public boolean getExitAtStop(TransitStopFacility stop) { - return ((PTPassengerDynLeg)dynLeg).getExitAtStop(stop); + return ((PTPassengerDynLeg) dynLeg).getExitAtStop(stop); } // PTPassengerAgent @Override public Id getDesiredAccessStopId() { - return ((PTPassengerDynLeg)dynLeg).getDesiredAccessStopId(); + return ((PTPassengerDynLeg) dynLeg).getDesiredAccessStopId(); } // PTPassengerAgent @Override public Id getDesiredDestinationStopId() { - return ((PTPassengerDynLeg)dynLeg).getDesiredDestinationStopId(); + return ((PTPassengerDynLeg) dynLeg).getDesiredDestinationStopId(); } // PTPassengerAgent diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/BenensonDynLeg.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/BenensonDynLeg.java index 5bd6ca248bb..c7b041ba21a 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/BenensonDynLeg.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/BenensonDynLeg.java @@ -21,30 +21,30 @@ /** * @author schlenther *

- * Benenson et al defined 3 phases of parking search + * Benenson et al. defined 3 phases of parking search * OBSERVING: observation of parking situation while driving towards destination * SEARCH_WHILE_APPROACH: estimating the amount of free parking lots on the way to destination * and if applicable parking before arriving * SEARCH_FOR_NEXT: taking the next free parking space if it isn't too far away from destination */ enum ParkingMode { - DRIVING, OBSERVING, SEARCH_WHILE_APPROACH, SEARCH_FOR_NEXT + DRIVING, OBSERVING, SEARCH_WHILE_APPROACH, SEARCH_FOR_NEXT } -public class BenensonDynLeg extends ParkingDynLeg{ +public class BenensonDynLeg extends ParkingDynLeg { private static final Logger logger = LogManager.getLogger(BenensonDynLeg.class); private static final boolean logForDebug = false; private double totalObservedParkingSpaces = 0.0; private double observedFreeParkingSpaces = 0.0; - private double firstDestinationLinkEnterTime = 0; - private ParkingMode legStage = ParkingMode.DRIVING; + private double firstDestinationLinkEnterTime = 0; + private ParkingMode legStage = ParkingMode.DRIVING; public BenensonDynLeg(String mode, NetworkRoute route, ParkingSearchLogic logic, - ParkingSearchManager parkingManager, Id vehicleId, MobsimTimer timer, EventsManager events) { + ParkingSearchManager parkingManager, Id vehicleId, MobsimTimer timer, EventsManager events) { super(mode, route, logic, parkingManager, vehicleId, timer, events); - if (!(logic instanceof BenensonParkingSearchLogic)){ + if (!(logic instanceof BenensonParkingSearchLogic)) { throw new RuntimeException(); } } @@ -55,56 +55,68 @@ public void movedOverNode(Id newLinkId) { currentLinkId = newLinkId; if (this.legStage == ParkingMode.DRIVING) { - if (((BenensonParkingSearchLogic) this.logic).transitionToObservingBehaviour(currentLinkId, this.route.getEndLinkId())) { - this.legStage = ParkingMode.OBSERVING; + if (((BenensonParkingSearchLogic) this.logic).transitionToObservingBehaviour(currentLinkId, this.route.getEndLinkId())) { + this.legStage = ParkingMode.OBSERVING; this.events.processEvent(new StartParkingSearchEvent(timer.getTimeOfDay(), vehicleId, currentLinkId)); - if(logForDebug)logger.error("vehicle " + this.vehicleId + " goes into observing on link " + this.currentLinkId); + if (logForDebug) { + logger.error("vehicle " + this.vehicleId + " goes into observing on link " + this.currentLinkId); + } } } - if(this.legStage == ParkingMode.OBSERVING ){ + if (this.legStage == ParkingMode.OBSERVING) { memorizeParkingSituationAndIsSomethingFree(); - if (((BenensonParkingSearchLogic) this.logic).transitionToParkingBehaviour(currentLinkId, this.route.getEndLinkId())) { - this.legStage = ParkingMode.SEARCH_WHILE_APPROACH; - if(logForDebug)logger.error("vehicle " + this.vehicleId + " goes into parking on link " + this.currentLinkId); + if (((BenensonParkingSearchLogic) this.logic).transitionToParkingBehaviour(currentLinkId, this.route.getEndLinkId())) { + this.legStage = ParkingMode.SEARCH_WHILE_APPROACH; + if (logForDebug) { + logger.error("vehicle " + this.vehicleId + " goes into parking on link " + this.currentLinkId); + } } } - if(this.legStage == ParkingMode.SEARCH_WHILE_APPROACH){ - if(currentLinkId.equals(route.getEndLinkId())){ + if (this.legStage == ParkingMode.SEARCH_WHILE_APPROACH) { + if (currentLinkId.equals(route.getEndLinkId())) { this.legStage = ParkingMode.SEARCH_FOR_NEXT; - this.firstDestinationLinkEnterTime = timer.getTimeOfDay(); - } - else{ - if(memorizeParkingSituationAndIsSomethingFree()){ + this.firstDestinationLinkEnterTime = timer.getTimeOfDay(); + } else { + if (memorizeParkingSituationAndIsSomethingFree()) { double pUnoccupied = 0; - if(this.totalObservedParkingSpaces > 0){ + if (this.totalObservedParkingSpaces > 0) { pUnoccupied = this.observedFreeParkingSpaces / this.totalObservedParkingSpaces; } - if ( ((BenensonParkingSearchLogic)this.logic).wantToParkHere(pUnoccupied, currentLinkId, route.getEndLinkId())){ - if (logForDebug) logger.error("vehicle " + this.vehicleId + " would like to park on link" + currentLinkId - + "\n \t pUnoccupied = " + pUnoccupied + "\n\t totalObservedParkingSpaces = " + totalObservedParkingSpaces + "\n\t observedFreeSpaces = " + this.observedFreeParkingSpaces); - hasFoundParking = parkingManager.reserveSpaceIfVehicleCanParkHere(vehicleId, currentLinkId); - } - } - else{ - if(logForDebug)logger.error("nothing free for vehicle " + vehicleId + " on link " + currentLinkId); + if (((BenensonParkingSearchLogic) this.logic).wantToParkHere(pUnoccupied, currentLinkId, route.getEndLinkId())) { + if (logForDebug) { + logger.error("vehicle " + this.vehicleId + " would like to park on link" + currentLinkId + + "\n \t pUnoccupied = " + pUnoccupied + "\n\t totalObservedParkingSpaces = " + totalObservedParkingSpaces + "\n\t " + + "observedFreeSpaces = " + this.observedFreeParkingSpaces); + } + hasFoundParking = parkingManager.reserveSpaceIfVehicleCanParkHere(vehicleId, currentLinkId); + } + } else { + if (logForDebug) { + logger.error("nothing free for vehicle " + vehicleId + " on link " + currentLinkId); + } } } } - if (this.legStage == ParkingMode.SEARCH_FOR_NEXT){ - if (logForDebug) logger.error("vehicle " + this.vehicleId + " is in PHASE3 on link " + this.currentLinkId); - //if( ((BenensonParkingSearchLogic)this.logic).isDriverInAcceptableDistance(currentLinkId, route.getEndLinkId(), this.firstDestLinkEnterTimer, timer.getTimeOfDay()) ){ + if (this.legStage == ParkingMode.SEARCH_FOR_NEXT) { + if (logForDebug) { + logger.error("vehicle " + this.vehicleId + " is in PHASE3 on link " + this.currentLinkId); + } + //if( ((BenensonParkingSearchLogic)this.logic).isDriverInAcceptableDistance(currentLinkId, route.getEndLinkId(), this + // .firstDestLinkEnterTimer, timer.getTimeOfDay()) ){ - hasFoundParking = parkingManager.reserveSpaceIfVehicleCanParkHere(vehicleId, currentLinkId); + hasFoundParking = parkingManager.reserveSpaceIfVehicleCanParkHere(vehicleId, currentLinkId); - if (logForDebug) logger.error("vehicle " + this.vehicleId + " tries in PHASE3 to park on link " + this.currentLinkId + ", " + - (int) (timer.getTimeOfDay() - this.firstDestinationLinkEnterTime) / 60 + ":" + (int) (timer.getTimeOfDay() - this.firstDestinationLinkEnterTime) % 60 - + " min after passing destination. Result: " + hasFoundParking); - //} - } - } + if (logForDebug) { + logger.error("vehicle " + this.vehicleId + " tries in PHASE3 to park on link " + this.currentLinkId + ", " + + (int) (timer.getTimeOfDay() - this.firstDestinationLinkEnterTime) / 60 + ":" + (int) (timer.getTimeOfDay() - this.firstDestinationLinkEnterTime) % 60 + + " min after passing destination. Result: " + hasFoundParking); + } + //} + } + } - /** + /** * returns true if there is at least one empty slot on the current link */ private boolean memorizeParkingSituationAndIsSomethingFree() { @@ -124,13 +136,14 @@ public Id getNextLinkId() { return route.getEndLinkId(); } return linkIds.get(currentLinkIdx + 1); - } - else { + } else { if (hasFoundParking) { - if(logForDebug)logger.error("vehicle " + this.vehicleId + " has found a parking on link " + this.currentLinkId + " after passing " + Math.abs((this.route.getLinkIds().size() - this.currentLinkIdx - 3)) + " links"); + if (logForDebug) { + logger.error("vehicle " + this.vehicleId + " has found a parking on link " + this.currentLinkId + " after passing " + Math.abs((this.route.getLinkIds() + .size() - this.currentLinkIdx - 3)) + " links"); + } return null; - } - else { + } else { if (this.currentAndNextParkLink != null) { if (currentAndNextParkLink.getFirst().equals(currentLinkId)) { // we already calculated this @@ -139,15 +152,15 @@ public Id getNextLinkId() { } Id nextLinkId; - if(this.legStage == ParkingMode.SEARCH_FOR_NEXT){ - nextLinkId = ((BenensonParkingSearchLogic) this.logic).getNextLinkRandomInAcceptableDistance(currentLinkId, this.route.getEndLinkId(), - vehicleId, firstDestinationLinkEnterTime, this.timer.getTimeOfDay(), mode); - } - else{ + if (this.legStage == ParkingMode.SEARCH_FOR_NEXT) { + nextLinkId = ((BenensonParkingSearchLogic) this.logic).getNextLinkRandomInAcceptableDistance(currentLinkId, + this.route.getEndLinkId(), + vehicleId, firstDestinationLinkEnterTime, this.timer.getTimeOfDay(), mode); + } else { nextLinkId = ((BenensonParkingSearchLogic) (this.logic)).getNextLinkBenensonRouting(currentLinkId, route.getEndLinkId(), mode); - } - currentAndNextParkLink = new Tuple<>(currentLinkId, nextLinkId); - return nextLinkId; + } + currentAndNextParkLink = new Tuple<>(currentLinkId, nextLinkId); + return nextLinkId; } } } diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/NearestParkingDynLeg.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/NearestParkingDynLeg.java index a5f4cdcf143..ba81ede9c1d 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/NearestParkingDynLeg.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/NearestParkingDynLeg.java @@ -45,10 +45,12 @@ public NearestParkingDynLeg(Leg currentPlannedLeg, NetworkRoute route, Plan plan this.currentPlannedLeg = currentPlannedLeg; this.plan = plan; this.planIndexNextActivity = planIndexNextActivity; - if (ParkingUtils.checkIfActivityHasNoParking(followingActivity)) + if (ParkingUtils.checkIfActivityHasNoParking(followingActivity)) { parkingAtEndOfLeg = false; - if (ParkingUtils.checkIfActivityHasPassengerInteraction(followingActivity)) + } + if (ParkingUtils.checkIfActivityHasPassengerInteraction(followingActivity)) { passangerInteractionAtParkingFacilityAtEndOfLeg = true; + } } @Override @@ -67,20 +69,22 @@ public void movedOverNode(Id newLinkId) { if (hasFoundParking) { this.events.processEvent(new ReserveParkingLocationEvent(timer.getTimeOfDay(), vehicleId, currentLinkId, currentLinkId)); nextSelectedParkingLink = currentLinkId; - } else + } else { ((FacilityBasedParkingManager) parkingManager).registerRejectedReservation(timer.getTimeOfDay()); + } } } } else if (followingActivity.getLinkId().equals(newLinkId)) { - if (alreadyReservedParking) + if (alreadyReservedParking) { hasFoundParking = true; - else { + } else { hasFoundParking = parkingManager.reserveSpaceIfVehicleCanParkHere(vehicleId, currentLinkId); if (hasFoundParking) { this.events.processEvent(new ReserveParkingLocationEvent(timer.getTimeOfDay(), vehicleId, currentLinkId, currentLinkId)); nextSelectedParkingLink = currentLinkId; - } else + } else { ((FacilityBasedParkingManager) parkingManager).registerRejectedReservation(timer.getTimeOfDay()); + } } } } @@ -138,11 +142,10 @@ public Id getNextLinkId() { // need to find the next link double nextPickupTime; double maxParkingDuration; - if (passangerInteractionAtParkingFacilityAtEndOfLeg){ + if (passangerInteractionAtParkingFacilityAtEndOfLeg) { nextPickupTime = 0.; maxParkingDuration = followingActivity.getMaximumDuration().seconds(); - } - else { + } else { nextPickupTime = currentPlannedLeg.getDepartureTime().seconds() + followingActivity.getMaximumDuration().seconds(); maxParkingDuration = nextPickupTime - timer.getTimeOfDay(); } @@ -163,11 +166,12 @@ public Id getNextLinkId() { nextSelectedParkingLink = nextPlanedParkingLink; if (((NearestParkingSpotSearchLogic) this.logic).canReserveParkingSlot()) { alreadyReservedParking = parkingManager.reserveSpaceIfVehicleCanParkHere(vehicleId, nextSelectedParkingLink); - if (alreadyReservedParking) + if (alreadyReservedParking) { this.events.processEvent( new ReserveParkingLocationEvent(timer.getTimeOfDay(), vehicleId, currentLinkId, nextSelectedParkingLink)); - else + } else { ((FacilityBasedParkingManager) parkingManager).registerRejectedReservation(timer.getTimeOfDay()); + } } else { this.events.processEvent( new SelectNewParkingLocationEvent(timer.getTimeOfDay(), vehicleId, currentLinkId, nextSelectedParkingLink)); @@ -176,13 +180,16 @@ public Id getNextLinkId() { } } currentAndNextParkLink = new Tuple<>(currentLinkId, nextLinkId); - if (((NearestParkingSpotSearchLogic) this.logic).getNextRoute() != null) + if (((NearestParkingSpotSearchLogic) this.logic).getNextRoute() != null) { currentPlannedLeg.setRoute(((NearestParkingSpotSearchLogic) this.logic).getNextRoute()); + } return nextLinkId; } } } + //yyyy I assume, the vehicle is removed from the link's queue and thus waiting for parking does not influence the behaviour of the mobsim? + // Does this make sense? paul, nov'24 private void createWaitingActivityUntilPassengerInteractionIsPossible(Id newLinkId, Id vehicleId, double now) { Activity waitingActivity = PopulationUtils.createActivityFromLinkId(ParkingUtils.WaitingForParkingActivityType, newLinkId); ParkingUtils.setNoParkingForActivity(waitingActivity); @@ -195,7 +202,8 @@ private void removeNextActivityAndFollowingLeg() { plan.getPlanElements().remove(planIndexNextActivity); plan.getPlanElements().remove(planIndexNextActivity); // log.info( -// plan.getPerson().getId().toString() + ": Parking activity after getOff point '" + ((Activity)plan.getPlanElements().get(planIndexNextActivity - 2)).getType() + "' is removed, because no parking facility was found."); +// plan.getPerson().getId().toString() + ": Parking activity after getOff point '" + ((Activity)plan.getPlanElements().get +// (planIndexNextActivity - 2)).getType() + "' is removed, because no parking facility was found."); } public boolean driveToBaseWithoutParking() { diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/ParkingAgentLogic.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/ParkingAgentLogic.java index dd2fb4fa74b..31e175a3d30 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/ParkingAgentLogic.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/ParkingAgentLogic.java @@ -19,25 +19,14 @@ package org.matsim.contrib.parking.parkingsearch.DynAgent.agentLogic; -import java.util.List; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Link; 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.Plan; -import org.matsim.api.core.v01.population.PlanElement; -import org.matsim.api.core.v01.population.Route; -import org.matsim.contrib.dynagent.DynAction; -import org.matsim.contrib.dynagent.DynActivity; -import org.matsim.contrib.dynagent.DynAgent; -import org.matsim.contrib.dynagent.DynAgentLogic; -import org.matsim.contrib.dynagent.IdleDynActivity; -import org.matsim.contrib.dynagent.StaticPassengerDynLeg; +import org.matsim.api.core.v01.population.*; +import org.matsim.contrib.dynagent.*; import org.matsim.contrib.parking.parkingsearch.DynAgent.ParkingDynLeg; import org.matsim.contrib.parking.parkingsearch.ParkingUtils; import org.matsim.contrib.parking.parkingsearch.manager.ParkingSearchManager; @@ -56,8 +45,12 @@ import org.matsim.pt.routes.TransitPassengerRoute; import org.matsim.vehicles.Vehicle; +import java.util.List; + /** + * This class represents the logic for a {@link DynAgent}. It can only handle car legs for parking. + * * @author jbischoff */ public class ParkingAgentLogic implements DynAgentLogic { @@ -139,17 +132,17 @@ public DynAction computeNextAction(DynAction oldAction, double now) { // ordinary activity: get next Leg, if car: go to car, otherwise add ordinary leg by other mode // walk-leg to car: add unpark activity // unpark activity: find the way to the next route & start leg - return switch (lastParkActionState) { - case ACTIVITY -> nextStateAfterActivity(oldAction, now); - case CARTRIP -> nextStateAfterCarTrip(oldAction, now); - case NONCARTRIP -> nextStateAfterNonCarTrip(oldAction, now); - case PARKACTIVITY -> nextStateAfterParkActivity(oldAction, now); - case UNPARKACTIVITY -> nextStateAfterUnParkActivity(oldAction, now); - case WALKFROMPARK -> nextStateAfterWalkFromPark(oldAction, now); - case WALKTOPARK -> nextStateAfterWalkToPark(oldAction, now); - }; + return switch (lastParkActionState) { + case ACTIVITY -> nextStateAfterActivity(oldAction, now); + case CARTRIP -> nextStateAfterCarTrip(oldAction, now); + case NONCARTRIP -> nextStateAfterNonCarTrip(oldAction, now); + case PARKACTIVITY -> nextStateAfterParkActivity(oldAction, now); + case UNPARKACTIVITY -> nextStateAfterUnParkActivity(oldAction, now); + case WALKFROMPARK -> nextStateAfterWalkFromPark(oldAction, now); + case WALKTOPARK -> nextStateAfterWalkToPark(oldAction, now); + }; - } + } protected DynAction nextStateAfterUnParkActivity(DynAction oldAction, double now) { // we have unparked, now we need to get going by car again. @@ -164,7 +157,9 @@ protected DynAction nextStateAfterUnParkActivity(DynAction oldAction, double now //this could be Car, Carsharing, Motorcylce, or whatever else mode we have, so we want our leg to reflect this. return new ParkingDynLeg(currentLeg.getMode(), actualRoute, parkingLogic, parkingManager, currentlyAssignedVehicleId, timer, events); - } else throw new RuntimeException("parking location mismatch"); + } else { + throw new RuntimeException("parking location mismatch"); + } } @@ -175,19 +170,25 @@ protected DynAction nextStateAfterWalkToPark(DynAction oldAction, double now) { } protected DynAction nextStateAfterWalkFromPark(DynAction oldAction, double now) { - //walkleg complete, time to get the next activity from the plan Elements and start it, this is basically the same as arriving on any other mode + //walkleg complete, time to get the next activity from the plan Elements and start it, this is basically the same as arriving on any other + // mode return nextStateAfterNonCarTrip(oldAction, now); } protected DynAction nextStateAfterParkActivity(DynAction oldAction, double now) { // add a walk leg after parking Leg currentPlannedLeg = (Leg) currentPlanElement; + + // yyyy I think we don't want LinkWrapperFacilities but the actual facilities. Right now, only calculates the teleportation from link to + // link, but if the parking happens on the same link as the activity, then it does not consider the coordinates. Thus, it produces a + // degenerated (0m and 0s) walk leg. paul, nov'24 Facility fromFacility = new LinkWrapperFacility(network.getLinks().get(agent.getCurrentLinkId())); Facility toFacility = new LinkWrapperFacility(network.getLinks().get(currentPlannedLeg.getRoute().getEndLinkId())); List walkTrip = walkRouter.calcRoute( DefaultRoutingRequest.withoutAttributes(fromFacility, toFacility, now, plan.getPerson())); if (walkTrip.size() != 1 || !(walkTrip.get(0) instanceof Leg walkLeg)) { - String message = "walkRouter returned something else than a single Leg, e.g. it routes walk on the network with non_network_walk to access the network. Not implemented in parking yet!"; + String message = "walkRouter returned something else than a single Leg, e.g. it routes walk on the network with non_network_walk to " + + "access the network. Not implemented in parking yet!"; log.error(message); throw new RuntimeException(message); } @@ -224,7 +225,9 @@ protected DynAction nextStateAfterCarTrip(DynAction oldAction, double now) { this.currentlyAssignedVehicleId = null; this.parkingLogic.reset(); return new IdleDynActivity(this.stageInteractionType, now + configGroup.getParkduration()); - } else throw new RuntimeException("No parking possible"); + } else { + throw new RuntimeException("No parking possible"); + } } protected DynAction nextStateAfterActivity(DynAction oldAction, double now) { @@ -233,15 +236,22 @@ protected DynAction nextStateAfterActivity(DynAction oldAction, double now) { planIndex++; this.currentPlanElement = plan.getPlanElements().get(planIndex); Leg currentLeg = (Leg) currentPlanElement; + + // yyyy can only handle car legs for parking :-( paul, nov'24 if (currentLeg.getMode().equals(TransportMode.car)) { Id vehicleId = Id.create(this.agent.getId(), Vehicle.class); Id parkLink = this.parkingManager.getVehicleParkingLocation(vehicleId); if (parkLink == null) { - //this is the first activity of a day and our parking manager does not provide informations about initial stages. We suppose the car is parked where we are + //this is the first activity of a day and our parking manager does not provide information about initial stages. We suppose the + // car is parked where we are parkLink = agent.getCurrentLinkId(); } + // yyyy I think we don't want LinkWrapperFacilities but the actual facilities. Right now, only calculates the teleportation from + // link to + // link, but if the parking happens on the same link as the activity, then it does not consider the coordinates. Thus, it produces a + // degenerated (0m and 0s) walk leg. paul, nov'24 Facility fromFacility = new LinkWrapperFacility(network.getLinks().get(agent.getCurrentLinkId())); Id teleportedParkLink = this.teleportationLogic.getVehicleLocation(agent.getCurrentLinkId(), vehicleId, parkLink, now, currentLeg.getMode()); @@ -249,7 +259,8 @@ protected DynAction nextStateAfterActivity(DynAction oldAction, double now) { List walkTrip = walkRouter.calcRoute( DefaultRoutingRequest.withoutAttributes(fromFacility, toFacility, now, plan.getPerson())); if (walkTrip.size() != 1 || !(walkTrip.get(0) instanceof Leg walkLeg)) { - String message = "walkRouter returned something else than a single Leg, e.g. it routes walk on the network with non_network_walk to access the network. Not implemented in parking yet!"; + String message = "walkRouter returned something else than a single Leg, e.g. it routes walk on the network with " + + "non_network_walk to access the network. Not implemented in parking yet!"; log.error(message); throw new RuntimeException(message); } @@ -271,9 +282,11 @@ protected DynAction nextStateAfterActivity(DynAction oldAction, double now) { return new StaticPassengerDynLeg(currentLeg.getRoute(), currentLeg.getMode()); } - } else throw new RuntimeException( - "no more leg to follow but activity is ending\nLastPlanElement: " + currentPlanElement.toString() + "\n Agent " + this.agent.getId() + "\nTime: " + Time.writeTime( - now)); + } else { + throw new RuntimeException( + "no more leg to follow but activity is ending\nLastPlanElement: " + currentPlanElement.toString() + "\n Agent " + this.agent.getId() + + "\nTime: " + Time.writeTime(now)); + } } } diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/manager/FacilityBasedParkingManager.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/manager/FacilityBasedParkingManager.java index 40d4934e838..8c8491381c3 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/manager/FacilityBasedParkingManager.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/manager/FacilityBasedParkingManager.java @@ -44,6 +44,12 @@ import java.util.Map.Entry; /** + * Manages vehicles parking actions at facilities or freely on the street. I.e. keeps track of the capacity of the facilities. This class has + * additional functionality: + * - It can handle parking reservations. + * - It triggers reporting of parking statistics. + * - It can handle vehicles waiting for a parking space. * + * * @author jbischoff, schlenther, Ricardo Ewert */ public class FacilityBasedParkingManager implements ParkingSearchManager { diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/manager/ZoneParkingManager.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/manager/ZoneParkingManager.java index 21d0ebdf06e..5dc503ac08a 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/manager/ZoneParkingManager.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/manager/ZoneParkingManager.java @@ -19,6 +19,9 @@ import java.util.Set; /** + * Extends the facility based manager, thus parks vehicles at facilities but also keeps track of the occupancy of zones. A zone is defined by a set + * of links. + * * @author tschlenther */ public class ZoneParkingManager extends FacilityBasedParkingManager { diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/sim/ParkingSearchConfigGroup.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/sim/ParkingSearchConfigGroup.java index d86ebccb779..176f26f3cda 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/sim/ParkingSearchConfigGroup.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/sim/ParkingSearchConfigGroup.java @@ -75,6 +75,7 @@ public double getParkduration() { return parkDuration; } + //yyyy shouldn't this parameter be facility specific? paul, nov'24 @StringGetter(AVGPARKINGSLOTLENGTH) public double getAvgparkingslotlength() { return avgParkingSlotLength; @@ -170,7 +171,8 @@ protected void checkConsistency(Config config) { super.checkConsistency(config); if (getFractionCanCheckFreeCapacitiesInAdvanced() != 0. && !getParkingSearchManagerType().equals(ParkingSearchManagerType.FacilityBasedParkingManager)) { - log.warn("Fraction of agents who can check free capacities in advanced has no impact on your selected ParkingSearchManagerType, because" + + log.warn("Fraction of agents who can check free capacities in advanced has no impact on your selected ParkingSearchManagerType, " + + "because" + " " + "it is only implemented for the FacilityBasedParkingManager."); } diff --git a/contribs/parking/src/test/java/org/matsim/contrib/parking/parkingsearch/facilityBasedParking/AbstractParkingTest.java b/contribs/parking/src/test/java/org/matsim/contrib/parking/parkingsearch/facilityBasedParking/AbstractParkingTest.java index 245043b1b3f..fee02ad587f 100644 --- a/contribs/parking/src/test/java/org/matsim/contrib/parking/parkingsearch/facilityBasedParking/AbstractParkingTest.java +++ b/contribs/parking/src/test/java/org/matsim/contrib/parking/parkingsearch/facilityBasedParking/AbstractParkingTest.java @@ -56,10 +56,6 @@ void testParking1_onlyFacilityParking() { Config config = getConfig(parkingConfig); config.plans().setInputFile("population1.xml"); run(config); - utils.copyFileFromOutputToInput("output_plans.xml.gz"); - utils.copyFileFromOutputToInput("output_events.xml.gz"); - utils.copyFileFromOutputToInput("ITERS/it.0/0.parkingStats.csv", "0.parkingStats.csv"); - utils.copyFileFromOutputToInput("ITERS/it.0/0.parkingStatsPerTimeSteps.csv", "0.parkingStatsPerTimeSteps.csv"); validate(); } @@ -74,10 +70,6 @@ void testParking10_onlyFacilityParking() { Config config = getConfig(parkingConfig); config.plans().setInputFile("population10.xml"); run(config); - utils.copyFileFromOutputToInput("output_plans.xml.gz"); - utils.copyFileFromOutputToInput("output_events.xml.gz"); - utils.copyFileFromOutputToInput("ITERS/it.0/0.parkingStats.csv", "0.parkingStats.csv"); - utils.copyFileFromOutputToInput("ITERS/it.0/0.parkingStatsPerTimeSteps.csv", "0.parkingStatsPerTimeSteps.csv"); validate(); }