From b24d01bff651500b1377d538c6304d644f0d5360 Mon Sep 17 00:00:00 2001 From: Kai Nagel Date: Mon, 12 Feb 2024 15:35:50 +0100 Subject: [PATCH 1/3] changes --- .../PC2/GeneralParkingModule.java | 50 ++---- .../PC2/infrastructure/PC2Parking.java | 2 +- .../PC2/infrastructure/PublicParking.java | 22 +-- .../PC2/scoring/ParkingScore.java | 4 +- .../PC2/scoring/ParkingScoreManager.java | 2 +- .../simulation/ParkingChoiceSimulation.java | 77 +++++---- .../PC2/simulation/ParkingInfrastructure.java | 18 +-- .../ParkingInfrastructureManager.java | 148 +++++++++--------- 8 files changed, 152 insertions(+), 171 deletions(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/GeneralParkingModule.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/GeneralParkingModule.java index 29b225d5397..3a85713682c 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/GeneralParkingModule.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/GeneralParkingModule.java @@ -13,59 +13,31 @@ public class GeneralParkingModule implements StartupListener, BeforeMobsimListen private final Controler controler; private ParkingScore parkingScoreManager; -// public final ParkingScore getParkingScoreManager() { -// return parkingScoreManager; -// } - - public final void setParkingScoreManager(ParkingScore parkingScoreManager) { - this.parkingScoreManager = parkingScoreManager; - } - private ParkingInfrastructure parkingInfrastructureManager; private ParkingChoiceSimulation parkingChoiceSimulation; public GeneralParkingModule(Controler controler){ this.controler = controler ; - controler.addControlerListener(this); } - - @Override - public void notifyStartup(StartupEvent event) { + + @Override public void notifyStartup(StartupEvent event) { parkingChoiceSimulation = new ParkingChoiceSimulation(controler.getScenario(), parkingInfrastructureManager); controler.getEvents().addHandler( parkingChoiceSimulation ); -// controler.addControlerListener(parkingSimulation); - // was not doing anything there. kai, jul'15 } -// public final ParkingInfrastructure getParkingInfrastructure() { -// return parkingInfrastructureManager; -// } - - public final void setParkingInfrastructurManager(ParkingInfrastructure parkingInfrastructureManager) { - this.parkingInfrastructureManager = parkingInfrastructureManager; + @Override public void notifyBeforeMobsim(BeforeMobsimEvent event) { + parkingScoreManager.notifyBeforeMobsim(); + parkingInfrastructureManager.notifyBeforeMobsim(); + parkingChoiceSimulation.notifyBeforeMobsim(); } -// @Deprecated -// // lower level objects may keep back pointers to higher level objects if they have to, but we prefer that they do not provide them -// // as a service. kai, apr'15 -// public final Controler getControler() { -// return controler; -// } - - @Override - public void notifyBeforeMobsim(BeforeMobsimEvent event) { - parkingScoreManager.prepareForNewIteration(); - parkingInfrastructureManager.reset(); - parkingChoiceSimulation.prepareForNewIteration(); + public final void setParkingScoreManager(ParkingScore parkingScoreManager) { + this.parkingScoreManager = parkingScoreManager; } -// protected final ParkingInfrastructure getParkingInfrastructureManager() { -// return parkingInfrastructureManager; -// } -// -// protected final ParkingChoiceSimulation getParkingSimulation() { -// return parkingSimulation; -// } + public final void setParkingInfrastructurManager(ParkingInfrastructure parkingInfrastructureManager) { + this.parkingInfrastructureManager = parkingInfrastructureManager; + } } diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/infrastructure/PC2Parking.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/infrastructure/PC2Parking.java index d0fdfda187d..0e2a9bc2cbb 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/infrastructure/PC2Parking.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/infrastructure/PC2Parking.java @@ -26,7 +26,7 @@ public interface PC2Parking { public Id getId(); - public int getMaximumParkingCapacity(); +// public int getMaximumParkingCapacity(); public int getAvailableParkingCapacity(); diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/infrastructure/PublicParking.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/infrastructure/PublicParking.java index 28a18a2dce8..93256534074 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/infrastructure/PublicParking.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/infrastructure/PublicParking.java @@ -25,12 +25,12 @@ public class PublicParking implements PC2Parking { - private Id id = null; - private int capacity =0; + private final Id id; + private final int capacity; private int availableParking=0; private Coord coord=null; private ParkingCostModel parkingCostModel=null; - private String groupName; + private final String groupName; public PublicParking(Id id, int capacity, Coord coord, ParkingCostModel parkingCostModel, String groupName){ this.id=id; @@ -56,14 +56,14 @@ public Coord getCoordinate(){ return coord; } - public boolean isParkingAvailable(){ - return availableParking>0; - } - - @Override - public int getMaximumParkingCapacity(){ - return capacity; - } +// public boolean isParkingAvailable(){ +// return availableParking>0; +// } +// +// @Override +// public int getMaximumParkingCapacity(){ +// return capacity; +// } @Override public int getAvailableParkingCapacity(){ diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/scoring/ParkingScore.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/scoring/ParkingScore.java index 1eed79efbf2..a6a36fadc7f 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/scoring/ParkingScore.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/scoring/ParkingScore.java @@ -18,7 +18,7 @@ public interface ParkingScore { void addScore(Id id, double incValue); - void prepareForNewIteration(); + void notifyBeforeMobsim(); double getParkingScoreScalingFactor(); @@ -34,4 +34,4 @@ public interface ParkingScore { void setRandomErrorTermManger(RandomErrorTermManager randomErrorTermManager); -} \ No newline at end of file +} diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/scoring/ParkingScoreManager.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/scoring/ParkingScoreManager.java index 49fd0109768..abc90d45b94 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/scoring/ParkingScoreManager.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/scoring/ParkingScoreManager.java @@ -108,7 +108,7 @@ public synchronized void addScore(Id id, double incValue) { } @Override - public synchronized void prepareForNewIteration() { + public synchronized void notifyBeforeMobsim() { scores = new DoubleValueHashMap<>(); } diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/simulation/ParkingChoiceSimulation.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/simulation/ParkingChoiceSimulation.java index 29bc9b7c65b..db2a710a0a8 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/simulation/ParkingChoiceSimulation.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/simulation/ParkingChoiceSimulation.java @@ -46,11 +46,9 @@ public final class ParkingChoiceSimulation implements PersonDepartureEventHandler, PersonArrivalEventHandler, ActivityEndEventHandler { - - private final ParkingInfrastructure parkingInfrastructureManager; private final Scenario scenario; - private IntegerValueHashMap> currentPlanElementIndex; + private IntegerValueHashMap> currentPlanElementIndices; private HashMap, ParkingOperationRequestAttributes> parkingOperationRequestAttributes; private DoubleValueHashMap> firstDepartureTimeOfDay; @@ -61,7 +59,7 @@ public ParkingChoiceSimulation(Scenario scenario, ParkingInfrastructure parkingI @Override public void handleEvent(ActivityEndEvent event) { - currentPlanElementIndex.increment(event.getPersonId()); + currentPlanElementIndices.increment(event.getPersonId() ); } @Override @@ -76,25 +74,37 @@ public void handleEvent(PersonDepartureEvent event) { } if (isFirstCarDepartureOfDay(event.getPersonId())) { - // (special case, think about it later) + // for the first departure of the day, we do not know when the parking actually started. The scoring is, in + // consequence, not done here, but done when _starting_ the _last_ parking of the day (see there). + // (yy what happens if the agent arrives by car but departs by some other mode, or the other way round? Can happen in particular if there is an additional home stop during the day.) ParkingOperationRequestAttributes parkingAttributes = new ParkingOperationRequestAttributes(); parkingAttributes.personId = event.getPersonId(); - // this is a trick to get the correct departure time + + // for the time being, we memorize a parking record with arrival time zero. This is corrected later, at the last arrival of the day. parkingAttributes.arrivalTime = 0; parkingAttributes.parkingDurationInSeconds = GeneralLib.getIntervalDuration(0, event.getTime()); parkingInfrastructureManager.personCarDepartureEvent(parkingAttributes); } else { + // parking has just ended: + + // finalize the corresponding record: ParkingOperationRequestAttributes parkingAttributes = parkingOperationRequestAttributes.get(event.getPersonId()); parkingAttributes.parkingDurationInSeconds = GeneralLib.getIntervalDuration(parkingAttributes.arrivalTime, event.getTime()); + + // hedge against a special case: if (parkingAttributes.parkingDurationInSeconds == 24 * 3600) { // (yyyy no idea what this is and why. kai, jul'15) + // (Presumably, the code is such that it cannot handle a parking duration of zero. Presumably, a parking + // duration of zero cannot happen, and therefore this is ok. However, if someone parks for exactly 24 hours, + // then this is at some point mapped back to zero, and then it may happen. kai, feb'24) parkingAttributes.parkingDurationInSeconds = 1; // not zero, because this might lead to NaN } - PC2Parking parking = parkingInfrastructureManager.personCarDepartureEvent(parkingAttributes); - parkingInfrastructureManager.scoreParkingOperation(parkingAttributes, parking); + // score the parking: + final PC2Parking parking = parkingInfrastructureManager.personCarDepartureEvent( parkingAttributes ); + parkingInfrastructureManager.scoreParkingOperation(parkingAttributes, parking ); } } @@ -106,7 +116,7 @@ public void handleEvent(PersonArrivalEvent event) { if (event.getLegMode().equalsIgnoreCase(TransportMode.car) && !event.getPersonId().toString().contains("pt") && isNotTransitAgent(event.getPersonId())) { // (exclude some cases (in a brittle way, i.e. based on IDs)) - // I think that this just packages some information together into the parkingAttributes: + // Generate most of the parking record (departure time will be added later): ParkingOperationRequestAttributes parkingAttributes = new ParkingOperationRequestAttributes(); { Link link = scenario.getNetwork().getLinks().get( event.getLinkId() ); @@ -120,9 +130,13 @@ public void handleEvent(PersonArrivalEvent event) { } if (isLastCarLegOfDay(personId)) { - // (special case, think about it later) - + // if this is the last arrival of the day, the parking record is already there, since it was generated at the first + // departure. However, the duration is not correct since at that time the arrival time was not known. + // (yy It looks to me that the arrivalTime remains at 0. why?) parkingAttributes.parkingDurationInSeconds = GeneralLib.getIntervalDuration(event.getTime(), firstDepartureTimeOfDay.get(personId)); + + // scoring of this special case is done further down, see there + } else { Activity activityBeforeNextCarLeg = getActivityBeforeNextCarLeg(personId); @@ -130,19 +144,19 @@ public void handleEvent(PersonArrivalEvent event) { double parkingDuration=0; if (endTime==Double.NEGATIVE_INFINITY || endTime==Double.POSITIVE_INFINITY){ - // (I think that this _can_ happen, especially in context of within-day replanning, if departure time is unknown. (*)) + // (in general, we take the (parking) end time from above. Sometimes, this end time does not have a useful value, in which case the current - // try to estimate parking duration + // try to estimate parking duration: Person person = scenario.getPopulation().getPersons().get(personId); List planElements = person.getSelectedPlan().getPlanElements(); - for (int i = currentPlanElementIndex.get(personId); i < planElements.size(); i++) { - if (planElements.get(i) instanceof Activity) { - parkingDuration+= ((Activity)planElements.get(i)).getMaximumDuration().seconds(); + for ( int ii = currentPlanElementIndices.get(personId ) ; ii < planElements.size(); ii++) { + if (planElements.get(ii) instanceof Activity) { + parkingDuration+= ((Activity)planElements.get(ii)).getMaximumDuration().seconds(); } - if (planElements.get(i) == activityBeforeNextCarLeg) { + if (planElements.get(ii) == activityBeforeNextCarLeg) { endTime=event.getTime()+parkingDuration; break; } @@ -150,15 +164,16 @@ public void handleEvent(PersonArrivalEvent event) { } parkingAttributes.parkingDurationInSeconds = GeneralLib.getIntervalDuration(event.getTime(), endTime); - // (This is the _estimated_ parking duration, since we are at arrival. This is needed to define the "best" parking + // (This is the _estimated_ parking duration, since we are at arrival, and in this special case we did not have the + // corresponding activity end time. This is needed to define the "best" parking // location ... cf. short-term/long-term parking at airports. Could rename the attributed into "expected...", but we // have seen at other places in the code that such attributes may change their interpretation based on context so will // not do this here.) } - parkingAttributes.legIndex = currentPlanElementIndex.get(personId); + parkingAttributes.legIndex = currentPlanElementIndices.get(personId ); - PC2Parking parking = parkingInfrastructureManager.parkVehicle(parkingAttributes); + final PC2Parking parking = parkingInfrastructureManager.parkVehicle(parkingAttributes); // to me this looks like first the agent arrives at his/her activity. And then the negative parking score is added after the // fact, however without consuming time. I.e. there is no physics. kai, jul'15 @@ -171,15 +186,11 @@ public void handleEvent(PersonArrivalEvent event) { } - currentPlanElementIndex.increment(personId); + currentPlanElementIndices.increment(personId ); } - private boolean isNotTransitAgent(Id persondId) { - return (Integer.parseInt(persondId.toString())< 1000000000); - } - - public void prepareForNewIteration() { - currentPlanElementIndex = new IntegerValueHashMap<>(); + public void notifyBeforeMobsim() { + currentPlanElementIndices = new IntegerValueHashMap<>(); parkingOperationRequestAttributes = new HashMap<>(); firstDepartureTimeOfDay = new DoubleValueHashMap<>(); @@ -215,6 +226,10 @@ public void prepareForNewIteration() { // === only private helper functions below this line === + private boolean isNotTransitAgent(Id persondId) { + return (Integer.parseInt(persondId.toString())< 1000000000); + } + private boolean isFirstCarDepartureOfDay(Id personId) { Person person = scenario.getPopulation().getPersons().get(personId); @@ -223,7 +238,7 @@ private boolean isFirstCarDepartureOfDay(Id personId) { } List planElements = person.getSelectedPlan().getPlanElements(); - for (int i = currentPlanElementIndex.get(personId) - 1; i >= 0; i--) { + for ( int i = currentPlanElementIndices.get(personId ) - 1 ; i >= 0; i--) { if (planElements.get(i) instanceof Leg) { Leg leg = (Leg) planElements.get(i); @@ -240,7 +255,7 @@ private boolean isFirstCarDepartureOfDay(Id personId) { private boolean isLastCarLegOfDay(Id personId) { Person person = scenario.getPopulation().getPersons().get(personId); List planElements = person.getSelectedPlan().getPlanElements(); - for (int i = currentPlanElementIndex.get(personId) + 1; i < planElements.size(); i++) { + for ( int i = currentPlanElementIndices.get(personId ) + 1 ; i < planElements.size(); i++) { if (planElements.get(i) instanceof Leg) { Leg Leg = (Leg) planElements.get(i); @@ -257,7 +272,7 @@ private Activity getActivityBeforeNextCarLeg(Id personId) { Person person = scenario.getPopulation().getPersons().get(personId); List planElements = person.getSelectedPlan().getPlanElements(); int indexOfNextCarLeg = -1; - for (int i = currentPlanElementIndex.get(personId) + 1; i < planElements.size(); i++) { + for ( int i = currentPlanElementIndices.get(personId ) + 1 ; i < planElements.size(); i++) { if (planElements.get(i) instanceof Leg) { Leg Leg = (Leg) planElements.get(i); @@ -281,7 +296,7 @@ private Activity getActivityBeforeNextCarLeg(Id personId) { private Activity getNextActivity(Id personId) { Person person = scenario.getPopulation().getPersons().get(personId); List planElements = person.getSelectedPlan().getPlanElements(); - for (int i = currentPlanElementIndex.get(personId); i < planElements.size(); i++) { + for ( int i = currentPlanElementIndices.get(personId ) ; i < planElements.size(); i++) { if (planElements.get(i) instanceof Activity) { return (Activity) planElements.get(i); } diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/simulation/ParkingInfrastructure.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/simulation/ParkingInfrastructure.java index d2b170ce801..c4ed7484a32 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/simulation/ParkingInfrastructure.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/simulation/ParkingInfrastructure.java @@ -17,18 +17,18 @@ public interface ParkingInfrastructure { void setPublicParkings(LinkedList publicParkings); - void setRentableParking(LinkedList rentableParkings); +// void setRentableParking(LinkedList rentableParkings); - void setPrivateParkingRestrictedToFacilities(LinkedList ppRestrictedToFacilities); +// void setPrivateParkingRestrictedToFacilities(LinkedList ppRestrictedToFacilities); - void reset(); + void notifyBeforeMobsim(); - PC2Parking parkAtClosestPublicParkingNonPersonalVehicle(Coord destCoordinate, String groupName); +// PC2Parking parkAtClosestPublicParkingNonPersonalVehicle(Coord destCoordinate, String groupName); - void logArrivalEventAtTimeZero(PC2Parking parking); +// void logArrivalEventAtTimeZero(PC2Parking parking); - PC2Parking parkAtClosestPublicParkingNonPersonalVehicle(Coord destCoordinate, String groupName, Id personId, - double parkingDurationInSeconds, double arrivalTime); +// PC2Parking parkAtClosestPublicParkingNonPersonalVehicle(Coord destCoordinate, String groupName, Id personId, +// double parkingDurationInSeconds, double arrivalTime); // TODO: make this method abstract // when person/vehicleId is clearly distinct, then I can change this to @@ -42,7 +42,7 @@ PC2Parking parkAtClosestPublicParkingNonPersonalVehicle(Coord destCoordinate, St void unParkVehicle(PC2Parking parking, double departureTime, Id personId); - ParkingScore getParkingScoreManager(); +// ParkingScore getParkingScoreManager(); EventsManager getEventsManager(); @@ -52,4 +52,4 @@ PC2Parking parkAtClosestPublicParkingNonPersonalVehicle(Coord destCoordinate, St void setAllParkings(HashMap, PC2Parking> allParkings); -} \ No newline at end of file +} diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/simulation/ParkingInfrastructureManager.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/simulation/ParkingInfrastructureManager.java index 72d6250a771..65c1cf8367f 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/simulation/ParkingInfrastructureManager.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingchoice/PC2/simulation/ParkingInfrastructureManager.java @@ -119,27 +119,27 @@ public static void addParkingToQuadTree(QuadTree quadTree, PC2Parkin quadTree.put(parking.getCoordinate().getX(), parking.getCoordinate().getY(), parking); } - @Override - public synchronized void setRentableParking(LinkedList rentableParkings) { - for (RentableParking pp : rentableParkings) { - rentablePrivateParking.put(pp.getOwnerId(), pp); - getAllParkings().put(pp.getId(), pp); - } - } - - @Override - public synchronized void setPrivateParkingRestrictedToFacilities( - LinkedList ppRestrictedToFacilities) { - for (PPRestrictedToFacilities pp : ppRestrictedToFacilities) { - for (Id facilityId : pp.getFacilityIds()) { - privateParkingsRestrictedToFacilities.put(facilityId, pp); - getAllParkings().put(pp.getId(), pp); - } - } - } +// @Override +// public synchronized void setRentableParking(LinkedList rentableParkings) { +// for (RentableParking pp : rentableParkings) { +// rentablePrivateParking.put(pp.getOwnerId(), pp); +// getAllParkings().put(pp.getId(), pp); +// } +// } +// +// @Override +// public synchronized void setPrivateParkingRestrictedToFacilities( +// LinkedList ppRestrictedToFacilities) { +// for (PPRestrictedToFacilities pp : ppRestrictedToFacilities) { +// for (Id facilityId : pp.getFacilityIds()) { +// privateParkingsRestrictedToFacilities.put(facilityId, pp); +// getAllParkings().put(pp.getId(), pp); +// } +// } +// } @Override - public synchronized void reset() { + public synchronized void notifyBeforeMobsim() { parkedVehicles.clear(); for (PC2Parking parking : getAllParkings().values()) { @@ -174,45 +174,45 @@ private synchronized QuadTree getPublicParkingQuadTree() { return publicParkingsQuadTree; } - @Override - public synchronized PC2Parking parkAtClosestPublicParkingNonPersonalVehicle(Coord destCoordinate, - String groupName) { - PC2Parking parking = null; - if (groupName == null) { - parking = publicParkingsQuadTree.getClosest(destCoordinate.getX(), destCoordinate.getY()); - } else { - QuadTree quadTree = publicParkingGroupQuadTrees.get(groupName); - parking = quadTree.getClosest(destCoordinate.getX(), destCoordinate.getY()); - - if (parking == null) { - throw new Error("system is in inconsistent state: " + - "not enough parking available for parkingGroupName:" + groupName); - } - } - parkVehicle(parking); - - return parking; - } - - @Override - public synchronized void logArrivalEventAtTimeZero(PC2Parking parking) { - eventsManager.processEvent(new ParkingArrivalEvent(0, parking.getId(), null, null, 0)); - } - - @Override - public synchronized PC2Parking parkAtClosestPublicParkingNonPersonalVehicle(Coord destCoordinate, String groupName, - Id personId, double parkingDurationInSeconds, double arrivalTime) { - PC2Parking parking = parkAtClosestPublicParkingNonPersonalVehicle(destCoordinate, groupName); - - double walkScore = parkingScoreManager.calcWalkScore(destCoordinate, parking, personId, - parkingDurationInSeconds); - parkingScoreManager.addScore(personId, walkScore); - - eventsManager.processEvent( - new ParkingArrivalEvent(arrivalTime, parking.getId(), personId, destCoordinate, walkScore)); - - return parking; - } +// @Override +// public synchronized PC2Parking parkAtClosestPublicParkingNonPersonalVehicle(Coord destCoordinate, +// String groupName) { +// PC2Parking parking = null; +// if (groupName == null) { +// parking = publicParkingsQuadTree.getClosest(destCoordinate.getX(), destCoordinate.getY()); +// } else { +// QuadTree quadTree = publicParkingGroupQuadTrees.get(groupName); +// parking = quadTree.getClosest(destCoordinate.getX(), destCoordinate.getY()); +// +// if (parking == null) { +// throw new Error("system is in inconsistent state: " + +// "not enough parking available for parkingGroupName:" + groupName); +// } +// } +// parkVehicle(parking); +// +// return parking; +// } + +// @Override +// public synchronized void logArrivalEventAtTimeZero(PC2Parking parking) { +// eventsManager.processEvent(new ParkingArrivalEvent(0, parking.getId(), null, null, 0)); +// } +// +// @Override +// public synchronized PC2Parking parkAtClosestPublicParkingNonPersonalVehicle(Coord destCoordinate, String groupName, +// Id personId, double parkingDurationInSeconds, double arrivalTime) { +// PC2Parking parking = parkAtClosestPublicParkingNonPersonalVehicle(destCoordinate, groupName); +// +// double walkScore = parkingScoreManager.calcWalkScore(destCoordinate, parking, personId, +// parkingDurationInSeconds); +// parkingScoreManager.addScore(personId, walkScore); +// +// eventsManager.processEvent( +// new ParkingArrivalEvent(arrivalTime, parking.getId(), personId, destCoordinate, walkScore)); +// +// return parking; +// } // TODO: make this method abstract // when person/vehicleId is clearly distinct, then I can change this to @@ -227,8 +227,7 @@ public synchronized PC2Parking parkVehicle(ParkingOperationRequestAttributes par boolean parkingFound = false; // first search for parking at selected facility: - for (PPRestrictedToFacilities pp : privateParkingsRestrictedToFacilities - .get(parkingOperationRequestAttributes.facilityId)) { + for (PPRestrictedToFacilities pp : privateParkingsRestrictedToFacilities.get(parkingOperationRequestAttributes.facilityId)) { if (pp.getAvailableParkingCapacity() > 0) { // this tells the parking lot to decrease the number of @@ -248,7 +247,7 @@ public synchronized PC2Parking parkVehicle(ParkingOperationRequestAttributes par if (!parkingFound) { Collection collection = getFilteredCollection(parkingOperationRequestAttributes, distance); - while (collection.size() == 0) { + while ( collection.isEmpty() ) { distance *= 2; collection = getFilteredCollection(parkingOperationRequestAttributes, distance); @@ -278,8 +277,7 @@ public synchronized PC2Parking parkVehicle(ParkingOperationRequestAttributes par selectedParking = poll.getKey(); if (rentablePrivateParking.containsKey(parkingOperationRequestAttributes.personId)) { - RentableParking rentableParking = rentablePrivateParking - .get(parkingOperationRequestAttributes.personId); + RentableParking rentableParking = rentablePrivateParking.get(parkingOperationRequestAttributes.personId); if (rentableParking.getAvailableParkingCapacity() > 0) { @@ -508,16 +506,12 @@ public synchronized void unParkVehicle(PC2Parking parking, double departureTime, if (!(parking instanceof PrivateParking)) { addParkingToQuadTree(publicParkingsQuadTree, parking); addParkingToQuadTree(publicParkingGroupQuadTrees.get(parking.getGroupName()), parking); - // I could speculate that full parking lots are removed from the - // quad tree, and it is re-added as soon - // as space becomes available. But this is not commented, and it - // also does not look like it would work in that way. - // kai, jul'15 - // No, actually I now think that it works. When - // remainingCapacity==0, then the parking is removed from the - // list, and - // when (again) ==1, it is re-inserted. In addition, it is - // re-inserted in reset. + + // I could speculate that full parking lots are removed from the quad tree, and it is re-added as soon as space + // becomes available. But this is not commented, and it also does not look like it would work in that way. kai, jul'15 + + // No, actually I now think that it works. When remainingCapacity==0, then the parking is removed from the list, and + // when (again) ==1, it is re-inserted. In addition, it is re-inserted in reset. } } @@ -528,10 +522,10 @@ public synchronized void unParkVehicle(PC2Parking parking, double departureTime, eventsManager.processEvent(new ParkingDepartureEvent(departureTime, parking.getId(), personId)); } - @Override - public synchronized ParkingScore getParkingScoreManager() { - return parkingScoreManager; - } +// @Override +// public synchronized ParkingScore getParkingScoreManager() { +// return parkingScoreManager; +// } @Override public synchronized EventsManager getEventsManager() { From 2054bbacfde4d957ddbddbd858271eb4ab759c91 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:37:07 +0000 Subject: [PATCH 2/3] Bump junit.version from 5.10.2 to 5.10.3 Bumps `junit.version` from 5.10.2 to 5.10.3. Updates `org.junit.jupiter:junit-jupiter-engine` from 5.10.2 to 5.10.3 - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.10.2...r5.10.3) Updates `org.junit.jupiter:junit-jupiter` from 5.10.2 to 5.10.3 - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.10.2...r5.10.3) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter-engine dependency-type: direct:development update-type: version-update:semver-patch - dependency-name: org.junit.jupiter:junit-jupiter dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 70842b4e875..0a677e59c8b 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ 7.0.0 2.17.1 2.5.0 - 5.10.2 + 5.10.3 From 126ffcd5ee636446c709c964d74c557292ce2337 Mon Sep 17 00:00:00 2001 From: rakow Date: Thu, 27 Jun 2024 20:36:22 +0200 Subject: [PATCH 3/3] norm subgroups to 1 (#3346) --- .../org/matsim/application/CommandRunner.java | 2 +- .../analysis/population/TripByGroupAnalysis.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/contribs/application/src/main/java/org/matsim/application/CommandRunner.java b/contribs/application/src/main/java/org/matsim/application/CommandRunner.java index b55fc548a56..ea0af2e6dd2 100644 --- a/contribs/application/src/main/java/org/matsim/application/CommandRunner.java +++ b/contribs/application/src/main/java/org/matsim/application/CommandRunner.java @@ -108,7 +108,7 @@ private void runCommand(Class clazz, Path input) thr MATSimAppCommand command = clazz.getDeclaredConstructor().newInstance(); String[] args = this.args.get(clazz); args = ArrayUtils.addAll(args, createArgs(clazz, args, input)); - log.info("Running {} with arguments: {}", clazz, Arrays.toString(args)); + log.info("Running {} with arguments: {}", clazz, String.join(" ", args)); command.execute(args); } diff --git a/contribs/application/src/main/java/org/matsim/application/analysis/population/TripByGroupAnalysis.java b/contribs/application/src/main/java/org/matsim/application/analysis/population/TripByGroupAnalysis.java index 47edfec0824..b63a58f5ed8 100644 --- a/contribs/application/src/main/java/org/matsim/application/analysis/population/TripByGroupAnalysis.java +++ b/contribs/application/src/main/java/org/matsim/application/analysis/population/TripByGroupAnalysis.java @@ -81,6 +81,22 @@ final class TripByGroupAnalysis { } } + // Norm shares per instance of each group to sum of 1 + for (Group group : this.groups) { + + String norm = group.columns.get(0); + if (group.columns.size() > 1) + throw new UnsupportedOperationException("Multiple columns not supported yet"); + + Table df = group.data; + for (String label : df.stringColumn(norm).asSet()) { + DoubleColumn dist_group = df.doubleColumn("share"); + Selection sel = df.stringColumn(norm).isEqualTo(label); + double total = dist_group.where(sel).sum(); + if (total > 0) + dist_group.set(sel, dist_group.divide(total)); + } + } } }