From 235fe65b5bce13bafe963af4126cb553c8296917 Mon Sep 17 00:00:00 2001 From: nixlaos Date: Wed, 12 Jul 2023 14:33:33 +0200 Subject: [PATCH 001/172] 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 8e47e6daf165bc7d56e5c4a07637c82f293a4e96 Mon Sep 17 00:00:00 2001 From: awagner Date: Mon, 24 Jul 2023 16:23:27 +0200 Subject: [PATCH 002/172] changed loadHouseholds when households eq. null --- .../core/scenario/ScenarioLoaderImpl.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/matsim/src/main/java/org/matsim/core/scenario/ScenarioLoaderImpl.java b/matsim/src/main/java/org/matsim/core/scenario/ScenarioLoaderImpl.java index 7685b927f9a..440ecdc19b1 100644 --- a/matsim/src/main/java/org/matsim/core/scenario/ScenarioLoaderImpl.java +++ b/matsim/src/main/java/org/matsim/core/scenario/ScenarioLoaderImpl.java @@ -257,20 +257,22 @@ private void loadHouseholds() { else { log.info("no households file set in config, not loading households"); } - final String fn = this.config.households().getInputHouseholdAttributesFile(); - if ((this.config.households() != null) && ( fn != null)) { - if (!this.config.households().isInsistingOnUsingDeprecatedHouseholdsAttributeFile()) { - throw new RuntimeException(HouseholdsConfigGroup.HOUSEHOLD_ATTRIBUTES_DEPRECATION_MESSAGE); + if ((this.config.households() != null)) { + final String fn = this.config.households().getInputHouseholdAttributesFile(); + if(( fn != null)) { + if (!this.config.households().isInsistingOnUsingDeprecatedHouseholdsAttributeFile()) { + throw new RuntimeException(HouseholdsConfigGroup.HOUSEHOLD_ATTRIBUTES_DEPRECATION_MESSAGE); + } + + URL householdAttributesFileName = ConfigGroup.getInputFileURL(this.config.getContext(), fn ) ; + log.info("loading household attributes from " + householdAttributesFileName); + parseObjectAttributesToAttributable( + householdAttributesFileName, + this.scenario.getHouseholds().getHouseholds().values(), + "householdAttributes not empty after going through all households, meaning that it contains material for householdIDs that " + + "are not in the container. This is not necessarily a bug so we will continue, but note that such material " + + "will no longer be contained in the output_* files."); } - - URL householdAttributesFileName = ConfigGroup.getInputFileURL(this.config.getContext(), fn ) ; - log.info("loading household attributes from " + householdAttributesFileName); - parseObjectAttributesToAttributable( - householdAttributesFileName, - this.scenario.getHouseholds().getHouseholds().values(), - "householdAttributes not empty after going through all households, meaning that it contains material for householdIDs that " + - "are not in the container. This is not necessarily a bug so we will continue, but note that such material " + - "will no longer be contained in the output_* files."); } else { log.info("no household-attributes file set in config, not loading any household attributes"); From 2ef28130513920e0c6a673c810d2a09f3f12764b Mon Sep 17 00:00:00 2001 From: nixlaos Date: Tue, 8 Aug 2023 16:14:51 +0200 Subject: [PATCH 003/172] 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 004/172] 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 005/172] 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 006/172] 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 007/172] 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 008/172] 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 009/172] 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 010/172] 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 011/172] 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 012/172] 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 013/172] 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 014/172] 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 015/172] 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 016/172] 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 017/172] 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 018/172] 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 019/172] 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 020/172] 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 021/172] 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 022/172] 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 023/172] 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 676064968c2d961991f44fb847f1fe6fad6dc327 Mon Sep 17 00:00:00 2001 From: Marcel Rieser Date: Mon, 9 Oct 2023 17:12:43 +0200 Subject: [PATCH 024/172] WIP. Getting rid of old transit router. --- .../RandomizingTransitRouterIT.java | 48 +- .../examples/TestSiouxFalls.java | 1 - .../minibus/integration/SubsidyTestIT.java | 29 +- .../contrib/pseudosimulation/RunPSimTest.java | 14 +- .../andreas/mzilske/bvg09/DataPrepare.java | 71 +- .../vsp/pt/ptdisturbances/EditTripsTest.java | 3 - .../matsim/pt/config/TransitConfigGroup.java | 14 +- .../pt/router/TransitLeastCostPathTree.java | 6 +- .../pt/router/TransitRouterImplFactory.java | 73 -- .../matsim/pt/router/TransitRouterModule.java | 3 +- .../matsim/examples/simple/PtScoringTest.java | 106 +-- ...ransitRouterNetworkTravelTimeCostTest.java | 217 ----- .../router/TransitRouterCustomDataTest.java | 209 ----- .../pt/router/TransitRouterImplTest.java | 869 ------------------ .../pt/router/TransitRouterModuleTest.java | 24 +- ...ransitRouterNetworkTravelTimeCostTest.java | 167 ---- .../TransitScheduleReprojectionIOTest.java | 24 +- 17 files changed, 158 insertions(+), 1720 deletions(-) delete mode 100644 matsim/src/main/java/org/matsim/pt/router/TransitRouterImplFactory.java delete mode 100644 matsim/src/test/java/org/matsim/pt/router/AdaptedTransitRouterNetworkTravelTimeCostTest.java delete mode 100644 matsim/src/test/java/org/matsim/pt/router/TransitRouterCustomDataTest.java delete mode 100644 matsim/src/test/java/org/matsim/pt/router/TransitRouterImplTest.java delete mode 100644 matsim/src/test/java/org/matsim/pt/router/TransitRouterNetworkTravelTimeCostTest.java diff --git a/contribs/common/src/test/java/org/matsim/contrib/common/randomizingtransitrouter/RandomizingTransitRouterIT.java b/contribs/common/src/test/java/org/matsim/contrib/common/randomizingtransitrouter/RandomizingTransitRouterIT.java index e703c6c4af6..7e506d5e265 100644 --- a/contribs/common/src/test/java/org/matsim/contrib/common/randomizingtransitrouter/RandomizingTransitRouterIT.java +++ b/contribs/common/src/test/java/org/matsim/contrib/common/randomizingtransitrouter/RandomizingTransitRouterIT.java @@ -54,11 +54,11 @@ */ public class RandomizingTransitRouterIT { private static final Logger log = LogManager.getLogger( RandomizingTransitRouterIT.class ) ; - + private static final class MyObserver implements PersonEntersVehicleEventHandler { // private enum ObservedVehicle{ pt_1009_1 /*direct, fast, with wait*/, pt_2009_1 /*direct, slow*/, pt_3009_1 /*with interchange*/} ; - - Map,Double> cnts = new HashMap<>() ; + + Map,Double> cnts = new HashMap<>() ; @Override public void reset(int iteration) { cnts.clear(); @@ -67,13 +67,13 @@ private static final class MyObserver implements PersonEntersVehicleEventHandler @Override public void handleEvent(PersonEntersVehicleEvent event) { cnts.merge( event.getVehicleId() , 1. , Double::sum ); } - + void printCounts() { for ( Entry, Double> entry : cnts.entrySet() ) { log.info( "Vehicle id: " + entry.getKey() + "; number of boards: " + entry.getValue() ) ; } } - + Map< Id, Double> getCounts() { return this.cnts ; } @@ -87,22 +87,22 @@ public final void test() { String outputDir = utils.getOutputDirectory() ; Config config = utils.createConfigWithPackageInputResourcePathAsContext(); - + config.network().setInputFile("network.xml"); config.plans().setInputFile("population.xml"); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); + config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.SwissRailRaptor); config.transit().setTransitScheduleFile("transitschedule.xml"); config.transit().setVehiclesFile("transitVehicles.xml"); config.transit().setUseTransit(true); - + config.controler().setOutputDirectory( outputDir ); config.controler().setLastIteration(20); config.controler().setCreateGraphs(false); config.controler().setDumpDataAtEnd(false); - + config.global().setNumberOfThreads(1); - + config.planCalcScore().addActivityParams( new ActivityParams("home").setTypicalDuration( 6*3600. ) ); config.planCalcScore().addActivityParams( new ActivityParams("education_100").setTypicalDuration( 6*3600. ) ); @@ -113,7 +113,7 @@ public final void test() { // yy changing the above (= no longer using createAvailableStrategyId) changes the results. :-( :-( :-( config.qsim().setEndTime(18.*3600.); - + config.timeAllocationMutator().setMutationRange(7200); config.timeAllocationMutator().setAffectingDuration(false); config.plans().setRemovingUnneccessaryPlanAttributes(true); @@ -125,39 +125,39 @@ public final void test() { // * The implicit activity coordinates may be elsewhere. // * The "fudged" walk distances may be different. // * It uses getNearestLinkEXACTLY, and thus activities may be attached to other links. - + config.vspExperimental().setWritingOutputEvents(true); config.vspExperimental().setVspDefaultsCheckingLevel( VspDefaultsCheckingLevel.warn ); - + // --- - + Scenario scenario = ScenarioUtils.loadScenario( config ) ; - + // --- - + Controler controler = new Controler( scenario ) ; controler.addOverridingModule( new RandomizingTransitRouterModule() ); final MyObserver observer = new MyObserver(); controler.getEvents().addHandler(observer); - + controler.run(); - + // --- - - observer.printCounts(); - + + observer.printCounts(); + // yyyy the following is just a regression test, making sure that results remain stable. In general, the randomized transit router // could be improved, for example along the lines of the randomized regular router, which uses a (hopefully unbiased) lognormal // distribution rather than a biased uniform distribution as is used here. kai, jul'15 - + Assert.assertEquals(36., observer.getCounts().get( Id.create("1009", Vehicle.class) ), 0.1 ); Assert.assertEquals( 8. /*6.*/ , observer.getCounts().get( Id.create("1012", Vehicle.class) ) , 0.1 ); Assert.assertEquals(22. /*21.*/, observer.getCounts().get( Id.create("2009", Vehicle.class) ) , 0.1 ); Assert.assertEquals(36., observer.getCounts().get( Id.create("3009", Vehicle.class) ) , 0.1 ); - - + + } } diff --git a/contribs/discrete_mode_choice/src/test/java/org/matsim/contrib/discrete_mode_choice/examples/TestSiouxFalls.java b/contribs/discrete_mode_choice/src/test/java/org/matsim/contrib/discrete_mode_choice/examples/TestSiouxFalls.java index 9d931e70283..c9e6a2610c2 100644 --- a/contribs/discrete_mode_choice/src/test/java/org/matsim/contrib/discrete_mode_choice/examples/TestSiouxFalls.java +++ b/contribs/discrete_mode_choice/src/test/java/org/matsim/contrib/discrete_mode_choice/examples/TestSiouxFalls.java @@ -28,7 +28,6 @@ public void testSiouxFallsWithSubtourModeChoiceReplacement() { URL scenarioURL = ExamplesUtils.getTestScenarioURL("siouxfalls-2014"); Config config = ConfigUtils.loadConfig(IOUtils.extendUrl(scenarioURL, "config_default.xml")); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); DiscreteModeChoiceConfigurator.configureAsSubtourModeChoiceReplacement(config); config.controler().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); diff --git a/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/SubsidyTestIT.java b/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/SubsidyTestIT.java index 10116f29b0c..b148eea6270 100644 --- a/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/SubsidyTestIT.java +++ b/contribs/minibus/src/test/java/org/matsim/contrib/minibus/integration/SubsidyTestIT.java @@ -42,23 +42,22 @@ import org.matsim.testcases.MatsimTestUtils; /** - * + * * Tests the functionality of adding subsidies to the operator's score. - * + * * @author ikaddoura */ public class SubsidyTestIT implements TabularFileHandler { - + @Rule public MatsimTestUtils utils = new MatsimTestUtils(); private final ArrayList pStatsResults = new ArrayList<>(); @Test public final void testSubsidyPControler() { - + Config config = ConfigUtils.loadConfig( utils.getClassInputDirectory() + "config.xml", new PConfigGroup() ) ; - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); PConfigGroup pConfig = (PConfigGroup) config.getModules().get(PConfigGroup.GROUP_NAME); pConfig.setSubsidyApproach("perPassenger"); @@ -69,18 +68,18 @@ public final void testSubsidyPControler() { config.plans().setInputFile(gridScenarioDirectory + "population_1000_per_hour_each_from_6_to_10.xml.gz"); config.controler().setOutputDirectory(utils.getOutputDirectory()); config.controler().setWriteEventsInterval(0); - Scenario scenario = ScenarioUtils.loadScenario(config); + Scenario scenario = ScenarioUtils.loadScenario(config); Controler controler = new Controler(scenario); - + controler.getConfig().controler().setCreateGraphs(true); - + controler.getConfig().controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists ); - + controler.addOverridingModule(new PModule()) ; controler.run(); - - // Check standard output files - + + // Check standard output files + List filesToCheckFor = new LinkedList<>(); filesToCheckFor.add(utils.getOutputDirectory() + "0.actsFromParatransitUsers.txt"); filesToCheckFor.add(utils.getOutputDirectory() + "pOperatorLogger.txt"); @@ -107,11 +106,11 @@ public final void testSubsidyPControler() { // Check final iteration Assert.assertEquals("Number of budget (final iteration)", "202319997.4909444700", this.pStatsResults.get(2)[9]); } - + @Override public void startRow(String[] row) { - this.pStatsResults.add(row); + this.pStatsResults.add(row); } - + } diff --git a/contribs/pseudosimulation/src/test/java/org/matsim/contrib/pseudosimulation/RunPSimTest.java b/contribs/pseudosimulation/src/test/java/org/matsim/contrib/pseudosimulation/RunPSimTest.java index 02d4125191c..d337a156715 100644 --- a/contribs/pseudosimulation/src/test/java/org/matsim/contrib/pseudosimulation/RunPSimTest.java +++ b/contribs/pseudosimulation/src/test/java/org/matsim/contrib/pseudosimulation/RunPSimTest.java @@ -47,13 +47,12 @@ public class RunPSimTest { */ @Test public void testA() { - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); config.controler().setCreateGraphs(false); PSimConfigGroup pSimConfigGroup = new PSimConfigGroup(); config.addModule(pSimConfigGroup); pSimConfigGroup.setIterationsPerCycle(20); - + config.plansCalcRoute().setRoutingRandomness(0.); //identify selector strategies @@ -95,12 +94,12 @@ public void testA() { ((Controler) runPSim.getMatsimControler()).addOverridingModule(new AbstractModule() { @Override - public void install() { + public void install() { this.bind(TransitEmulator.class).to(NoTransitEmulator.class); } }); - - + + runPSim.run(); double psimScore = execScoreTracker.executedScore; logger.info("RunPSim score was " + psimScore); @@ -117,14 +116,13 @@ public void install() { /** * For comparison run 2 normal qsim iterations. Psim score should be slightly higher than default Controler score. - * + * * Prior to implementing routing mode RunPSimTest tested only that psimScore outperformed default Controler on this * test for executed score by a margin > 1%. In the last commit in matsim master where the test ran, the psim score * in testA() was 134.52369453719413 and qsim score in testB was 131.84309487251033). */ @Test public void testB() { - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); config.controler().setOutputDirectory(utils.getOutputDirectory()); config.controler().setLastIteration(2); config.controler().setCreateGraphs(false); @@ -134,7 +132,7 @@ public void testB() { ExecScoreTracker execScoreTracker = new ExecScoreTracker(controler); controler.addControlerListener(execScoreTracker); controler.run(); - + double qsimScore = execScoreTracker.executedScore; logger.info("Default controler score was " + qsimScore ); // Assert.assertEquals("Default controler score changed.", 131.84309487251033d, qsimScore, MatsimTestUtils.EPSILON); diff --git a/contribs/vsp/src/main/java/playground/vsp/andreas/mzilske/bvg09/DataPrepare.java b/contribs/vsp/src/main/java/playground/vsp/andreas/mzilske/bvg09/DataPrepare.java index d380efe7262..b19ef6e3f5a 100644 --- a/contribs/vsp/src/main/java/playground/vsp/andreas/mzilske/bvg09/DataPrepare.java +++ b/contribs/vsp/src/main/java/playground/vsp/andreas/mzilske/bvg09/DataPrepare.java @@ -53,7 +53,6 @@ import org.matsim.pt.UmlaufInterpolator; import org.matsim.pt.config.TransitConfigGroup; import org.matsim.pt.router.TransitRouterConfig; -import org.matsim.pt.router.TransitRouterImpl; import org.matsim.pt.transitSchedule.TransitScheduleWriterV1; import org.matsim.pt.transitSchedule.api.TransitLine; import org.matsim.pt.transitSchedule.api.TransitScheduleWriter; @@ -184,39 +183,43 @@ protected void routePopulation() { } protected void visualizeRouterNetwork() { - - TransitRouterConfig transitRouterConfig = new TransitRouterConfig(this.scenario.getConfig().planCalcScore() - , this.scenario.getConfig().plansCalcRoute(), this.scenario.getConfig().transitRouter(), - this.scenario.getConfig().vspExperimental()); - - TransitRouterImpl router = new TransitRouterImpl(transitRouterConfig, this.scenario.getTransitSchedule() ); - Network routerNet = router.getTransitRouterNetwork(); - - log.info("create vis network"); - MutableScenario visScenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); - Network visNet = visScenario.getNetwork(); - - for (Node node : routerNet.getNodes().values()) { - visNet.getFactory().createNode(node.getId(), node.getCoord()); - visNet.addNode(node); - } - for (Link link : routerNet.getLinks().values()) { - Link l = visNet.getFactory().createLink(link.getId(), visNet.getNodes().get(link.getFromNode().getId()), visNet.getNodes().get(link.getToNode().getId())); - l.setLength(link.getLength()); - l.setFreespeed(link.getFreespeed()); - l.setCapacity(link.getCapacity()); - l.setNumberOfLanes(link.getNumberOfLanes()); - } - - log.info("write routerNet.xml"); - new NetworkWriter(visNet).write("visNet.xml"); - - log.info("start visualizer"); - EventsManager events = EventsUtils.createEventsManager(); - QSim otfVisQSim = new QSimBuilder(visScenario.getConfig()).useDefaults().build(visScenario, events); - OnTheFlyServer server = OTFVis.startServerAndRegisterWithQSim(visScenario.getConfig(), visScenario, events, otfVisQSim); - OTFClientLive.run(visScenario.getConfig(), server); - otfVisQSim.run(); + throw new RuntimeException("this works no longer, sorry."); + + /* I commented this code out, as it directly refers to the old and inefficient TransitRouterImpl + which got removed at the Code Sprint 2023 in Berlin. // mrieser, 2023oct09 + */ + +// TransitRouterConfig transitRouterConfig = new TransitRouterConfig(this.scenario.getConfig().planCalcScore() +// , this.scenario.getConfig().plansCalcRoute(), this.scenario.getConfig().transitRouter(), +// this.scenario.getConfig().vspExperimental()); +// TransitRouterImpl router = new TransitRouterImpl(transitRouterConfig, this.scenario.getTransitSchedule() ); +// Network routerNet = router.getTransitRouterNetwork(); +// +// log.info("create vis network"); +// MutableScenario visScenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); +// Network visNet = visScenario.getNetwork(); +// +// for (Node node : routerNet.getNodes().values()) { +// visNet.getFactory().createNode(node.getId(), node.getCoord()); +// visNet.addNode(node); +// } +// for (Link link : routerNet.getLinks().values()) { +// Link l = visNet.getFactory().createLink(link.getId(), visNet.getNodes().get(link.getFromNode().getId()), visNet.getNodes().get(link.getToNode().getId())); +// l.setLength(link.getLength()); +// l.setFreespeed(link.getFreespeed()); +// l.setCapacity(link.getCapacity()); +// l.setNumberOfLanes(link.getNumberOfLanes()); +// } +// +// log.info("write routerNet.xml"); +// new NetworkWriter(visNet).write("visNet.xml"); +// +// log.info("start visualizer"); +// EventsManager events = EventsUtils.createEventsManager(); +// QSim otfVisQSim = new QSimBuilder(visScenario.getConfig()).useDefaults().build(visScenario, events); +// OnTheFlyServer server = OTFVis.startServerAndRegisterWithQSim(visScenario.getConfig(), visScenario, events, otfVisQSim); +// OTFClientLive.run(visScenario.getConfig(), server); +// otfVisQSim.run(); } private void buildUmlaeufe() { diff --git a/contribs/vsp/src/test/java/playground/vsp/pt/ptdisturbances/EditTripsTest.java b/contribs/vsp/src/test/java/playground/vsp/pt/ptdisturbances/EditTripsTest.java index d82509af72c..f5e1b690f99 100644 --- a/contribs/vsp/src/test/java/playground/vsp/pt/ptdisturbances/EditTripsTest.java +++ b/contribs/vsp/src/test/java/playground/vsp/pt/ptdisturbances/EditTripsTest.java @@ -158,7 +158,6 @@ public void testAgentLeavesStop() { HashMap, Double> arrivalTimes = new HashMap<>(); HashMap, List> trips = new HashMap<>(); Config config = ConfigUtils.loadConfig(configURL); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); String outputDirectory = utils.getOutputDirectory(); config.controler().setOutputDirectory(outputDirectory); Scenario scenario = ScenarioUtils.loadScenario(config); @@ -277,7 +276,6 @@ public void testAgentIsAtTeleportLegAndLeavesStop() { HashMap, Double> arrivalTimes = new HashMap<>(); HashMap, List> trips = new HashMap<>(); Config config = ConfigUtils.loadConfig(configURL); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); String outputDirectory = utils.getOutputDirectory(); config.controler().setOutputDirectory(outputDirectory); Scenario scenario = ScenarioUtils.loadScenario(config); @@ -356,7 +354,6 @@ public void testAgentIsAtTeleportLegAndWaitsAtStop() { HashMap, Double> arrivalTimes = new HashMap<>(); HashMap, List> trips = new HashMap<>(); Config config = ConfigUtils.loadConfig(configURL); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); String outputDirectory = utils.getOutputDirectory(); config.controler().setOutputDirectory(outputDirectory); Scenario scenario = ScenarioUtils.loadScenario(config); diff --git a/matsim/src/main/java/org/matsim/pt/config/TransitConfigGroup.java b/matsim/src/main/java/org/matsim/pt/config/TransitConfigGroup.java index 742ef7d945a..fa2be75da28 100644 --- a/matsim/src/main/java/org/matsim/pt/config/TransitConfigGroup.java +++ b/matsim/src/main/java/org/matsim/pt/config/TransitConfigGroup.java @@ -51,7 +51,7 @@ public class TransitConfigGroup extends ReflectiveConfigGroup { private static final String INSISTING_ON_USING_DEPRECATED_ATTRIBUTE_FILE = "insistingOnUsingDeprecatedAttributeFiles" ; private static final String USING_TRANSIT_IN_MOBSIM = "usingTransitInMobsim" ; - public enum TransitRoutingAlgorithmType {DijkstraBased, SwissRailRaptor} + public enum TransitRoutingAlgorithmType {@Deprecated DijkstraBased, SwissRailRaptor} public static final String TRANSIT_ATTRIBUTES_DEPRECATION_MESSAGE = "using the separate transit stops and lines attribute files is deprecated." + " Add the information directly into each stop or line, using " + @@ -67,7 +67,7 @@ public enum TransitRoutingAlgorithmType {DijkstraBased, SwissRailRaptor} private Set transitModes; private TransitRoutingAlgorithmType routingAlgorithmType = TransitRoutingAlgorithmType.SwissRailRaptor; - + // --- private static final String USE_TRANSIT = "useTransit"; private boolean useTransit = false; @@ -159,7 +159,7 @@ public Set getTransitModes() { public String getTransitLinesAttributesFile() { return transitLinesAttributesFile; } - + @StringSetter( TRANSIT_LINES_ATTRIBUTES ) public void setTransitLinesAttributesFile(final String transitLinesAttributesFile) { this.transitLinesAttributesFile = transitLinesAttributesFile; @@ -172,12 +172,12 @@ public String getTransitStopsAttributesFile() { public URL getTransitStopsAttributesFileURL(URL context) { return ConfigGroup.getInputFileURL(context, getTransitStopsAttributesFile()) ; } - + @StringSetter( TRANSIT_STOPS_ATTRIBUTES ) public void setTransitStopsAttributesFile(final String transitStopsAttributesFile) { this.transitStopsAttributesFile = transitStopsAttributesFile; } - + @StringGetter( USE_TRANSIT ) public boolean isUseTransit() { return this.useTransit; @@ -207,7 +207,7 @@ public String getInputScheduleCRS() { public void setInputScheduleCRS(String inputScheduleCRS) { this.inputScheduleCRS = inputScheduleCRS; } - + public static final String BOARDING_ACCEPTANCE_CMT="under which conditions agent boards transit vehicle" ; public enum BoardingAcceptance { checkLineAndStop, checkStopOnly } private BoardingAcceptance boardingAcceptance = BoardingAcceptance.checkLineAndStop ; @@ -217,7 +217,7 @@ public BoardingAcceptance getBoardingAcceptance() { public void setBoardingAcceptance(BoardingAcceptance boardingAcceptance) { this.boardingAcceptance = boardingAcceptance; } - + private boolean usingTransitInMobsim = true ; @StringSetter( USING_TRANSIT_IN_MOBSIM ) public final void setUsingTransitInMobsim( boolean val ) { diff --git a/matsim/src/main/java/org/matsim/pt/router/TransitLeastCostPathTree.java b/matsim/src/main/java/org/matsim/pt/router/TransitLeastCostPathTree.java index 92a8f0202e2..19bfbe2c2f1 100644 --- a/matsim/src/main/java/org/matsim/pt/router/TransitLeastCostPathTree.java +++ b/matsim/src/main/java/org/matsim/pt/router/TransitLeastCostPathTree.java @@ -47,9 +47,9 @@ import org.matsim.vehicles.Vehicle; /** - * This class is based on and similar to org.matsim.pt.router.MultiNodeDijkstra + * This class is based on and similar to org.matsim.contrib.eventsBasedPTRouter.MultiNodeDijkstra * - * In contrast to org.matsim.pt.router.MultiNodeDijkstra, however, it stores the last + * In contrast to org.matsim.contrib.eventsBasedPTRouter.MultiNodeDijkstra, however, it stores the last * LeastCostPathTree. It is, therefore, much faster than it, in cases where many routes * starting with the same fromNode are calculated subsequently as every route from that * fromCoord can be retrieved now without having to compute the tree again. @@ -531,4 +531,4 @@ protected DijkstraNodeData getData(final Node n) { return r; } -} \ No newline at end of file +} diff --git a/matsim/src/main/java/org/matsim/pt/router/TransitRouterImplFactory.java b/matsim/src/main/java/org/matsim/pt/router/TransitRouterImplFactory.java deleted file mode 100644 index 9842e1b09ac..00000000000 --- a/matsim/src/main/java/org/matsim/pt/router/TransitRouterImplFactory.java +++ /dev/null @@ -1,73 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * TransitRouterImplFactory.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2010 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.pt.router; - -import org.matsim.core.api.experimental.events.EventsManager; -import org.matsim.core.config.Config; -import org.matsim.pt.transitSchedule.api.TransitSchedule; - -import jakarta.inject.Inject; -import jakarta.inject.Provider; -import jakarta.inject.Singleton; - -/** - * @author mrieser - */ -@Singleton -public class TransitRouterImplFactory implements Provider { - - private final TransitRouterConfig config; - private final TransitSchedule transitSchedule; - private TransitRouterNetwork routerNetwork; - private PreparedTransitSchedule preparedTransitSchedule; - - @Inject - TransitRouterImplFactory(final TransitSchedule schedule, final EventsManager events, final Config config) { - this(schedule, new TransitRouterConfig( - config.planCalcScore(), - config.plansCalcRoute(), - config.transitRouter(), - config.vspExperimental())); - events.addHandler((TransitScheduleChangedEventHandler) event -> { - routerNetwork = null; - preparedTransitSchedule = null; - }); - } - - public TransitRouterImplFactory(final TransitSchedule schedule, final TransitRouterConfig config) { - this.config = config; - this.transitSchedule = schedule; - } - - @Override - public TransitRouter get() { - if (this.routerNetwork == null) { - this.routerNetwork = TransitRouterNetwork.createFromSchedule(transitSchedule, this.config.getBeelineWalkConnectionDistance()); - } - if (this.preparedTransitSchedule == null) { - this.preparedTransitSchedule = new PreparedTransitSchedule(transitSchedule); - } - - TransitRouterNetworkTravelTimeAndDisutility ttCalculator = new TransitRouterNetworkTravelTimeAndDisutility(this.config, this.preparedTransitSchedule); - return new TransitRouterImpl(this.config, this.preparedTransitSchedule, this.routerNetwork, ttCalculator, ttCalculator); - } - -} diff --git a/matsim/src/main/java/org/matsim/pt/router/TransitRouterModule.java b/matsim/src/main/java/org/matsim/pt/router/TransitRouterModule.java index ea6102825c8..95b724568f6 100644 --- a/matsim/src/main/java/org/matsim/pt/router/TransitRouterModule.java +++ b/matsim/src/main/java/org/matsim/pt/router/TransitRouterModule.java @@ -32,8 +32,7 @@ public void install() { if (getConfig().transit().isUseTransit()) { switch (getConfig().transit().getRoutingAlgorithmType()) { case DijkstraBased: - bind(TransitRouter.class).toProvider(TransitRouterImplFactory.class); - break; + throw new RuntimeException("'DijkstraBased' is no longer supported as a transit routing algorithm. Use 'SwissRailRaptor' instead."); case SwissRailRaptor: install(new SwissRailRaptorModule()); break; diff --git a/matsim/src/test/java/org/matsim/examples/simple/PtScoringTest.java b/matsim/src/test/java/org/matsim/examples/simple/PtScoringTest.java index b7a7551dfbd..90f70bfd755 100644 --- a/matsim/src/test/java/org/matsim/examples/simple/PtScoringTest.java +++ b/matsim/src/test/java/org/matsim/examples/simple/PtScoringTest.java @@ -18,7 +18,7 @@ * *********************************************************************** */ /** - * + * */ package org.matsim.examples.simple; @@ -58,18 +58,18 @@ public class PtScoringTest { @Parameter public TypicalDurationScoreComputation typicalDurationScoreComputation; - + @Parameterized.Parameters public static Object[] testParameters() { - return new Object[] {TypicalDurationScoreComputation.relative,TypicalDurationScoreComputation.uniform}; + return new Object[] {TypicalDurationScoreComputation.relative, TypicalDurationScoreComputation.uniform}; } - + @Rule public MatsimTestUtils utils = new MatsimTestUtils(); @Test public void test_PtScoringLineswitch() { Config config = this.utils.loadConfig(IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("pt-simple-lineswitch"), "config.xml")); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); + config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.SwissRailRaptor); PlanCalcScoreConfigGroup pcs = config.planCalcScore() ; if(this.typicalDurationScoreComputation.equals(TypicalDurationScoreComputation.uniform)){ @@ -77,7 +77,7 @@ public void test_PtScoringLineswitch() { params.setTypicalDurationScoreComputation(typicalDurationScoreComputation); } } - + pcs.setWriteExperiencedPlans(true); Controler controler = new Controler(config); @@ -99,7 +99,7 @@ public void test_PtScoringLineswitch() { double typicalDuration_s = pcs.getActivityParams("home").getTypicalDuration().seconds(); double priority = 1. ; - + // double zeroUtilityDurationHome_s = CharyparNagelScoringUtils.computeZeroUtilityDuration_s(priority, typicalDuration_s); ActivityUtilityParameters.Builder builder = new ActivityUtilityParameters.Builder( pcs.getActivityParams("home") ) ; ActivityUtilityParameters params = builder.build() ; @@ -130,7 +130,7 @@ public void test_PtScoringLineswitch() { double score = pcs.getModes().get(TransportMode.walk).getMarginalUtilityOfTraveling() * (stop1Arr-homeAct1End)/3600. ; System.out.println("score after walk: " + score ) ; - // (pt interaction activity) + // (pt interaction activity) System.out.println("score after pt interact: " + score ) ; // yyyy wait is not separately scored!! @@ -141,14 +141,14 @@ public void test_PtScoringLineswitch() { score += pcs.getModes().get(TransportMode.pt).getMarginalUtilityOfTraveling() * (leaveVeh-enterVeh)/3600. ; System.out.println("score after travel pt: " + score ) ; - // (pt interaction activity) + // (pt interaction activity) System.out.println("score after pt interact: " + score ) ; score += pcs.getModes().get(TransportMode.walk).getMarginalUtilityOfTraveling() * (home2Arr-ptIA2ActEnd)/3600. ; System.out.println("score after walk: " + score ) ; final double duration = homeAct2End-home2Arr; - double tmpScore = (pcs.getPerforming_utils_hr()/3600.) * typicalDuration_s + double tmpScore = (pcs.getPerforming_utils_hr()/3600.) * typicalDuration_s * Math.log(duration/zeroUtilityDurationHome_s) ; if ( tmpScore < 0 ) { System.out.println("home2score< 0; replacing ... ") ; @@ -163,7 +163,7 @@ public void test_PtScoringLineswitch() { score += pcs.getModes().get(TransportMode.walk).getMarginalUtilityOfTraveling() * (stop2Arr-homeAct2End)/3600. ; System.out.println("score after walk: " + score ) ; - // (pt interaction activity) + // (pt interaction activity) System.out.println("score after pt int act: " + score ) ; score += pcs.getModes().get(TransportMode.pt).getMarginalUtilityOfTraveling() * (enterVeh2-ptIA3ActEnd)/3600. ; @@ -172,7 +172,7 @@ public void test_PtScoringLineswitch() { score += pcs.getModes().get(TransportMode.pt).getMarginalUtilityOfTraveling() * (leaveVeh2-enterVeh2)/3600. ; System.out.println("score after travel pt: " + score ) ; - // (pt interaction activity) + // (pt interaction activity) System.out.println("score after pt int act: " + score ) ; score += pcs.getModes().get(TransportMode.walk).getMarginalUtilityOfTraveling() * (stop3Arr-ptIA4ActEnd)/3600. ; @@ -183,7 +183,7 @@ public void test_PtScoringLineswitch() { // ------ - // (pt interaction activity) + // (pt interaction activity) System.out.println("score after pt int act: " + score ) ; score += pcs.getModes().get(TransportMode.pt).getMarginalUtilityOfTraveling() * (enterVeh3-ptIA5ActEnd)/3600. ; @@ -192,13 +192,13 @@ public void test_PtScoringLineswitch() { score += pcs.getModes().get(TransportMode.pt).getMarginalUtilityOfTraveling() * (leaveVeh3-enterVeh3)/3600. ; System.out.println("score after travel pt: " + score ) ; - // (pt interaction activity) + // (pt interaction activity) System.out.println("score after pt int act: " + score ) ; score += pcs.getModes().get(TransportMode.walk).getMarginalUtilityOfTraveling() * (home3Arr-ptIA6ActEnd)/3600. ; System.out.println("score after walk: " + score ) ; - score += (pcs.getPerforming_utils_hr()/3600.) * typicalDuration_s + score += (pcs.getPerforming_utils_hr()/3600.) * typicalDuration_s * Math.log((homeAct1End-home3Arr+24.*3600)/zeroUtilityDurationHome_s) ; System.out.println("score after home act: " + score ) ; @@ -208,28 +208,28 @@ public void test_PtScoringLineswitch() { // (there is only one person, but we need to get it) System.out.println(" score: " + pp.getSelectedPlan().getScore() ) ; - + if(this.typicalDurationScoreComputation.equals(TypicalDurationScoreComputation.uniform)){ - Assert.assertEquals(-21.28929580072052, pp.getSelectedPlan().getScore(), MatsimTestUtils.EPSILON ) ; + Assert.assertEquals(-21.280962467387187, pp.getSelectedPlan().getScore(), MatsimTestUtils.EPSILON ) ; } else{ - Assert.assertEquals(27.46011565686209, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; + Assert.assertEquals(27.468448990195423, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; } - + } } @Test public void test_PtScoringLineswitchAndPtConstant() { Config config = this.utils.loadConfig(IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("pt-simple-lineswitch"), "config.xml")); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); + config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.SwissRailRaptor); PlanCalcScoreConfigGroup pcs = config.planCalcScore() ; if(this.typicalDurationScoreComputation.equals(TypicalDurationScoreComputation.uniform)) for(ActivityParams params : pcs.getActivityParams()){ params.setTypicalDurationScoreComputation(typicalDurationScoreComputation); } - + pcs.setWriteExperiencedPlans(true); pcs.getModes().get(TransportMode.pt).setConstant(1.); @@ -247,7 +247,7 @@ public void test_PtScoringLineswitchAndPtConstant() { for (Event event : allEvents) { System.out.println(event.toString()); } - + double typicalDuration_s = pcs.getActivityParams("home").getTypicalDuration().seconds(); double priority = 1. ; @@ -280,7 +280,7 @@ public void test_PtScoringLineswitchAndPtConstant() { double score = pcs.getModes().get(TransportMode.walk).getMarginalUtilityOfTraveling() * (stop1Arr-homeAct1End)/3600. ; System.out.println("score after walk: " + score ) ; - // (pt interaction activity) + // (pt interaction activity) System.out.println("score after pt interact: " + score ) ; score += pcs.getModes().get(TransportMode.pt).getConstant(); @@ -294,13 +294,13 @@ public void test_PtScoringLineswitchAndPtConstant() { score += pcs.getModes().get(TransportMode.pt).getMarginalUtilityOfTraveling() * (leaveVeh-enterVeh)/3600. ; System.out.println("score after travel pt: " + score ) ; - // (pt interaction activity) + // (pt interaction activity) System.out.println("score after pt interact: " + score ) ; score += pcs.getModes().get(TransportMode.walk).getMarginalUtilityOfTraveling() * (home2Arr-ptIA2ActEnd)/3600. ; System.out.println("score after walk: " + score ) ; - double tmpScore = (pcs.getPerforming_utils_hr()/3600.) * typicalDuration_s + double tmpScore = (pcs.getPerforming_utils_hr()/3600.) * typicalDuration_s * Math.log((homeAct2End-home2Arr)/zeroUtilityDurationHome_s) ; if ( tmpScore < 0 ) { System.out.println("home2score< 0; replacing ... ") ; @@ -315,7 +315,7 @@ public void test_PtScoringLineswitchAndPtConstant() { score += pcs.getModes().get(TransportMode.walk).getMarginalUtilityOfTraveling() * (stop2Arr-homeAct2End)/3600. ; System.out.println("score after walk: " + score ) ; - // (pt interaction activity) + // (pt interaction activity) System.out.println("score after pt int act: " + score ) ; score += pcs.getModes().get(TransportMode.pt).getConstant(); @@ -327,7 +327,7 @@ public void test_PtScoringLineswitchAndPtConstant() { score += pcs.getModes().get(TransportMode.pt).getMarginalUtilityOfTraveling() * (leaveVeh2-enterVeh2)/3600. ; System.out.println("score after travel pt: " + score ) ; - // (pt interaction activity) + // (pt interaction activity) System.out.println("score after pt int act: " + score ) ; score += pcs.getModes().get(TransportMode.walk).getMarginalUtilityOfTraveling() * (stop3Arr-ptIA4ActEnd)/3600. ; @@ -338,7 +338,7 @@ public void test_PtScoringLineswitchAndPtConstant() { // ------ - // (pt interaction activity) + // (pt interaction activity) System.out.println("score after pt int act: " + score ) ; score += pcs.getModes().get(TransportMode.pt).getMarginalUtilityOfTraveling() * (enterVeh3-ptIA5ActEnd)/3600. ; @@ -347,13 +347,13 @@ public void test_PtScoringLineswitchAndPtConstant() { score += pcs.getModes().get(TransportMode.pt).getMarginalUtilityOfTraveling() * (leaveVeh3-enterVeh3)/3600. ; System.out.println("score after travel pt: " + score ) ; - // (pt interaction activity) + // (pt interaction activity) System.out.println("score after pt int act: " + score ) ; score += pcs.getModes().get(TransportMode.walk).getMarginalUtilityOfTraveling() * (home3Arr-ptIA6ActEnd)/3600. ; System.out.println("score after walk: " + score ) ; - score += (pcs.getPerforming_utils_hr()/3600.) * typicalDuration_s + score += (pcs.getPerforming_utils_hr()/3600.) * typicalDuration_s * Math.log((homeAct1End-home3Arr+24.*3600)/zeroUtilityDurationHome_s) ; System.out.println("score after home act: " + score ) ; @@ -363,33 +363,33 @@ public void test_PtScoringLineswitchAndPtConstant() { // (there is only one person, but we need to get it) System.out.println(" score: " + pp.getSelectedPlan().getScore() ) ; - + if(this.typicalDurationScoreComputation.equals(TypicalDurationScoreComputation.uniform)){ // Assert.assertEquals(89.14608279715044, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; - Assert.assertEquals(-19.28929580072052, pp.getSelectedPlan().getScore(), MatsimTestUtils.EPSILON ) ; + Assert.assertEquals(-19.280962467387187, pp.getSelectedPlan().getScore(), MatsimTestUtils.EPSILON ) ; } else{ - Assert.assertEquals(29.46011565686209, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; + Assert.assertEquals(29.468448990195423, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; } - + } } @Test public void test_PtScoring_Wait() { Config config = this.utils.loadConfig(IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("pt-simple"), "config.xml")); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); + config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.SwissRailRaptor); PlanCalcScoreConfigGroup pcs = config.planCalcScore() ; - + if(this.typicalDurationScoreComputation.equals(TypicalDurationScoreComputation.uniform)){ for(ActivityParams params : pcs.getActivityParams()){ params.setTypicalDurationScoreComputation(typicalDurationScoreComputation); } } - + pcs.setWriteExperiencedPlans(true); pcs.setMarginalUtlOfWaitingPt_utils_hr(-18.0) ; - + Controler controler = new Controler(config); controler.getConfig().controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles); controler.getConfig().controler().setCreateGraphs(false); @@ -404,7 +404,7 @@ public void test_PtScoring_Wait() { for (Event event : allEvents) { System.out.println(event.toString()); } - + double typicalDuration_s = pcs.getActivityParams("home").getTypicalDuration().seconds(); double priority = 1. ; @@ -423,7 +423,7 @@ public void test_PtScoring_Wait() { double score = pcs.getModes().get(TransportMode.walk).getMarginalUtilityOfTraveling() * (timeTransitWalk/3600.) ; System.out.println("score: " + score ) ; - // (pt interaction activity) + // (pt interaction activity) System.out.println("score: " + score ) ; System.out.println("marginalUtlOfWaitPt: " + pcs.getMarginalUtlOfWaitingPt_utils_hr() ) ; @@ -436,7 +436,7 @@ public void test_PtScoring_Wait() { score += pcs.getModes().get(TransportMode.pt).getMarginalUtilityOfTraveling() * timeTransitInVeh/3600. ; System.out.println("score: " + score ) ; - // (pt interaction activity) + // (pt interaction activity) System.out.println("score: " + score ) ; score += pcs.getModes().get(TransportMode.walk).getMarginalUtilityOfTraveling() * timeTransitWalk2/3600. ; @@ -451,12 +451,12 @@ public void test_PtScoring_Wait() { // (there is only one person, but we need to get it) System.out.println("agent score: " + pp.getSelectedPlan().getScore() ) ; - + if(this.typicalDurationScoreComputation.equals(TypicalDurationScoreComputation.uniform)){ - Assert.assertEquals(89.14608279715044, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; + Assert.assertEquals(89.13108279715044, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; } else{ - Assert.assertEquals(137.14608279715043, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; + Assert.assertEquals(137.1310827971504, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; } } @@ -465,14 +465,14 @@ public void test_PtScoring_Wait() { @Test public void test_PtScoring() { Config config = this.utils.loadConfig(IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("pt-simple"), "config.xml")); - config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.DijkstraBased); + config.transit().setRoutingAlgorithmType(TransitRoutingAlgorithmType.SwissRailRaptor); PlanCalcScoreConfigGroup pcs = config.planCalcScore() ; if(this.typicalDurationScoreComputation.equals(TypicalDurationScoreComputation.uniform)) for(ActivityParams params : pcs.getActivityParams()){ params.setTypicalDurationScoreComputation(typicalDurationScoreComputation); } - + pcs.setWriteExperiencedPlans(true); Controler controler = new Controler(config); @@ -508,7 +508,7 @@ public void test_PtScoring() { double score = pcs.getModes().get(TransportMode.walk).getMarginalUtilityOfTraveling() * (timeTransitWalk/3600.) ; System.out.println("score: " + score ) ; - // (pt interaction activity) + // (pt interaction activity) System.out.println("score: " + score ) ; // score += pcs.getMarginalUtlOfWaitingPt_utils_hr() * timeTransitWait/3600. ; @@ -519,7 +519,7 @@ public void test_PtScoring() { score += pcs.getModes().get(TransportMode.pt).getMarginalUtilityOfTraveling() * timeTransitInVeh/3600. ; System.out.println("score: " + score ) ; - // (pt interaction activity) + // (pt interaction activity) System.out.println("score: " + score ) ; score += pcs.getModes().get(TransportMode.walk).getMarginalUtilityOfTraveling() * timeTransitWalk2/3600. ; @@ -534,15 +534,15 @@ public void test_PtScoring() { // (there is only one person, but we need to get it) System.out.println(" score: " + pp.getSelectedPlan().getScore() ) ; - + if(this.typicalDurationScoreComputation.equals(TypicalDurationScoreComputation.uniform)){ - Assert.assertEquals(89.85608279715044, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; + Assert.assertEquals(89.87441613048377, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; } else{ - Assert.assertEquals(137.85608279715044, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; + Assert.assertEquals(137.87441613048375, pp.getSelectedPlan().getScore(),MatsimTestUtils.EPSILON ) ; } - - + + } } diff --git a/matsim/src/test/java/org/matsim/pt/router/AdaptedTransitRouterNetworkTravelTimeCostTest.java b/matsim/src/test/java/org/matsim/pt/router/AdaptedTransitRouterNetworkTravelTimeCostTest.java deleted file mode 100644 index f4eacd02b10..00000000000 --- a/matsim/src/test/java/org/matsim/pt/router/AdaptedTransitRouterNetworkTravelTimeCostTest.java +++ /dev/null @@ -1,217 +0,0 @@ -/* *********************************************************************** * - * project: org.matsim.* - * TransitRouterNetworkTravelTimeCostTest.java - * * - * *********************************************************************** * - * * - * copyright : (C) 2009 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.pt.router; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.matsim.pt.router.TransitRouterNetwork.TransitRouterNetworkLink; -import org.matsim.testcases.MatsimTestUtils; - -/** - * Tests that specifically look at the computation of the out-of-vehicle wait time. There is overlap with the original tests; it is most - * probably possible to combine/condense them. - *

- * Comments: