From 2cb98ce3981e968bae67a51e0ecddfcc1e8fd0ae Mon Sep 17 00:00:00 2001 From: Tobias Kohl Date: Thu, 26 Oct 2023 11:47:29 +0200 Subject: [PATCH 1/2] read penalty from attribute and make it a whole number --- .../contrib/parking/parkingproxy/CarEgressWalkChanger.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/CarEgressWalkChanger.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/CarEgressWalkChanger.java index 5799a639d39..ee2a32a759e 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/CarEgressWalkChanger.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/CarEgressWalkChanger.java @@ -119,14 +119,15 @@ public void notifyBeforeMobsim(BeforeMobsimEvent event) { * by that time (calling this method twice, first with {@code false}, then with {@code true} should yield the original plans) */ private void changeEgressTimesByGridcell(Collection population, boolean reverse) { - int sign = reverse ? -1 : 1; for (Person p : population) { for (LegActPair walkActPair : this.egressFinder.findEgressWalks(p.getSelectedPlan())) { - double penalty = sign * this.observer.getPenaltyCalculator().getPenalty(walkActPair.leg.getDepartureTime().seconds(), walkActPair.act.getCoord()); - setTimes(walkActPair, penalty); if (reverse) { + double penalty = (double) walkActPair.leg.getAttributes().getAttribute(PENALTY_ATTRIBUTE); + setTimes(walkActPair, -penalty); walkActPair.leg.getAttributes().removeAttribute(PENALTY_ATTRIBUTE); } else { + double penalty = Math.round(this.observer.getPenaltyCalculator().getPenalty(walkActPair.leg.getDepartureTime().seconds(), walkActPair.act.getCoord())); + setTimes(walkActPair, penalty); walkActPair.leg.getAttributes().putAttribute(PENALTY_ATTRIBUTE, penalty); } } From 22fd1b3f49a792c748866913543315aac30b0c5e Mon Sep 17 00:00:00 2001 From: Tobias Kohl Date: Tue, 21 Nov 2023 10:58:45 +0100 Subject: [PATCH 2/2] account for possible null atribute --- .../parking/parkingproxy/CarEgressWalkChanger.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/CarEgressWalkChanger.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/CarEgressWalkChanger.java index ee2a32a759e..b78bd899b78 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/CarEgressWalkChanger.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingproxy/CarEgressWalkChanger.java @@ -122,9 +122,11 @@ private void changeEgressTimesByGridcell(Collection population for (Person p : population) { for (LegActPair walkActPair : this.egressFinder.findEgressWalks(p.getSelectedPlan())) { if (reverse) { - double penalty = (double) walkActPair.leg.getAttributes().getAttribute(PENALTY_ATTRIBUTE); - setTimes(walkActPair, -penalty); - walkActPair.leg.getAttributes().removeAttribute(PENALTY_ATTRIBUTE); + Object readPenalty = walkActPair.leg.getAttributes().getAttribute(PENALTY_ATTRIBUTE); + if (readPenalty != null) { + setTimes(walkActPair, - (double) readPenalty); + walkActPair.leg.getAttributes().removeAttribute(PENALTY_ATTRIBUTE); + } } else { double penalty = Math.round(this.observer.getPenaltyCalculator().getPenalty(walkActPair.leg.getDepartureTime().seconds(), walkActPair.act.getCoord())); setTimes(walkActPair, penalty);