From 235fe65b5bce13bafe963af4126cb553c8296917 Mon Sep 17 00:00:00 2001 From: nixlaos Date: Wed, 12 Jul 2023 14:33:33 +0200 Subject: [PATCH 01/54] added converters for missing freight events --- .../freight/events/CarrierEventsReaders.java | 7 ++++++- .../freight/events/CarrierServiceEndEvent.java | 15 +++++++++++++++ .../freight/events/CarrierServiceStartEvent.java | 16 ++++++++++++++++ .../events/CarrierShipmentDeliveryEndEvent.java | 16 ++++++++++++++++ .../CarrierShipmentDeliveryStartEvent.java | 16 ++++++++++++++++ .../events/CarrierShipmentPickupEndEvent.java | 16 ++++++++++++++++ .../events/CarrierShipmentPickupStartEvent.java | 16 ++++++++++++++++ 7 files changed, 101 insertions(+), 1 deletion(-) diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierEventsReaders.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierEventsReaders.java index c268d7d1184..20eb9dad5a8 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierEventsReaders.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierEventsReaders.java @@ -36,9 +36,14 @@ public class CarrierEventsReaders { public static Map createCustomEventMappers() { return Map.of( + CarrierServiceStartEvent.EVENT_TYPE, CarrierServiceStartEvent::convert, + CarrierServiceEndEvent.EVENT_TYPE, CarrierServiceEndEvent::convert, + CarrierShipmentDeliveryStartEvent.EVENT_TYPE, CarrierShipmentDeliveryStartEvent::convert, + CarrierShipmentDeliveryEndEvent.EVENT_TYPE, CarrierShipmentDeliveryEndEvent::convert, + CarrierShipmentPickupStartEvent.EVENT_TYPE, CarrierShipmentPickupStartEvent::convert, + CarrierShipmentPickupEndEvent.EVENT_TYPE, CarrierShipmentPickupEndEvent::convert, CarrierTourStartEvent.EVENT_TYPE, CarrierTourStartEvent::convert, // CarrierTourEndEvent.EVENT_TYPE, CarrierTourEndEvent::convert - // more will follow later, KMT feb'23 ); } diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierServiceEndEvent.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierServiceEndEvent.java index e1527edc9b0..0c4585932a0 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierServiceEndEvent.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierServiceEndEvent.java @@ -24,6 +24,8 @@ import java.util.Map; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.events.GenericEvent; +import org.matsim.api.core.v01.network.Link; import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierService; import org.matsim.vehicles.Vehicle; @@ -67,4 +69,17 @@ public Map getAttributes() { attr.put(ATTRIBUTE_SERVICE_DURATION, String.valueOf(serviceDuration)); return attr; } + + public static CarrierServiceEndEvent convert(GenericEvent event) { + Map attributes = event.getAttributes(); + double time = Double.parseDouble(attributes.get(ATTRIBUTE_TIME)); + Id carrierId = Id.create(attributes.get(ATTRIBUTE_CARRIER_ID), Carrier.class); + Id carrierServiceId = Id.create(attributes.get(ATTRIBUTE_SERVICE_ID), CarrierService.class); + Id locationLinkId = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); + CarrierService service = CarrierService.Builder.newInstance(carrierServiceId, locationLinkId) + .setServiceDuration(Double.parseDouble(attributes.get(ATTRIBUTE_SERVICE_DURATION))) + .build(); + Id vehicleId = Id.create(attributes.get(ATTRIBUTE_VEHICLE), Vehicle.class); + return new CarrierServiceEndEvent(time, carrierId, service, vehicleId); + } } diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierServiceStartEvent.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierServiceStartEvent.java index 719bfc96978..6c8550df63f 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierServiceStartEvent.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierServiceStartEvent.java @@ -22,6 +22,8 @@ package org.matsim.contrib.freight.events; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.events.GenericEvent; +import org.matsim.api.core.v01.network.Link; import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierService; import org.matsim.vehicles.Vehicle; @@ -77,4 +79,18 @@ public Map getAttributes() { attr.put(ATTRIBUTE_CAPACITYDEMAND, String.valueOf(capacityDemand)); return attr; } + + public static CarrierServiceStartEvent convert(GenericEvent event) { + Map attributes = event.getAttributes(); + double time = Double.parseDouble(attributes.get(ATTRIBUTE_TIME)); + Id carrierId = Id.create(attributes.get(ATTRIBUTE_CARRIER_ID), Carrier.class); + Id carrierServiceId = Id.create(attributes.get(ATTRIBUTE_SERVICE_ID), CarrierService.class); + Id locationLinkId = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); + CarrierService service = CarrierService.Builder.newInstance(carrierServiceId, locationLinkId) + .setServiceDuration(Double.parseDouble(attributes.get(ATTRIBUTE_SERVICE_DURATION))) + .setCapacityDemand(Integer.parseInt(attributes.get(ATTRIBUTE_CAPACITYDEMAND))) + .build(); + Id vehicleId = Id.create(attributes.get(ATTRIBUTE_VEHICLE), Vehicle.class); + return new CarrierServiceStartEvent(time, carrierId, service, vehicleId); + } } diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentDeliveryEndEvent.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentDeliveryEndEvent.java index 9e702f3359d..eb462b77a88 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentDeliveryEndEvent.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentDeliveryEndEvent.java @@ -22,6 +22,8 @@ package org.matsim.contrib.freight.events; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.events.GenericEvent; +import org.matsim.api.core.v01.network.Link; import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierShipment; import org.matsim.vehicles.Vehicle; @@ -76,4 +78,18 @@ public Map getAttributes() { return attr; } + public static CarrierShipmentDeliveryEndEvent convert(GenericEvent event) { + var attributes = event.getAttributes(); + double time = Double.parseDouble(attributes.get(ATTRIBUTE_TIME)); + Id carrierId = Id.create(attributes.get(ATTRIBUTE_CARRIER_ID), Carrier.class); + Id shipmentId = Id.create(attributes.get(ATTRIBUTE_SHIPMENT_ID), CarrierShipment.class); + Id shipmentTo = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); + int size = Integer.parseInt(attributes.get(ATTRIBUTE_CAPACITYDEMAND)); + CarrierShipment shipment = CarrierShipment.Builder.newInstance(shipmentId, null, shipmentTo, size) + .setDeliveryServiceTime(Double.parseDouble(attributes.get(ATTRIBUTE_SERVICE_DURATION))) + .build(); + Id vehicleId = Id.createVehicleId(attributes.get(ATTRIBUTE_VEHICLE)); + return new CarrierShipmentDeliveryEndEvent(time, carrierId, shipment, vehicleId); + } + } diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentDeliveryStartEvent.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentDeliveryStartEvent.java index 6e097bbe64d..08b77671842 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentDeliveryStartEvent.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentDeliveryStartEvent.java @@ -22,6 +22,8 @@ package org.matsim.contrib.freight.events; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.events.GenericEvent; +import org.matsim.api.core.v01.network.Link; import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierShipment; import org.matsim.vehicles.Vehicle; @@ -75,4 +77,18 @@ public Map getAttributes() { return attr; } + public static CarrierShipmentDeliveryStartEvent convert(GenericEvent event) { + var attributes = event.getAttributes(); + double time = Double.parseDouble(attributes.get(ATTRIBUTE_TIME)); + Id carrierId = Id.create(attributes.get(ATTRIBUTE_CARRIER_ID), Carrier.class); + Id shipmentId = Id.create(attributes.get(ATTRIBUTE_SHIPMENT_ID), CarrierShipment.class); + Id shipmentTo = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); + int size = Integer.parseInt(attributes.get(ATTRIBUTE_CAPACITYDEMAND)); + CarrierShipment shipment = CarrierShipment.Builder.newInstance(shipmentId, null, shipmentTo, size) + .setDeliveryServiceTime(Double.parseDouble(attributes.get(ATTRIBUTE_SERVICE_DURATION))) + .build(); + Id vehicleId = Id.createVehicleId(attributes.get(ATTRIBUTE_VEHICLE)); + return new CarrierShipmentDeliveryStartEvent(time, carrierId, shipment, vehicleId); + } + } diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentPickupEndEvent.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentPickupEndEvent.java index 664dbfa45c7..e88ead0cb37 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentPickupEndEvent.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentPickupEndEvent.java @@ -22,6 +22,8 @@ package org.matsim.contrib.freight.events; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.events.GenericEvent; +import org.matsim.api.core.v01.network.Link; import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierShipment; import org.matsim.vehicles.Vehicle; @@ -69,4 +71,18 @@ public Map getAttributes() { attr.put(ATTRIBUTE_CAPACITYDEMAND, String.valueOf(capacityDemand)); return attr; } + + public static CarrierShipmentPickupEndEvent convert(GenericEvent event) { + Map attributes = event.getAttributes(); + double time = Double.parseDouble(attributes.get(ATTRIBUTE_TIME)); + Id carrierId = Id.create(attributes.get(ATTRIBUTE_CARRIER_ID), Carrier.class); + Id shipmentId = Id.create(attributes.get(ATTRIBUTE_SHIPMENT_ID), CarrierShipment.class); + Id shipmentFrom = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); + int shipmentSize = Integer.parseInt(attributes.get(ATTRIBUTE_CAPACITYDEMAND)); + CarrierShipment shipment = CarrierShipment.Builder.newInstance(shipmentId, shipmentFrom, null, shipmentSize) + .setPickupServiceTime(Double.parseDouble(attributes.get(ATTRIBUTE_PICKUP_DURATION))) + .build(); + Id vehicleId = Id.createVehicleId(attributes.get(ATTRIBUTE_VEHICLE)); + return new CarrierShipmentPickupEndEvent(time, carrierId, shipment, vehicleId); + } } diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentPickupStartEvent.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentPickupStartEvent.java index 7285434d134..4f7725e6ece 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentPickupStartEvent.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentPickupStartEvent.java @@ -22,6 +22,8 @@ package org.matsim.contrib.freight.events; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.events.GenericEvent; +import org.matsim.api.core.v01.network.Link; import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierShipment; import org.matsim.vehicles.Vehicle; @@ -69,4 +71,18 @@ public Map getAttributes() { attr.put(ATTRIBUTE_CAPACITYDEMAND, String.valueOf(capacityDemand)); return attr; } + + public static CarrierShipmentPickupStartEvent convert(GenericEvent event) { + Map attributes = event.getAttributes(); + double time = Double.parseDouble(attributes.get(ATTRIBUTE_TIME)); + Id carrierId = Id.create(attributes.get(ATTRIBUTE_CARRIER_ID), Carrier.class); + Id shipmentId = Id.create(attributes.get(ATTRIBUTE_SHIPMENT_ID), CarrierShipment.class); + Id shipmentFrom = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); + int shipmentSize = Integer.parseInt(attributes.get(ATTRIBUTE_CAPACITYDEMAND)); + CarrierShipment shipment = CarrierShipment.Builder.newInstance(shipmentId, shipmentFrom, null, shipmentSize) + .setPickupServiceTime(Double.parseDouble(attributes.get(ATTRIBUTE_PICKUP_DURATION))) + .build(); + Id vehicleId = Id.createVehicleId(attributes.get(ATTRIBUTE_VEHICLE)); + return new CarrierShipmentPickupStartEvent(time, carrierId, shipment, vehicleId); + } } From 2ef28130513920e0c6a673c810d2a09f3f12764b Mon Sep 17 00:00:00 2001 From: nixlaos Date: Tue, 8 Aug 2023 16:14:51 +0200 Subject: [PATCH 02/54] added test for reading in carrier events --- .../carrier/CarrierEventsReadersTest.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 contribs/freight/src/test/java/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest.java diff --git a/contribs/freight/src/test/java/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest.java b/contribs/freight/src/test/java/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest.java new file mode 100644 index 00000000000..f19068177c2 --- /dev/null +++ b/contribs/freight/src/test/java/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest.java @@ -0,0 +1,52 @@ +package org.matsim.contrib.freight.carrier; + +import org.junit.Rule; +import org.junit.Test; +import org.matsim.contrib.freight.events.CarrierEventsReaders; +import org.matsim.core.api.experimental.events.EventsManager; +import org.matsim.core.events.EventsUtils; +import org.matsim.core.events.MatsimEventsReader; +import org.matsim.testcases.MatsimTestUtils; +import org.matsim.testcases.utils.EventsCollector; + +import static org.junit.Assert.assertEquals; + +public class CarrierEventsReadersTest { + + @Rule + public final MatsimTestUtils utils = new MatsimTestUtils(); + + @Test + public void testWriteReadServiceBasedEvents() { + EventsManager eventsManager = EventsUtils.createEventsManager(); + EventsCollector collector = new EventsCollector(); + MatsimEventsReader carrierEventsReaders = CarrierEventsReaders.createEventsReader(eventsManager); + + eventsManager.addHandler(collector); + eventsManager.initProcessing(); + carrierEventsReaders.readFile(utils.getClassInputDirectory() + "serviceBasedEventsFile.xml"); + eventsManager.finishProcessing(); + + assertEquals("number of events should be same", collector.getEvents().size(), collector.getEvents().size()); + MatsimTestUtils.assertEqualEventsFiles(utils.getClassInputDirectory() + "serviceBasedEventsFile.xml", utils.getClassInputDirectory() + "serviceBasedEventsFileWritten.xml"); + MatsimTestUtils.assertEqualFilesLineByLine(utils.getClassInputDirectory() + "serviceBasedEventsFile.xml", utils.getClassInputDirectory() + "serviceBasedEventsFileWritten.xml"); + } + + @Test + public void testWriteReadShipmentBasedEvents() { + EventsManager eventsManager = EventsUtils.createEventsManager(); + EventsCollector collector = new EventsCollector(); + MatsimEventsReader carrierEventsReaders = CarrierEventsReaders.createEventsReader(eventsManager); + + eventsManager.addHandler(collector); + eventsManager.initProcessing(); + carrierEventsReaders.readFile(utils.getClassInputDirectory() + "shipmentBasedEventsFile.xml"); + eventsManager.finishProcessing(); + + assertEquals("number of events should be same", collector.getEvents().size(), collector.getEvents().size()); + MatsimTestUtils.assertEqualEventsFiles(utils.getClassInputDirectory() + "shipmentBasedEventsFile.xml", utils.getClassInputDirectory() + "shipmentBasedEventsFileWritten.xml"); + MatsimTestUtils.assertEqualFilesLineByLine(utils.getClassInputDirectory() + "shipmentBasedEventsFile.xml", utils.getClassInputDirectory() + "shipmentBasedEventsFileWritten.xml"); + } + + +} From 06276dfca7ffecae01e1e7c92a6325b2c67014f2 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 7 Sep 2023 10:04:41 +0200 Subject: [PATCH 03/54] add method in ParkingUtils to set NoParking for activity --- .../DynAgent/NearestParkingDynLeg.java | 4 ++-- .../parking/parkingsearch/ParkingUtils.java | 23 ++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) 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 96bbd7928c5..d91fdc68ae2 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 @@ -5,6 +5,7 @@ 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.contrib.parking.parkingsearch.ParkingUtils; import org.matsim.contrib.parking.parkingsearch.events.RemoveParkingActivityEvent; import org.matsim.contrib.parking.parkingsearch.events.ReserveParkingLocationEvent; import org.matsim.contrib.parking.parkingsearch.events.SelectNewParkingLocationEvent; @@ -43,8 +44,7 @@ public NearestParkingDynLeg(Leg currentPlannedLeg, NetworkRoute route, Plan plan this.currentPlannedLeg = currentPlannedLeg; this.plan = plan; this.planIndexNextActivity = planIndexNextActivity; - if (followingActivity.getAttributes().getAsMap().containsKey("parking") && followingActivity.getAttributes().getAttribute("parking").equals( - "noParking")) + if (!ParkingUtils.checkIfActivityHasParking(followingActivity)) parkingAtEndOfLeg = false; } diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java index fc5abd290c6..727876d0ae4 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java @@ -21,13 +21,14 @@ import org.matsim.api.core.v01.Coord; import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.population.Activity; import java.util.ArrayList; import java.util.List; import java.util.Random; /** - * @author jbischoff, tschlenther + * @author jbischoff, tschlenther, Ricardo Ewert * */ public class ParkingUtils { @@ -143,4 +144,24 @@ public static List getOutgoingLinksForMode(Link link, String mode) { return outGoingModeLinks; } + /** + * Checks if the activity has parking while the activity. + * + * @param followingActivity + * @return + */ + public static boolean checkIfActivityHasParking(Activity followingActivity) { + return !(followingActivity.getAttributes().getAsMap().containsKey("parking") && followingActivity.getAttributes().getAttribute( + "parking").equals( + "noParking")); + } + + /** + * Sets that while this activity we simulate no parking activities. + * + * @param activity + */ + public static void setNoParkingForActivity(Activity activity) { + activity.getAttributes().putAttribute("parking", "noParking"); + } } From d07ecaecbaf6bf51ea9b99db4d839c7fca6f1247 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 8 Sep 2023 10:35:00 +0200 Subject: [PATCH 04/54] formatting --- .../agentLogic/ParkingAgentLogic.java | 107 +++++++++--------- 1 file changed, 52 insertions(+), 55 deletions(-) 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 2bda5aa8698..ef91df3ed30 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 @@ -59,25 +59,25 @@ /** * @author jbischoff - * */ public class ParkingAgentLogic implements DynAgentLogic { - public enum LastParkActionState { + public enum LastParkActionState { - // we have the following cases of ending dynacts: - NONCARTRIP, // non-car trip arrival: start Activity - CARTRIP, // car-trip arrival: add park-car activity - PARKACTIVITY, // park-car activity: get next PlanElement & add walk leg to activity location - WALKFROMPARK ,// walk-leg to act: start next PlanElement Activity - ACTIVITY, // ordinary activity: get next Leg, if car: go to car, otherwise add ordinary leg by other mode - WALKTOPARK, // walk-leg to car: add unpark activity - UNPARKACTIVITY // unpark activity: find the way to the next route & start leg + // we have the following cases of ending dynacts: + NONCARTRIP, // non-car trip arrival: start Activity + CARTRIP, // car-trip arrival: add park-car activity + PARKACTIVITY, // park-car activity: get next PlanElement & add walk leg to activity location + WALKFROMPARK,// walk-leg to act: start next PlanElement Activity + ACTIVITY, // ordinary activity: get next Leg, if car: go to car, otherwise add ordinary leg by other mode + WALKTOPARK, // walk-leg to car: add unpark activity + UNPARKACTIVITY // unpark activity: find the way to the next route & start leg } + protected LastParkActionState lastParkActionState; protected DynAgent agent; protected int planIndex; -// protected Iterator planElemIter; + // protected Iterator planElemIter; protected Plan plan; protected PlanElement currentPlanElement; protected ParkingSearchManager parkingManager; @@ -88,20 +88,18 @@ public enum LastParkActionState { protected EventsManager events; protected ParkingSearchLogic parkingLogic; protected VehicleTeleportationLogic teleportationLogic; - protected boolean isinitialLocation = true; + protected boolean isInitialLocation = true; protected Id currentlyAssignedVehicleId = null; protected String stageInteractionType = null; protected ParkingSearchConfigGroup configGroup; protected static final Logger log = LogManager.getLogger(ParkingAgentLogic.class); /** - * @param plan - * (always starts with Activity) + * @param plan (always starts with Activity) */ - public ParkingAgentLogic(Plan plan, ParkingSearchManager parkingManager, RoutingModule walkRouter, Network network, - ParkingRouter parkingRouter, EventsManager events, ParkingSearchLogic parkingLogic, MobsimTimer timer, - VehicleTeleportationLogic teleportationLogic, ParkingSearchConfigGroup configGroup) { -// planElemIter = plan.getPlanElements().iterator(); + public ParkingAgentLogic(Plan plan, ParkingSearchManager parkingManager, RoutingModule walkRouter, Network network, + ParkingRouter parkingRouter, EventsManager events, ParkingSearchLogic parkingLogic, MobsimTimer timer, + VehicleTeleportationLogic teleportationLogic, ParkingSearchConfigGroup configGroup) { this.plan = plan; this.parkingManager = parkingManager; this.walkRouter = walkRouter; @@ -141,27 +139,27 @@ 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 - switch (lastParkActionState){ - case ACTIVITY: - return nextStateAfterActivity(oldAction, now); + switch (lastParkActionState) { + case ACTIVITY: + return nextStateAfterActivity(oldAction, now); - case CARTRIP: - return nextStateAfterCarTrip(oldAction,now); + case CARTRIP: + return nextStateAfterCarTrip(oldAction, now); - case NONCARTRIP: - return nextStateAfterNonCarTrip(oldAction,now); + case NONCARTRIP: + return nextStateAfterNonCarTrip(oldAction, now); - case PARKACTIVITY: - return nextStateAfterParkActivity(oldAction,now); + case PARKACTIVITY: + return nextStateAfterParkActivity(oldAction, now); - case UNPARKACTIVITY: - return nextStateAfterUnParkActivity(oldAction,now); + case UNPARKACTIVITY: + return nextStateAfterUnParkActivity(oldAction, now); - case WALKFROMPARK: - return nextStateAfterWalkFromPark(oldAction,now); + case WALKFROMPARK: + return nextStateAfterWalkFromPark(oldAction, now); - case WALKTOPARK: - return nextStateAfterWalkToPark(oldAction,now); + case WALKTOPARK: + return nextStateAfterWalkToPark(oldAction, now); } throw new RuntimeException("unreachable code"); @@ -174,15 +172,14 @@ protected DynAction nextStateAfterUnParkActivity(DynAction oldAction, double now Leg currentPlannedLeg = (Leg) currentPlanElement; Route plannedRoute = currentPlannedLeg.getRoute(); NetworkRoute actualRoute = this.parkingRouter.getRouteFromParkingToDestination(plannedRoute.getEndLinkId(), now, agent.getCurrentLinkId()); - if ((this.parkingManager.unParkVehicleHere(currentlyAssignedVehicleId, agent.getCurrentLinkId(), now))||(isinitialLocation)){ + if ((this.parkingManager.unParkVehicleHere(currentlyAssignedVehicleId, agent.getCurrentLinkId(), now)) || (isInitialLocation)) { this.lastParkActionState = LastParkActionState.CARTRIP; - isinitialLocation = false; + isInitialLocation = false; Leg currentLeg = (Leg) this.currentPlanElement; //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"); } @@ -200,10 +197,11 @@ protected DynAction nextStateAfterWalkFromPark(DynAction oldAction, double now) protected DynAction nextStateAfterParkActivity(DynAction oldAction, double now) { // add a walk leg after parking Leg currentPlannedLeg = (Leg) currentPlanElement; - 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)) { + 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)) { 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); @@ -223,11 +221,11 @@ protected DynAction nextStateAfterNonCarTrip(DynAction oldAction, double now) { final double endTime; if (nextPlannedActivity.getEndTime().isUndefined()) { if (nextPlannedActivity.getMaximumDuration().isUndefined()) { - endTime = Double.POSITIVE_INFINITY; - //last activity of a day - } else { + endTime = Double.POSITIVE_INFINITY; + //last activity of a day + } else { endTime = now + nextPlannedActivity.getMaximumDuration().seconds(); - } + } } else { endTime = nextPlannedActivity.getEndTime().seconds(); } @@ -237,13 +235,12 @@ protected DynAction nextStateAfterNonCarTrip(DynAction oldAction, double now) { protected DynAction nextStateAfterCarTrip(DynAction oldAction, double now) { // car trip is complete, we have found a parking space (not part of the logic), block it and start to park - if (this.parkingManager.parkVehicleHere(Id.create(this.agent.getId(), Vehicle.class), agent.getCurrentLinkId(), now)){ - this.lastParkActionState = LastParkActionState.PARKACTIVITY; - this.currentlyAssignedVehicleId = null; - this.parkingLogic.reset(); + if (this.parkingManager.parkVehicleHere(Id.create(this.agent.getId(), Vehicle.class), agent.getCurrentLinkId(), now)) { + this.lastParkActionState = LastParkActionState.PARKACTIVITY; + 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) { @@ -263,10 +260,10 @@ protected DynAction nextStateAfterActivity(DynAction oldAction, double now) { Facility fromFacility = new LinkWrapperFacility(network.getLinks().get(agent.getCurrentLinkId())); Id teleportedParkLink = this.teleportationLogic.getVehicleLocation(agent.getCurrentLinkId(), vehicleId, parkLink, now, - currentLeg.getMode()); + currentLeg.getMode()); Facility toFacility = new LinkWrapperFacility(network.getLinks().get(teleportedParkLink)); List walkTrip = walkRouter.calcRoute( - DefaultRoutingRequest.withoutAttributes(fromFacility, toFacility, now, plan.getPerson())); + DefaultRoutingRequest.withoutAttributes(fromFacility, toFacility, now, plan.getPerson())); if (walkTrip.size() != 1 || !(walkTrip.get(0) instanceof Leg)) { 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); @@ -292,8 +289,8 @@ protected DynAction nextStateAfterActivity(DynAction oldAction, double 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)); + "no more leg to follow but activity is ending\nLastPlanElement: " + currentPlanElement.toString() + "\n Agent " + this.agent.getId() + "\nTime: " + Time.writeTime( + now)); } } From faf0544f1ef490787b096af23539df06767caa58 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 8 Sep 2023 10:39:29 +0200 Subject: [PATCH 05/54] formatting --- .../agentLogic/BenensonParkingAgentLogic.java | 19 +++++++++---------- .../MemoryBasedParkingAgentLogic.java | 12 ++++++------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/BenensonParkingAgentLogic.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/BenensonParkingAgentLogic.java index c799cbc1355..381bfd331d2 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/BenensonParkingAgentLogic.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/BenensonParkingAgentLogic.java @@ -1,5 +1,5 @@ /** - * + * */ package org.matsim.contrib.parking.parkingsearch.DynAgent.agentLogic; @@ -9,7 +9,6 @@ import org.matsim.api.core.v01.population.Route; import org.matsim.contrib.dynagent.DynAction; import org.matsim.contrib.parking.parkingsearch.DynAgent.BenensonDynLeg; -import org.matsim.contrib.parking.parkingsearch.DynAgent.agentLogic.ParkingAgentLogic; import org.matsim.contrib.parking.parkingsearch.manager.ParkingSearchManager; import org.matsim.contrib.parking.parkingsearch.manager.vehicleteleportationlogic.VehicleTeleportationLogic; import org.matsim.contrib.parking.parkingsearch.routing.ParkingRouter; @@ -29,37 +28,37 @@ public class BenensonParkingAgentLogic extends ParkingAgentLogic { /** * @param plan * @param parkingManager - * @param walkLegFactory + * @param walkRouter * @param parkingRouter * @param events * @param parkingLogic * @param timer * @param teleportationLogic */ - - + + public BenensonParkingAgentLogic(Plan plan, ParkingSearchManager parkingManager, RoutingModule walkRouter, Network network, ParkingRouter parkingRouter, EventsManager events, ParkingSearchLogic parkingLogic, MobsimTimer timer, VehicleTeleportationLogic teleportationLogic, ParkingSearchConfigGroup configGroup) { super(plan, parkingManager, walkRouter, network, parkingRouter, events, parkingLogic, timer, teleportationLogic, configGroup); } - + @Override protected DynAction nextStateAfterUnParkActivity(DynAction oldAction, double now) { // we have unparked, now we need to get going by car again. - + Leg currentPlannedLeg = (Leg) currentPlanElement; Route plannedRoute = currentPlannedLeg.getRoute(); NetworkRoute actualRoute = this.parkingRouter.getRouteFromParkingToDestination(plannedRoute.getEndLinkId(), now, agent.getCurrentLinkId()); - if ((this.parkingManager.unParkVehicleHere(currentlyAssignedVehicleId, agent.getCurrentLinkId(), now))||(isinitialLocation)){ + if ((this.parkingManager.unParkVehicleHere(currentlyAssignedVehicleId, agent.getCurrentLinkId(), now))||(isInitialLocation)){ this.lastParkActionState = LastParkActionState.CARTRIP; - isinitialLocation = false; + isInitialLocation = false; Leg currentLeg = (Leg) this.currentPlanElement; //this could be Car, Carsharing, Motorcylce, or whatever else mode we have, so we want our leg to reflect this. return new BenensonDynLeg(currentLeg.getMode(), actualRoute, parkingLogic, parkingManager, currentlyAssignedVehicleId, timer, events); } else throw new RuntimeException("parking location mismatch"); - + } } diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/MemoryBasedParkingAgentLogic.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/MemoryBasedParkingAgentLogic.java index dbe7b937923..b7358bc6a39 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/MemoryBasedParkingAgentLogic.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/MemoryBasedParkingAgentLogic.java @@ -1,5 +1,5 @@ /** - * + * */ package org.matsim.contrib.parking.parkingsearch.DynAgent.agentLogic; @@ -31,22 +31,22 @@ public MemoryBasedParkingAgentLogic(Plan plan, ParkingSearchManager parkingManag super(plan, parkingManager, walkRouter, network, parkingRouter, events, parkingLogic, timer, teleportationLogic, configGroup); } - + @Override protected DynAction nextStateAfterUnParkActivity(DynAction oldAction, double now) { // we have unparked, now we need to get going by car again. - + Leg currentPlannedLeg = (Leg) currentPlanElement; Route plannedRoute = currentPlannedLeg.getRoute(); NetworkRoute actualRoute = this.parkingRouter.getRouteFromParkingToDestination(plannedRoute.getEndLinkId(), now, agent.getCurrentLinkId()); - if ((this.parkingManager.unParkVehicleHere(currentlyAssignedVehicleId, agent.getCurrentLinkId(), now))||(isinitialLocation)){ + if ((this.parkingManager.unParkVehicleHere(currentlyAssignedVehicleId, agent.getCurrentLinkId(), now))||(isInitialLocation)){ this.lastParkActionState = LastParkActionState.CARTRIP; - isinitialLocation = false; + isInitialLocation = false; Leg currentLeg = (Leg) this.currentPlanElement; //this could be Car, Carsharing, Motorcylce, or whatever else mode we have, so we want our leg to reflect this. return new DistanceMemoryDynLeg(currentLeg.getMode(), actualRoute, parkingLogic, parkingManager, currentlyAssignedVehicleId, timer, events); } else throw new RuntimeException("parking location mismatch"); - + } } From f6f36b2c0cf8352af8dae3915ad337b537262796 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 8 Sep 2023 11:55:11 +0200 Subject: [PATCH 06/54] formatting --- .../NearestParkingSpotAgentLogic.java | 42 ++++++------------ .../agentLogic/ParkingAgentLogic.java | 43 ++++++------------- 2 files changed, 26 insertions(+), 59 deletions(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java index faec3310574..c34afb85a10 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java @@ -54,31 +54,16 @@ public DynAction computeNextAction(DynAction oldAction, double now) { if (lastParkActionState.equals(LastParkActionState.CARTRIP) && ((NearestParkingDynLeg) oldAction).driveToBaseWithoutParking()) this.lastParkActionState = LastParkActionState.WALKFROMPARK; - switch (lastParkActionState) { - case ACTIVITY: - return nextStateAfterActivity(oldAction, now); - - case CARTRIP: - return nextStateAfterCarTrip(oldAction, now); - - case NONCARTRIP: - return nextStateAfterNonCarTrip(oldAction, now); - - case PARKACTIVITY: - return nextStateAfterParkActivity(oldAction, now); - - case UNPARKACTIVITY: - return nextStateAfterUnParkActivity(oldAction, now); - - case WALKFROMPARK: - return nextStateAfterWalkFromPark(oldAction, now); - - case WALKTOPARK: - return nextStateAfterWalkToPark(oldAction, now); - - } - throw new RuntimeException("unreachable code"); - } + 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); + }; + } @Override protected DynAction nextStateAfterUnParkActivity(DynAction oldAction, double now) { @@ -90,9 +75,9 @@ protected DynAction nextStateAfterUnParkActivity(DynAction oldAction, double now actualRoute.setVehicleId(currentlyAssignedVehicleId); if (!plannedRoute.getStartLinkId().equals(actualRoute.getStartLinkId())) currentPlannedLeg.setRoute(actualRoute); - if ((this.parkingManager.unParkVehicleHere(currentlyAssignedVehicleId, agent.getCurrentLinkId(), now)) || (isinitialLocation)) { + if ((this.parkingManager.unParkVehicleHere(currentlyAssignedVehicleId, agent.getCurrentLinkId(), now)) || (isInitialLocation)) { this.lastParkActionState = LastParkActionState.CARTRIP; - isinitialLocation = false; + isInitialLocation = false; // Leg currentLeg = (Leg) this.currentPlanElement; int planIndexNextActivity = planIndex + 1; Activity nextPlanElement = (Activity) plan.getPlanElements().get(planIndexNextActivity); @@ -151,12 +136,11 @@ protected DynAction nextStateAfterActivity(DynAction oldAction, double now) { Facility toFacility = new LinkWrapperFacility(network.getLinks().get(teleportedParkLink)); List walkTrip = walkRouter.calcRoute( DefaultRoutingRequest.withoutAttributes(fromFacility, toFacility, now, plan.getPerson())); - if (walkTrip.size() != 1 || !(walkTrip.get(0) instanceof Leg)) { + 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!"; log.error(message); throw new RuntimeException(message); } - Leg walkLeg = (Leg) walkTrip.get(0); this.currentlyAssignedVehicleId = vehicleId; this.stageInteractionType = ParkingUtils.PARKACTIVITYTYPE; if (!walkLeg.getTravelTime().equals(OptionalTime.defined(0.))) { 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 ef91df3ed30..c6ad7d3901b 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 @@ -139,32 +139,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 - switch (lastParkActionState) { - case ACTIVITY: - return nextStateAfterActivity(oldAction, now); - - case CARTRIP: - return nextStateAfterCarTrip(oldAction, now); - - case NONCARTRIP: - return nextStateAfterNonCarTrip(oldAction, now); - - case PARKACTIVITY: - return nextStateAfterParkActivity(oldAction, now); - - case UNPARKACTIVITY: - return nextStateAfterUnParkActivity(oldAction, now); - - case WALKFROMPARK: - return nextStateAfterWalkFromPark(oldAction, now); - - case WALKTOPARK: - return nextStateAfterWalkToPark(oldAction, now); - - } - throw new RuntimeException("unreachable code"); - - } + 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. @@ -201,12 +186,11 @@ protected DynAction nextStateAfterParkActivity(DynAction oldAction, double now) 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)) { + 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!"; log.error(message); throw new RuntimeException(message); } - Leg walkLeg = (Leg) walkTrip.get(0); this.lastParkActionState = LastParkActionState.WALKFROMPARK; this.stageInteractionType = null; return new StaticPassengerDynLeg(walkLeg.getRoute(), walkLeg.getMode()); @@ -264,12 +248,11 @@ protected DynAction nextStateAfterActivity(DynAction oldAction, double now) { Facility toFacility = new LinkWrapperFacility(network.getLinks().get(teleportedParkLink)); List walkTrip = walkRouter.calcRoute( DefaultRoutingRequest.withoutAttributes(fromFacility, toFacility, now, plan.getPerson())); - if (walkTrip.size() != 1 || !(walkTrip.get(0) instanceof Leg)) { + 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!"; log.error(message); throw new RuntimeException(message); } - Leg walkLeg = (Leg) walkTrip.get(0); this.lastParkActionState = LastParkActionState.WALKTOPARK; this.currentlyAssignedVehicleId = vehicleId; this.stageInteractionType = ParkingUtils.PARKACTIVITYTYPE; From 0fad894165c69242ddfd73e68994407e20c2e6f7 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 8 Sep 2023 11:55:37 +0200 Subject: [PATCH 07/54] add logger --- .../parking/parkingsearch/DynAgent/NearestParkingDynLeg.java | 3 +++ 1 file changed, 3 insertions(+) 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 d91fdc68ae2..8b427f23325 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 @@ -1,5 +1,7 @@ package org.matsim.contrib.parking.parkingsearch.DynAgent; +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.network.Link; import org.matsim.api.core.v01.population.Activity; @@ -35,6 +37,7 @@ public class NearestParkingDynLeg extends ParkingDynLeg { private final int planIndexNextActivity; private Plan plan; private Id nextSelectedParkingLink = null; + protected static final Logger log = LogManager.getLogger(NearestParkingDynLeg.class); public NearestParkingDynLeg(Leg currentPlannedLeg, NetworkRoute route, Plan plan, int planIndexNextActivity, ParkingSearchLogic logic, ParkingSearchManager parkingManager, Id vehicleId, MobsimTimer timer, EventsManager events) { From 74779207a6ae56598400bc7899ef08b220e5864a Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 8 Sep 2023 12:00:54 +0200 Subject: [PATCH 08/54] add functionality for passengerInteraction only at parkingFacility --- .../DynAgent/NearestParkingDynLeg.java | 28 +++++++++-- .../NearestParkingSpotAgentLogic.java | 12 ++--- .../manager/FacilityBasedParkingManager.java | 34 +++++++++++++ .../search/NearestParkingSpotSearchLogic.java | 50 ++++++++++++------- 4 files changed, 96 insertions(+), 28 deletions(-) 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 8b427f23325..54bd6a53b75 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 @@ -29,6 +29,7 @@ */ public class NearestParkingDynLeg extends ParkingDynLeg { private boolean parkingAtEndOfLeg = true; + private boolean passangerInteractionAtEndOfLeg = false; private boolean reachedDestinationWithoutParking = false; private boolean alreadyReservedParking = false; private boolean driveToBaseWithoutParking = false; @@ -47,8 +48,10 @@ public NearestParkingDynLeg(Leg currentPlannedLeg, NetworkRoute route, Plan plan this.currentPlannedLeg = currentPlannedLeg; this.plan = plan; this.planIndexNextActivity = planIndexNextActivity; - if (!ParkingUtils.checkIfActivityHasParking(followingActivity)) + if (ParkingUtils.checkIfActivityHasNoParking(followingActivity)) parkingAtEndOfLeg = false; + if (ParkingUtils.checkIfActivityHasPassengerInteraction(followingActivity)) + passangerInteractionAtEndOfLeg = true; } @Override @@ -88,7 +91,7 @@ public void movedOverNode(Id newLinkId) { @Override public Id getNextLinkId() { - if (!parkingMode && parkingAtEndOfLeg) { + if (!passangerInteractionAtEndOfLeg && (!parkingMode && parkingAtEndOfLeg)) { parkingMode = true; this.events.processEvent(new StartParkingSearchEvent(timer.getTimeOfDay(), vehicleId, currentLinkId)); } @@ -103,7 +106,7 @@ public Id getNextLinkId() { } else { if (hasFoundParking || reachedDestinationWithoutParking) { // easy, we can just park where at our destination link - if (hasFoundParking) { + if (hasFoundParking && !passangerInteractionAtEndOfLeg) { double parkingDuration; double expectedDrivingDurationToPickup; double drivingDurationFromDropOff = timer.getTimeOfDay() - currentPlannedLeg.getDepartureTime().seconds(); @@ -118,6 +121,21 @@ public Id getNextLinkId() { parkingDuration = followingActivity.getMaximumDuration().seconds() - drivingDurationFromDropOff - expectedDrivingDurationToPickup; followingActivity.setMaximumDuration(parkingDuration); } + if (plan.getPlanElements().size() > planIndexNextActivity + 2) { + Activity activityAfterFollowing = (Activity) plan.getPlanElements().get(planIndexNextActivity + 2); + if (activityAfterFollowing.getType().equals("parking_activity")) { + boolean canParkAtGetOffFacility = ((FacilityBasedParkingManager) parkingManager).canParkAtThisFacilityUntilEnd(currentLinkId, + activityAfterFollowing.getMaximumDuration().seconds(), followingActivity.getMaximumDuration().seconds(), + ((Activity) plan.getPlanElements().get(planIndexNextActivity + 4)).getMaximumDuration().seconds(), timer.getTimeOfDay()); + if (canParkAtGetOffFacility) { + plan.getPlanElements().remove(planIndexNextActivity + 3); + plan.getPlanElements().remove(planIndexNextActivity + 1); +// log.info( +// plan.getPerson().getId().toString() + ": Parking activity can take place at getOff point. " + followingActivity.getType() + "The legs between getOff and parking are removed!"); + } + } + } + this.logic.reset(); return null; } else { @@ -131,7 +149,7 @@ public Id getNextLinkId() { double nextPickupTime = followingActivity.getStartTime().seconds() + followingActivity.getMaximumDuration().seconds(); double maxParkingDuration = followingActivity.getMaximumDuration().seconds() - (followingActivity.getStartTime().seconds() - timer.getTimeOfDay()); Id nextLinkId = ((NearestParkingSpotSearchLogic) this.logic).getNextLink(currentLinkId, route.getEndLinkId(), vehicleId, mode, - timer.getTimeOfDay(), maxParkingDuration, nextPickupTime); + timer.getTimeOfDay(), maxParkingDuration, nextPickupTime, passangerInteractionAtEndOfLeg); if (((NearestParkingSpotSearchLogic) this.logic).isNextParkingActivitySkipped() && parkingAtEndOfLeg) { removeNextActivityAndFollowingLeg(); parkingAtEndOfLeg = false; @@ -169,6 +187,8 @@ public Id getNextLinkId() { 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."); } public boolean driveToBaseWithoutParking() { diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java index c34afb85a10..65329687b6f 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java @@ -81,8 +81,7 @@ protected DynAction nextStateAfterUnParkActivity(DynAction oldAction, double now // Leg currentLeg = (Leg) this.currentPlanElement; int planIndexNextActivity = planIndex + 1; Activity nextPlanElement = (Activity) plan.getPlanElements().get(planIndexNextActivity); - if (nextPlanElement.getAttributes().getAsMap().containsKey("parking") && nextPlanElement.getAttributes().getAttribute("parking").equals( - "noParking")) + if (ParkingUtils.checkIfActivityHasNoParking(nextPlanElement)) this.lastParkActionState = LastParkActionState.WALKFROMPARK; //this could be Car, Carsharing, Motorcylce, or whatever else mode we have, so we want our leg to reflect this. return new NearestParkingDynLeg(currentPlannedLeg, actualRoute, plan, planIndexNextActivity, parkingLogic, parkingManager, @@ -118,6 +117,8 @@ protected DynAction nextStateAfterActivity(DynAction oldAction, double now) { // we could either depart by car or not next if (plan.getPlanElements().size() >= planIndex + 1) { + if (plan.getPlanElements().get(planIndex +1) instanceof Activity) + return nextStateAfterNonCarTrip(oldAction, now); planIndex++; this.currentPlanElement = plan.getPlanElements().get(planIndex); Leg currentLeg = (Leg) currentPlanElement; @@ -172,10 +173,9 @@ protected DynAction nextStateAfterActivity(DynAction oldAction, double now) { protected DynAction nextStateAfterWalkToPark(DynAction oldAction, double now) { //walk2park is complete, we can unpark. this.lastParkActionState = LastParkActionState.UNPARKACTIVITY; - PlanElement beforePlanElement = plan.getPlanElements().get(planIndex - 1); - if (beforePlanElement.getAttributes().getAsMap().containsKey("parking") && beforePlanElement.getAttributes().getAttribute("parking").equals( - "noParking")) - return nextStateAfterUnParkActivity(oldAction, now); + Activity beforePlanElement = (Activity) plan.getPlanElements().get(planIndex - 1); + if (ParkingUtils.checkIfActivityHasNoParking(beforePlanElement)) + return nextStateAfterUnParkActivity(oldAction, now); // wenn kein Parken dann einfach weiter return new IdleDynActivity(this.stageInteractionType, now + configGroup.getUnparkduration()); } } 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 ce0cc3a9e4d..4216752407f 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 @@ -30,6 +30,7 @@ import org.matsim.contrib.parking.parkingsearch.sim.ParkingSearchConfigGroup; import org.matsim.core.utils.misc.Time; import org.matsim.facilities.ActivityFacility; +import org.matsim.facilities.ActivityOption; import org.matsim.vehicles.Vehicle; import java.util.*; @@ -109,6 +110,39 @@ public boolean reserveSpaceIfVehicleCanParkHere(Id vehicleId, Id return canPark; } + /** + * Checks if it is possible if you can park at this link for the complete time. + * + * @param linkId + * @param stopDuration + * @param getOffDuration + * @param pickUpDuration + * @param now + * @return + */ + public boolean canParkAtThisFacilityUntilEnd(Id linkId, double stopDuration, double getOffDuration, double pickUpDuration, double now) { + Set> facilities = this.facilitiesPerLink.get(linkId); + if (facilities != null) { + double totalNeededParkingDuration = getOffDuration + stopDuration + pickUpDuration; + for (Id facility : facilities) { + double maxParkingDurationAtFacilityInHours = Double.MAX_VALUE; + if (this.parkingFacilities.get(facility).getAttributes().getAsMap().containsKey("maxParkingDurationInHours")) + maxParkingDurationAtFacilityInHours = (double) this.parkingFacilities.get(facility).getAttributes().getAsMap().get( + "maxParkingDurationInHours"); + if (maxParkingDurationAtFacilityInHours > totalNeededParkingDuration) { + ActivityOption parkingOptions = this.parkingFacilities.get(facility).getActivityOptions().get("parking"); + if (!parkingOptions.getOpeningTimes().isEmpty()) { + if ((parkingOptions.getOpeningTimes().first().getStartTime() == 0 && parkingOptions.getOpeningTimes().first().getEndTime() == 24 * 3600)) + if (parkingOptions.getOpeningTimes().first().getStartTime() <= now && parkingOptions.getOpeningTimes().first().getEndTime() >= now + totalNeededParkingDuration) + return true; + } else + return true; + } + } + } + return false; + } + private boolean linkIdHasAvailableParkingForVehicle(Id linkId, Id vid) { // LogManager.getLogger(getClass()).info("link "+linkId+" vehicle "+vid); if (!this.facilitiesPerLink.containsKey(linkId) && !canParkOnlyAtFacilities) { diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/search/NearestParkingSpotSearchLogic.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/search/NearestParkingSpotSearchLogic.java index 041e74c2198..21530d67fe9 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/search/NearestParkingSpotSearchLogic.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/search/NearestParkingSpotSearchLogic.java @@ -79,19 +79,21 @@ public NearestParkingSpotSearchLogic(Network network, ParkingRouter parkingRoute * @param baseLinkId linkId of the origin destination where the parkingSearch starts */ public Id getNextLink(Id currentLinkId, Id baseLinkId, Id vehicleId, String mode, double now, - double maxParkingDuration, double nextPickupTime) { + double maxParkingDuration, double nextPickupTime, boolean passangerInteractionAtEndOfLeg) { if (actualRoute == null) { - actualRoute = findRouteToNearestParkingFacility(baseLinkId, currentLinkId, canCheckParkingCapacitiesInAdvanced, now, maxParkingDuration); - checkIfDrivingToNextParkingLocationIsPossible(currentLinkId, baseLinkId, now, nextPickupTime); + actualRoute = findRouteToNearestParkingFacility(baseLinkId, currentLinkId, canCheckParkingCapacitiesInAdvanced, now, maxParkingDuration, passangerInteractionAtEndOfLeg); + if (!passangerInteractionAtEndOfLeg) + checkIfDrivingToNextParkingLocationIsPossible(currentLinkId, baseLinkId, now, nextPickupTime); if (actualRoute != null) { actualRoute.setVehicleId(vehicleId); } triedParking.clear(); } else if (currentLinkId.equals(actualRoute.getEndLinkId()) && !skipParkingActivity) { currentLinkIdx = 0; - actualRoute = findRouteToNearestParkingFacility(baseLinkId, currentLinkId, canCheckParkingCapacitiesInAdvanced, now, maxParkingDuration); - checkIfDrivingToNextParkingLocationIsPossible(currentLinkId, baseLinkId, now, nextPickupTime); + actualRoute = findRouteToNearestParkingFacility(baseLinkId, currentLinkId, canCheckParkingCapacitiesInAdvanced, now, maxParkingDuration, passangerInteractionAtEndOfLeg); + if (!passangerInteractionAtEndOfLeg) + checkIfDrivingToNextParkingLocationIsPossible(currentLinkId, baseLinkId, now, nextPickupTime); if (actualRoute != null) { actualRoute.setVehicleId(vehicleId); } @@ -175,7 +177,7 @@ public boolean isUseRandomLinkChoice() { } private NetworkRoute findRouteToNearestParkingFacility(Id baseLinkId, Id currentLinkId, boolean canCheckParkingCapacitiesInAdvanced, - double now, double maxParkingDuration) { + double now, double maxParkingDuration, boolean passangerInteractionAtEndOfLeg) { TreeMap euclideanDistanceToParkingFacilities = new TreeMap<>(); ActivityFacility nearstActivityFacility = null; NetworkRoute selectedRoute = null; @@ -190,22 +192,16 @@ private NetworkRoute findRouteToNearestParkingFacility(Id baseLinkId, Id now || parkingOptions.getOpeningTimes().first().getEndTime() < latestEndOfParking) - continue; + if (parkingOptions.getOpeningTimes().first().getStartTime() > now && parkingOptions.getOpeningTimes().first().getEndTime() < latestEndOfParking) + continue; } - //check if approx. the max parking time at facility will not exceed + //check if approx. the max parking time at facility will not exceed, assumption: "parking duration - 30 minutes" is parking Time. if (activityFacility.getAttributes().getAsMap().containsKey("maxParkingDurationInHours")) { //TODO vielleicht etwas sparsamer machen double maxParkingDurationAtFacility = 3600 * (double) activityFacility.getAttributes().getAsMap().get("maxParkingDurationInHours"); - if (maxParkingDuration > maxParkingDurationAtFacility) - continue; - double expectedTravelTimeFromParkingToBase = getExpectedTravelTime(baseLinkId, now, activityFacility.getLinkId()); - double expectedTravelTimeFromCurrentToParking = getExpectedTravelTime(activityFacility.getLinkId(), now, currentLinkId); - double expectedParkingTime = maxParkingDuration - expectedTravelTimeFromCurrentToParking - expectedTravelTimeFromParkingToBase; - if (expectedParkingTime > maxParkingDurationAtFacility) + if (maxParkingDuration - 30*60 > maxParkingDurationAtFacility) continue; } // create Euclidean distances to the parking activities to find routes only to the nearest facilities in the next step @@ -213,7 +209,11 @@ private NetworkRoute findRouteToNearestParkingFacility(Id baseLinkId, Id baseLinkId, Id maxParkingDurationAtFacility) + continue; + } counter++; NetworkRoute possibleRoute = this.parkingRouter.getRouteFromParkingToDestination(activityFacility.getLinkId(), now, currentLinkId); + // reason is that we expect that the driver will always take the nearest possible getOff point to reduce the walk distance for the guests + if (passangerInteractionAtEndOfLeg){ + selectedRoute = possibleRoute; + nearstActivityFacility = activityFacility; + break; + } double travelTimeToParking = possibleRoute.getTravelTime().seconds(); double travelTimeFromParking = travelTimeToParking; if (!baseLinkId.equals(currentLinkId)) { From 772c004ae8c4149ee03503e31564e3afeb1aaad2 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 8 Sep 2023 12:01:39 +0200 Subject: [PATCH 09/54] formatting --- .../manager/FacilityBasedParkingManager.java | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) 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 4216752407f..c292088c333 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 @@ -37,8 +37,7 @@ import java.util.Map.Entry; /** - * @author jbischoff, schlenther - * + * @author jbischoff, schlenther */ public class FacilityBasedParkingManager implements ParkingSearchManager { @@ -55,7 +54,7 @@ public class FacilityBasedParkingManager implements ParkingSearchManager { protected Map, Id> parkingReservation = new HashMap<>(); protected Map, Id> parkingLocationsOutsideFacilities = new HashMap<>(); protected Map, Set>> facilitiesPerLink = new HashMap<>(); - protected Network network; + protected Network network; protected boolean canParkOnlyAtFacilities; private final int maxSlotIndex; private final int maxTime; @@ -64,14 +63,15 @@ public class FacilityBasedParkingManager implements ParkingSearchManager { @Inject public FacilityBasedParkingManager(Scenario scenario) { - ParkingSearchConfigGroup psConfigGroup = (ParkingSearchConfigGroup) scenario.getConfig().getModules().get(ParkingSearchConfigGroup.GROUP_NAME); + ParkingSearchConfigGroup psConfigGroup = (ParkingSearchConfigGroup) scenario.getConfig().getModules().get( + ParkingSearchConfigGroup.GROUP_NAME); canParkOnlyAtFacilities = psConfigGroup.getCanParkOnlyAtFacilities(); this.network = scenario.getNetwork(); parkingFacilities = scenario.getActivityFacilities() - .getFacilitiesForActivityType(ParkingUtils.PARKACTIVITYTYPE); + .getFacilitiesForActivityType(ParkingUtils.PARKACTIVITYTYPE); LogManager.getLogger(getClass()).info(parkingFacilities.toString()); - this.timeBinSize = 15*60; - this.maxTime = 24 * 3600 -1; + this.timeBinSize = 15 * 60; + this.maxTime = 24 * 3600 - 1; this.maxSlotIndex = (this.maxTime / this.timeBinSize) + 1; this.startTime = 9 * 3600; @@ -160,7 +160,7 @@ private boolean linkIdHasAvailableParkingForVehicle(Id linkId, Id Set> parkingFacilitiesAtLink = this.facilitiesPerLink.get(linkId); for (Id fac : parkingFacilitiesAtLink) { double cap = this.parkingFacilities.get(fac).getActivityOptions().get(ParkingUtils.PARKACTIVITYTYPE) - .getCapacity(); + .getCapacity(); this.reservationsRequests.get(fac).increment(); if (this.occupation.get(fac).doubleValue() < cap) { // LogManager.getLogger(getClass()).info("occ: @@ -184,7 +184,7 @@ public Id getVehicleParkingLocation(Id vehicleId) { @Override public boolean parkVehicleHere(Id vehicleId, Id linkId, double time) { - return parkVehicleAtLink(vehicleId, linkId, time); + return parkVehicleAtLink(vehicleId, linkId, time); } protected boolean parkVehicleAtLink(Id vehicleId, Id linkId, double time) { @@ -201,7 +201,7 @@ protected boolean parkVehicleAtLink(Id vehicleId, Id linkId, doub return true; } else { throw new RuntimeException("no parking reservation found for vehicle " + vehicleId.toString() - + "arrival on link " + linkId + " with parking restriction"); + + "arrival on link " + linkId + " with parking restriction"); } } } @@ -227,11 +227,13 @@ public List produceStatistics() { for (Entry, MutableLong> e : this.occupation.entrySet()) { Id linkId = this.parkingFacilities.get(e.getKey()).getLinkId(); double capacity = this.parkingFacilities.get(e.getKey()).getActivityOptions() - .get(ParkingUtils.PARKACTIVITYTYPE).getCapacity(); + .get(ParkingUtils.PARKACTIVITYTYPE).getCapacity(); double x = this.parkingFacilities.get(e.getKey()).getCoord().getX(); double y = this.parkingFacilities.get(e.getKey()).getCoord().getY(); - String s = linkId.toString() + ";" + x + ";" + y + ";" + e.getKey().toString() + ";" + capacity + ";" + e.getValue().toString() + ";" + this.reservationsRequests.get(e.getKey()).toString() + ";" + this.numberOfParkedVehicles.get(e.getKey()).toString() + ";" + this.rejectedReservations.get(e.getKey()).toString(); + String s = linkId.toString() + ";" + x + ";" + y + ";" + e.getKey().toString() + ";" + capacity + ";" + e.getValue().toString() + ";" + this.reservationsRequests.get( + e.getKey()).toString() + ";" + this.numberOfParkedVehicles.get(e.getKey()).toString() + ";" + this.rejectedReservations.get( + e.getKey()).toString(); stats.add(s); } return stats; @@ -242,30 +244,31 @@ public List produceTimestepsStatistics() { for (int time : rejectedReservationsByTime.keySet()) { String s = Time.writeTime(time, Time.TIMEFORMAT_HHMM) + ";" + rejectedReservationsByTime.get(time) + ";" + foundParkingByTime.get( - time) + ";" + unparkByTime.get(time); + time) + ";" + unparkByTime.get(time); stats.add(s); } return stats; } - public double getNrOfAllParkingSpacesOnLink (Id linkId){ + + public double getNrOfAllParkingSpacesOnLink(Id linkId) { double allSpaces = 0; Set> parkingFacilitiesAtLink = this.facilitiesPerLink.get(linkId); if (!(parkingFacilitiesAtLink == null)) { - for (Id fac : parkingFacilitiesAtLink){ + for (Id fac : parkingFacilitiesAtLink) { allSpaces += this.parkingFacilities.get(fac).getActivityOptions().get(ParkingUtils.PARKACTIVITYTYPE).getCapacity(); } } return allSpaces; } - public double getNrOfFreeParkingSpacesOnLink (Id linkId){ + public double getNrOfFreeParkingSpacesOnLink(Id linkId) { double allFreeSpaces = 0; Set> parkingFacilitiesAtLink = this.facilitiesPerLink.get(linkId); if (parkingFacilitiesAtLink == null) { return 0; } else { - for (Id fac : parkingFacilitiesAtLink){ + for (Id fac : parkingFacilitiesAtLink) { int cap = (int) this.parkingFacilities.get(fac).getActivityOptions().get(ParkingUtils.PARKACTIVITYTYPE).getCapacity(); allFreeSpaces += (cap - this.occupation.get(fac).intValue()); } @@ -277,11 +280,11 @@ public Map, ActivityFacility> getParkingFacilities() { return this.parkingFacilities; } - public void registerRejectedReservation(double now){ + public void registerRejectedReservation(double now) { rejectedReservationsByTime.get(getTimeSlotIndex(now) * timeBinSize).increment(); } - public TreeSet getTimeSteps(){ + public TreeSet getTimeSteps() { TreeSet timeSteps = new TreeSet<>(); int slotIndex = 0; while (slotIndex <= maxSlotIndex) { @@ -295,7 +298,7 @@ private int getTimeSlotIndex(final double time) { if (time > this.maxTime) { return this.maxSlotIndex; } - return ((int)time / this.timeBinSize); + return ((int) time / this.timeBinSize); } @Override From 878e6c267f51dcbc6160f47af4d293adbbb70dec Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 8 Sep 2023 12:02:00 +0200 Subject: [PATCH 10/54] rename parameter --- .../parking/parkingsearch/DynAgent/NearestParkingDynLeg.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 54bd6a53b75..d4271b089be 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 @@ -109,7 +109,7 @@ public Id getNextLinkId() { if (hasFoundParking && !passangerInteractionAtEndOfLeg) { double parkingDuration; double expectedDrivingDurationToPickup; - double drivingDurationFromDropOff = timer.getTimeOfDay() - currentPlannedLeg.getDepartureTime().seconds(); + double drivingDurationFromGetOff = timer.getTimeOfDay() - currentPlannedLeg.getDepartureTime().seconds(); if (nextSelectedParkingLink.equals(currentLinkId)) { expectedDrivingDurationToPickup = ((NearestParkingSpotSearchLogic) this.logic).getExpectedTravelTime( @@ -118,7 +118,7 @@ public Id getNextLinkId() { expectedDrivingDurationToPickup = ((NearestParkingSpotSearchLogic) this.logic).getExpectedTravelTime( currentPlannedLeg.getRoute().getStartLinkId(), timer.getTimeOfDay(), currentLinkId); } - parkingDuration = followingActivity.getMaximumDuration().seconds() - drivingDurationFromDropOff - expectedDrivingDurationToPickup; + parkingDuration = followingActivity.getMaximumDuration().seconds() - drivingDurationFromGetOff - expectedDrivingDurationToPickup; followingActivity.setMaximumDuration(parkingDuration); } if (plan.getPlanElements().size() > planIndexNextActivity + 2) { From 0acdeb565511b450ce9fc3ada8a0bac6b107f38f Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 8 Sep 2023 12:02:18 +0200 Subject: [PATCH 11/54] correct mistake for calculation --- .../parking/parkingsearch/DynAgent/NearestParkingDynLeg.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d4271b089be..701a26d9c58 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 @@ -147,7 +147,7 @@ public Id getNextLinkId() { } // need to find the next link double nextPickupTime = followingActivity.getStartTime().seconds() + followingActivity.getMaximumDuration().seconds(); - double maxParkingDuration = followingActivity.getMaximumDuration().seconds() - (followingActivity.getStartTime().seconds() - timer.getTimeOfDay()); + double maxParkingDuration = nextPickupTime - timer.getTimeOfDay(); Id nextLinkId = ((NearestParkingSpotSearchLogic) this.logic).getNextLink(currentLinkId, route.getEndLinkId(), vehicleId, mode, timer.getTimeOfDay(), maxParkingDuration, nextPickupTime, passangerInteractionAtEndOfLeg); if (((NearestParkingSpotSearchLogic) this.logic).isNextParkingActivitySkipped() && parkingAtEndOfLeg) { From 44c8fe9c17134616e5c44a26ae3fb4615c572947 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 8 Sep 2023 12:02:32 +0200 Subject: [PATCH 12/54] correct spelling --- .../DynAgent/agentLogic/NearestParkingSpotAgentLogic.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java index 65329687b6f..af609a5d874 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java @@ -127,7 +127,7 @@ protected DynAction nextStateAfterActivity(DynAction oldAction, double now) { 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(); } From 2dbcd4159fa25d77c49cbb8cb265c22637cd12a5 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 8 Sep 2023 12:03:17 +0200 Subject: [PATCH 13/54] add and correct helper methods --- .../parking/parkingsearch/ParkingUtils.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java index 727876d0ae4..154f64aa675 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java @@ -150,10 +150,10 @@ public static List getOutgoingLinksForMode(Link link, String mode) { * @param followingActivity * @return */ - public static boolean checkIfActivityHasParking(Activity followingActivity) { - return !(followingActivity.getAttributes().getAsMap().containsKey("parking") && followingActivity.getAttributes().getAttribute( - "parking").equals( - "noParking")); + public static boolean checkIfActivityHasNoParking(Activity followingActivity) { + return followingActivity.getAttributes().getAsMap().containsKey("parking") && followingActivity.getAttributes().getAttribute( + "parking").equals("noParking"); + } /** @@ -164,4 +164,17 @@ public static boolean checkIfActivityHasParking(Activity followingActivity) { public static void setNoParkingForActivity(Activity activity) { activity.getAttributes().putAttribute("parking", "noParking"); } + + /** TODO + * @param getOffActivity + */ + public static void setPassangerInteractionForActivity(Activity getOffActivity) { + getOffActivity.getAttributes().putAttribute("parking", "PassangerInteraction"); + } + + public static boolean checkIfActivityHasPassengerInteraction(Activity followingActivity) { + return followingActivity.getAttributes().getAsMap().containsKey("parking") && followingActivity.getAttributes().getAttribute( + "parking").equals( + "PassangerInteraction"); + } } From 8ae1ff0620c257603d73f8cce3bb8f8da60e4c27 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 8 Sep 2023 20:58:55 +0200 Subject: [PATCH 14/54] set leg departure for plan --- .../DynAgent/agentLogic/NearestParkingSpotAgentLogic.java | 1 + 1 file changed, 1 insertion(+) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java index af609a5d874..5abd1021035 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java @@ -70,6 +70,7 @@ protected DynAction nextStateAfterUnParkActivity(DynAction oldAction, double now // we have unparked, now we need to get going by car again. Leg currentPlannedLeg = (Leg) currentPlanElement; + currentPlannedLeg.setDepartureTime(timer.getTimeOfDay()); Route plannedRoute = currentPlannedLeg.getRoute(); NetworkRoute actualRoute = this.parkingRouter.getRouteFromParkingToDestination(plannedRoute.getEndLinkId(), now, agent.getCurrentLinkId()); actualRoute.setVehicleId(currentlyAssignedVehicleId); From 449c9869e5e57ff81698d40e2230b9e05c7a9ba9 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 8 Sep 2023 21:02:18 +0200 Subject: [PATCH 15/54] add functionality that you can park at facility until Pickup --- .../DynAgent/NearestParkingDynLeg.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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 701a26d9c58..ddb440d8e37 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 @@ -121,9 +121,21 @@ public Id getNextLinkId() { parkingDuration = followingActivity.getMaximumDuration().seconds() - drivingDurationFromGetOff - expectedDrivingDurationToPickup; followingActivity.setMaximumDuration(parkingDuration); } - if (plan.getPlanElements().size() > planIndexNextActivity + 2) { + if (plan.getPlanElements().size() > planIndexNextActivity + 2 || followingActivity.getType().equals("parking_activity")) { Activity activityAfterFollowing = (Activity) plan.getPlanElements().get(planIndexNextActivity + 2); - if (activityAfterFollowing.getType().equals("parking_activity")) { + // check if the following parkingActivity is at same link as the next Pickup and the parking is possible until the pickup + if (followingActivity.getType().equals("parking_activity") && currentLinkId.equals(activityAfterFollowing.getLinkId())) { + boolean canParkAtFacilityUntilGetIn = ((FacilityBasedParkingManager) parkingManager).canParkAtThisFacilityUntilEnd( + currentLinkId, + followingActivity.getMaximumDuration().seconds(), 0., + activityAfterFollowing.getMaximumDuration().seconds(), timer.getTimeOfDay()); + if (canParkAtFacilityUntilGetIn) { + plan.getPlanElements().remove(planIndexNextActivity + 1); +// log.info( +// plan.getPerson().getId().toString() + ": Parking activity can take place until GetIn. " + followingActivity.getType() + "The leg between parking and GetIn is been removed!"); + } + } else if (activityAfterFollowing.getType().equals("parking_activity")) { + // checks if parking from GetOff until pickup at this facility is possible boolean canParkAtGetOffFacility = ((FacilityBasedParkingManager) parkingManager).canParkAtThisFacilityUntilEnd(currentLinkId, activityAfterFollowing.getMaximumDuration().seconds(), followingActivity.getMaximumDuration().seconds(), ((Activity) plan.getPlanElements().get(planIndexNextActivity + 4)).getMaximumDuration().seconds(), timer.getTimeOfDay()); @@ -133,6 +145,8 @@ public Id getNextLinkId() { // log.info( // plan.getPerson().getId().toString() + ": Parking activity can take place at getOff point. " + followingActivity.getType() + "The legs between getOff and parking are removed!"); } +// else log.info( +// plan.getPerson().getId().toString() + ": Parking activity can NOT take place at getOff point. " + followingActivity.getType() + "Bus will search for another facility!"); } } From 383e96a6773ec661f8d52d757df1bf3357f67cf0 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 8 Sep 2023 21:03:52 +0200 Subject: [PATCH 16/54] add stage parking time for calculation --- .../parking/parkingsearch/DynAgent/NearestParkingDynLeg.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 ddb440d8e37..9de1aaebad4 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 @@ -118,7 +118,9 @@ public Id getNextLinkId() { expectedDrivingDurationToPickup = ((NearestParkingSpotSearchLogic) this.logic).getExpectedTravelTime( currentPlannedLeg.getRoute().getStartLinkId(), timer.getTimeOfDay(), currentLinkId); } - parkingDuration = followingActivity.getMaximumDuration().seconds() - drivingDurationFromGetOff - expectedDrivingDurationToPickup; + parkingDuration = followingActivity.getMaximumDuration().seconds() + - drivingDurationFromGetOff - expectedDrivingDurationToPickup + - ((FacilityBasedParkingManager) parkingManager).getParkStageActivityDuration(); followingActivity.setMaximumDuration(parkingDuration); } if (plan.getPlanElements().size() > planIndexNextActivity + 2 || followingActivity.getType().equals("parking_activity")) { From e757826c869f201624903520a283a60612eb38cf Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 8 Sep 2023 21:04:24 +0200 Subject: [PATCH 17/54] change typ of configGroup object --- .../parkingsearch/manager/FacilityBasedParkingManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 c292088c333..8eed497583b 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 @@ -55,6 +55,7 @@ public class FacilityBasedParkingManager implements ParkingSearchManager { protected Map, Id> parkingLocationsOutsideFacilities = new HashMap<>(); protected Map, Set>> facilitiesPerLink = new HashMap<>(); protected Network network; + protected ParkingSearchConfigGroup psConfigGroup; protected boolean canParkOnlyAtFacilities; private final int maxSlotIndex; private final int maxTime; @@ -63,7 +64,7 @@ public class FacilityBasedParkingManager implements ParkingSearchManager { @Inject public FacilityBasedParkingManager(Scenario scenario) { - ParkingSearchConfigGroup psConfigGroup = (ParkingSearchConfigGroup) scenario.getConfig().getModules().get( + psConfigGroup = (ParkingSearchConfigGroup) scenario.getConfig().getModules().get( ParkingSearchConfigGroup.GROUP_NAME); canParkOnlyAtFacilities = psConfigGroup.getCanParkOnlyAtFacilities(); this.network = scenario.getNetwork(); From a0be06ee94dfbe49277bbe6123cbb0643a50a2b0 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 8 Sep 2023 21:04:40 +0200 Subject: [PATCH 18/54] fix missing factor --- .../parkingsearch/manager/FacilityBasedParkingManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8eed497583b..179301f66de 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 @@ -128,7 +128,7 @@ public boolean canParkAtThisFacilityUntilEnd(Id linkId, double stopDuratio for (Id facility : facilities) { double maxParkingDurationAtFacilityInHours = Double.MAX_VALUE; if (this.parkingFacilities.get(facility).getAttributes().getAsMap().containsKey("maxParkingDurationInHours")) - maxParkingDurationAtFacilityInHours = (double) this.parkingFacilities.get(facility).getAttributes().getAsMap().get( + maxParkingDurationAtFacilityInHours = 3600 * (double) this.parkingFacilities.get(facility).getAttributes().getAsMap().get( "maxParkingDurationInHours"); if (maxParkingDurationAtFacilityInHours > totalNeededParkingDuration) { ActivityOption parkingOptions = this.parkingFacilities.get(facility).getActivityOptions().get("parking"); From ece7be73d44fbc3b111748a0962deac29321db83 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Fri, 8 Sep 2023 21:05:56 +0200 Subject: [PATCH 19/54] add helping methods to get staging parking durations --- .../manager/FacilityBasedParkingManager.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 179301f66de..fee30b52488 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 @@ -302,6 +302,24 @@ private int getTimeSlotIndex(final double time) { return ((int) time / this.timeBinSize); } + /** + * Gives the duration of the staging activity of parking + * + * @return + */ + public double getParkStageActivityDuration() { + return psConfigGroup.getParkduration(); + } + + /** + * Gives the duration of the staging activity of unparking + * + * @return + */ + public double getUnParkStageActivityDuration() { + return psConfigGroup.getUnparkduration(); + } + @Override public void reset(int iteration) { for (Id fac : this.rejectedReservations.keySet()) { From 5f1ab73222f9dc45c91e8c07573bd86bde8779ec Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Tue, 3 Oct 2023 11:42:41 +0200 Subject: [PATCH 20/54] clean up --- .../manager/ZoneParkingManager.java | 119 +++++++++--------- 1 file changed, 61 insertions(+), 58 deletions(-) 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 5311933db84..21be364d996 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 @@ -1,5 +1,5 @@ /** - * + * */ package org.matsim.contrib.parking.parkingsearch.manager; @@ -23,90 +23,92 @@ */ public class ZoneParkingManager extends FacilityBasedParkingManager { - private HashMap>> linksOfZone; - private HashMap totalCapOfZone; - private HashMap occupationOfZone; - + private HashMap>> linksOfZone; + private HashMap totalCapOfZone; + private HashMap occupationOfZone; + /** * @param scenario */ @Inject public ZoneParkingManager(Scenario scenario, String[] pathToZoneTxtFiles) { super(scenario); - - this.linksOfZone = new HashMap>>(); - this.totalCapOfZone = new HashMap(); - this.occupationOfZone = new HashMap(); - - for(String zone: pathToZoneTxtFiles){ + + this.linksOfZone = new HashMap>>(); + this.totalCapOfZone = new HashMap(); + this.occupationOfZone = new HashMap(); + + for (String zone : pathToZoneTxtFiles) { readZone(zone); } - - for(String zone: this.linksOfZone.keySet()){ + + for (String zone : this.linksOfZone.keySet()) { calculateTotalZoneParkCapacity(zone); - this.occupationOfZone.put(zone,0.0); + this.occupationOfZone.put(zone, 0.0); } } - + /** * reads in a tabular file that declares which link id's are in the monitored zone - * the part between the last '/' and the file type extension in the given path is considered to be the zone name + * the part between the last '/' and the file type extension in the given path is considered to be the zone name * @param pathToZoneFile */ - void readZone(String pathToZoneFile){ - String zone = pathToZoneFile.substring(pathToZoneFile.lastIndexOf("/")+1, pathToZoneFile.lastIndexOf(".")); - + void readZone(String pathToZoneFile) { + String zone = pathToZoneFile.substring(pathToZoneFile.lastIndexOf("/") + 1, pathToZoneFile.lastIndexOf(".")); + HashSet> links = new HashSet>(); - + TabularFileParserConfig config = new TabularFileParserConfig(); - config.setDelimiterTags(new String[] {"\t"}); - config.setFileName(pathToZoneFile); - config.setCommentTags(new String[] { "#" }); - new TabularFileParser().parse(config, new TabularFileHandler() { + config.setDelimiterTags(new String[]{"\t"}); + config.setFileName(pathToZoneFile); + config.setCommentTags(new String[]{"#"}); + new TabularFileParser().parse(config, new TabularFileHandler() { @Override public void startRow(String[] row) { Id linkId = Id.createLinkId(row[0]); links.add(linkId); } - - }); - - this.linksOfZone.put(zone, links); + + }); + + this.linksOfZone.put(zone, links); } - - private void calculateTotalZoneParkCapacity(String zoneName){ + + private void calculateTotalZoneParkCapacity(String zoneName) { double cap = 0.0; - for(Id link : this.linksOfZone.get(zoneName)){ + for (Id link : this.linksOfZone.get(zoneName)) { cap += getNrOfAllParkingSpacesOnLink(link); - } + } this.totalCapOfZone.put(zoneName, cap); } - + @Override public boolean parkVehicleHere(Id vehicleId, Id linkId, double time) { if (parkVehicleAtLink(vehicleId, linkId, time)) { - for(String zone : this.linksOfZone.keySet()){ - if(linksOfZone.get(zone).contains(linkId) && this.facilitiesPerLink.containsKey(linkId)){ + for (String zone : this.linksOfZone.keySet()) { + if (linksOfZone.get(zone).contains(linkId) && this.facilitiesPerLink.containsKey(linkId)) { double newOcc = this.occupationOfZone.get(zone) + 1; - if(this.totalCapOfZone.get(zone) vehicleId, Id linkId, double time) { if (!this.parkingLocations.containsKey(vehicleId)) { @@ -115,35 +117,36 @@ public boolean unParkVehicleHere(Id vehicleId, Id linkId, double } else { Id fac = this.parkingLocations.remove(vehicleId); this.occupation.get(fac).decrement(); - + Id parkingLink = this.parkingFacilities.get(fac).getLinkId(); - for(String zone : this.linksOfZone.keySet()){ - if(linksOfZone.get(zone).contains(parkingLink)){ + for (String zone : this.linksOfZone.keySet()) { + if (linksOfZone.get(zone).contains(parkingLink)) { double newOcc = this.occupationOfZone.get(zone) - 1; - if(newOcc < 0 ){ - //in iteration 0 agents can "leave parking spaces" (get into traffic), but the manager didn't record them to be parked + if (newOcc < 0) { + //in iteration 0 agents can "leave parking spaces" (get into traffic), but the manager didn't record them to be parked newOcc = 0; } - this.occupationOfZone.put(zone,newOcc); + this.occupationOfZone.put(zone, newOcc); } } - return true; + return true; } } - - - public double getOccupancyRatioOfZone(String zone){ - if(!(this.linksOfZone.keySet().contains(zone))) throw new RuntimeException("zone " + zone + " was not defined. thus, could'nt calculate occupancy ratio."); + + + public double getOccupancyRatioOfZone(String zone) { + if (!(this.linksOfZone.keySet().contains(zone))) + throw new RuntimeException("zone " + zone + " was not defined. thus, could'nt calculate occupancy ratio."); return (this.occupationOfZone.get(zone) / this.totalCapOfZone.get(zone)); } - - public Set getZones(){ + + public Set getZones() { return this.linksOfZone.keySet(); } - - public double getTotalCapacityOfZone(String zone){ + + public double getTotalCapacityOfZone(String zone) { return this.totalCapOfZone.get(zone); } - + } From 65589e12bc0bdf5391245e510d7867a8506da3d7 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 5 Oct 2023 09:58:25 +0200 Subject: [PATCH 21/54] rename parameter and add comment --- .../parking/parkingsearch/ParkingUtils.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java index 154f64aa675..2384fe1c999 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java @@ -165,15 +165,23 @@ public static void setNoParkingForActivity(Activity activity) { activity.getAttributes().putAttribute("parking", "noParking"); } - /** TODO - * @param getOffActivity + /** + * This activity has a passenger interaction. This would mean that the location is fixed, and can not be changed. + * + * @param activity */ - public static void setPassangerInteractionForActivity(Activity getOffActivity) { - getOffActivity.getAttributes().putAttribute("parking", "PassangerInteraction"); + public static void setPassangerInteractionForActivity(Activity activity) { + activity.getAttributes().putAttribute("parking", "PassangerInteraction"); } - public static boolean checkIfActivityHasPassengerInteraction(Activity followingActivity) { - return followingActivity.getAttributes().getAsMap().containsKey("parking") && followingActivity.getAttributes().getAttribute( + /** + * Checks if the activity has a passanger interaction. This would mean that the location is fixed, and can not be changed. + * + * @param activity + * @return + */ + public static boolean checkIfActivityHasPassengerInteraction(Activity activity) { + return activity.getAttributes().getAsMap().containsKey("parking") && activity.getAttributes().getAttribute( "parking").equals( "PassangerInteraction"); } From 5e50d86826d9a0a6bb2dcc6a53e6ced8d88c8999 Mon Sep 17 00:00:00 2001 From: nixlaos Date: Thu, 5 Oct 2023 10:55:26 +0200 Subject: [PATCH 22/54] added test input, changed filenames in test --- .../carrier/CarrierEventsReadersTest.java | 14 +- .../serviceBasedEvents.xml | 195 ++++++++++++++ .../shipmentBasedEvents.xml | 243 ++++++++++++++++++ 3 files changed, 446 insertions(+), 6 deletions(-) create mode 100644 contribs/freight/test/input/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest/serviceBasedEvents.xml create mode 100644 contribs/freight/test/input/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest/shipmentBasedEvents.xml diff --git a/contribs/freight/src/test/java/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest.java b/contribs/freight/src/test/java/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest.java index f19068177c2..43509b23a37 100644 --- a/contribs/freight/src/test/java/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest.java +++ b/contribs/freight/src/test/java/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest.java @@ -24,12 +24,14 @@ public void testWriteReadServiceBasedEvents() { eventsManager.addHandler(collector); eventsManager.initProcessing(); - carrierEventsReaders.readFile(utils.getClassInputDirectory() + "serviceBasedEventsFile.xml"); + carrierEventsReaders.readFile(utils.getClassInputDirectory() + "serviceBasedEvents.xml"); eventsManager.finishProcessing(); + //Hier müsste dann wohl "serviceBasedEventsWritten.xml" geschrieben werden und dann auch nochmal der eventsManager für die ausgeschriebene Datei durchlaufen werden + assertEquals("number of events should be same", collector.getEvents().size(), collector.getEvents().size()); - MatsimTestUtils.assertEqualEventsFiles(utils.getClassInputDirectory() + "serviceBasedEventsFile.xml", utils.getClassInputDirectory() + "serviceBasedEventsFileWritten.xml"); - MatsimTestUtils.assertEqualFilesLineByLine(utils.getClassInputDirectory() + "serviceBasedEventsFile.xml", utils.getClassInputDirectory() + "serviceBasedEventsFileWritten.xml"); + MatsimTestUtils.assertEqualEventsFiles(utils.getClassInputDirectory() + "serviceBasedEvents.xml", utils.getClassInputDirectory() + "serviceBasedEventsWritten.xml"); + MatsimTestUtils.assertEqualFilesLineByLine(utils.getClassInputDirectory() + "serviceBasedEvents.xml", utils.getClassInputDirectory() + "serviceBasedEventsWritten.xml"); } @Test @@ -40,12 +42,12 @@ public void testWriteReadShipmentBasedEvents() { eventsManager.addHandler(collector); eventsManager.initProcessing(); - carrierEventsReaders.readFile(utils.getClassInputDirectory() + "shipmentBasedEventsFile.xml"); + carrierEventsReaders.readFile(utils.getClassInputDirectory() + "shipmentBasedEvents.xml"); eventsManager.finishProcessing(); assertEquals("number of events should be same", collector.getEvents().size(), collector.getEvents().size()); - MatsimTestUtils.assertEqualEventsFiles(utils.getClassInputDirectory() + "shipmentBasedEventsFile.xml", utils.getClassInputDirectory() + "shipmentBasedEventsFileWritten.xml"); - MatsimTestUtils.assertEqualFilesLineByLine(utils.getClassInputDirectory() + "shipmentBasedEventsFile.xml", utils.getClassInputDirectory() + "shipmentBasedEventsFileWritten.xml"); + MatsimTestUtils.assertEqualEventsFiles(utils.getClassInputDirectory() + "shipmentBasedEvents.xml", utils.getClassInputDirectory() + "shipmentBasedEventsWritten.xml"); + MatsimTestUtils.assertEqualFilesLineByLine(utils.getClassInputDirectory() + "shipmentBasedEvents.xml", utils.getClassInputDirectory() + "shipmentBasedEventsWritten.xml"); } diff --git a/contribs/freight/test/input/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest/serviceBasedEvents.xml b/contribs/freight/test/input/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest/serviceBasedEvents.xml new file mode 100644 index 00000000000..f2bb0c1175e --- /dev/null +++ b/contribs/freight/test/input/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest/serviceBasedEvents.xml @@ -0,0 +1,195 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/contribs/freight/test/input/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest/shipmentBasedEvents.xml b/contribs/freight/test/input/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest/shipmentBasedEvents.xml new file mode 100644 index 00000000000..82c90c41829 --- /dev/null +++ b/contribs/freight/test/input/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest/shipmentBasedEvents.xml @@ -0,0 +1,243 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From f4f4a63f611049dae40e99c20f01279109222597 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Wed, 11 Oct 2023 10:45:07 +0200 Subject: [PATCH 23/54] rename parameter name --- .../DynAgent/NearestParkingDynLeg.java | 9 +++++---- .../search/NearestParkingSpotSearchLogic.java | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) 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 9de1aaebad4..03287f3cf6e 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 @@ -29,7 +29,7 @@ */ public class NearestParkingDynLeg extends ParkingDynLeg { private boolean parkingAtEndOfLeg = true; - private boolean passangerInteractionAtEndOfLeg = false; + private boolean passangerInteractionAtParkingFacilityAtEndOfLeg = false; private boolean reachedDestinationWithoutParking = false; private boolean alreadyReservedParking = false; private boolean driveToBaseWithoutParking = false; @@ -51,7 +51,7 @@ public NearestParkingDynLeg(Leg currentPlannedLeg, NetworkRoute route, Plan plan if (ParkingUtils.checkIfActivityHasNoParking(followingActivity)) parkingAtEndOfLeg = false; if (ParkingUtils.checkIfActivityHasPassengerInteraction(followingActivity)) - passangerInteractionAtEndOfLeg = true; + passangerInteractionAtParkingFacilityAtEndOfLeg = true; } @Override @@ -91,7 +91,7 @@ public void movedOverNode(Id newLinkId) { @Override public Id getNextLinkId() { - if (!passangerInteractionAtEndOfLeg && (!parkingMode && parkingAtEndOfLeg)) { + if (!passangerInteractionAtParkingFacilityAtEndOfLeg && (!parkingMode && parkingAtEndOfLeg)) { parkingMode = true; this.events.processEvent(new StartParkingSearchEvent(timer.getTimeOfDay(), vehicleId, currentLinkId)); } @@ -106,7 +106,7 @@ public Id getNextLinkId() { } else { if (hasFoundParking || reachedDestinationWithoutParking) { // easy, we can just park where at our destination link - if (hasFoundParking && !passangerInteractionAtEndOfLeg) { + if (hasFoundParking && !passangerInteractionAtParkingFacilityAtEndOfLeg) { double parkingDuration; double expectedDrivingDurationToPickup; double drivingDurationFromGetOff = timer.getTimeOfDay() - currentPlannedLeg.getDepartureTime().seconds(); @@ -166,6 +166,7 @@ public Id getNextLinkId() { double maxParkingDuration = nextPickupTime - timer.getTimeOfDay(); Id nextLinkId = ((NearestParkingSpotSearchLogic) this.logic).getNextLink(currentLinkId, route.getEndLinkId(), vehicleId, mode, timer.getTimeOfDay(), maxParkingDuration, nextPickupTime, passangerInteractionAtEndOfLeg); + timer.getTimeOfDay(), maxParkingDuration, nextPickupTime, passangerInteractionAtParkingFacilityAtEndOfLeg, if (((NearestParkingSpotSearchLogic) this.logic).isNextParkingActivitySkipped() && parkingAtEndOfLeg) { removeNextActivityAndFollowingLeg(); parkingAtEndOfLeg = false; diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/search/NearestParkingSpotSearchLogic.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/search/NearestParkingSpotSearchLogic.java index 21530d67fe9..aebbc23aee8 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/search/NearestParkingSpotSearchLogic.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/search/NearestParkingSpotSearchLogic.java @@ -79,8 +79,15 @@ public NearestParkingSpotSearchLogic(Network network, ParkingRouter parkingRoute * @param baseLinkId linkId of the origin destination where the parkingSearch starts */ public Id getNextLink(Id currentLinkId, Id baseLinkId, Id vehicleId, String mode, double now, - double maxParkingDuration, double nextPickupTime, boolean passangerInteractionAtEndOfLeg) { - + double maxParkingDuration, double nextPickupTime, boolean passangerInteractionAtParkingFacilityAtEndOfLeg, + Coord coordOfAttraction) { + double maxAdditionalDistanceToAttraction = Double.MAX_VALUE; + // if a passenger interaction take place at a facility the walking distance to the attraction should be not extended by the value of maxAdditionalDistanceToAttraction + if (passangerInteractionAtParkingFacilityAtEndOfLeg) { + if (Double.isNaN(distanceFromBaseToAttraction)) + findDistanceBetweenBaseLinkAndAttraction(baseLinkId, coordOfAttraction); + maxAdditionalDistanceToAttraction = 200.; + } if (actualRoute == null) { actualRoute = findRouteToNearestParkingFacility(baseLinkId, currentLinkId, canCheckParkingCapacitiesInAdvanced, now, maxParkingDuration, passangerInteractionAtEndOfLeg); if (!passangerInteractionAtEndOfLeg) @@ -177,7 +184,9 @@ public boolean isUseRandomLinkChoice() { } private NetworkRoute findRouteToNearestParkingFacility(Id baseLinkId, Id currentLinkId, boolean canCheckParkingCapacitiesInAdvanced, - double now, double maxParkingDuration, boolean passangerInteractionAtEndOfLeg) { + double now, double maxParkingDuration, + boolean passangerInteractionAtParkingFacilityAtEndOfLeg, double maxDistanceFromBase, + Coord coordOfAttraction) { TreeMap euclideanDistanceToParkingFacilities = new TreeMap<>(); ActivityFacility nearstActivityFacility = null; NetworkRoute selectedRoute = null; @@ -210,7 +219,7 @@ private NetworkRoute findRouteToNearestParkingFacility(Id baseLinkId, Id baseLinkId, Id Date: Wed, 11 Oct 2023 10:47:32 +0200 Subject: [PATCH 24/54] add distance to attraction and update for fix location for passengerInteraction --- .../DynAgent/NearestParkingDynLeg.java | 2 +- .../search/NearestParkingSpotSearchLogic.java | 52 +++++++++++++++---- 2 files changed, 42 insertions(+), 12 deletions(-) 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 03287f3cf6e..41091487c63 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 @@ -165,8 +165,8 @@ public Id getNextLinkId() { double nextPickupTime = followingActivity.getStartTime().seconds() + followingActivity.getMaximumDuration().seconds(); double maxParkingDuration = nextPickupTime - timer.getTimeOfDay(); Id nextLinkId = ((NearestParkingSpotSearchLogic) this.logic).getNextLink(currentLinkId, route.getEndLinkId(), vehicleId, mode, - timer.getTimeOfDay(), maxParkingDuration, nextPickupTime, passangerInteractionAtEndOfLeg); timer.getTimeOfDay(), maxParkingDuration, nextPickupTime, passangerInteractionAtParkingFacilityAtEndOfLeg, + followingActivity.getCoord()); if (((NearestParkingSpotSearchLogic) this.logic).isNextParkingActivitySkipped() && parkingAtEndOfLeg) { removeNextActivityAndFollowingLeg(); parkingAtEndOfLeg = false; diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/search/NearestParkingSpotSearchLogic.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/search/NearestParkingSpotSearchLogic.java index aebbc23aee8..d87bf0408fe 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/search/NearestParkingSpotSearchLogic.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/search/NearestParkingSpotSearchLogic.java @@ -49,6 +49,7 @@ public class NearestParkingSpotSearchLogic implements ParkingSearchLogic { private NetworkRoute actualRoute = null; private final boolean canReserveParkingSlot; private final boolean canCheckParkingCapacitiesInAdvanced; + private double distanceFromBaseToAttraction = Double.NaN; private boolean useRandomLinkChoice; private int currentLinkIdx; private final HashSet> triedParking; @@ -89,21 +90,22 @@ public Id getNextLink(Id currentLinkId, Id baseLinkId, Id getNextLink(Id currentLinkId, Id baseLinkId, Id baseLinkId, Coord coordOfAttraction) { + for (ActivityFacility activityFacility : activityFacilities.values()) { + if (activityFacility.getLinkId().equals(baseLinkId)) + distanceFromBaseToAttraction = NetworkUtils.getEuclideanDistance(activityFacility.getCoord(), + coordOfAttraction); + } + } + /** * Checks if it is possible to drive to the new parking facility and to drive back to the base without extending the startTime of the following activity. * If the resulting parking time at the new facility is less then 5 minutes the vehicle will drive directly to the next activity location. @@ -194,7 +210,7 @@ private NetworkRoute findRouteToNearestParkingFacility(Id baseLinkId, Id baseLinkId, Id maxParkingDurationAtFacility) continue; } + + //TODO beschreiben was passiert + if (passangerInteractionAtParkingFacilityAtEndOfLeg) { + double distanceBetweenThisParkingFacilityAndTheAttraction = NetworkUtils.getEuclideanDistance(activityFacility.getCoord(), + coordOfAttraction); + if (distanceBetweenThisParkingFacilityAndTheAttraction - distanceFromBaseToAttraction > maxDistanceFromBase) + continue; + } // create Euclidean distances to the parking activities to find routes only to the nearest facilities in the next step Coord coordBaseLink = network.getLinks().get(baseLinkId).getCoord(); Coord coordCurrentLink = network.getLinks().get(currentLinkId).getCoord(); @@ -241,6 +265,11 @@ private NetworkRoute findRouteToNearestParkingFacility(Id baseLinkId, Id triedParking.size()) + if (triedParking.contains(activityFacility.getId())) + continue; + if (passangerInteractionAtParkingFacilityAtEndOfLeg && euclideanDistanceToParkingFacilities.size() == triedParking.size()) + triedParking.clear(); NetworkRoute possibleRoute = this.parkingRouter.getRouteFromParkingToDestination(activityFacility.getLinkId(), now, currentLinkId); // reason is that we expect that the driver will always take the nearest possible getOff point to reduce the walk distance for the guests @@ -299,6 +328,7 @@ public void reset() { actualRoute = null; currentLinkIdx = 0; skipParkingActivity = false; + distanceFromBaseToAttraction = Double.NaN; } } From 171413f0683effe998ea3ab853b80fc302fb45c1 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Wed, 11 Oct 2023 20:18:43 +0200 Subject: [PATCH 25/54] add author --- .../parkingsearch/manager/FacilityBasedParkingManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fee30b52488..da384b59675 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 @@ -37,7 +37,7 @@ import java.util.Map.Entry; /** - * @author jbischoff, schlenther + * @author jbischoff, schlenther, Ricardo Ewert */ public class FacilityBasedParkingManager implements ParkingSearchManager { From 4d81f8a8985bc1ae75ca530f2f9a74ebfb3235c3 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 12 Oct 2023 11:10:49 +0200 Subject: [PATCH 26/54] rename parking stage activity name --- .../NearestParkingSpotAgentLogic.java | 2 +- .../agentLogic/ParkingAgentLogic.java | 2 +- .../parking/parkingsearch/ParkingUtils.java | 2 +- .../evaluation/ParkingSlotVisualiser.java | 404 +++++++++--------- .../manager/FacilityBasedParkingManager.java | 10 +- .../manager/ZoneParkingManager.java | 2 +- 6 files changed, 211 insertions(+), 211 deletions(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java index 5abd1021035..1ec9f5a468f 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java @@ -144,7 +144,7 @@ protected DynAction nextStateAfterActivity(DynAction oldAction, double now) { throw new RuntimeException(message); } this.currentlyAssignedVehicleId = vehicleId; - this.stageInteractionType = ParkingUtils.PARKACTIVITYTYPE; + this.stageInteractionType = ParkingUtils.ParkingStageInteractionType; if (!walkLeg.getTravelTime().equals(OptionalTime.defined(0.))) { this.lastParkActionState = LastParkActionState.WALKTOPARK; return new StaticPassengerDynLeg(walkLeg.getRoute(), walkLeg.getMode()); 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 c6ad7d3901b..dd2fb4fa74b 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 @@ -255,7 +255,7 @@ protected DynAction nextStateAfterActivity(DynAction oldAction, double now) { } this.lastParkActionState = LastParkActionState.WALKTOPARK; this.currentlyAssignedVehicleId = vehicleId; - this.stageInteractionType = ParkingUtils.PARKACTIVITYTYPE; + this.stageInteractionType = ParkingUtils.ParkingStageInteractionType; return new StaticPassengerDynLeg(walkLeg.getRoute(), walkLeg.getMode()); } else if (currentLeg.getMode().equals(TransportMode.pt)) { if (currentLeg.getRoute() instanceof TransitPassengerRoute) { diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java index 2384fe1c999..d10b3d4a9b4 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java @@ -33,7 +33,7 @@ */ public class ParkingUtils { - static public final String PARKACTIVITYTYPE = "parking"; + static public final String ParkingStageInteractionType = "parking"; static public final int NO_OF_LINKS_TO_GET_ON_ROUTE = 5; diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingSlotVisualiser.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingSlotVisualiser.java index e475acbb181..8de88458df1 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingSlotVisualiser.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingSlotVisualiser.java @@ -1,202 +1,202 @@ -/* *********************************************************************** * - * project: org.matsim.* - * *********************************************************************** * - * * - * copyright : (C) ${year} by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** */ - -package org.matsim.contrib.parking.parkingsearch.evaluation; - -import com.google.inject.Inject; -import org.apache.commons.lang3.mutable.MutableDouble; -import org.apache.logging.log4j.LogManager; -import org.matsim.api.core.v01.Coord; -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.Scenario; -import org.matsim.api.core.v01.events.PersonEntersVehicleEvent; -import org.matsim.api.core.v01.events.PersonLeavesVehicleEvent; -import org.matsim.api.core.v01.events.VehicleEntersTrafficEvent; -import org.matsim.api.core.v01.events.VehicleLeavesTrafficEvent; -import org.matsim.api.core.v01.events.handler.PersonEntersVehicleEventHandler; -import org.matsim.api.core.v01.events.handler.PersonLeavesVehicleEventHandler; -import org.matsim.api.core.v01.events.handler.VehicleEntersTrafficEventHandler; -import org.matsim.api.core.v01.events.handler.VehicleLeavesTrafficEventHandler; -import org.matsim.api.core.v01.network.Link; -import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.parking.parkingsearch.ParkingUtils; -import org.matsim.core.controler.events.IterationEndsEvent; -import org.matsim.core.controler.listener.IterationEndsListener; -import org.matsim.core.gbl.MatsimRandom; -import org.matsim.core.utils.collections.Tuple; -import org.matsim.core.utils.io.IOUtils; -import org.matsim.facilities.ActivityFacility; -import org.matsim.vehicles.Vehicle; - -import java.io.BufferedWriter; -import java.io.IOException; -import java.util.*; -import java.util.Map.Entry; - -public class ParkingSlotVisualiser implements PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, VehicleLeavesTrafficEventHandler, VehicleEntersTrafficEventHandler, IterationEndsListener { - - Network network; - - protected Map, ParkingSlotManager> slotsOnLink = new HashMap, ParkingSlotManager>(); - protected Map, Double> midnightParkers = new HashMap, Double>(); - protected Map, ParkingSlotManager> vehiclesResponsibleManager = new HashMap<>(); - Random r = MatsimRandom.getLocalInstance(); - protected List parkings = new ArrayList<>(); - - Map, Id> parkedVehicles = new HashMap, Id>(); - - /** - * - */ - @Inject - public ParkingSlotVisualiser(Scenario scenario) { - this.network = scenario.getNetwork(); - Map, ActivityFacility> parkingFacilities = scenario.getActivityFacilities().getFacilitiesForActivityType( - ParkingUtils.PARKACTIVITYTYPE); - initialize(parkingFacilities); - } - - public ParkingSlotVisualiser(Network network, Map, ActivityFacility> parkingFacilities) { - this.network = network; - initialize(parkingFacilities); - } - - private void initialize(Map, ActivityFacility> parkingFacilities) { - Map, MutableDouble> nrOfSlotsPerLink = new HashMap, MutableDouble>(); - for (ActivityFacility fac : parkingFacilities.values()) { - Id linkId = fac.getLinkId(); - if (nrOfSlotsPerLink.containsKey(linkId)) { - nrOfSlotsPerLink.get(linkId).add(fac.getActivityOptions().get(ParkingUtils.PARKACTIVITYTYPE).getCapacity()); - } else { - nrOfSlotsPerLink.put(linkId, new MutableDouble(fac.getActivityOptions().get(ParkingUtils.PARKACTIVITYTYPE).getCapacity())); - } - } - - for (Id linkID : nrOfSlotsPerLink.keySet()) { -// LogManager.getLogger(getClass()).info("initialize parking visualisation for link " + linkID); - this.slotsOnLink.put(linkID, new ParkingSlotManager(network.getLinks().get(linkID), nrOfSlotsPerLink.get(linkID).intValue())); - } - } - - - @Override - public void reset(int iteration) { - for (Id link : this.slotsOnLink.keySet()) { - this.slotsOnLink.get(link).setAllParkingTimesToZero(); - } - } - - @Override - public void handleEvent(VehicleLeavesTrafficEvent event) { - if (this.slotsOnLink.containsKey(event.getLinkId())) { - this.vehiclesResponsibleManager.put(event.getVehicleId(), this.slotsOnLink.get(event.getLinkId())); - } - } - - @Override - public void handleEvent(PersonLeavesVehicleEvent event) { - ParkingSlotManager manager = this.vehiclesResponsibleManager.remove(event.getVehicleId()); - if (manager != null) { - Tuple parkingTuple = manager.processParking(event.getTime(), event.getVehicleId()); - this.parkings.add(manager.getLinkId() + ";" + parkingTuple.getSecond() + ";" + event.getTime() + ";" + - parkingTuple.getFirst().getX() + ";" + parkingTuple.getFirst().getY() + ";" + "free"); - this.parkedVehicles.put(event.getVehicleId(), manager.getLinkId()); - } - } - - - @Override - public void handleEvent(PersonEntersVehicleEvent event) { - if (this.parkedVehicles.containsKey(event.getVehicleId())) { - ParkingSlotManager manager = this.slotsOnLink.get(this.parkedVehicles.get(event.getVehicleId())); - Tuple parkingTuple = manager.processUnParking(event.getTime(), event.getVehicleId()); - this.parkings.add(manager.getLinkId() + ";" + parkingTuple.getSecond() + ";" + event.getTime() + ";" + - parkingTuple.getFirst().getX() + ";" + parkingTuple.getFirst().getY() + ";" + "veh" + event.getVehicleId()); - this.parkedVehicles.remove(event.getVehicleId()); - } else { - midnightParkers.put(event.getVehicleId(), event.getTime()); - } - } - - /* (non-Javadoc) - * @see org.matsim.api.core.v01.events.handler.VehicleEntersTrafficEventHandler#handleEvent(org.matsim.api.core.v01.events.VehicleEntersTrafficEvent) - */ - @Override - public void handleEvent(VehicleEntersTrafficEvent event) { - if (this.midnightParkers.containsKey(event.getVehicleId())) { - if (this.slotsOnLink.containsKey(event.getLinkId())) { - ParkingSlotManager manager = this.slotsOnLink.get(event.getLinkId()); - Tuple parkingTuple = manager.processUnParking(event.getTime(), event.getVehicleId()); - if (parkingTuple != null) { - this.parkings.add(manager.getLinkId() + ";" + parkingTuple.getSecond() + ";" + event.getTime() + ";" + - parkingTuple.getFirst().getX() + ";" + parkingTuple.getFirst().getY() + ";" + "veh" + event.getVehicleId()); - } - } - this.midnightParkers.remove(event.getVehicleId()); - } - } - - public void finishDay() { - - for (Id linkId : this.slotsOnLink.keySet()) { - ParkingSlotManager manager = this.slotsOnLink.get(linkId); - Map, Tuple> occupiedSlots = manager.getOccupiedSlots(); - - double endOfDay = 30 * 3600; - for (Entry, Tuple> e : occupiedSlots.entrySet()) { - Tuple parkingTuple = e.getValue(); - this.parkings.add(manager.getLinkId() + ";" + parkingTuple.getSecond() + ";" + endOfDay + ";" + - parkingTuple.getFirst().getX() + ";" + parkingTuple.getFirst().getY() + ";" + "veh" + e.getKey()); - - // set back to 0 - } - - List> freeSlots = manager.getFreeSlots(); - for (Tuple parkingTuple : freeSlots) { - this.parkings.add(manager.getLinkId() + ";" + parkingTuple.getSecond() + ";" + endOfDay + ";" + - parkingTuple.getFirst().getX() + ";" + parkingTuple.getFirst().getY() + ";" + "free"); - } - } - } - - public void plotSlotOccupation(String filename) { - String head = "LinkId;from;To;X;Y;OccupiedByVehicle"; - BufferedWriter bw = IOUtils.getBufferedWriter(filename); - try { - bw.write(head); - for (String s : this.parkings) { - bw.newLine(); - bw.write(s); - } - bw.flush(); - bw.close(); - } catch (IOException e) { - e.printStackTrace(); - } - LogManager.getLogger(getClass()).info("FINISHED WRITING PARKING SLOT VISUALISATION FILE TO: " + filename); - } - - @Override - public void notifyIterationEnds(IterationEndsEvent event) { - String path = event.getServices().getControlerIO().getIterationFilename(event.getIteration(), - "ParkingSlots_it" + event.getIteration() + ".csv"); - this.finishDay(); - this.plotSlotOccupation(path); - } -} - +/* *********************************************************************** * + * project: org.matsim.* + * *********************************************************************** * + * * + * copyright : (C) ${year} by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** */ + +package org.matsim.contrib.parking.parkingsearch.evaluation; + +import com.google.inject.Inject; +import org.apache.commons.lang3.mutable.MutableDouble; +import org.apache.logging.log4j.LogManager; +import org.matsim.api.core.v01.Coord; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.events.PersonEntersVehicleEvent; +import org.matsim.api.core.v01.events.PersonLeavesVehicleEvent; +import org.matsim.api.core.v01.events.VehicleEntersTrafficEvent; +import org.matsim.api.core.v01.events.VehicleLeavesTrafficEvent; +import org.matsim.api.core.v01.events.handler.PersonEntersVehicleEventHandler; +import org.matsim.api.core.v01.events.handler.PersonLeavesVehicleEventHandler; +import org.matsim.api.core.v01.events.handler.VehicleEntersTrafficEventHandler; +import org.matsim.api.core.v01.events.handler.VehicleLeavesTrafficEventHandler; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.parking.parkingsearch.ParkingUtils; +import org.matsim.core.controler.events.IterationEndsEvent; +import org.matsim.core.controler.listener.IterationEndsListener; +import org.matsim.core.gbl.MatsimRandom; +import org.matsim.core.utils.collections.Tuple; +import org.matsim.core.utils.io.IOUtils; +import org.matsim.facilities.ActivityFacility; +import org.matsim.vehicles.Vehicle; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.util.*; +import java.util.Map.Entry; + +public class ParkingSlotVisualiser implements PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, VehicleLeavesTrafficEventHandler, VehicleEntersTrafficEventHandler, IterationEndsListener { + + Network network; + + protected Map, ParkingSlotManager> slotsOnLink = new HashMap, ParkingSlotManager>(); + protected Map, Double> midnightParkers = new HashMap, Double>(); + protected Map, ParkingSlotManager> vehiclesResponsibleManager = new HashMap<>(); + Random r = MatsimRandom.getLocalInstance(); + protected List parkings = new ArrayList<>(); + + Map, Id> parkedVehicles = new HashMap, Id>(); + + /** + * + */ + @Inject + public ParkingSlotVisualiser(Scenario scenario) { + this.network = scenario.getNetwork(); + Map, ActivityFacility> parkingFacilities = scenario.getActivityFacilities().getFacilitiesForActivityType( + ParkingUtils.ParkingStageInteractionType); + initialize(parkingFacilities); + } + + public ParkingSlotVisualiser(Network network, Map, ActivityFacility> parkingFacilities) { + this.network = network; + initialize(parkingFacilities); + } + + private void initialize(Map, ActivityFacility> parkingFacilities) { + Map, MutableDouble> nrOfSlotsPerLink = new HashMap, MutableDouble>(); + for (ActivityFacility fac : parkingFacilities.values()) { + Id linkId = fac.getLinkId(); + if (nrOfSlotsPerLink.containsKey(linkId)) { + nrOfSlotsPerLink.get(linkId).add(fac.getActivityOptions().get(ParkingUtils.ParkingStageInteractionType).getCapacity()); + } else { + nrOfSlotsPerLink.put(linkId, new MutableDouble(fac.getActivityOptions().get(ParkingUtils.ParkingStageInteractionType).getCapacity())); + } + } + + for (Id linkID : nrOfSlotsPerLink.keySet()) { +// LogManager.getLogger(getClass()).info("initialize parking visualisation for link " + linkID); + this.slotsOnLink.put(linkID, new ParkingSlotManager(network.getLinks().get(linkID), nrOfSlotsPerLink.get(linkID).intValue())); + } + } + + + @Override + public void reset(int iteration) { + for (Id link : this.slotsOnLink.keySet()) { + this.slotsOnLink.get(link).setAllParkingTimesToZero(); + } + } + + @Override + public void handleEvent(VehicleLeavesTrafficEvent event) { + if (this.slotsOnLink.containsKey(event.getLinkId())) { + this.vehiclesResponsibleManager.put(event.getVehicleId(), this.slotsOnLink.get(event.getLinkId())); + } + } + + @Override + public void handleEvent(PersonLeavesVehicleEvent event) { + ParkingSlotManager manager = this.vehiclesResponsibleManager.remove(event.getVehicleId()); + if (manager != null) { + Tuple parkingTuple = manager.processParking(event.getTime(), event.getVehicleId()); + this.parkings.add(manager.getLinkId() + ";" + parkingTuple.getSecond() + ";" + event.getTime() + ";" + + parkingTuple.getFirst().getX() + ";" + parkingTuple.getFirst().getY() + ";" + "free"); + this.parkedVehicles.put(event.getVehicleId(), manager.getLinkId()); + } + } + + + @Override + public void handleEvent(PersonEntersVehicleEvent event) { + if (this.parkedVehicles.containsKey(event.getVehicleId())) { + ParkingSlotManager manager = this.slotsOnLink.get(this.parkedVehicles.get(event.getVehicleId())); + Tuple parkingTuple = manager.processUnParking(event.getTime(), event.getVehicleId()); + this.parkings.add(manager.getLinkId() + ";" + parkingTuple.getSecond() + ";" + event.getTime() + ";" + + parkingTuple.getFirst().getX() + ";" + parkingTuple.getFirst().getY() + ";" + "veh" + event.getVehicleId()); + this.parkedVehicles.remove(event.getVehicleId()); + } else { + midnightParkers.put(event.getVehicleId(), event.getTime()); + } + } + + /* (non-Javadoc) + * @see org.matsim.api.core.v01.events.handler.VehicleEntersTrafficEventHandler#handleEvent(org.matsim.api.core.v01.events.VehicleEntersTrafficEvent) + */ + @Override + public void handleEvent(VehicleEntersTrafficEvent event) { + if (this.midnightParkers.containsKey(event.getVehicleId())) { + if (this.slotsOnLink.containsKey(event.getLinkId())) { + ParkingSlotManager manager = this.slotsOnLink.get(event.getLinkId()); + Tuple parkingTuple = manager.processUnParking(event.getTime(), event.getVehicleId()); + if (parkingTuple != null) { + this.parkings.add(manager.getLinkId() + ";" + parkingTuple.getSecond() + ";" + event.getTime() + ";" + + parkingTuple.getFirst().getX() + ";" + parkingTuple.getFirst().getY() + ";" + "veh" + event.getVehicleId()); + } + } + this.midnightParkers.remove(event.getVehicleId()); + } + } + + public void finishDay() { + + for (Id linkId : this.slotsOnLink.keySet()) { + ParkingSlotManager manager = this.slotsOnLink.get(linkId); + Map, Tuple> occupiedSlots = manager.getOccupiedSlots(); + + double endOfDay = 30 * 3600; + for (Entry, Tuple> e : occupiedSlots.entrySet()) { + Tuple parkingTuple = e.getValue(); + this.parkings.add(manager.getLinkId() + ";" + parkingTuple.getSecond() + ";" + endOfDay + ";" + + parkingTuple.getFirst().getX() + ";" + parkingTuple.getFirst().getY() + ";" + "veh" + e.getKey()); + + // set back to 0 + } + + List> freeSlots = manager.getFreeSlots(); + for (Tuple parkingTuple : freeSlots) { + this.parkings.add(manager.getLinkId() + ";" + parkingTuple.getSecond() + ";" + endOfDay + ";" + + parkingTuple.getFirst().getX() + ";" + parkingTuple.getFirst().getY() + ";" + "free"); + } + } + } + + public void plotSlotOccupation(String filename) { + String head = "LinkId;from;To;X;Y;OccupiedByVehicle"; + BufferedWriter bw = IOUtils.getBufferedWriter(filename); + try { + bw.write(head); + for (String s : this.parkings) { + bw.newLine(); + bw.write(s); + } + bw.flush(); + bw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + LogManager.getLogger(getClass()).info("FINISHED WRITING PARKING SLOT VISUALISATION FILE TO: " + filename); + } + + @Override + public void notifyIterationEnds(IterationEndsEvent event) { + String path = event.getServices().getControlerIO().getIterationFilename(event.getIteration(), + "ParkingSlots_it" + event.getIteration() + ".csv"); + this.finishDay(); + this.plotSlotOccupation(path); + } +} + 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 da384b59675..059d3213893 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 @@ -69,7 +69,7 @@ public FacilityBasedParkingManager(Scenario scenario) { canParkOnlyAtFacilities = psConfigGroup.getCanParkOnlyAtFacilities(); this.network = scenario.getNetwork(); parkingFacilities = scenario.getActivityFacilities() - .getFacilitiesForActivityType(ParkingUtils.PARKACTIVITYTYPE); + .getFacilitiesForActivityType(ParkingUtils.ParkingStageInteractionType); LogManager.getLogger(getClass()).info(parkingFacilities.toString()); this.timeBinSize = 15 * 60; this.maxTime = 24 * 3600 - 1; @@ -160,7 +160,7 @@ private boolean linkIdHasAvailableParkingForVehicle(Id linkId, Id } Set> parkingFacilitiesAtLink = this.facilitiesPerLink.get(linkId); for (Id fac : parkingFacilitiesAtLink) { - double cap = this.parkingFacilities.get(fac).getActivityOptions().get(ParkingUtils.PARKACTIVITYTYPE) + double cap = this.parkingFacilities.get(fac).getActivityOptions().get(ParkingUtils.ParkingStageInteractionType) .getCapacity(); this.reservationsRequests.get(fac).increment(); if (this.occupation.get(fac).doubleValue() < cap) { @@ -228,7 +228,7 @@ public List produceStatistics() { for (Entry, MutableLong> e : this.occupation.entrySet()) { Id linkId = this.parkingFacilities.get(e.getKey()).getLinkId(); double capacity = this.parkingFacilities.get(e.getKey()).getActivityOptions() - .get(ParkingUtils.PARKACTIVITYTYPE).getCapacity(); + .get(ParkingUtils.ParkingStageInteractionType).getCapacity(); double x = this.parkingFacilities.get(e.getKey()).getCoord().getX(); double y = this.parkingFacilities.get(e.getKey()).getCoord().getY(); @@ -257,7 +257,7 @@ public double getNrOfAllParkingSpacesOnLink(Id linkId) { Set> parkingFacilitiesAtLink = this.facilitiesPerLink.get(linkId); if (!(parkingFacilitiesAtLink == null)) { for (Id fac : parkingFacilitiesAtLink) { - allSpaces += this.parkingFacilities.get(fac).getActivityOptions().get(ParkingUtils.PARKACTIVITYTYPE).getCapacity(); + allSpaces += this.parkingFacilities.get(fac).getActivityOptions().get(ParkingUtils.ParkingStageInteractionType).getCapacity(); } } return allSpaces; @@ -270,7 +270,7 @@ public double getNrOfFreeParkingSpacesOnLink(Id linkId) { return 0; } else { for (Id fac : parkingFacilitiesAtLink) { - int cap = (int) this.parkingFacilities.get(fac).getActivityOptions().get(ParkingUtils.PARKACTIVITYTYPE).getCapacity(); + int cap = (int) this.parkingFacilities.get(fac).getActivityOptions().get(ParkingUtils.ParkingStageInteractionType).getCapacity(); allFreeSpaces += (cap - this.occupation.get(fac).intValue()); } } 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 21be364d996..b9fbebe4699 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 @@ -94,7 +94,7 @@ public boolean parkVehicleHere(Id vehicleId, Id linkId, double ti String s = "FacilityID: " + this.parkingLocations.get(vehicleId); String t = "Occupied: " + this.occupation.get(this.parkingLocations.get(vehicleId)); String u = "Capacity: " + this.parkingFacilities.get(this.parkingLocations.get(vehicleId)).getActivityOptions().get( - ParkingUtils.PARKACTIVITYTYPE).getCapacity(); + ParkingUtils.ParkingStageInteractionType).getCapacity(); String v = "TotalCapacityOnLink: " + getNrOfAllParkingSpacesOnLink(linkId); throw new RuntimeException("occupancy of zone " + zone + " is higher than 100%. Capacity= " + this.totalCapOfZone.get( zone) + " occupancy=" + newOcc + "time = " + time From 40e16d4bdacce75a9d67b656fea41fe5086d2d3a Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 12 Oct 2023 11:33:58 +0200 Subject: [PATCH 27/54] add fixed activity names for parking --- .../org/matsim/contrib/parking/parkingsearch/ParkingUtils.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java index d10b3d4a9b4..c3f2a38eb87 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/ParkingUtils.java @@ -34,6 +34,8 @@ public class ParkingUtils { static public final String ParkingStageInteractionType = "parking"; + static public final String ParkingActivityType = "parking_activity"; + static public final String WaitingForParkingActivityType = "waitingForParkingSpace_activity"; static public final int NO_OF_LINKS_TO_GET_ON_ROUTE = 5; From 30bfb3f3867bac002cbea8247c306c7383c7d9a4 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 12 Oct 2023 19:33:32 +0200 Subject: [PATCH 28/54] change parameter name and add waiting vehicles --- .../manager/FacilityBasedParkingManager.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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 059d3213893..553c93a932e 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,7 +44,7 @@ public class FacilityBasedParkingManager implements ParkingSearchManager { protected Map, Integer> capacity = new HashMap<>(); protected Map, MutableLong> occupation = new HashMap<>(); protected Map, MutableLong> reservationsRequests = new HashMap<>(); - protected Map, MutableLong> rejectedReservations = new HashMap<>(); + protected Map, MutableLong> rejectedParkingRequest = new HashMap<>(); protected Map, MutableLong> numberOfParkedVehicles = new HashMap<>(); protected TreeMap rejectedReservationsByTime = new TreeMap<>(); protected TreeMap foundParkingByTime = new TreeMap<>(); @@ -84,10 +84,12 @@ public FacilityBasedParkingManager(Scenario scenario) { } parkingOnLink.add(fac.getId()); this.facilitiesPerLink.put(linkId, parkingOnLink); + this.waitingVehicles.computeIfAbsent(linkId, (k) -> new TreeMap<>()); this.occupation.put(fac.getId(), new MutableLong(0)); this.reservationsRequests.put(fac.getId(), new MutableLong(0)); - this.rejectedReservations.put(fac.getId(), new MutableLong(0)); + this.rejectedParkingRequest.put(fac.getId(), new MutableLong(0)); this.numberOfParkedVehicles.put(fac.getId(), new MutableLong(0)); + this.numberOfWaitingActivities.put(fac.getId(), new MutableLong(0)); } int slotIndex = getTimeSlotIndex(startTime); while (slotIndex <= maxSlotIndex) { @@ -171,7 +173,7 @@ private boolean linkIdHasAvailableParkingForVehicle(Id linkId, Id return true; } - this.rejectedReservations.get(fac).increment(); + this.rejectedParkingRequest.get(fac).increment(); } return false; } @@ -233,7 +235,8 @@ public List produceStatistics() { double y = this.parkingFacilities.get(e.getKey()).getCoord().getY(); String s = linkId.toString() + ";" + x + ";" + y + ";" + e.getKey().toString() + ";" + capacity + ";" + e.getValue().toString() + ";" + this.reservationsRequests.get( - e.getKey()).toString() + ";" + this.numberOfParkedVehicles.get(e.getKey()).toString() + ";" + this.rejectedReservations.get( + e.getKey()).toString() + ";" + this.numberOfParkedVehicles.get(e.getKey()).toString() + ";" + this.rejectedParkingRequest.get( + e.getKey()).toString()+ ";" + this.numberOfWaitingActivities.get( e.getKey()).toString(); stats.add(s); } @@ -322,8 +325,8 @@ public double getUnParkStageActivityDuration() { @Override public void reset(int iteration) { - for (Id fac : this.rejectedReservations.keySet()) { - this.rejectedReservations.get(fac).setValue(0); + for (Id fac : this.rejectedParkingRequest.keySet()) { + this.rejectedParkingRequest.get(fac).setValue(0); this.reservationsRequests.get(fac).setValue(0); this.numberOfParkedVehicles.get(fac).setValue(0); } From d25ff3ab12c2d27953cee02087f94c2bf072fc8f Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 12 Oct 2023 20:08:55 +0200 Subject: [PATCH 29/54] add outputs for combine parking with getOff/getIn --- .../evaluation/ParkingListener.java | 2 +- .../manager/FacilityBasedParkingManager.java | 31 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingListener.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingListener.java index 9203fe45526..35c3191eef7 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingListener.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingListener.java @@ -82,7 +82,7 @@ private void writeStats(List produceStatistics, int iteration) { BufferedWriter bw = IOUtils.getBufferedWriter(output.getIterationFilename(iteration, "parkingStats.csv")); try { - String header = "linkId;X;Y;parkingFacility;capacity;EndOccupation;reservationsRequests;numberOfParkedVehicles;rejectedReservations"; + String header = "linkId;X;Y;parkingFacility;capacity;EndOccupation;reservationsRequests;numberOfParkedVehicles;rejectedParkingRequest;numberOfWaitingActivities;numberOfStaysFromGetOffUntilGetIn;numberOfParkingBeforeGetIn"; bw.write(header); bw.newLine(); for (String s : produceStatistics){ 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 553c93a932e..f9b174c8322 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 @@ -46,6 +46,10 @@ public class FacilityBasedParkingManager implements ParkingSearchManager { protected Map, MutableLong> reservationsRequests = new HashMap<>(); protected Map, MutableLong> rejectedParkingRequest = new HashMap<>(); protected Map, MutableLong> numberOfParkedVehicles = new HashMap<>(); + protected Map, MutableLong> numberOfWaitingActivities = new HashMap<>(); + protected Map, MutableLong> numberOfStaysFromGetOffUntilGetIn = new HashMap<>(); + protected Map, MutableLong> numberOfParkingBeforeGetIn = new HashMap<>(); + protected Map, TreeMap>> waitingVehicles = new HashMap<>(); protected TreeMap rejectedReservationsByTime = new TreeMap<>(); protected TreeMap foundParkingByTime = new TreeMap<>(); protected TreeMap unparkByTime = new TreeMap<>(); @@ -90,6 +94,8 @@ public FacilityBasedParkingManager(Scenario scenario) { this.rejectedParkingRequest.put(fac.getId(), new MutableLong(0)); this.numberOfParkedVehicles.put(fac.getId(), new MutableLong(0)); this.numberOfWaitingActivities.put(fac.getId(), new MutableLong(0)); + this.numberOfStaysFromGetOffUntilGetIn.put(fac.getId(), new MutableLong(0)); + this.numberOfParkingBeforeGetIn.put(fac.getId(), new MutableLong(0)); } int slotIndex = getTimeSlotIndex(startTime); while (slotIndex <= maxSlotIndex) { @@ -236,8 +242,8 @@ public List produceStatistics() { String s = linkId.toString() + ";" + x + ";" + y + ";" + e.getKey().toString() + ";" + capacity + ";" + e.getValue().toString() + ";" + this.reservationsRequests.get( e.getKey()).toString() + ";" + this.numberOfParkedVehicles.get(e.getKey()).toString() + ";" + this.rejectedParkingRequest.get( - e.getKey()).toString()+ ";" + this.numberOfWaitingActivities.get( - e.getKey()).toString(); + e.getKey()).toString() + ";" + this.numberOfWaitingActivities.get( + e.getKey()).toString() + ";" + this.numberOfStaysFromGetOffUntilGetIn.get(e.getKey()).intValue() + ";" + this.numberOfParkingBeforeGetIn.get(e.getKey()).intValue(); stats.add(s); } return stats; @@ -329,6 +335,27 @@ public void reset(int iteration) { this.rejectedParkingRequest.get(fac).setValue(0); this.reservationsRequests.get(fac).setValue(0); this.numberOfParkedVehicles.get(fac).setValue(0); + this.numberOfWaitingActivities.get(fac).setValue(0); } + waitingVehicles.clear(); + } + + public void addVehicleForWaitingForParking(Id linkId, Id vehicleId, double now) { +// System.out.println(now + ": vehicle " +vehicleId.toString() + " starts waiting here: " + linkId.toString()); + waitingVehicles.get(linkId).put(now + getParkStageActivityDuration() + 1, vehicleId); + for (Id fac : this.facilitiesPerLink.get(linkId)) { + this.numberOfWaitingActivities.get(fac).increment(); + break; + } + + } + } + } + public void registerStayFromGetOffUntilGetIn(Id vehcileId) { + this.numberOfStaysFromGetOffUntilGetIn.get(parkingLocations.get(vehcileId)).increment(); + } + + public void registerParkingBeforeGetIn(Id vehcileId) { + this.numberOfParkingBeforeGetIn.get(parkingLocations.get(vehcileId)).increment(); } } From 48b3c56a68dcacb311d8490b2ed0b678cd54b3fb Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 12 Oct 2023 20:09:24 +0200 Subject: [PATCH 30/54] add StartWaitingForParkingEvent --- .../events/StartWaitingForParkingEvent.java | 68 +++++++++++++++++++ .../StartWaitingForParkingEventHandler.java | 32 +++++++++ .../manager/FacilityBasedParkingManager.java | 23 +++++++ 3 files changed, 123 insertions(+) create mode 100644 contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/events/StartWaitingForParkingEvent.java create mode 100644 contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/events/StartWaitingForParkingEventHandler.java diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/events/StartWaitingForParkingEvent.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/events/StartWaitingForParkingEvent.java new file mode 100644 index 00000000000..992fd8763e6 --- /dev/null +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/events/StartWaitingForParkingEvent.java @@ -0,0 +1,68 @@ +/* *********************************************************************** * + * project: org.matsim.* + * * + * *********************************************************************** * + * * + * copyright : (C) 2016 by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** */ + +package org.matsim.contrib.parking.parkingsearch.events; + +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.events.Event; +import org.matsim.api.core.v01.network.Link; +import org.matsim.vehicles.Vehicle; + +import java.util.Map; + +/** + * @author jbischoff + */ + +public class StartWaitingForParkingEvent extends Event { + public static final String EVENT_TYPE = "started waiting for parking"; + public static final String ATTRIBUTE_VEHICLE = "vehicle"; + public static final String ATTRIBUTE_LINK = "link"; + private final Id linkId; + private final Id vehicleId; + + public StartWaitingForParkingEvent(final double time, Id vehicleId, Id linkId) { + super(time); + this.linkId = linkId; + this.vehicleId = vehicleId; + + } + + @Override + public String getEventType() { + return EVENT_TYPE; + } + + public Id getLinkId() { + return linkId; + } + + public Id getVehicleId() { + return vehicleId; + } + + @Override + public Map getAttributes() { + Map attr = super.getAttributes(); + attr.put(ATTRIBUTE_VEHICLE, this.vehicleId.toString()); + attr.put(ATTRIBUTE_LINK, this.linkId.toString()); + return attr; + } + +} diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/events/StartWaitingForParkingEventHandler.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/events/StartWaitingForParkingEventHandler.java new file mode 100644 index 00000000000..24d5beb7d33 --- /dev/null +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/events/StartWaitingForParkingEventHandler.java @@ -0,0 +1,32 @@ +/* *********************************************************************** * + * project: org.matsim.* + * * + * *********************************************************************** * + * * + * copyright : (C) 2016 by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** */ + +package org.matsim.contrib.parking.parkingsearch.events; + +import org.matsim.core.events.handler.EventHandler; + +/** + * @author jbischoff + */ + +public interface StartWaitingForParkingEventHandler extends EventHandler { + + public void handleEvent(StartWaitingForParkingEvent event); + +} 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 f9b174c8322..41d30bcd63c 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 @@ -349,8 +349,31 @@ public void addVehicleForWaitingForParking(Id linkId, Id vehicleI } } + + public void checkFreeCapacitiesForWaitingVehicles(QSim qSim, double now) { + for (Id linkId : waitingVehicles.keySet()) { + if (!waitingVehicles.get(linkId).isEmpty()) { + for (Id fac : this.facilitiesPerLink.get(linkId)) { + int cap = (int) this.parkingFacilities.get(fac).getActivityOptions().get(ParkingUtils.ParkingStageInteractionType).getCapacity(); + while (this.occupation.get(fac).intValue() < cap && !waitingVehicles.get(linkId).isEmpty()) { + double startWaitingTime = waitingVehicles.get(linkId).firstKey(); + if (startWaitingTime > now) + break; + Id vehcileId = waitingVehicles.get(linkId).remove(startWaitingTime); + DynAgent agent = (DynAgent) qSim.getAgents().get(Id.createPersonId(vehcileId.toString())); + reserveSpaceIfVehicleCanParkHere(vehcileId, linkId); + agent.endActivityAndComputeNextState(now); + qsim.rescheduleActivityEnd(agent); + } + } + } } } + + public void setQSim(QSim qSim) { + qsim = qSim; + } + public void registerStayFromGetOffUntilGetIn(Id vehcileId) { this.numberOfStaysFromGetOffUntilGetIn.get(parkingLocations.get(vehcileId)).increment(); } From ba1675c22304b3c3581fb1fcb55e110bb10d1edd Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 12 Oct 2023 20:15:30 +0200 Subject: [PATCH 31/54] add functionality to check free capacities for each timestep --- .../evaluation/ParkingListener.java | 19 +++++++++++++++++-- .../manager/FacilityBasedParkingManager.java | 3 +++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingListener.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingListener.java index 35c3191eef7..27a17f1921b 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingListener.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingListener.java @@ -26,9 +26,13 @@ import org.matsim.core.controler.OutputDirectoryHierarchy; import org.matsim.core.controler.events.IterationEndsEvent; import org.matsim.core.controler.listener.IterationEndsListener; +import org.matsim.core.mobsim.framework.events.MobsimBeforeSimStepEvent; +import org.matsim.core.mobsim.framework.events.MobsimInitializedEvent; +import org.matsim.core.mobsim.framework.listeners.MobsimBeforeSimStepListener; +import org.matsim.core.mobsim.framework.listeners.MobsimInitializedListener; +import org.matsim.core.mobsim.qsim.QSim; import org.matsim.core.utils.io.IOUtils; - import java.io.BufferedWriter; import java.io.IOException; import java.util.List; @@ -38,7 +42,7 @@ * */ -public class ParkingListener implements IterationEndsListener { +public class ParkingListener implements IterationEndsListener, MobsimBeforeSimStepListener, MobsimInitializedListener { @Inject ParkingSearchManager manager; @@ -99,4 +103,15 @@ private void writeStats(List produceStatistics, int iteration) { } + @Override + public void notifyMobsimBeforeSimStep(MobsimBeforeSimStepEvent event) { + ((FacilityBasedParkingManager) manager).checkFreeCapacitiesForWaitingVehicles((QSim) event.getQueueSimulation(), event.getSimulationTime()); + } + + @Override + public void notifyMobsimInitialized(final MobsimInitializedEvent e) { + QSim qSim = (QSim) e.getQueueSimulation(); + ((FacilityBasedParkingManager) manager).setQSim(qSim); + + } } 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 41d30bcd63c..d6e36dd8b9b 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 @@ -26,8 +26,10 @@ import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.dynagent.DynAgent; import org.matsim.contrib.parking.parkingsearch.ParkingUtils; import org.matsim.contrib.parking.parkingsearch.sim.ParkingSearchConfigGroup; +import org.matsim.core.mobsim.qsim.QSim; import org.matsim.core.utils.misc.Time; import org.matsim.facilities.ActivityFacility; import org.matsim.facilities.ActivityOption; @@ -61,6 +63,7 @@ public class FacilityBasedParkingManager implements ParkingSearchManager { protected Network network; protected ParkingSearchConfigGroup psConfigGroup; protected boolean canParkOnlyAtFacilities; + private QSim qsim; private final int maxSlotIndex; private final int maxTime; private final int timeBinSize; From ff6bad9f395cfc7a831e59d8946266478b4ec354 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 12 Oct 2023 20:17:12 +0200 Subject: [PATCH 32/54] change parameter name --- .../parking/parkingsearch/evaluation/ParkingListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingListener.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingListener.java index 27a17f1921b..41e370c8065 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingListener.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingListener.java @@ -63,7 +63,7 @@ private void writeStatsByTimesteps(List produceBeneStatistics, int itera BufferedWriter bw = IOUtils.getBufferedWriter(output.getIterationFilename(iteration, "parkingStatsPerTimeSteps.csv")); try { - String header = "time;rejectedReservations;foundParking;unpark"; + String header = "time;rejectedParkingRequest;foundParking;unpark"; bw.write(header); bw.newLine(); for (String s : produceBeneStatistics){ From f29a21c14d238f3dc2fafd174490bcb7f0b002c3 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 12 Oct 2023 20:17:35 +0200 Subject: [PATCH 33/54] make map protected --- .../parking/parkingsearch/evaluation/ParkingSlotVisualiser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingSlotVisualiser.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingSlotVisualiser.java index 8de88458df1..50587d72059 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingSlotVisualiser.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/evaluation/ParkingSlotVisualiser.java @@ -58,7 +58,7 @@ public class ParkingSlotVisualiser implements PersonEntersVehicleEventHandler, P Random r = MatsimRandom.getLocalInstance(); protected List parkings = new ArrayList<>(); - Map, Id> parkedVehicles = new HashMap, Id>(); + protected Map, Id> parkedVehicles = new HashMap, Id>(); /** * From 28a2e9c0c9c4200f572b41b6755e616782be9968 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 12 Oct 2023 20:29:03 +0200 Subject: [PATCH 34/54] integrate waiting activity handling and check of parking until next activity is possible --- .../NearestParkingSpotAgentLogic.java | 101 +++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java index 1ec9f5a468f..0e8bf3da7f2 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java @@ -10,6 +10,7 @@ import org.matsim.contrib.dynagent.StaticPassengerDynLeg; import org.matsim.contrib.parking.parkingsearch.DynAgent.NearestParkingDynLeg; import org.matsim.contrib.parking.parkingsearch.ParkingUtils; +import org.matsim.contrib.parking.parkingsearch.manager.FacilityBasedParkingManager; import org.matsim.contrib.parking.parkingsearch.manager.ParkingSearchManager; import org.matsim.contrib.parking.parkingsearch.manager.vehicleteleportationlogic.VehicleTeleportationLogic; import org.matsim.contrib.parking.parkingsearch.routing.ParkingRouter; @@ -118,8 +119,21 @@ protected DynAction nextStateAfterActivity(DynAction oldAction, double now) { // we could either depart by car or not next if (plan.getPlanElements().size() >= planIndex + 1) { - if (plan.getPlanElements().get(planIndex +1) instanceof Activity) + if (plan.getPlanElements().get(planIndex) instanceof Activity && ((Activity) plan.getPlanElements().get(planIndex)).getType().equals( + ParkingUtils.WaitingForParkingActivityType)) { + //now the waiting activity has finished and we can park now + this.parkingManager.parkVehicleHere(Id.create(this.agent.getId(), Vehicle.class), agent.getCurrentLinkId(), now); return nextStateAfterNonCarTrip(oldAction, now); + } + if (plan.getPlanElements().get(planIndex + 1) instanceof Activity) + return nextStateAfterNonCarTrip(oldAction, now); + if (plan.getPlanElements().get(planIndex) instanceof Activity && ((Activity) plan.getPlanElements().get(planIndex)).getType().contains("_GetOff")) { + ((Activity) plan.getPlanElements().get(planIndex)).setEndTime(now); + ((Activity) plan.getPlanElements().get(planIndex + 4)).setStartTime(now + ((Activity) plan.getPlanElements().get(planIndex + 2)).getMaximumDuration().seconds()); + boolean possibleToStay = checkIfParkingFacilityFollowsAndPossibleToStay(this.planIndex,this.planIndex + 2); + if (possibleToStay) + return nextStateAfterNonCarTrip(oldAction, now); + } planIndex++; this.currentPlanElement = plan.getPlanElements().get(planIndex); Leg currentLeg = (Leg) currentPlanElement; @@ -179,4 +193,89 @@ protected DynAction nextStateAfterWalkToPark(DynAction oldAction, double now) { return nextStateAfterUnParkActivity(oldAction, now); // wenn kein Parken dann einfach weiter return new IdleDynActivity(this.stageInteractionType, now + configGroup.getUnparkduration()); } + + @Override + protected DynAction nextStateAfterCarTrip(DynAction oldAction, double now) { + if (this.plan.getPlanElements().get(planIndex + 1) instanceof Activity && ((Activity) this.plan.getPlanElements().get( + planIndex + 1)).getType().equals(ParkingUtils.WaitingForParkingActivityType)) { + //next activity is waiting for parking. Thats why we have no parkVehicleHere at this moment + this.lastParkActionState = LastParkActionState.PARKACTIVITY; + this.currentlyAssignedVehicleId = null; + this.parkingLogic.reset(); + return new IdleDynActivity(this.stageInteractionType, now + configGroup.getParkduration()); + } + // car trip is complete, we have found a parking space (not part of the logic), block it and start to park + if (this.parkingManager.parkVehicleHere(Id.create(this.agent.getId(), Vehicle.class), agent.getCurrentLinkId(), now)) { + this.lastParkActionState = LastParkActionState.PARKACTIVITY; + this.currentlyAssignedVehicleId = null; + this.parkingLogic.reset(); + return new IdleDynActivity(this.stageInteractionType, now + configGroup.getParkduration()); + } else throw new RuntimeException("No parking possible"); + } + + @Override + protected DynAction nextStateAfterNonCarTrip(DynAction oldAction, double now) { + + this.currentPlanElement = plan.getPlanElements().get(planIndex + 1); + Activity nextPlannedActivity = (Activity) this.currentPlanElement; + // checks if it is possible to stay from getOff until getIn or if you can extend parking here until getIn + if (nextPlannedActivity.getType().equals(ParkingUtils.ParkingActivityType) && plan.getPlanElements().get(planIndex + 2) instanceof Leg) { + checkIfParkingFacilityFollowsAndPossibleToStay(planIndex + 1,planIndex + 1); + } + // switch back to activity + planIndex++; + this.lastParkActionState = LastParkActionState.ACTIVITY; + final double endTime; + if (nextPlannedActivity.getEndTime().isUndefined()) { + if (nextPlannedActivity.getMaximumDuration().isUndefined()) { + endTime = Double.POSITIVE_INFINITY; + //last activity of a day + } else { + endTime = now + nextPlannedActivity.getMaximumDuration().seconds(); + } + } else { + endTime = nextPlannedActivity.getEndTime().seconds(); + } + return new IdleDynActivity(nextPlannedActivity.getType(), endTime); + + } + + private boolean checkIfParkingFacilityFollowsAndPossibleToStay(int indexOfCurrentActivity, int indexOfParkingActivity) { + int indexOfFollowingActivity = indexOfCurrentActivity + 2; + Activity followingActivity = ((Activity) plan.getPlanElements().get(indexOfFollowingActivity)); + //checks if it is possible to stay from the current getOff until the getIn + if (indexOfFollowingActivity == indexOfParkingActivity) { + Activity currentActivity = ((Activity) plan.getPlanElements().get(this.planIndex)); + Activity activityAfterFollowing = ((Activity) plan.getPlanElements().get(this.planIndex + 4)); + if (agent.getCurrentLinkId().equals(activityAfterFollowing.getLinkId())) { + boolean canParkAtFacilityUntilGetIn = ((FacilityBasedParkingManager) parkingManager).canParkAtThisFacilityUntilEnd( + agent.getCurrentLinkId(), + followingActivity.getMaximumDuration().seconds(), currentActivity.getMaximumDuration().seconds(), + activityAfterFollowing.getMaximumDuration().seconds(), timer.getTimeOfDay()); + if (canParkAtFacilityUntilGetIn) { + plan.getPlanElements().remove(this.planIndex + 3); + plan.getPlanElements().remove(this.planIndex + 1); + ((FacilityBasedParkingManager) parkingManager).registerStayFromGetOffUntilGetIn(this.agent.getVehicle().getId()); + return true; + } + } + } + // checks if the now started parking activity can extend until the end of the following GetIn activity + else if (indexOfCurrentActivity == indexOfParkingActivity) { + Activity currentActivity = ((Activity) plan.getPlanElements().get(this.planIndex + 1)); + if (agent.getCurrentLinkId().equals(followingActivity.getLinkId())) { + boolean canParkAtFacilityUntilGetIn = ((FacilityBasedParkingManager) parkingManager).canParkAtThisFacilityUntilEnd( + agent.getCurrentLinkId(), + currentActivity.getMaximumDuration().seconds(), 0., + followingActivity.getMaximumDuration().seconds(), timer.getTimeOfDay()); + if (canParkAtFacilityUntilGetIn) { + plan.getPlanElements().remove(indexOfParkingActivity + 1); + currentActivity.setEndTime(followingActivity.getStartTime().seconds()); + ((FacilityBasedParkingManager) parkingManager).registerParkingBeforeGetIn(this.agent.getVehicle().getId()); + return true; + } + } + } + return false; + } } From fb9a37158ecb01fa3708f8ba6e74e81a4015af5b Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 12 Oct 2023 20:29:55 +0200 Subject: [PATCH 35/54] add method to add waiting activity --- .../DynAgent/NearestParkingDynLeg.java | 42 ++++++------------- 1 file changed, 13 insertions(+), 29 deletions(-) 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 41091487c63..2bba67958aa 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 @@ -104,6 +104,11 @@ public Id getNextLinkId() { return linkIds.get(currentLinkIdx + 1); } else { + if (passangerInteractionAtParkingFacilityAtEndOfLeg && !hasFoundParking && followingActivity.getLinkId().equals(currentLinkId)) { + createWaitingActivityUntilPassengerInteractionIsPossible(currentLinkId, vehicleId, timer.getTimeOfDay()); + this.events + .processEvent(new StartWaitingForParkingEvent(timer.getTimeOfDay(), vehicleId, currentLinkId)); + } if (hasFoundParking || reachedDestinationWithoutParking) { // easy, we can just park where at our destination link if (hasFoundParking && !passangerInteractionAtParkingFacilityAtEndOfLeg) { @@ -123,35 +128,6 @@ public Id getNextLinkId() { - ((FacilityBasedParkingManager) parkingManager).getParkStageActivityDuration(); followingActivity.setMaximumDuration(parkingDuration); } - if (plan.getPlanElements().size() > planIndexNextActivity + 2 || followingActivity.getType().equals("parking_activity")) { - Activity activityAfterFollowing = (Activity) plan.getPlanElements().get(planIndexNextActivity + 2); - // check if the following parkingActivity is at same link as the next Pickup and the parking is possible until the pickup - if (followingActivity.getType().equals("parking_activity") && currentLinkId.equals(activityAfterFollowing.getLinkId())) { - boolean canParkAtFacilityUntilGetIn = ((FacilityBasedParkingManager) parkingManager).canParkAtThisFacilityUntilEnd( - currentLinkId, - followingActivity.getMaximumDuration().seconds(), 0., - activityAfterFollowing.getMaximumDuration().seconds(), timer.getTimeOfDay()); - if (canParkAtFacilityUntilGetIn) { - plan.getPlanElements().remove(planIndexNextActivity + 1); -// log.info( -// plan.getPerson().getId().toString() + ": Parking activity can take place until GetIn. " + followingActivity.getType() + "The leg between parking and GetIn is been removed!"); - } - } else if (activityAfterFollowing.getType().equals("parking_activity")) { - // checks if parking from GetOff until pickup at this facility is possible - boolean canParkAtGetOffFacility = ((FacilityBasedParkingManager) parkingManager).canParkAtThisFacilityUntilEnd(currentLinkId, - activityAfterFollowing.getMaximumDuration().seconds(), followingActivity.getMaximumDuration().seconds(), - ((Activity) plan.getPlanElements().get(planIndexNextActivity + 4)).getMaximumDuration().seconds(), timer.getTimeOfDay()); - if (canParkAtGetOffFacility) { - plan.getPlanElements().remove(planIndexNextActivity + 3); - plan.getPlanElements().remove(planIndexNextActivity + 1); -// log.info( -// plan.getPerson().getId().toString() + ": Parking activity can take place at getOff point. " + followingActivity.getType() + "The legs between getOff and parking are removed!"); - } -// else log.info( -// plan.getPerson().getId().toString() + ": Parking activity can NOT take place at getOff point. " + followingActivity.getType() + "Bus will search for another facility!"); - } - } - this.logic.reset(); return null; } else { @@ -201,6 +177,14 @@ public Id getNextLinkId() { } } + private void createWaitingActivityUntilPassengerInteractionIsPossible(Id newLinkId, Id vehicleId, double now) { + Activity waitingActivity = PopulationUtils.createActivityFromLinkId(ParkingUtils.WaitingForParkingActivityType, newLinkId); + ParkingUtils.setNoParkingForActivity(waitingActivity); + plan.getPlanElements().add(planIndexNextActivity, waitingActivity); + hasFoundParking = true; + ((FacilityBasedParkingManager) parkingManager).addVehicleForWaitingForParking(newLinkId, vehicleId, now); + } + private void removeNextActivityAndFollowingLeg() { plan.getPlanElements().remove(planIndexNextActivity); plan.getPlanElements().remove(planIndexNextActivity); From d0cfdf55f143f60d78bd4fbe3bba2a1f5f2893d6 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 12 Oct 2023 20:30:54 +0200 Subject: [PATCH 36/54] change nextPickupTime calculation --- .../DynAgent/NearestParkingDynLeg.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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 2bba67958aa..e43bddee672 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 @@ -8,16 +8,14 @@ import org.matsim.api.core.v01.population.Leg; import org.matsim.api.core.v01.population.Plan; import org.matsim.contrib.parking.parkingsearch.ParkingUtils; -import org.matsim.contrib.parking.parkingsearch.events.RemoveParkingActivityEvent; -import org.matsim.contrib.parking.parkingsearch.events.ReserveParkingLocationEvent; -import org.matsim.contrib.parking.parkingsearch.events.SelectNewParkingLocationEvent; -import org.matsim.contrib.parking.parkingsearch.events.StartParkingSearchEvent; +import org.matsim.contrib.parking.parkingsearch.events.*; import org.matsim.contrib.parking.parkingsearch.manager.FacilityBasedParkingManager; import org.matsim.contrib.parking.parkingsearch.manager.ParkingSearchManager; import org.matsim.contrib.parking.parkingsearch.search.NearestParkingSpotSearchLogic; import org.matsim.contrib.parking.parkingsearch.search.ParkingSearchLogic; import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.mobsim.framework.MobsimTimer; +import org.matsim.core.population.PopulationUtils; import org.matsim.core.population.routes.NetworkRoute; import org.matsim.core.utils.collections.Tuple; import org.matsim.vehicles.Vehicle; @@ -138,8 +136,16 @@ public Id getNextLinkId() { } } // need to find the next link - double nextPickupTime = followingActivity.getStartTime().seconds() + followingActivity.getMaximumDuration().seconds(); - double maxParkingDuration = nextPickupTime - timer.getTimeOfDay(); + double nextPickupTime; + double maxParkingDuration; + if (passangerInteractionAtParkingFacilityAtEndOfLeg){ + nextPickupTime = 0.; + maxParkingDuration = followingActivity.getMaximumDuration().seconds(); + } + else { + nextPickupTime = currentPlannedLeg.getDepartureTime().seconds() + followingActivity.getMaximumDuration().seconds(); + maxParkingDuration = nextPickupTime - timer.getTimeOfDay(); + } Id nextLinkId = ((NearestParkingSpotSearchLogic) this.logic).getNextLink(currentLinkId, route.getEndLinkId(), vehicleId, mode, timer.getTimeOfDay(), maxParkingDuration, nextPickupTime, passangerInteractionAtParkingFacilityAtEndOfLeg, followingActivity.getCoord()); From 0ac5059fc61553a2dee03fd122b4c687c4f6ce8c Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 12 Oct 2023 20:31:13 +0200 Subject: [PATCH 37/54] clean up --- .../parking/parkingsearch/DynAgent/NearestParkingDynLeg.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e43bddee672..a5f4cdcf143 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 @@ -42,7 +42,6 @@ public NearestParkingDynLeg(Leg currentPlannedLeg, NetworkRoute route, Plan plan ParkingSearchManager parkingManager, Id vehicleId, MobsimTimer timer, EventsManager events) { super(currentPlannedLeg.getMode(), route, logic, parkingManager, vehicleId, timer, events); this.followingActivity = (Activity) plan.getPlanElements().get(planIndexNextActivity); - followingActivity.setStartTime(timer.getTimeOfDay()); this.currentPlannedLeg = currentPlannedLeg; this.plan = plan; this.planIndexNextActivity = planIndexNextActivity; @@ -110,6 +109,7 @@ public Id getNextLinkId() { if (hasFoundParking || reachedDestinationWithoutParking) { // easy, we can just park where at our destination link if (hasFoundParking && !passangerInteractionAtParkingFacilityAtEndOfLeg) { + //calculate parkingTime for parking_activity double parkingDuration; double expectedDrivingDurationToPickup; double drivingDurationFromGetOff = timer.getTimeOfDay() - currentPlannedLeg.getDepartureTime().seconds(); From db7320227410f5595a52339366ecc71221afa6b4 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 12 Oct 2023 20:43:30 +0200 Subject: [PATCH 38/54] add comment --- .../DynAgent/agentLogic/NearestParkingSpotAgentLogic.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java index 0e8bf3da7f2..5b2a25b93ac 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java @@ -130,6 +130,7 @@ protected DynAction nextStateAfterActivity(DynAction oldAction, double now) { if (plan.getPlanElements().get(planIndex) instanceof Activity && ((Activity) plan.getPlanElements().get(planIndex)).getType().contains("_GetOff")) { ((Activity) plan.getPlanElements().get(planIndex)).setEndTime(now); ((Activity) plan.getPlanElements().get(planIndex + 4)).setStartTime(now + ((Activity) plan.getPlanElements().get(planIndex + 2)).getMaximumDuration().seconds()); + // checks if it is possible to stay from getOff until getIn boolean possibleToStay = checkIfParkingFacilityFollowsAndPossibleToStay(this.planIndex,this.planIndex + 2); if (possibleToStay) return nextStateAfterNonCarTrip(oldAction, now); @@ -218,7 +219,7 @@ protected DynAction nextStateAfterNonCarTrip(DynAction oldAction, double now) { this.currentPlanElement = plan.getPlanElements().get(planIndex + 1); Activity nextPlannedActivity = (Activity) this.currentPlanElement; - // checks if it is possible to stay from getOff until getIn or if you can extend parking here until getIn + // checks if you can extend parking here until getIn if (nextPlannedActivity.getType().equals(ParkingUtils.ParkingActivityType) && plan.getPlanElements().get(planIndex + 2) instanceof Leg) { checkIfParkingFacilityFollowsAndPossibleToStay(planIndex + 1,planIndex + 1); } From cec714b2b73ac250b5165c39ea79ab60ff224312 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 12 Oct 2023 21:13:44 +0200 Subject: [PATCH 39/54] rename method --- .../DynAgent/agentLogic/NearestParkingSpotAgentLogic.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java index 5b2a25b93ac..6f809a7ebef 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java @@ -131,7 +131,7 @@ protected DynAction nextStateAfterActivity(DynAction oldAction, double now) { ((Activity) plan.getPlanElements().get(planIndex)).setEndTime(now); ((Activity) plan.getPlanElements().get(planIndex + 4)).setStartTime(now + ((Activity) plan.getPlanElements().get(planIndex + 2)).getMaximumDuration().seconds()); // checks if it is possible to stay from getOff until getIn - boolean possibleToStay = checkIfParkingFacilityFollowsAndPossibleToStay(this.planIndex,this.planIndex + 2); + boolean possibleToStay = checkIfParkingIsPossibleUntilNextActivities(this.planIndex,this.planIndex + 2); if (possibleToStay) return nextStateAfterNonCarTrip(oldAction, now); } @@ -221,7 +221,7 @@ protected DynAction nextStateAfterNonCarTrip(DynAction oldAction, double now) { Activity nextPlannedActivity = (Activity) this.currentPlanElement; // checks if you can extend parking here until getIn if (nextPlannedActivity.getType().equals(ParkingUtils.ParkingActivityType) && plan.getPlanElements().get(planIndex + 2) instanceof Leg) { - checkIfParkingFacilityFollowsAndPossibleToStay(planIndex + 1,planIndex + 1); + checkIfParkingIsPossibleUntilNextActivities(planIndex + 1,planIndex + 1); } // switch back to activity planIndex++; @@ -241,7 +241,7 @@ protected DynAction nextStateAfterNonCarTrip(DynAction oldAction, double now) { } - private boolean checkIfParkingFacilityFollowsAndPossibleToStay(int indexOfCurrentActivity, int indexOfParkingActivity) { + private boolean checkIfParkingIsPossibleUntilNextActivities(int indexOfCurrentActivity, int indexOfParkingActivity) { int indexOfFollowingActivity = indexOfCurrentActivity + 2; Activity followingActivity = ((Activity) plan.getPlanElements().get(indexOfFollowingActivity)); //checks if it is possible to stay from the current getOff until the getIn From 60f691be2d42937fcac55fd8584b16ad0433fc85 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 12 Oct 2023 21:14:04 +0200 Subject: [PATCH 40/54] add check if current is parking or not --- .../DynAgent/agentLogic/NearestParkingSpotAgentLogic.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java index 6f809a7ebef..f3a7e671b14 100644 --- a/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java +++ b/contribs/parking/src/main/java/org/matsim/contrib/parking/parkingsearch/DynAgent/agentLogic/NearestParkingSpotAgentLogic.java @@ -248,7 +248,8 @@ private boolean checkIfParkingIsPossibleUntilNextActivities(int indexOfCurrentAc if (indexOfFollowingActivity == indexOfParkingActivity) { Activity currentActivity = ((Activity) plan.getPlanElements().get(this.planIndex)); Activity activityAfterFollowing = ((Activity) plan.getPlanElements().get(this.planIndex + 4)); - if (agent.getCurrentLinkId().equals(activityAfterFollowing.getLinkId())) { + if (agent.getCurrentLinkId().equals(activityAfterFollowing.getLinkId()) && !ParkingUtils.checkIfActivityHasNoParking( + (Activity) currentPlanElement)) { boolean canParkAtFacilityUntilGetIn = ((FacilityBasedParkingManager) parkingManager).canParkAtThisFacilityUntilEnd( agent.getCurrentLinkId(), followingActivity.getMaximumDuration().seconds(), currentActivity.getMaximumDuration().seconds(), @@ -264,7 +265,8 @@ private boolean checkIfParkingIsPossibleUntilNextActivities(int indexOfCurrentAc // checks if the now started parking activity can extend until the end of the following GetIn activity else if (indexOfCurrentActivity == indexOfParkingActivity) { Activity currentActivity = ((Activity) plan.getPlanElements().get(this.planIndex + 1)); - if (agent.getCurrentLinkId().equals(followingActivity.getLinkId())) { + if (agent.getCurrentLinkId().equals(followingActivity.getLinkId()) && !ParkingUtils.checkIfActivityHasNoParking( + followingActivity)) { boolean canParkAtFacilityUntilGetIn = ((FacilityBasedParkingManager) parkingManager).canParkAtThisFacilityUntilEnd( agent.getCurrentLinkId(), currentActivity.getMaximumDuration().seconds(), 0., From 2145cf2dd7c65d93192206bc9b473587f1be0528 Mon Sep 17 00:00:00 2001 From: Ricardo Ewert Date: Thu, 12 Oct 2023 21:14:55 +0200 Subject: [PATCH 41/54] formatting --- .../parkingsearch/manager/FacilityBasedParkingManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d6e36dd8b9b..9b3b8eff107 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 @@ -213,7 +213,7 @@ protected boolean parkVehicleAtLink(Id vehicleId, Id linkId, doub return true; } else { throw new RuntimeException("no parking reservation found for vehicle " + vehicleId.toString() - + "arrival on link " + linkId + " with parking restriction"); + + " arrival on link " + linkId + " with parking restriction"); } } } From 32142fce553b3397eb3f3caec202cb035ace2d01 Mon Sep 17 00:00:00 2001 From: nixlaos Date: Mon, 16 Oct 2023 11:50:07 +0200 Subject: [PATCH 42/54] completing Test for CarrierEventsReaders --- .../carrier/CarrierEventsReadersTest.java | 79 ++++++++++++------- 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/contribs/freight/src/test/java/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest.java b/contribs/freight/src/test/java/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest.java index 43509b23a37..a299877ec30 100644 --- a/contribs/freight/src/test/java/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest.java +++ b/contribs/freight/src/test/java/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest.java @@ -2,14 +2,18 @@ import org.junit.Rule; import org.junit.Test; -import org.matsim.contrib.freight.events.CarrierEventsReaders; +import org.matsim.contrib.freight.events.*; import org.matsim.core.api.experimental.events.EventsManager; +import org.matsim.core.config.groups.ControlerConfigGroup; import org.matsim.core.events.EventsUtils; -import org.matsim.core.events.MatsimEventsReader; +import org.matsim.core.events.algorithms.EventWriterXML; import org.matsim.testcases.MatsimTestUtils; import org.matsim.testcases.utils.EventsCollector; -import static org.junit.Assert.assertEquals; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import static org.assertj.core.api.Assertions.*; public class CarrierEventsReadersTest { @@ -18,37 +22,58 @@ public class CarrierEventsReadersTest { @Test public void testWriteReadServiceBasedEvents() { - EventsManager eventsManager = EventsUtils.createEventsManager(); - EventsCollector collector = new EventsCollector(); - MatsimEventsReader carrierEventsReaders = CarrierEventsReaders.createEventsReader(eventsManager); + EventsManager eventsManager1 = EventsUtils.createEventsManager(); + EventsManager eventsManager2 = EventsUtils.createEventsManager(); + EventsCollector collector1 = new EventsCollector(); + EventsCollector collector2 = new EventsCollector(); + + eventsManager1.addHandler(collector1); + eventsManager1.initProcessing(); + CarrierEventsReaders.createEventsReader(eventsManager1) + .readFile(utils.getClassInputDirectory() + "serviceBasedEvents.xml"); + eventsManager1.finishProcessing(); - eventsManager.addHandler(collector); - eventsManager.initProcessing(); - carrierEventsReaders.readFile(utils.getClassInputDirectory() + "serviceBasedEvents.xml"); - eventsManager.finishProcessing(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + EventWriterXML writer = new EventWriterXML(outputStream); + collector1.getEvents().forEach(writer::handleEvent); + writer.closeFile(); - //Hier müsste dann wohl "serviceBasedEventsWritten.xml" geschrieben werden und dann auch nochmal der eventsManager für die ausgeschriebene Datei durchlaufen werden + eventsManager2.addHandler(collector2); + eventsManager2.initProcessing(); + CarrierEventsReaders.createEventsReader(eventsManager2) + .readStream(new ByteArrayInputStream(outputStream.toByteArray()), ControlerConfigGroup.EventsFileFormat.xml); + eventsManager2.finishProcessing(); - assertEquals("number of events should be same", collector.getEvents().size(), collector.getEvents().size()); - MatsimTestUtils.assertEqualEventsFiles(utils.getClassInputDirectory() + "serviceBasedEvents.xml", utils.getClassInputDirectory() + "serviceBasedEventsWritten.xml"); - MatsimTestUtils.assertEqualFilesLineByLine(utils.getClassInputDirectory() + "serviceBasedEvents.xml", utils.getClassInputDirectory() + "serviceBasedEventsWritten.xml"); + assertThat(collector1.getEvents()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyElementsOf(collector2.getEvents()); } @Test public void testWriteReadShipmentBasedEvents() { - EventsManager eventsManager = EventsUtils.createEventsManager(); - EventsCollector collector = new EventsCollector(); - MatsimEventsReader carrierEventsReaders = CarrierEventsReaders.createEventsReader(eventsManager); - - eventsManager.addHandler(collector); - eventsManager.initProcessing(); - carrierEventsReaders.readFile(utils.getClassInputDirectory() + "shipmentBasedEvents.xml"); - eventsManager.finishProcessing(); - - assertEquals("number of events should be same", collector.getEvents().size(), collector.getEvents().size()); - MatsimTestUtils.assertEqualEventsFiles(utils.getClassInputDirectory() + "shipmentBasedEvents.xml", utils.getClassInputDirectory() + "shipmentBasedEventsWritten.xml"); - MatsimTestUtils.assertEqualFilesLineByLine(utils.getClassInputDirectory() + "shipmentBasedEvents.xml", utils.getClassInputDirectory() + "shipmentBasedEventsWritten.xml"); - } + EventsManager eventsManager1 = EventsUtils.createEventsManager(); + EventsManager eventsManager2 = EventsUtils.createEventsManager(); + EventsCollector collector1 = new EventsCollector(); + EventsCollector collector2 = new EventsCollector(); + + eventsManager1.addHandler(collector1); + eventsManager1.initProcessing(); + CarrierEventsReaders.createEventsReader(eventsManager1) + .readFile(utils.getClassInputDirectory() + "shipmentBasedEvents.xml"); + eventsManager1.finishProcessing(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + EventWriterXML writer = new EventWriterXML(outputStream); + collector1.getEvents().forEach(writer::handleEvent); + writer.closeFile(); + + eventsManager2.addHandler(collector2); + eventsManager2.initProcessing(); + CarrierEventsReaders.createEventsReader(eventsManager2) + .readStream(new ByteArrayInputStream(outputStream.toByteArray()), ControlerConfigGroup.EventsFileFormat.xml); + eventsManager2.finishProcessing(); + + assertThat(collector1.getEvents()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyElementsOf(collector2.getEvents()); + } } From 2f25c7a5b7a23f57466784896cb5458cae540604 Mon Sep 17 00:00:00 2001 From: nixlaos Date: Mon, 16 Oct 2023 11:52:33 +0200 Subject: [PATCH 43/54] add missing interfaces for freight events, minor renames --- ...eightShipmentDeliveryEndEventHandler.java} | 4 +- ...ightShipmentDeliveryStartEventHandler.java | 37 +++++++++++++++++++ ...FreightShipmentPickupEndEventHandler.java} | 4 +- ...reightShipmentPickupStartEventHandler.java | 35 ++++++++++++++++++ .../analysis/FreightAnalysisEventHandler.java | 6 +-- .../MyShipmentTrackerEventHandler.java | 8 ++-- 6 files changed, 83 insertions(+), 11 deletions(-) rename contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/{FreightShipmentDeliveryEventHandler.java => FreightShipmentDeliveryEndEventHandler.java} (92%) create mode 100644 contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java rename contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/{FreightShipmentPickupEventHandler.java => FreightShipmentPickupEndEventHandler.java} (92%) create mode 100644 contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupStartEventHandler.java diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEventHandler.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java similarity index 92% rename from contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEventHandler.java rename to contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java index c3560daf9c5..f6c7565a5e1 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java @@ -25,12 +25,12 @@ import org.matsim.core.events.handler.EventHandler; /** - * Interface to listen to shipmentDeliveredEvents. + * Interface to listen to shipmentDeliveryEndEvents. * * @author sschroeder * */ -public interface FreightShipmentDeliveryEventHandler extends EventHandler { +public interface FreightShipmentDeliveryEndEventHandler extends EventHandler { void handleEvent(CarrierShipmentDeliveryEndEvent event); diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java new file mode 100644 index 00000000000..05d6c7cf122 --- /dev/null +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java @@ -0,0 +1,37 @@ +/* + * *********************************************************************** * + * project: org.matsim.* + * *********************************************************************** * + * * + * copyright : (C) by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** + * + */ + +package org.matsim.contrib.freight.events.eventhandler; + +import org.matsim.contrib.freight.events.CarrierShipmentDeliveryStartEvent; +import org.matsim.core.events.handler.EventHandler; + +/** + * Interface to listen to shipmentDeliveryStartEvents. + * + * @author nrichter + * + */ +public interface FreightShipmentDeliveryStartEventHandler extends EventHandler { + + void handleEvent(CarrierShipmentDeliveryStartEvent event); + +} diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEventHandler.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEndEventHandler.java similarity index 92% rename from contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEventHandler.java rename to contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEndEventHandler.java index 43f0671150e..ce0155ab05c 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEndEventHandler.java @@ -25,11 +25,11 @@ import org.matsim.core.events.handler.EventHandler; /** - * Interface to listen to shipmentPickedUpEvents. + * Interface to listen to shipmentPickedUpEndEvents. * * @author sschroeder * */ -public interface FreightShipmentPickupEventHandler extends EventHandler { +public interface FreightShipmentPickupEndEventHandler extends EventHandler { void handleEvent(CarrierShipmentPickupEndEvent event); } diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupStartEventHandler.java new file mode 100644 index 00000000000..516fbf3bf2c --- /dev/null +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupStartEventHandler.java @@ -0,0 +1,35 @@ +/* + * *********************************************************************** * + * project: org.matsim.* + * *********************************************************************** * + * * + * copyright : (C) by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** + * + */ + +package org.matsim.contrib.freight.events.eventhandler; + +import org.matsim.contrib.freight.events.CarrierShipmentPickupStartEvent; +import org.matsim.core.events.handler.EventHandler; + +/** + * Interface to listen to shipmentPickedUpStartEvents. + * + * @author nrichter + * + */ +public interface FreightShipmentPickupStartEventHandler extends EventHandler { + void handleEvent(CarrierShipmentPickupStartEvent event); +} diff --git a/contribs/vsp/src/main/java/org/matsim/contrib/freight/analysis/FreightAnalysisEventHandler.java b/contribs/vsp/src/main/java/org/matsim/contrib/freight/analysis/FreightAnalysisEventHandler.java index 15a0dd00702..cfe72166273 100644 --- a/contribs/vsp/src/main/java/org/matsim/contrib/freight/analysis/FreightAnalysisEventHandler.java +++ b/contribs/vsp/src/main/java/org/matsim/contrib/freight/analysis/FreightAnalysisEventHandler.java @@ -38,8 +38,8 @@ import org.matsim.contrib.freight.events.CarrierShipmentPickupEndEvent; import org.matsim.contrib.freight.events.eventhandler.FreightServiceEndEventHandler; import org.matsim.contrib.freight.events.eventhandler.FreightServiceStartEventHandler; -import org.matsim.contrib.freight.events.eventhandler.FreightShipmentDeliveryEventHandler; -import org.matsim.contrib.freight.events.eventhandler.FreightShipmentPickupEventHandler; +import org.matsim.contrib.freight.events.eventhandler.FreightShipmentDeliveryEndEventHandler; +import org.matsim.contrib.freight.events.eventhandler.FreightShipmentPickupEndEventHandler; import org.matsim.core.network.NetworkUtils; import org.matsim.core.utils.io.UncheckedIOException; import org.matsim.vehicles.Vehicle; @@ -59,7 +59,7 @@ * */ @Deprecated(since = "apr23") -class FreightAnalysisEventHandler implements ActivityStartEventHandler, LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, FreightShipmentPickupEventHandler, FreightShipmentDeliveryEventHandler, FreightServiceStartEventHandler, FreightServiceEndEventHandler { +class FreightAnalysisEventHandler implements ActivityStartEventHandler, LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, FreightShipmentPickupEndEventHandler, FreightShipmentDeliveryEndEventHandler, FreightServiceStartEventHandler, FreightServiceEndEventHandler { private final static Logger log = LogManager.getLogger(FreightAnalysisEventHandler.class); private final Vehicles vehicles; diff --git a/contribs/vsp/src/test/java/org/matsim/contrib/freight/analysis/MyShipmentTrackerEventHandler.java b/contribs/vsp/src/test/java/org/matsim/contrib/freight/analysis/MyShipmentTrackerEventHandler.java index 6b2409d7e3d..7600629ffe0 100644 --- a/contribs/vsp/src/test/java/org/matsim/contrib/freight/analysis/MyShipmentTrackerEventHandler.java +++ b/contribs/vsp/src/test/java/org/matsim/contrib/freight/analysis/MyShipmentTrackerEventHandler.java @@ -8,11 +8,11 @@ import org.matsim.contrib.freight.carrier.Carriers; import org.matsim.contrib.freight.events.CarrierShipmentDeliveryEndEvent; import org.matsim.contrib.freight.events.CarrierShipmentPickupEndEvent; -import org.matsim.contrib.freight.events.eventhandler.FreightShipmentDeliveryEventHandler; -import org.matsim.contrib.freight.events.eventhandler.FreightShipmentPickupEventHandler; +import org.matsim.contrib.freight.events.eventhandler.FreightShipmentDeliveryEndEventHandler; +import org.matsim.contrib.freight.events.eventhandler.FreightShipmentPickupEndEventHandler; import org.matsim.vehicles.Vehicles; -public class MyShipmentTrackerEventHandler implements ActivityStartEventHandler, FreightShipmentPickupEventHandler, FreightShipmentDeliveryEventHandler { +public class MyShipmentTrackerEventHandler implements ActivityStartEventHandler, FreightShipmentPickupEndEventHandler, FreightShipmentDeliveryEndEventHandler { private final Vehicles vehicles; private final Network network; @@ -48,7 +48,7 @@ public void handleEvent(CarrierShipmentPickupEndEvent event) { @Override public void reset(int iteration) { - FreightShipmentPickupEventHandler.super.reset(iteration); + FreightShipmentPickupEndEventHandler.super.reset(iteration); } @Override From cb17bf4891d9cf1d41a8401d921064bebf6d78f0 Mon Sep 17 00:00:00 2001 From: nixlaos Date: Mon, 16 Oct 2023 11:57:59 +0200 Subject: [PATCH 44/54] Revert "add missing interfaces for freight events, minor renames" This reverts commit 2f25c7a5b7a23f57466784896cb5458cae540604. --- ... FreightShipmentDeliveryEventHandler.java} | 4 +- ...ightShipmentDeliveryStartEventHandler.java | 37 ------------------- ...=> FreightShipmentPickupEventHandler.java} | 4 +- ...reightShipmentPickupStartEventHandler.java | 35 ------------------ .../analysis/FreightAnalysisEventHandler.java | 6 +-- .../MyShipmentTrackerEventHandler.java | 8 ++-- 6 files changed, 11 insertions(+), 83 deletions(-) rename contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/{FreightShipmentDeliveryEndEventHandler.java => FreightShipmentDeliveryEventHandler.java} (92%) delete mode 100644 contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java rename contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/{FreightShipmentPickupEndEventHandler.java => FreightShipmentPickupEventHandler.java} (92%) delete mode 100644 contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupStartEventHandler.java diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEventHandler.java similarity index 92% rename from contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java rename to contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEventHandler.java index f6c7565a5e1..c3560daf9c5 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEventHandler.java @@ -25,12 +25,12 @@ import org.matsim.core.events.handler.EventHandler; /** - * Interface to listen to shipmentDeliveryEndEvents. + * Interface to listen to shipmentDeliveredEvents. * * @author sschroeder * */ -public interface FreightShipmentDeliveryEndEventHandler extends EventHandler { +public interface FreightShipmentDeliveryEventHandler extends EventHandler { void handleEvent(CarrierShipmentDeliveryEndEvent event); diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java deleted file mode 100644 index 05d6c7cf122..00000000000 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * *********************************************************************** * - * project: org.matsim.* - * *********************************************************************** * - * * - * copyright : (C) by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** - * - */ - -package org.matsim.contrib.freight.events.eventhandler; - -import org.matsim.contrib.freight.events.CarrierShipmentDeliveryStartEvent; -import org.matsim.core.events.handler.EventHandler; - -/** - * Interface to listen to shipmentDeliveryStartEvents. - * - * @author nrichter - * - */ -public interface FreightShipmentDeliveryStartEventHandler extends EventHandler { - - void handleEvent(CarrierShipmentDeliveryStartEvent event); - -} diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEndEventHandler.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEventHandler.java similarity index 92% rename from contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEndEventHandler.java rename to contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEventHandler.java index ce0155ab05c..43f0671150e 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEndEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEventHandler.java @@ -25,11 +25,11 @@ import org.matsim.core.events.handler.EventHandler; /** - * Interface to listen to shipmentPickedUpEndEvents. + * Interface to listen to shipmentPickedUpEvents. * * @author sschroeder * */ -public interface FreightShipmentPickupEndEventHandler extends EventHandler { +public interface FreightShipmentPickupEventHandler extends EventHandler { void handleEvent(CarrierShipmentPickupEndEvent event); } diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupStartEventHandler.java deleted file mode 100644 index 516fbf3bf2c..00000000000 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupStartEventHandler.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * *********************************************************************** * - * project: org.matsim.* - * *********************************************************************** * - * * - * copyright : (C) by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** - * - */ - -package org.matsim.contrib.freight.events.eventhandler; - -import org.matsim.contrib.freight.events.CarrierShipmentPickupStartEvent; -import org.matsim.core.events.handler.EventHandler; - -/** - * Interface to listen to shipmentPickedUpStartEvents. - * - * @author nrichter - * - */ -public interface FreightShipmentPickupStartEventHandler extends EventHandler { - void handleEvent(CarrierShipmentPickupStartEvent event); -} diff --git a/contribs/vsp/src/main/java/org/matsim/contrib/freight/analysis/FreightAnalysisEventHandler.java b/contribs/vsp/src/main/java/org/matsim/contrib/freight/analysis/FreightAnalysisEventHandler.java index cfe72166273..15a0dd00702 100644 --- a/contribs/vsp/src/main/java/org/matsim/contrib/freight/analysis/FreightAnalysisEventHandler.java +++ b/contribs/vsp/src/main/java/org/matsim/contrib/freight/analysis/FreightAnalysisEventHandler.java @@ -38,8 +38,8 @@ import org.matsim.contrib.freight.events.CarrierShipmentPickupEndEvent; import org.matsim.contrib.freight.events.eventhandler.FreightServiceEndEventHandler; import org.matsim.contrib.freight.events.eventhandler.FreightServiceStartEventHandler; -import org.matsim.contrib.freight.events.eventhandler.FreightShipmentDeliveryEndEventHandler; -import org.matsim.contrib.freight.events.eventhandler.FreightShipmentPickupEndEventHandler; +import org.matsim.contrib.freight.events.eventhandler.FreightShipmentDeliveryEventHandler; +import org.matsim.contrib.freight.events.eventhandler.FreightShipmentPickupEventHandler; import org.matsim.core.network.NetworkUtils; import org.matsim.core.utils.io.UncheckedIOException; import org.matsim.vehicles.Vehicle; @@ -59,7 +59,7 @@ * */ @Deprecated(since = "apr23") -class FreightAnalysisEventHandler implements ActivityStartEventHandler, LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, FreightShipmentPickupEndEventHandler, FreightShipmentDeliveryEndEventHandler, FreightServiceStartEventHandler, FreightServiceEndEventHandler { +class FreightAnalysisEventHandler implements ActivityStartEventHandler, LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, FreightShipmentPickupEventHandler, FreightShipmentDeliveryEventHandler, FreightServiceStartEventHandler, FreightServiceEndEventHandler { private final static Logger log = LogManager.getLogger(FreightAnalysisEventHandler.class); private final Vehicles vehicles; diff --git a/contribs/vsp/src/test/java/org/matsim/contrib/freight/analysis/MyShipmentTrackerEventHandler.java b/contribs/vsp/src/test/java/org/matsim/contrib/freight/analysis/MyShipmentTrackerEventHandler.java index 7600629ffe0..6b2409d7e3d 100644 --- a/contribs/vsp/src/test/java/org/matsim/contrib/freight/analysis/MyShipmentTrackerEventHandler.java +++ b/contribs/vsp/src/test/java/org/matsim/contrib/freight/analysis/MyShipmentTrackerEventHandler.java @@ -8,11 +8,11 @@ import org.matsim.contrib.freight.carrier.Carriers; import org.matsim.contrib.freight.events.CarrierShipmentDeliveryEndEvent; import org.matsim.contrib.freight.events.CarrierShipmentPickupEndEvent; -import org.matsim.contrib.freight.events.eventhandler.FreightShipmentDeliveryEndEventHandler; -import org.matsim.contrib.freight.events.eventhandler.FreightShipmentPickupEndEventHandler; +import org.matsim.contrib.freight.events.eventhandler.FreightShipmentDeliveryEventHandler; +import org.matsim.contrib.freight.events.eventhandler.FreightShipmentPickupEventHandler; import org.matsim.vehicles.Vehicles; -public class MyShipmentTrackerEventHandler implements ActivityStartEventHandler, FreightShipmentPickupEndEventHandler, FreightShipmentDeliveryEndEventHandler { +public class MyShipmentTrackerEventHandler implements ActivityStartEventHandler, FreightShipmentPickupEventHandler, FreightShipmentDeliveryEventHandler { private final Vehicles vehicles; private final Network network; @@ -48,7 +48,7 @@ public void handleEvent(CarrierShipmentPickupEndEvent event) { @Override public void reset(int iteration) { - FreightShipmentPickupEndEventHandler.super.reset(iteration); + FreightShipmentPickupEventHandler.super.reset(iteration); } @Override From 2b6b6ed3013482c78c0858546496613d690fe8e3 Mon Sep 17 00:00:00 2001 From: nixlaos Date: Mon, 16 Oct 2023 12:52:19 +0200 Subject: [PATCH 45/54] fixing error --- .../carriers/CarrierEventsReadersTest.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java index a299877ec30..b418cf800cf 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java @@ -1,20 +1,19 @@ -package org.matsim.contrib.freight.carrier; +package org.matsim.freight.carriers; +import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.matsim.contrib.freight.events.*; import org.matsim.core.api.experimental.events.EventsManager; -import org.matsim.core.config.groups.ControlerConfigGroup; +import org.matsim.core.config.groups.ControllerConfigGroup; import org.matsim.core.events.EventsUtils; import org.matsim.core.events.algorithms.EventWriterXML; +import org.matsim.freight.carriers.events.CarrierEventsReaders; import org.matsim.testcases.MatsimTestUtils; import org.matsim.testcases.utils.EventsCollector; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import static org.assertj.core.api.Assertions.*; - public class CarrierEventsReadersTest { @Rule @@ -41,11 +40,10 @@ public void testWriteReadServiceBasedEvents() { eventsManager2.addHandler(collector2); eventsManager2.initProcessing(); CarrierEventsReaders.createEventsReader(eventsManager2) - .readStream(new ByteArrayInputStream(outputStream.toByteArray()), ControlerConfigGroup.EventsFileFormat.xml); + .readStream(new ByteArrayInputStream(outputStream.toByteArray()), ControllerConfigGroup.EventsFileFormat.xml); eventsManager2.finishProcessing(); - assertThat(collector1.getEvents()).usingRecursiveFieldByFieldElementComparator() - .containsExactlyElementsOf(collector2.getEvents()); + Assert.assertEquals(collector1.getEvents(), collector2.getEvents()); } @Test @@ -69,11 +67,10 @@ public void testWriteReadShipmentBasedEvents() { eventsManager2.addHandler(collector2); eventsManager2.initProcessing(); CarrierEventsReaders.createEventsReader(eventsManager2) - .readStream(new ByteArrayInputStream(outputStream.toByteArray()), ControlerConfigGroup.EventsFileFormat.xml); + .readStream(new ByteArrayInputStream(outputStream.toByteArray()), ControllerConfigGroup.EventsFileFormat.xml); eventsManager2.finishProcessing(); - assertThat(collector1.getEvents()).usingRecursiveFieldByFieldElementComparator() - .containsExactlyElementsOf(collector2.getEvents()); + Assert.assertEquals(collector1.getEvents(), collector2.getEvents()); } } From 77516570df3c045724458556d9e9122afabbc166 Mon Sep 17 00:00:00 2001 From: nixlaos Date: Mon, 16 Oct 2023 13:00:45 +0200 Subject: [PATCH 46/54] moved test input --- .../carriers}/CarrierEventsReadersTest/serviceBasedEvents.xml | 0 .../carriers}/CarrierEventsReadersTest/shipmentBasedEvents.xml | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename contribs/freight/test/input/org/matsim/{contrib/freight/carrier => freight/carriers}/CarrierEventsReadersTest/serviceBasedEvents.xml (100%) rename contribs/freight/test/input/org/matsim/{contrib/freight/carrier => freight/carriers}/CarrierEventsReadersTest/shipmentBasedEvents.xml (100%) diff --git a/contribs/freight/test/input/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest/serviceBasedEvents.xml b/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/serviceBasedEvents.xml similarity index 100% rename from contribs/freight/test/input/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest/serviceBasedEvents.xml rename to contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/serviceBasedEvents.xml diff --git a/contribs/freight/test/input/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest/shipmentBasedEvents.xml b/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/shipmentBasedEvents.xml similarity index 100% rename from contribs/freight/test/input/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest/shipmentBasedEvents.xml rename to contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/shipmentBasedEvents.xml From 23d99e65379f0792c9c7a9a4352e7d18b8f8006b Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Thu, 19 Oct 2023 14:38:48 +0200 Subject: [PATCH 47/54] fix wrong attribute in event convertion --- .../carriers/events/CarrierShipmentDeliveryEndEvent.java | 2 +- .../carriers/events/CarrierShipmentDeliveryStartEvent.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryEndEvent.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryEndEvent.java index c49c04aa533..c02717031fa 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryEndEvent.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryEndEvent.java @@ -84,7 +84,7 @@ public static CarrierShipmentDeliveryEndEvent convert(GenericEvent event) { Id shipmentTo = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); int size = Integer.parseInt(attributes.get(CarrierEventAttributes.ATTRIBUTE_CAPACITYDEMAND)); CarrierShipment shipment = CarrierShipment.Builder.newInstance(shipmentId, null, shipmentTo, size) - .setDeliveryServiceTime(Double.parseDouble(attributes.get(CarrierEventAttributes.ATTRIBUTE_SERVICE_DURATION))) + .setDeliveryServiceTime(Double.parseDouble(attributes.get(CarrierEventAttributes.ATTRIBUTE_DROPOFF_DURATION))) .build(); Id vehicleId = Id.createVehicleId(attributes.get(ATTRIBUTE_VEHICLE)); return new CarrierShipmentDeliveryEndEvent(time, carrierId, shipment, vehicleId); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryStartEvent.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryStartEvent.java index e12222973c1..43cf21fc752 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryStartEvent.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryStartEvent.java @@ -85,7 +85,7 @@ public static CarrierShipmentDeliveryStartEvent convert(GenericEvent event) { Id shipmentTo = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); int size = Integer.parseInt(attributes.get(ATTRIBUTE_CAPACITYDEMAND)); CarrierShipment shipment = CarrierShipment.Builder.newInstance(shipmentId, null, shipmentTo, size) - .setDeliveryServiceTime(Double.parseDouble(attributes.get(ATTRIBUTE_SERVICE_DURATION))) + .setDeliveryServiceTime(Double.parseDouble(attributes.get(ATTRIBUTE_DROPOFF_DURATION))) .build(); Id vehicleId = Id.createVehicleId(attributes.get(ATTRIBUTE_VEHICLE)); return new CarrierShipmentDeliveryStartEvent(time, carrierId, shipment, vehicleId); From 1e8be707ae3f0ec85b9a3769926bb0e6ad57bc85 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Thu, 19 Oct 2023 14:45:11 +0200 Subject: [PATCH 48/54] add missing events handlers and rename existing one. We have two events per dropoff / pickup: start and end. --- ...eightShipmentDeliveryEndEventHandler.java} | 2 +- ...ightShipmentDeliveryStartEventHandler.java | 37 +++++++++++++++++++ ...FreightShipmentPickupEndEventHandler.java} | 2 +- ...reightShipmentPickupStartEventHandler.java | 35 ++++++++++++++++++ .../analysis/FreightAnalysisEventHandler.java | 6 +-- .../MyShipmentTrackerEventHandler.java | 8 ++-- 6 files changed, 81 insertions(+), 9 deletions(-) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightShipmentDeliveryEventHandler.java => FreightShipmentDeliveryEndEventHandler.java} (95%) create mode 100644 contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightShipmentPickupEventHandler.java => FreightShipmentPickupEndEventHandler.java} (95%) create mode 100644 contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupStartEventHandler.java diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java similarity index 95% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java index 858a91fdca5..da7c2f805e3 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java @@ -30,7 +30,7 @@ * @author sschroeder * */ -public interface FreightShipmentDeliveryEventHandler extends EventHandler { +public interface FreightShipmentDeliveryEndEventHandler extends EventHandler { void handleEvent(CarrierShipmentDeliveryEndEvent event); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java new file mode 100644 index 00000000000..1d0dc74c0f6 --- /dev/null +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java @@ -0,0 +1,37 @@ +/* + * *********************************************************************** * + * project: org.matsim.* + * *********************************************************************** * + * * + * copyright : (C) by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** + * + */ + +package org.matsim.freight.carriers.events.eventhandler; + +import org.matsim.core.events.handler.EventHandler; +import org.matsim.freight.carriers.events.CarrierShipmentDeliveryStartEvent; + +/** + * Interface to listen to shipmentDeliveredEvents. + * + * @author sschroeder + * + */ +public interface FreightShipmentDeliveryStartEventHandler extends EventHandler { + + void handleEvent(CarrierShipmentDeliveryStartEvent event); + +} diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEndEventHandler.java similarity index 95% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEndEventHandler.java index 126942b432f..aeca9d324d8 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEndEventHandler.java @@ -30,6 +30,6 @@ * @author sschroeder * */ -public interface FreightShipmentPickupEventHandler extends EventHandler { +public interface FreightShipmentPickupEndEventHandler extends EventHandler { void handleEvent(CarrierShipmentPickupEndEvent event); } diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupStartEventHandler.java new file mode 100644 index 00000000000..e0b13e5cbcc --- /dev/null +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupStartEventHandler.java @@ -0,0 +1,35 @@ +/* + * *********************************************************************** * + * project: org.matsim.* + * *********************************************************************** * + * * + * copyright : (C) by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** + * + */ + +package org.matsim.freight.carriers.events.eventhandler; + +import org.matsim.core.events.handler.EventHandler; +import org.matsim.freight.carriers.events.CarrierShipmentPickupStartEvent; + +/** + * Interface to listen to shipmentPickedUpEvents. + * + * @author sschroeder + * + */ +public interface FreightShipmentPickupStartEventHandler extends EventHandler { + void handleEvent(CarrierShipmentPickupStartEvent event); +} diff --git a/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java b/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java index 5a9daccf1cf..89f50649dd9 100644 --- a/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java +++ b/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java @@ -38,8 +38,8 @@ import org.matsim.freight.carriers.events.CarrierShipmentPickupEndEvent; import org.matsim.freight.carriers.events.eventhandler.FreightServiceEndEventHandler; import org.matsim.freight.carriers.events.eventhandler.FreightServiceStartEventHandler; -import org.matsim.freight.carriers.events.eventhandler.FreightShipmentDeliveryEventHandler; -import org.matsim.freight.carriers.events.eventhandler.FreightShipmentPickupEventHandler; +import org.matsim.freight.carriers.events.eventhandler.FreightShipmentDeliveryEndEventHandler; +import org.matsim.freight.carriers.events.eventhandler.FreightShipmentPickupEndEventHandler; import org.matsim.core.network.NetworkUtils; import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.Vehicles; @@ -59,7 +59,7 @@ * */ @Deprecated(since = "apr23") -class FreightAnalysisEventHandler implements ActivityStartEventHandler, LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, FreightShipmentPickupEventHandler, FreightShipmentDeliveryEventHandler, FreightServiceStartEventHandler, FreightServiceEndEventHandler { +class FreightAnalysisEventHandler implements ActivityStartEventHandler, LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, FreightShipmentPickupEndEventHandler, FreightShipmentDeliveryEndEventHandler, FreightServiceStartEventHandler, FreightServiceEndEventHandler { private final static Logger log = LogManager.getLogger(FreightAnalysisEventHandler.class); private final Vehicles vehicles; diff --git a/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyShipmentTrackerEventHandler.java b/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyShipmentTrackerEventHandler.java index 35b455b8944..3ff13bfa29a 100644 --- a/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyShipmentTrackerEventHandler.java +++ b/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyShipmentTrackerEventHandler.java @@ -29,11 +29,11 @@ import org.matsim.freight.carriers.Carriers; import org.matsim.freight.carriers.events.CarrierShipmentDeliveryEndEvent; import org.matsim.freight.carriers.events.CarrierShipmentPickupEndEvent; -import org.matsim.freight.carriers.events.eventhandler.FreightShipmentDeliveryEventHandler; -import org.matsim.freight.carriers.events.eventhandler.FreightShipmentPickupEventHandler; +import org.matsim.freight.carriers.events.eventhandler.FreightShipmentDeliveryEndEventHandler; +import org.matsim.freight.carriers.events.eventhandler.FreightShipmentPickupEndEventHandler; import org.matsim.vehicles.Vehicles; -public class MyShipmentTrackerEventHandler implements ActivityStartEventHandler, FreightShipmentPickupEventHandler, FreightShipmentDeliveryEventHandler { +public class MyShipmentTrackerEventHandler implements ActivityStartEventHandler, FreightShipmentPickupEndEventHandler, FreightShipmentDeliveryEndEventHandler { private final Vehicles vehicles; private final Network network; @@ -69,7 +69,7 @@ public void handleEvent(CarrierShipmentPickupEndEvent event) { @Override public void reset(int iteration) { - FreightShipmentPickupEventHandler.super.reset(iteration); + FreightShipmentPickupEndEventHandler.super.reset(iteration); } @Override From 54a353eb97290d1dcfdbeda2e0802564129b91ad Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Thu, 19 Oct 2023 14:46:52 +0200 Subject: [PATCH 49/54] Update test (and input). Now it will also (at least) count the number of corresponding events. --- .../carriers/CarrierEventsReadersTest.java | 96 +++- .../serviceBasedEvents.xml | 396 ++++++++-------- .../shipmentBasedEvents.xml | 430 ++++++++---------- 3 files changed, 490 insertions(+), 432 deletions(-) diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java index b418cf800cf..7495ddfc0fd 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java @@ -3,16 +3,20 @@ import org.junit.Assert; import org.junit.Rule; import org.junit.Test; +import org.matsim.api.core.v01.events.Event; import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.config.groups.ControllerConfigGroup; import org.matsim.core.events.EventsUtils; import org.matsim.core.events.algorithms.EventWriterXML; -import org.matsim.freight.carriers.events.CarrierEventsReaders; +import org.matsim.freight.carriers.events.*; +import org.matsim.freight.carriers.events.eventhandler.*; import org.matsim.testcases.MatsimTestUtils; import org.matsim.testcases.utils.EventsCollector; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.List; public class CarrierEventsReadersTest { @@ -46,6 +50,25 @@ public void testWriteReadServiceBasedEvents() { Assert.assertEquals(collector1.getEvents(), collector2.getEvents()); } + + @Test + public void testReadServiceBasedEvents() { + + EventsManager eventsManager = EventsUtils.createEventsManager(); + TestEventHandlerTours eventHandlerTours = new TestEventHandlerTours(); + TestEventHandlerServices eventHandlerServices = new TestEventHandlerServices(); + + eventsManager.addHandler(eventHandlerTours); + eventsManager.addHandler(eventHandlerServices); + eventsManager.initProcessing(); + CarrierEventsReaders.createEventsReader(eventsManager) + .readFile(utils.getClassInputDirectory() + "serviceBasedEvents.xml"); + eventsManager.finishProcessing(); + + Assert.assertEquals("Number of tour related carrier events is not correct", 4 , eventHandlerTours.handledEvents.size()); + Assert.assertEquals("Number of service related carrier events is not correct", 14 , eventHandlerServices.handledEvents.size()); + } + @Test public void testWriteReadShipmentBasedEvents() { EventsManager eventsManager1 = EventsUtils.createEventsManager(); @@ -56,7 +79,7 @@ public void testWriteReadShipmentBasedEvents() { eventsManager1.addHandler(collector1); eventsManager1.initProcessing(); CarrierEventsReaders.createEventsReader(eventsManager1) - .readFile(utils.getClassInputDirectory() + "shipmentBasedEvents.xml"); + .readFile(utils.getClassInputDirectory() + "shipmentBasedEvents.xml"); eventsManager1.finishProcessing(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); @@ -67,10 +90,77 @@ public void testWriteReadShipmentBasedEvents() { eventsManager2.addHandler(collector2); eventsManager2.initProcessing(); CarrierEventsReaders.createEventsReader(eventsManager2) - .readStream(new ByteArrayInputStream(outputStream.toByteArray()), ControllerConfigGroup.EventsFileFormat.xml); + .readStream(new ByteArrayInputStream(outputStream.toByteArray()), ControllerConfigGroup.EventsFileFormat.xml); eventsManager2.finishProcessing(); Assert.assertEquals(collector1.getEvents(), collector2.getEvents()); } + @Test + public void testReadShipmentBasedEvents() { + + EventsManager eventsManager = EventsUtils.createEventsManager(); + TestEventHandlerTours eventHandlerTours = new TestEventHandlerTours(); + TestEventHandlerShipments testEventHandlerShipments = new TestEventHandlerShipments(); + + eventsManager.addHandler(eventHandlerTours); + eventsManager.addHandler(testEventHandlerShipments); + eventsManager.initProcessing(); + CarrierEventsReaders.createEventsReader(eventsManager) + .readFile(utils.getClassInputDirectory() + "shipmentBasedEvents.xml"); + eventsManager.finishProcessing(); + + Assert.assertEquals("Number of tour related carrier events is not correct", 2 , eventHandlerTours.handledEvents.size()); + Assert.assertEquals("Number of shipments related carrier events is not correct", 20 , testEventHandlerShipments.handledEvents.size()); + } + + private static class TestEventHandlerTours + implements FreightTourStartEventHandler, FreightTourEndEventHandler { + private final List handledEvents = new ArrayList<>(); + + + @Override public void handleEvent(CarrierTourEndEvent event) { + handledEvents.add(event); + } + + @Override public void handleEvent(CarrierTourStartEvent event) { + handledEvents.add(event); + } + } + + private static class TestEventHandlerServices + implements FreightServiceStartEventHandler, FreightServiceEndEventHandler { + private final List handledEvents = new ArrayList<>(); + + @Override public void handleEvent(CarrierServiceEndEvent event) { + handledEvents.add(event); + } + + @Override public void handleEvent(CarrierServiceStartEvent event) { + handledEvents.add(event); + } + + } + + private static class TestEventHandlerShipments + implements FreightShipmentDeliveryStartEventHandler, FreightShipmentDeliveryEndEventHandler, FreightShipmentPickupStartEventHandler, FreightShipmentPickupEndEventHandler { + private final List handledEvents = new ArrayList<>(); + + + @Override public void handleEvent(CarrierShipmentDeliveryEndEvent event) { + handledEvents.add(event); + } + + @Override public void handleEvent(CarrierShipmentPickupEndEvent event) { + handledEvents.add(event); + } + + @Override public void handleEvent(CarrierShipmentDeliveryStartEvent event) { + handledEvents.add(event); + } + + @Override public void handleEvent(CarrierShipmentPickupStartEvent event) { + handledEvents.add(event); + } + } } diff --git a/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/serviceBasedEvents.xml b/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/serviceBasedEvents.xml index f2bb0c1175e..b4121096264 100644 --- a/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/serviceBasedEvents.xml +++ b/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/serviceBasedEvents.xml @@ -1,195 +1,213 @@ + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/shipmentBasedEvents.xml b/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/shipmentBasedEvents.xml index 82c90c41829..ca675a9bcbf 100644 --- a/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/shipmentBasedEvents.xml +++ b/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/shipmentBasedEvents.xml @@ -1,243 +1,193 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From d888d9a7836f9f5d331355dc36fe93d5f3e169e0 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Thu, 19 Oct 2023 14:49:09 +0200 Subject: [PATCH 50/54] rename "Freight" eventsHandler to "Carrier" eventsHandler --- ...Handler.java => CarrierServiceEndEventHandler.java} | 2 +- ...ndler.java => CarrierServiceStartEventHandler.java} | 2 +- ...ava => CarrierShipmentDeliveryEndEventHandler.java} | 2 +- ...a => CarrierShipmentDeliveryStartEventHandler.java} | 2 +- ....java => CarrierShipmentPickupEndEventHandler.java} | 2 +- ...ava => CarrierShipmentPickupStartEventHandler.java} | 2 +- ...entHandler.java => CarrierTourEndEventHandler.java} | 2 +- ...tHandler.java => CarrierTourStartEventHandler.java} | 2 +- .../eventhandler/Vehicle2CarrierEventHandler.java | 2 +- .../freight/carriers/CarrierEventsReadersTest.java | 6 +++--- .../carriers/analysis/FreightAnalysisEventHandler.java | 10 +++++----- .../analysis/MyServiceTrackerEventHandler.java | 6 +++--- .../analysis/MyShipmentTrackerEventHandler.java | 8 ++++---- 13 files changed, 24 insertions(+), 24 deletions(-) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightServiceEndEventHandler.java => CarrierServiceEndEventHandler.java} (95%) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightServiceStartEventHandler.java => CarrierServiceStartEventHandler.java} (96%) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightShipmentDeliveryEndEventHandler.java => CarrierShipmentDeliveryEndEventHandler.java} (96%) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightShipmentDeliveryStartEventHandler.java => CarrierShipmentDeliveryStartEventHandler.java} (96%) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightShipmentPickupEndEventHandler.java => CarrierShipmentPickupEndEventHandler.java} (96%) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightShipmentPickupStartEventHandler.java => CarrierShipmentPickupStartEventHandler.java} (96%) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightTourEndEventHandler.java => CarrierTourEndEventHandler.java} (95%) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightTourStartEventHandler.java => CarrierTourStartEventHandler.java} (95%) diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightServiceEndEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierServiceEndEventHandler.java similarity index 95% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightServiceEndEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierServiceEndEventHandler.java index 65db8298b92..11ccfde0372 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightServiceEndEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierServiceEndEventHandler.java @@ -25,7 +25,7 @@ import org.matsim.core.events.handler.EventHandler; import org.matsim.freight.carriers.events.CarrierServiceEndEvent; -public interface FreightServiceEndEventHandler extends EventHandler{ +public interface CarrierServiceEndEventHandler extends EventHandler{ void handleEvent( CarrierServiceEndEvent event ); } diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightServiceStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierServiceStartEventHandler.java similarity index 96% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightServiceStartEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierServiceStartEventHandler.java index 78534b0337e..a8ea55c13e8 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightServiceStartEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierServiceStartEventHandler.java @@ -25,7 +25,7 @@ import org.matsim.freight.carriers.events.CarrierServiceStartEvent; -public interface FreightServiceStartEventHandler extends EventHandler { +public interface CarrierServiceStartEventHandler extends EventHandler { void handleEvent( CarrierServiceStartEvent event ); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentDeliveryEndEventHandler.java similarity index 96% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentDeliveryEndEventHandler.java index da7c2f805e3..b2cc8ff31dc 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentDeliveryEndEventHandler.java @@ -30,7 +30,7 @@ * @author sschroeder * */ -public interface FreightShipmentDeliveryEndEventHandler extends EventHandler { +public interface CarrierShipmentDeliveryEndEventHandler extends EventHandler { void handleEvent(CarrierShipmentDeliveryEndEvent event); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentDeliveryStartEventHandler.java similarity index 96% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentDeliveryStartEventHandler.java index 1d0dc74c0f6..df8a7b9785a 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentDeliveryStartEventHandler.java @@ -30,7 +30,7 @@ * @author sschroeder * */ -public interface FreightShipmentDeliveryStartEventHandler extends EventHandler { +public interface CarrierShipmentDeliveryStartEventHandler extends EventHandler { void handleEvent(CarrierShipmentDeliveryStartEvent event); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEndEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentPickupEndEventHandler.java similarity index 96% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEndEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentPickupEndEventHandler.java index aeca9d324d8..4c7282c29c7 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEndEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentPickupEndEventHandler.java @@ -30,6 +30,6 @@ * @author sschroeder * */ -public interface FreightShipmentPickupEndEventHandler extends EventHandler { +public interface CarrierShipmentPickupEndEventHandler extends EventHandler { void handleEvent(CarrierShipmentPickupEndEvent event); } diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentPickupStartEventHandler.java similarity index 96% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupStartEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentPickupStartEventHandler.java index e0b13e5cbcc..79c2426f023 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupStartEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentPickupStartEventHandler.java @@ -30,6 +30,6 @@ * @author sschroeder * */ -public interface FreightShipmentPickupStartEventHandler extends EventHandler { +public interface CarrierShipmentPickupStartEventHandler extends EventHandler { void handleEvent(CarrierShipmentPickupStartEvent event); } diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightTourEndEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierTourEndEventHandler.java similarity index 95% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightTourEndEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierTourEndEventHandler.java index 7a91f767c4d..2d30ce4d70c 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightTourEndEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierTourEndEventHandler.java @@ -25,7 +25,7 @@ import org.matsim.freight.carriers.events.CarrierTourEndEvent; -public interface FreightTourEndEventHandler extends EventHandler { +public interface CarrierTourEndEventHandler extends EventHandler { void handleEvent( CarrierTourEndEvent event ); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightTourStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierTourStartEventHandler.java similarity index 95% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightTourStartEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierTourStartEventHandler.java index 21b14f86ce0..5f4b26ce4bb 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightTourStartEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierTourStartEventHandler.java @@ -25,7 +25,7 @@ import org.matsim.freight.carriers.events.CarrierTourStartEvent; -public interface FreightTourStartEventHandler extends EventHandler { +public interface CarrierTourStartEventHandler extends EventHandler { void handleEvent( CarrierTourStartEvent event ); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/Vehicle2CarrierEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/Vehicle2CarrierEventHandler.java index e116ab1493e..bc9236decbf 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/Vehicle2CarrierEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/Vehicle2CarrierEventHandler.java @@ -36,7 +36,7 @@ * * @author kturner */ -public final class Vehicle2CarrierEventHandler implements FreightTourStartEventHandler, FreightTourEndEventHandler { +public final class Vehicle2CarrierEventHandler implements CarrierTourStartEventHandler, CarrierTourEndEventHandler { // Comment from Janek (in https://github.com/matsim-org/matsim-libs/pull/2128) diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java index 7495ddfc0fd..d3c3d81eea0 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java @@ -115,7 +115,7 @@ public void testReadShipmentBasedEvents() { } private static class TestEventHandlerTours - implements FreightTourStartEventHandler, FreightTourEndEventHandler { + implements CarrierTourStartEventHandler, CarrierTourEndEventHandler { private final List handledEvents = new ArrayList<>(); @@ -129,7 +129,7 @@ private static class TestEventHandlerTours } private static class TestEventHandlerServices - implements FreightServiceStartEventHandler, FreightServiceEndEventHandler { + implements CarrierServiceStartEventHandler, CarrierServiceEndEventHandler { private final List handledEvents = new ArrayList<>(); @Override public void handleEvent(CarrierServiceEndEvent event) { @@ -143,7 +143,7 @@ private static class TestEventHandlerServices } private static class TestEventHandlerShipments - implements FreightShipmentDeliveryStartEventHandler, FreightShipmentDeliveryEndEventHandler, FreightShipmentPickupStartEventHandler, FreightShipmentPickupEndEventHandler { + implements CarrierShipmentDeliveryStartEventHandler, CarrierShipmentDeliveryEndEventHandler, CarrierShipmentPickupStartEventHandler, CarrierShipmentPickupEndEventHandler { private final List handledEvents = new ArrayList<>(); diff --git a/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java b/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java index 89f50649dd9..2f322e8640f 100644 --- a/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java +++ b/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java @@ -36,10 +36,10 @@ import org.matsim.freight.carriers.events.CarrierServiceStartEvent; import org.matsim.freight.carriers.events.CarrierShipmentDeliveryEndEvent; import org.matsim.freight.carriers.events.CarrierShipmentPickupEndEvent; -import org.matsim.freight.carriers.events.eventhandler.FreightServiceEndEventHandler; -import org.matsim.freight.carriers.events.eventhandler.FreightServiceStartEventHandler; -import org.matsim.freight.carriers.events.eventhandler.FreightShipmentDeliveryEndEventHandler; -import org.matsim.freight.carriers.events.eventhandler.FreightShipmentPickupEndEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierServiceEndEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierServiceStartEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierShipmentDeliveryEndEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierShipmentPickupEndEventHandler; import org.matsim.core.network.NetworkUtils; import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.Vehicles; @@ -59,7 +59,7 @@ * */ @Deprecated(since = "apr23") -class FreightAnalysisEventHandler implements ActivityStartEventHandler, LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, FreightShipmentPickupEndEventHandler, FreightShipmentDeliveryEndEventHandler, FreightServiceStartEventHandler, FreightServiceEndEventHandler { +class FreightAnalysisEventHandler implements ActivityStartEventHandler, LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, CarrierShipmentPickupEndEventHandler, CarrierShipmentDeliveryEndEventHandler, CarrierServiceStartEventHandler, CarrierServiceEndEventHandler { private final static Logger log = LogManager.getLogger(FreightAnalysisEventHandler.class); private final Vehicles vehicles; diff --git a/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyServiceTrackerEventHandler.java b/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyServiceTrackerEventHandler.java index 43c9dd2d524..ae51676c57b 100644 --- a/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyServiceTrackerEventHandler.java +++ b/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyServiceTrackerEventHandler.java @@ -29,11 +29,11 @@ import org.matsim.freight.carriers.Carriers; import org.matsim.freight.carriers.events.CarrierServiceEndEvent; import org.matsim.freight.carriers.events.CarrierServiceStartEvent; -import org.matsim.freight.carriers.events.eventhandler.FreightServiceEndEventHandler; -import org.matsim.freight.carriers.events.eventhandler.FreightServiceStartEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierServiceEndEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierServiceStartEventHandler; import org.matsim.vehicles.Vehicles; - class MyServiceTrackerEventHandler implements ActivityStartEventHandler, FreightServiceStartEventHandler, FreightServiceEndEventHandler { + class MyServiceTrackerEventHandler implements ActivityStartEventHandler, CarrierServiceStartEventHandler, CarrierServiceEndEventHandler { private final Vehicles vehicles; private final Network network; private final Carriers carriers; diff --git a/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyShipmentTrackerEventHandler.java b/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyShipmentTrackerEventHandler.java index 3ff13bfa29a..178652c1c7d 100644 --- a/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyShipmentTrackerEventHandler.java +++ b/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyShipmentTrackerEventHandler.java @@ -29,11 +29,11 @@ import org.matsim.freight.carriers.Carriers; import org.matsim.freight.carriers.events.CarrierShipmentDeliveryEndEvent; import org.matsim.freight.carriers.events.CarrierShipmentPickupEndEvent; -import org.matsim.freight.carriers.events.eventhandler.FreightShipmentDeliveryEndEventHandler; -import org.matsim.freight.carriers.events.eventhandler.FreightShipmentPickupEndEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierShipmentDeliveryEndEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierShipmentPickupEndEventHandler; import org.matsim.vehicles.Vehicles; -public class MyShipmentTrackerEventHandler implements ActivityStartEventHandler, FreightShipmentPickupEndEventHandler, FreightShipmentDeliveryEndEventHandler { +public class MyShipmentTrackerEventHandler implements ActivityStartEventHandler, CarrierShipmentPickupEndEventHandler, CarrierShipmentDeliveryEndEventHandler { private final Vehicles vehicles; private final Network network; @@ -69,7 +69,7 @@ public void handleEvent(CarrierShipmentPickupEndEvent event) { @Override public void reset(int iteration) { - FreightShipmentPickupEndEventHandler.super.reset(iteration); + CarrierShipmentPickupEndEventHandler.super.reset(iteration); } @Override From 376a7ec6a95d83ee42ca2cd77403f71bc1b02239 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 20 Oct 2023 16:09:23 +0200 Subject: [PATCH 51/54] add in-code created test as well. add copyright --- .../carriers/CarrierEventsReadersTest.java | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java index d3c3d81eea0..37a4cabaf82 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java @@ -1,9 +1,31 @@ +/* + * *********************************************************************** * + * project: org.matsim.* + * *********************************************************************** * + * * + * copyright : (C) 2023 by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** * + */ + package org.matsim.freight.carriers; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; +import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.events.Event; +import org.matsim.api.core.v01.network.Link; import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.config.groups.ControllerConfigGroup; import org.matsim.core.events.EventsUtils; @@ -12,17 +34,44 @@ import org.matsim.freight.carriers.events.eventhandler.*; import org.matsim.testcases.MatsimTestUtils; import org.matsim.testcases.utils.EventsCollector; +import org.matsim.vehicles.Vehicle; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.List; + +/** + * @author Kai Martins-Turner (kturner) + * @author Niclas Richter (nixlaos) + */ public class CarrierEventsReadersTest { + @Rule public final MatsimTestUtils utils = new MatsimTestUtils(); + private final Id linkId = Id.createLinkId("demoLink"); + private final Id linkId2 = Id.createLinkId("demoLink2"); + private final Id carrierId = Id.create("testCarrier", Carrier.class); + private final Id vehicleId = Id.createVehicleId("myVehicle"); + + private final Id tourId = Id.create("myCarrierTour", Tour.class); + private final CarrierService service = CarrierService.Builder.newInstance(Id.create("service42", CarrierService.class), linkId2 ).build(); + private final CarrierShipment shipment = CarrierShipment.Builder.newInstance(Id.create("shipment11", CarrierShipment.class), linkId, linkId2,7 ).build(); + + private final List carrierEvents = List.of( + new CarrierTourStartEvent(10, carrierId, linkId, vehicleId, tourId), + new CarrierTourEndEvent(500, carrierId, linkId, vehicleId, tourId), + new CarrierServiceStartEvent(20, carrierId, service, vehicleId), + new CarrierServiceEndEvent(25, carrierId, service, vehicleId), + new CarrierShipmentPickupStartEvent(100, carrierId, shipment, vehicleId), + new CarrierShipmentPickupEndEvent(115, carrierId, shipment, vehicleId), + new CarrierShipmentDeliveryStartEvent(210, carrierId, shipment, vehicleId), + new CarrierShipmentDeliveryEndEvent(225, carrierId, shipment, vehicleId) + ); + @Test public void testWriteReadServiceBasedEvents() { EventsManager eventsManager1 = EventsUtils.createEventsManager(); @@ -114,6 +163,42 @@ public void testReadShipmentBasedEvents() { Assert.assertEquals("Number of shipments related carrier events is not correct", 20 , testEventHandlerShipments.handledEvents.size()); } + + /** + * This test is testing the reader with some locally created events (see above). + * This test is inspired by the DrtEventsReaderTest from michalm. + */ + @Test + public void testReader() { + var outputStream = new ByteArrayOutputStream(); + EventWriterXML writer = new EventWriterXML(outputStream); + carrierEvents.forEach(writer::handleEvent); + writer.closeFile(); + + EventsManager eventsManager = EventsUtils.createEventsManager(); + TestEventHandlerTours eventHandlerTours = new TestEventHandlerTours(); + TestEventHandlerServices eventHandlerServices = new TestEventHandlerServices(); + TestEventHandlerShipments eventHandlerShipments = new TestEventHandlerShipments(); + + eventsManager.addHandler(eventHandlerTours); + eventsManager.addHandler(eventHandlerServices); + eventsManager.addHandler(eventHandlerShipments); + + eventsManager.initProcessing(); + CarrierEventsReaders.createEventsReader(eventsManager) + .readStream(new ByteArrayInputStream(outputStream.toByteArray()), + ControllerConfigGroup.EventsFileFormat.xml); + eventsManager.finishProcessing(); + + var handledEvents = new ArrayList(); + handledEvents.addAll(eventHandlerTours.handledEvents); + handledEvents.addAll(eventHandlerServices.handledEvents); + handledEvents.addAll(eventHandlerShipments.handledEvents); + + //Please note: This test is sensitive to the order of events as they are added in carrierEvents (input) and the resukts of the handler... + Assert.assertArrayEquals(carrierEvents.toArray(), handledEvents.toArray()); + } + private static class TestEventHandlerTours implements CarrierTourStartEventHandler, CarrierTourEndEventHandler { private final List handledEvents = new ArrayList<>(); From d303fb299bc67b22700376cd1906b8d9200e8962 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 20 Oct 2023 20:37:23 +0000 Subject: [PATCH 52/54] build(deps): bump io.grpc:grpc-all from 1.58.0 to 1.59.0 Bumps [io.grpc:grpc-all](https://github.com/grpc/grpc-java) from 1.58.0 to 1.59.0. - [Release notes](https://github.com/grpc/grpc-java/releases) - [Commits](https://github.com/grpc/grpc-java/compare/v1.58.0...v1.59.0) --- updated-dependencies: - dependency-name: io.grpc:grpc-all dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- contribs/hybridsim/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contribs/hybridsim/pom.xml b/contribs/hybridsim/pom.xml index 2a8fffb488b..fe40487e7f4 100644 --- a/contribs/hybridsim/pom.xml +++ b/contribs/hybridsim/pom.xml @@ -11,7 +11,7 @@ 3.24.4 - 1.58.0 + 1.59.0 From 378ac20663ff361373cebf06fe7dc18f291b69aa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 20 Oct 2023 20:54:37 +0000 Subject: [PATCH 53/54] build(deps): bump org.glassfish.jaxb:jaxb-bom from 4.0.3 to 4.0.4 Bumps org.glassfish.jaxb:jaxb-bom from 4.0.3 to 4.0.4. --- updated-dependencies: - dependency-name: org.glassfish.jaxb:jaxb-bom dependency-type: direct:production 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 8be88f56e2f..f6535a1769f 100644 --- a/pom.xml +++ b/pom.xml @@ -177,7 +177,7 @@ org.glassfish.jaxb jaxb-bom - 4.0.3 + 4.0.4 pom import From 3503aa4322da210270b3f49a1f43a334324e7ce6 Mon Sep 17 00:00:00 2001 From: Michal Maciejewski Date: Sun, 22 Oct 2023 12:00:37 +0200 Subject: [PATCH 54/54] mvn: require mvn version 3.8+ This is to get more consistent build behaviour across different machines. Mvn 3.6.3 is now 4 years old and sometimes does not work well with newer JDKs (16+). --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f6535a1769f..39e44dc135a 100644 --- a/pom.xml +++ b/pom.xml @@ -346,7 +346,7 @@ - 3.6.3 + 3.8