From 235fe65b5bce13bafe963af4126cb553c8296917 Mon Sep 17 00:00:00 2001 From: nixlaos Date: Wed, 12 Jul 2023 14:33:33 +0200 Subject: [PATCH 01/13] added converters for missing freight events --- .../freight/events/CarrierEventsReaders.java | 7 ++++++- .../freight/events/CarrierServiceEndEvent.java | 15 +++++++++++++++ .../freight/events/CarrierServiceStartEvent.java | 16 ++++++++++++++++ .../events/CarrierShipmentDeliveryEndEvent.java | 16 ++++++++++++++++ .../CarrierShipmentDeliveryStartEvent.java | 16 ++++++++++++++++ .../events/CarrierShipmentPickupEndEvent.java | 16 ++++++++++++++++ .../events/CarrierShipmentPickupStartEvent.java | 16 ++++++++++++++++ 7 files changed, 101 insertions(+), 1 deletion(-) diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierEventsReaders.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierEventsReaders.java index c268d7d1184..20eb9dad5a8 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierEventsReaders.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierEventsReaders.java @@ -36,9 +36,14 @@ public class CarrierEventsReaders { public static Map createCustomEventMappers() { return Map.of( + CarrierServiceStartEvent.EVENT_TYPE, CarrierServiceStartEvent::convert, + CarrierServiceEndEvent.EVENT_TYPE, CarrierServiceEndEvent::convert, + CarrierShipmentDeliveryStartEvent.EVENT_TYPE, CarrierShipmentDeliveryStartEvent::convert, + CarrierShipmentDeliveryEndEvent.EVENT_TYPE, CarrierShipmentDeliveryEndEvent::convert, + CarrierShipmentPickupStartEvent.EVENT_TYPE, CarrierShipmentPickupStartEvent::convert, + CarrierShipmentPickupEndEvent.EVENT_TYPE, CarrierShipmentPickupEndEvent::convert, CarrierTourStartEvent.EVENT_TYPE, CarrierTourStartEvent::convert, // CarrierTourEndEvent.EVENT_TYPE, CarrierTourEndEvent::convert - // more will follow later, KMT feb'23 ); } diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierServiceEndEvent.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierServiceEndEvent.java index e1527edc9b0..0c4585932a0 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierServiceEndEvent.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierServiceEndEvent.java @@ -24,6 +24,8 @@ import java.util.Map; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.events.GenericEvent; +import org.matsim.api.core.v01.network.Link; import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierService; import org.matsim.vehicles.Vehicle; @@ -67,4 +69,17 @@ public Map getAttributes() { attr.put(ATTRIBUTE_SERVICE_DURATION, String.valueOf(serviceDuration)); return attr; } + + public static CarrierServiceEndEvent convert(GenericEvent event) { + Map attributes = event.getAttributes(); + double time = Double.parseDouble(attributes.get(ATTRIBUTE_TIME)); + Id carrierId = Id.create(attributes.get(ATTRIBUTE_CARRIER_ID), Carrier.class); + Id carrierServiceId = Id.create(attributes.get(ATTRIBUTE_SERVICE_ID), CarrierService.class); + Id locationLinkId = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); + CarrierService service = CarrierService.Builder.newInstance(carrierServiceId, locationLinkId) + .setServiceDuration(Double.parseDouble(attributes.get(ATTRIBUTE_SERVICE_DURATION))) + .build(); + Id vehicleId = Id.create(attributes.get(ATTRIBUTE_VEHICLE), Vehicle.class); + return new CarrierServiceEndEvent(time, carrierId, service, vehicleId); + } } diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierServiceStartEvent.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierServiceStartEvent.java index 719bfc96978..6c8550df63f 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierServiceStartEvent.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierServiceStartEvent.java @@ -22,6 +22,8 @@ package org.matsim.contrib.freight.events; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.events.GenericEvent; +import org.matsim.api.core.v01.network.Link; import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierService; import org.matsim.vehicles.Vehicle; @@ -77,4 +79,18 @@ public Map getAttributes() { attr.put(ATTRIBUTE_CAPACITYDEMAND, String.valueOf(capacityDemand)); return attr; } + + public static CarrierServiceStartEvent convert(GenericEvent event) { + Map attributes = event.getAttributes(); + double time = Double.parseDouble(attributes.get(ATTRIBUTE_TIME)); + Id carrierId = Id.create(attributes.get(ATTRIBUTE_CARRIER_ID), Carrier.class); + Id carrierServiceId = Id.create(attributes.get(ATTRIBUTE_SERVICE_ID), CarrierService.class); + Id locationLinkId = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); + CarrierService service = CarrierService.Builder.newInstance(carrierServiceId, locationLinkId) + .setServiceDuration(Double.parseDouble(attributes.get(ATTRIBUTE_SERVICE_DURATION))) + .setCapacityDemand(Integer.parseInt(attributes.get(ATTRIBUTE_CAPACITYDEMAND))) + .build(); + Id vehicleId = Id.create(attributes.get(ATTRIBUTE_VEHICLE), Vehicle.class); + return new CarrierServiceStartEvent(time, carrierId, service, vehicleId); + } } diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentDeliveryEndEvent.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentDeliveryEndEvent.java index 9e702f3359d..eb462b77a88 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentDeliveryEndEvent.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentDeliveryEndEvent.java @@ -22,6 +22,8 @@ package org.matsim.contrib.freight.events; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.events.GenericEvent; +import org.matsim.api.core.v01.network.Link; import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierShipment; import org.matsim.vehicles.Vehicle; @@ -76,4 +78,18 @@ public Map getAttributes() { return attr; } + public static CarrierShipmentDeliveryEndEvent convert(GenericEvent event) { + var attributes = event.getAttributes(); + double time = Double.parseDouble(attributes.get(ATTRIBUTE_TIME)); + Id carrierId = Id.create(attributes.get(ATTRIBUTE_CARRIER_ID), Carrier.class); + Id shipmentId = Id.create(attributes.get(ATTRIBUTE_SHIPMENT_ID), CarrierShipment.class); + Id shipmentTo = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); + int size = Integer.parseInt(attributes.get(ATTRIBUTE_CAPACITYDEMAND)); + CarrierShipment shipment = CarrierShipment.Builder.newInstance(shipmentId, null, shipmentTo, size) + .setDeliveryServiceTime(Double.parseDouble(attributes.get(ATTRIBUTE_SERVICE_DURATION))) + .build(); + Id vehicleId = Id.createVehicleId(attributes.get(ATTRIBUTE_VEHICLE)); + return new CarrierShipmentDeliveryEndEvent(time, carrierId, shipment, vehicleId); + } + } diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentDeliveryStartEvent.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentDeliveryStartEvent.java index 6e097bbe64d..08b77671842 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentDeliveryStartEvent.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentDeliveryStartEvent.java @@ -22,6 +22,8 @@ package org.matsim.contrib.freight.events; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.events.GenericEvent; +import org.matsim.api.core.v01.network.Link; import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierShipment; import org.matsim.vehicles.Vehicle; @@ -75,4 +77,18 @@ public Map getAttributes() { return attr; } + public static CarrierShipmentDeliveryStartEvent convert(GenericEvent event) { + var attributes = event.getAttributes(); + double time = Double.parseDouble(attributes.get(ATTRIBUTE_TIME)); + Id carrierId = Id.create(attributes.get(ATTRIBUTE_CARRIER_ID), Carrier.class); + Id shipmentId = Id.create(attributes.get(ATTRIBUTE_SHIPMENT_ID), CarrierShipment.class); + Id shipmentTo = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); + int size = Integer.parseInt(attributes.get(ATTRIBUTE_CAPACITYDEMAND)); + CarrierShipment shipment = CarrierShipment.Builder.newInstance(shipmentId, null, shipmentTo, size) + .setDeliveryServiceTime(Double.parseDouble(attributes.get(ATTRIBUTE_SERVICE_DURATION))) + .build(); + Id vehicleId = Id.createVehicleId(attributes.get(ATTRIBUTE_VEHICLE)); + return new CarrierShipmentDeliveryStartEvent(time, carrierId, shipment, vehicleId); + } + } diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentPickupEndEvent.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentPickupEndEvent.java index 664dbfa45c7..e88ead0cb37 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentPickupEndEvent.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentPickupEndEvent.java @@ -22,6 +22,8 @@ package org.matsim.contrib.freight.events; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.events.GenericEvent; +import org.matsim.api.core.v01.network.Link; import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierShipment; import org.matsim.vehicles.Vehicle; @@ -69,4 +71,18 @@ public Map getAttributes() { attr.put(ATTRIBUTE_CAPACITYDEMAND, String.valueOf(capacityDemand)); return attr; } + + public static CarrierShipmentPickupEndEvent convert(GenericEvent event) { + Map attributes = event.getAttributes(); + double time = Double.parseDouble(attributes.get(ATTRIBUTE_TIME)); + Id carrierId = Id.create(attributes.get(ATTRIBUTE_CARRIER_ID), Carrier.class); + Id shipmentId = Id.create(attributes.get(ATTRIBUTE_SHIPMENT_ID), CarrierShipment.class); + Id shipmentFrom = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); + int shipmentSize = Integer.parseInt(attributes.get(ATTRIBUTE_CAPACITYDEMAND)); + CarrierShipment shipment = CarrierShipment.Builder.newInstance(shipmentId, shipmentFrom, null, shipmentSize) + .setPickupServiceTime(Double.parseDouble(attributes.get(ATTRIBUTE_PICKUP_DURATION))) + .build(); + Id vehicleId = Id.createVehicleId(attributes.get(ATTRIBUTE_VEHICLE)); + return new CarrierShipmentPickupEndEvent(time, carrierId, shipment, vehicleId); + } } diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentPickupStartEvent.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentPickupStartEvent.java index 7285434d134..4f7725e6ece 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentPickupStartEvent.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/CarrierShipmentPickupStartEvent.java @@ -22,6 +22,8 @@ package org.matsim.contrib.freight.events; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.events.GenericEvent; +import org.matsim.api.core.v01.network.Link; import org.matsim.contrib.freight.carrier.Carrier; import org.matsim.contrib.freight.carrier.CarrierShipment; import org.matsim.vehicles.Vehicle; @@ -69,4 +71,18 @@ public Map getAttributes() { attr.put(ATTRIBUTE_CAPACITYDEMAND, String.valueOf(capacityDemand)); return attr; } + + public static CarrierShipmentPickupStartEvent convert(GenericEvent event) { + Map attributes = event.getAttributes(); + double time = Double.parseDouble(attributes.get(ATTRIBUTE_TIME)); + Id carrierId = Id.create(attributes.get(ATTRIBUTE_CARRIER_ID), Carrier.class); + Id shipmentId = Id.create(attributes.get(ATTRIBUTE_SHIPMENT_ID), CarrierShipment.class); + Id shipmentFrom = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); + int shipmentSize = Integer.parseInt(attributes.get(ATTRIBUTE_CAPACITYDEMAND)); + CarrierShipment shipment = CarrierShipment.Builder.newInstance(shipmentId, shipmentFrom, null, shipmentSize) + .setPickupServiceTime(Double.parseDouble(attributes.get(ATTRIBUTE_PICKUP_DURATION))) + .build(); + Id vehicleId = Id.createVehicleId(attributes.get(ATTRIBUTE_VEHICLE)); + return new CarrierShipmentPickupStartEvent(time, carrierId, shipment, vehicleId); + } } From 2ef28130513920e0c6a673c810d2a09f3f12764b Mon Sep 17 00:00:00 2001 From: nixlaos Date: Tue, 8 Aug 2023 16:14:51 +0200 Subject: [PATCH 02/13] 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 5e50d86826d9a0a6bb2dcc6a53e6ced8d88c8999 Mon Sep 17 00:00:00 2001 From: nixlaos Date: Thu, 5 Oct 2023 10:55:26 +0200 Subject: [PATCH 03/13] 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 32142fce553b3397eb3f3caec202cb035ace2d01 Mon Sep 17 00:00:00 2001 From: nixlaos Date: Mon, 16 Oct 2023 11:50:07 +0200 Subject: [PATCH 04/13] completing Test for CarrierEventsReaders --- .../carrier/CarrierEventsReadersTest.java | 79 ++++++++++++------- 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/contribs/freight/src/test/java/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest.java b/contribs/freight/src/test/java/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest.java index 43509b23a37..a299877ec30 100644 --- a/contribs/freight/src/test/java/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest.java +++ b/contribs/freight/src/test/java/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest.java @@ -2,14 +2,18 @@ import org.junit.Rule; import org.junit.Test; -import org.matsim.contrib.freight.events.CarrierEventsReaders; +import org.matsim.contrib.freight.events.*; import org.matsim.core.api.experimental.events.EventsManager; +import org.matsim.core.config.groups.ControlerConfigGroup; import org.matsim.core.events.EventsUtils; -import org.matsim.core.events.MatsimEventsReader; +import org.matsim.core.events.algorithms.EventWriterXML; import org.matsim.testcases.MatsimTestUtils; import org.matsim.testcases.utils.EventsCollector; -import static org.junit.Assert.assertEquals; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import static org.assertj.core.api.Assertions.*; public class CarrierEventsReadersTest { @@ -18,37 +22,58 @@ public class CarrierEventsReadersTest { @Test public void testWriteReadServiceBasedEvents() { - EventsManager eventsManager = EventsUtils.createEventsManager(); - EventsCollector collector = new EventsCollector(); - MatsimEventsReader carrierEventsReaders = CarrierEventsReaders.createEventsReader(eventsManager); + EventsManager eventsManager1 = EventsUtils.createEventsManager(); + EventsManager eventsManager2 = EventsUtils.createEventsManager(); + EventsCollector collector1 = new EventsCollector(); + EventsCollector collector2 = new EventsCollector(); + + eventsManager1.addHandler(collector1); + eventsManager1.initProcessing(); + CarrierEventsReaders.createEventsReader(eventsManager1) + .readFile(utils.getClassInputDirectory() + "serviceBasedEvents.xml"); + eventsManager1.finishProcessing(); - eventsManager.addHandler(collector); - eventsManager.initProcessing(); - carrierEventsReaders.readFile(utils.getClassInputDirectory() + "serviceBasedEvents.xml"); - eventsManager.finishProcessing(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + EventWriterXML writer = new EventWriterXML(outputStream); + collector1.getEvents().forEach(writer::handleEvent); + writer.closeFile(); - //Hier müsste dann wohl "serviceBasedEventsWritten.xml" geschrieben werden und dann auch nochmal der eventsManager für die ausgeschriebene Datei durchlaufen werden + eventsManager2.addHandler(collector2); + eventsManager2.initProcessing(); + CarrierEventsReaders.createEventsReader(eventsManager2) + .readStream(new ByteArrayInputStream(outputStream.toByteArray()), ControlerConfigGroup.EventsFileFormat.xml); + eventsManager2.finishProcessing(); - assertEquals("number of events should be same", collector.getEvents().size(), collector.getEvents().size()); - MatsimTestUtils.assertEqualEventsFiles(utils.getClassInputDirectory() + "serviceBasedEvents.xml", utils.getClassInputDirectory() + "serviceBasedEventsWritten.xml"); - MatsimTestUtils.assertEqualFilesLineByLine(utils.getClassInputDirectory() + "serviceBasedEvents.xml", utils.getClassInputDirectory() + "serviceBasedEventsWritten.xml"); + assertThat(collector1.getEvents()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyElementsOf(collector2.getEvents()); } @Test public void testWriteReadShipmentBasedEvents() { - EventsManager eventsManager = EventsUtils.createEventsManager(); - EventsCollector collector = new EventsCollector(); - MatsimEventsReader carrierEventsReaders = CarrierEventsReaders.createEventsReader(eventsManager); - - eventsManager.addHandler(collector); - eventsManager.initProcessing(); - carrierEventsReaders.readFile(utils.getClassInputDirectory() + "shipmentBasedEvents.xml"); - eventsManager.finishProcessing(); - - assertEquals("number of events should be same", collector.getEvents().size(), collector.getEvents().size()); - MatsimTestUtils.assertEqualEventsFiles(utils.getClassInputDirectory() + "shipmentBasedEvents.xml", utils.getClassInputDirectory() + "shipmentBasedEventsWritten.xml"); - MatsimTestUtils.assertEqualFilesLineByLine(utils.getClassInputDirectory() + "shipmentBasedEvents.xml", utils.getClassInputDirectory() + "shipmentBasedEventsWritten.xml"); - } + EventsManager eventsManager1 = EventsUtils.createEventsManager(); + EventsManager eventsManager2 = EventsUtils.createEventsManager(); + EventsCollector collector1 = new EventsCollector(); + EventsCollector collector2 = new EventsCollector(); + + eventsManager1.addHandler(collector1); + eventsManager1.initProcessing(); + CarrierEventsReaders.createEventsReader(eventsManager1) + .readFile(utils.getClassInputDirectory() + "shipmentBasedEvents.xml"); + eventsManager1.finishProcessing(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + EventWriterXML writer = new EventWriterXML(outputStream); + collector1.getEvents().forEach(writer::handleEvent); + writer.closeFile(); + + eventsManager2.addHandler(collector2); + eventsManager2.initProcessing(); + CarrierEventsReaders.createEventsReader(eventsManager2) + .readStream(new ByteArrayInputStream(outputStream.toByteArray()), ControlerConfigGroup.EventsFileFormat.xml); + eventsManager2.finishProcessing(); + + assertThat(collector1.getEvents()).usingRecursiveFieldByFieldElementComparator() + .containsExactlyElementsOf(collector2.getEvents()); + } } From 2f25c7a5b7a23f57466784896cb5458cae540604 Mon Sep 17 00:00:00 2001 From: nixlaos Date: Mon, 16 Oct 2023 11:52:33 +0200 Subject: [PATCH 05/13] add missing interfaces for freight events, minor renames --- ...eightShipmentDeliveryEndEventHandler.java} | 4 +- ...ightShipmentDeliveryStartEventHandler.java | 37 +++++++++++++++++++ ...FreightShipmentPickupEndEventHandler.java} | 4 +- ...reightShipmentPickupStartEventHandler.java | 35 ++++++++++++++++++ .../analysis/FreightAnalysisEventHandler.java | 6 +-- .../MyShipmentTrackerEventHandler.java | 8 ++-- 6 files changed, 83 insertions(+), 11 deletions(-) rename contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/{FreightShipmentDeliveryEventHandler.java => FreightShipmentDeliveryEndEventHandler.java} (92%) create mode 100644 contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java rename contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/{FreightShipmentPickupEventHandler.java => FreightShipmentPickupEndEventHandler.java} (92%) create mode 100644 contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupStartEventHandler.java diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEventHandler.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java similarity index 92% rename from contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEventHandler.java rename to contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java index c3560daf9c5..f6c7565a5e1 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java @@ -25,12 +25,12 @@ import org.matsim.core.events.handler.EventHandler; /** - * Interface to listen to shipmentDeliveredEvents. + * Interface to listen to shipmentDeliveryEndEvents. * * @author sschroeder * */ -public interface FreightShipmentDeliveryEventHandler extends EventHandler { +public interface FreightShipmentDeliveryEndEventHandler extends EventHandler { void handleEvent(CarrierShipmentDeliveryEndEvent event); diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java new file mode 100644 index 00000000000..05d6c7cf122 --- /dev/null +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java @@ -0,0 +1,37 @@ +/* + * *********************************************************************** * + * project: org.matsim.* + * *********************************************************************** * + * * + * copyright : (C) by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** + * + */ + +package org.matsim.contrib.freight.events.eventhandler; + +import org.matsim.contrib.freight.events.CarrierShipmentDeliveryStartEvent; +import org.matsim.core.events.handler.EventHandler; + +/** + * Interface to listen to shipmentDeliveryStartEvents. + * + * @author nrichter + * + */ +public interface FreightShipmentDeliveryStartEventHandler extends EventHandler { + + void handleEvent(CarrierShipmentDeliveryStartEvent event); + +} diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEventHandler.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEndEventHandler.java similarity index 92% rename from contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEventHandler.java rename to contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEndEventHandler.java index 43f0671150e..ce0155ab05c 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEndEventHandler.java @@ -25,11 +25,11 @@ import org.matsim.core.events.handler.EventHandler; /** - * Interface to listen to shipmentPickedUpEvents. + * Interface to listen to shipmentPickedUpEndEvents. * * @author sschroeder * */ -public interface FreightShipmentPickupEventHandler extends EventHandler { +public interface FreightShipmentPickupEndEventHandler extends EventHandler { void handleEvent(CarrierShipmentPickupEndEvent event); } diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupStartEventHandler.java new file mode 100644 index 00000000000..516fbf3bf2c --- /dev/null +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupStartEventHandler.java @@ -0,0 +1,35 @@ +/* + * *********************************************************************** * + * project: org.matsim.* + * *********************************************************************** * + * * + * copyright : (C) by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** + * + */ + +package org.matsim.contrib.freight.events.eventhandler; + +import org.matsim.contrib.freight.events.CarrierShipmentPickupStartEvent; +import org.matsim.core.events.handler.EventHandler; + +/** + * Interface to listen to shipmentPickedUpStartEvents. + * + * @author nrichter + * + */ +public interface FreightShipmentPickupStartEventHandler extends EventHandler { + void handleEvent(CarrierShipmentPickupStartEvent event); +} diff --git a/contribs/vsp/src/main/java/org/matsim/contrib/freight/analysis/FreightAnalysisEventHandler.java b/contribs/vsp/src/main/java/org/matsim/contrib/freight/analysis/FreightAnalysisEventHandler.java index 15a0dd00702..cfe72166273 100644 --- a/contribs/vsp/src/main/java/org/matsim/contrib/freight/analysis/FreightAnalysisEventHandler.java +++ b/contribs/vsp/src/main/java/org/matsim/contrib/freight/analysis/FreightAnalysisEventHandler.java @@ -38,8 +38,8 @@ import org.matsim.contrib.freight.events.CarrierShipmentPickupEndEvent; import org.matsim.contrib.freight.events.eventhandler.FreightServiceEndEventHandler; import org.matsim.contrib.freight.events.eventhandler.FreightServiceStartEventHandler; -import org.matsim.contrib.freight.events.eventhandler.FreightShipmentDeliveryEventHandler; -import org.matsim.contrib.freight.events.eventhandler.FreightShipmentPickupEventHandler; +import org.matsim.contrib.freight.events.eventhandler.FreightShipmentDeliveryEndEventHandler; +import org.matsim.contrib.freight.events.eventhandler.FreightShipmentPickupEndEventHandler; import org.matsim.core.network.NetworkUtils; import org.matsim.core.utils.io.UncheckedIOException; import org.matsim.vehicles.Vehicle; @@ -59,7 +59,7 @@ * */ @Deprecated(since = "apr23") -class FreightAnalysisEventHandler implements ActivityStartEventHandler, LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, FreightShipmentPickupEventHandler, FreightShipmentDeliveryEventHandler, FreightServiceStartEventHandler, FreightServiceEndEventHandler { +class FreightAnalysisEventHandler implements ActivityStartEventHandler, LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, FreightShipmentPickupEndEventHandler, FreightShipmentDeliveryEndEventHandler, FreightServiceStartEventHandler, FreightServiceEndEventHandler { private final static Logger log = LogManager.getLogger(FreightAnalysisEventHandler.class); private final Vehicles vehicles; diff --git a/contribs/vsp/src/test/java/org/matsim/contrib/freight/analysis/MyShipmentTrackerEventHandler.java b/contribs/vsp/src/test/java/org/matsim/contrib/freight/analysis/MyShipmentTrackerEventHandler.java index 6b2409d7e3d..7600629ffe0 100644 --- a/contribs/vsp/src/test/java/org/matsim/contrib/freight/analysis/MyShipmentTrackerEventHandler.java +++ b/contribs/vsp/src/test/java/org/matsim/contrib/freight/analysis/MyShipmentTrackerEventHandler.java @@ -8,11 +8,11 @@ import org.matsim.contrib.freight.carrier.Carriers; import org.matsim.contrib.freight.events.CarrierShipmentDeliveryEndEvent; import org.matsim.contrib.freight.events.CarrierShipmentPickupEndEvent; -import org.matsim.contrib.freight.events.eventhandler.FreightShipmentDeliveryEventHandler; -import org.matsim.contrib.freight.events.eventhandler.FreightShipmentPickupEventHandler; +import org.matsim.contrib.freight.events.eventhandler.FreightShipmentDeliveryEndEventHandler; +import org.matsim.contrib.freight.events.eventhandler.FreightShipmentPickupEndEventHandler; import org.matsim.vehicles.Vehicles; -public class MyShipmentTrackerEventHandler implements ActivityStartEventHandler, FreightShipmentPickupEventHandler, FreightShipmentDeliveryEventHandler { +public class MyShipmentTrackerEventHandler implements ActivityStartEventHandler, FreightShipmentPickupEndEventHandler, FreightShipmentDeliveryEndEventHandler { private final Vehicles vehicles; private final Network network; @@ -48,7 +48,7 @@ public void handleEvent(CarrierShipmentPickupEndEvent event) { @Override public void reset(int iteration) { - FreightShipmentPickupEventHandler.super.reset(iteration); + FreightShipmentPickupEndEventHandler.super.reset(iteration); } @Override From cb17bf4891d9cf1d41a8401d921064bebf6d78f0 Mon Sep 17 00:00:00 2001 From: nixlaos Date: Mon, 16 Oct 2023 11:57:59 +0200 Subject: [PATCH 06/13] Revert "add missing interfaces for freight events, minor renames" This reverts commit 2f25c7a5b7a23f57466784896cb5458cae540604. --- ... FreightShipmentDeliveryEventHandler.java} | 4 +- ...ightShipmentDeliveryStartEventHandler.java | 37 ------------------- ...=> FreightShipmentPickupEventHandler.java} | 4 +- ...reightShipmentPickupStartEventHandler.java | 35 ------------------ .../analysis/FreightAnalysisEventHandler.java | 6 +-- .../MyShipmentTrackerEventHandler.java | 8 ++-- 6 files changed, 11 insertions(+), 83 deletions(-) rename contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/{FreightShipmentDeliveryEndEventHandler.java => FreightShipmentDeliveryEventHandler.java} (92%) delete mode 100644 contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java rename contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/{FreightShipmentPickupEndEventHandler.java => FreightShipmentPickupEventHandler.java} (92%) delete mode 100644 contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupStartEventHandler.java diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEventHandler.java similarity index 92% rename from contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java rename to contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEventHandler.java index f6c7565a5e1..c3560daf9c5 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryEventHandler.java @@ -25,12 +25,12 @@ import org.matsim.core.events.handler.EventHandler; /** - * Interface to listen to shipmentDeliveryEndEvents. + * Interface to listen to shipmentDeliveredEvents. * * @author sschroeder * */ -public interface FreightShipmentDeliveryEndEventHandler extends EventHandler { +public interface FreightShipmentDeliveryEventHandler extends EventHandler { void handleEvent(CarrierShipmentDeliveryEndEvent event); diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java deleted file mode 100644 index 05d6c7cf122..00000000000 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * *********************************************************************** * - * project: org.matsim.* - * *********************************************************************** * - * * - * copyright : (C) by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** - * - */ - -package org.matsim.contrib.freight.events.eventhandler; - -import org.matsim.contrib.freight.events.CarrierShipmentDeliveryStartEvent; -import org.matsim.core.events.handler.EventHandler; - -/** - * Interface to listen to shipmentDeliveryStartEvents. - * - * @author nrichter - * - */ -public interface FreightShipmentDeliveryStartEventHandler extends EventHandler { - - void handleEvent(CarrierShipmentDeliveryStartEvent event); - -} diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEndEventHandler.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEventHandler.java similarity index 92% rename from contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEndEventHandler.java rename to contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEventHandler.java index ce0155ab05c..43f0671150e 100644 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEndEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupEventHandler.java @@ -25,11 +25,11 @@ import org.matsim.core.events.handler.EventHandler; /** - * Interface to listen to shipmentPickedUpEndEvents. + * Interface to listen to shipmentPickedUpEvents. * * @author sschroeder * */ -public interface FreightShipmentPickupEndEventHandler extends EventHandler { +public interface FreightShipmentPickupEventHandler extends EventHandler { void handleEvent(CarrierShipmentPickupEndEvent event); } diff --git a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupStartEventHandler.java deleted file mode 100644 index 516fbf3bf2c..00000000000 --- a/contribs/freight/src/main/java/org/matsim/contrib/freight/events/eventhandler/FreightShipmentPickupStartEventHandler.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * *********************************************************************** * - * project: org.matsim.* - * *********************************************************************** * - * * - * copyright : (C) by the members listed in the COPYING, * - * LICENSE and WARRANTY file. * - * email : info at matsim dot org * - * * - * *********************************************************************** * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * See also COPYING, LICENSE and WARRANTY file * - * * - * *********************************************************************** - * - */ - -package org.matsim.contrib.freight.events.eventhandler; - -import org.matsim.contrib.freight.events.CarrierShipmentPickupStartEvent; -import org.matsim.core.events.handler.EventHandler; - -/** - * Interface to listen to shipmentPickedUpStartEvents. - * - * @author nrichter - * - */ -public interface FreightShipmentPickupStartEventHandler extends EventHandler { - void handleEvent(CarrierShipmentPickupStartEvent event); -} diff --git a/contribs/vsp/src/main/java/org/matsim/contrib/freight/analysis/FreightAnalysisEventHandler.java b/contribs/vsp/src/main/java/org/matsim/contrib/freight/analysis/FreightAnalysisEventHandler.java index cfe72166273..15a0dd00702 100644 --- a/contribs/vsp/src/main/java/org/matsim/contrib/freight/analysis/FreightAnalysisEventHandler.java +++ b/contribs/vsp/src/main/java/org/matsim/contrib/freight/analysis/FreightAnalysisEventHandler.java @@ -38,8 +38,8 @@ import org.matsim.contrib.freight.events.CarrierShipmentPickupEndEvent; import org.matsim.contrib.freight.events.eventhandler.FreightServiceEndEventHandler; import org.matsim.contrib.freight.events.eventhandler.FreightServiceStartEventHandler; -import org.matsim.contrib.freight.events.eventhandler.FreightShipmentDeliveryEndEventHandler; -import org.matsim.contrib.freight.events.eventhandler.FreightShipmentPickupEndEventHandler; +import org.matsim.contrib.freight.events.eventhandler.FreightShipmentDeliveryEventHandler; +import org.matsim.contrib.freight.events.eventhandler.FreightShipmentPickupEventHandler; import org.matsim.core.network.NetworkUtils; import org.matsim.core.utils.io.UncheckedIOException; import org.matsim.vehicles.Vehicle; @@ -59,7 +59,7 @@ * */ @Deprecated(since = "apr23") -class FreightAnalysisEventHandler implements ActivityStartEventHandler, LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, FreightShipmentPickupEndEventHandler, FreightShipmentDeliveryEndEventHandler, FreightServiceStartEventHandler, FreightServiceEndEventHandler { +class FreightAnalysisEventHandler implements ActivityStartEventHandler, LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, FreightShipmentPickupEventHandler, FreightShipmentDeliveryEventHandler, FreightServiceStartEventHandler, FreightServiceEndEventHandler { private final static Logger log = LogManager.getLogger(FreightAnalysisEventHandler.class); private final Vehicles vehicles; diff --git a/contribs/vsp/src/test/java/org/matsim/contrib/freight/analysis/MyShipmentTrackerEventHandler.java b/contribs/vsp/src/test/java/org/matsim/contrib/freight/analysis/MyShipmentTrackerEventHandler.java index 7600629ffe0..6b2409d7e3d 100644 --- a/contribs/vsp/src/test/java/org/matsim/contrib/freight/analysis/MyShipmentTrackerEventHandler.java +++ b/contribs/vsp/src/test/java/org/matsim/contrib/freight/analysis/MyShipmentTrackerEventHandler.java @@ -8,11 +8,11 @@ import org.matsim.contrib.freight.carrier.Carriers; import org.matsim.contrib.freight.events.CarrierShipmentDeliveryEndEvent; import org.matsim.contrib.freight.events.CarrierShipmentPickupEndEvent; -import org.matsim.contrib.freight.events.eventhandler.FreightShipmentDeliveryEndEventHandler; -import org.matsim.contrib.freight.events.eventhandler.FreightShipmentPickupEndEventHandler; +import org.matsim.contrib.freight.events.eventhandler.FreightShipmentDeliveryEventHandler; +import org.matsim.contrib.freight.events.eventhandler.FreightShipmentPickupEventHandler; import org.matsim.vehicles.Vehicles; -public class MyShipmentTrackerEventHandler implements ActivityStartEventHandler, FreightShipmentPickupEndEventHandler, FreightShipmentDeliveryEndEventHandler { +public class MyShipmentTrackerEventHandler implements ActivityStartEventHandler, FreightShipmentPickupEventHandler, FreightShipmentDeliveryEventHandler { private final Vehicles vehicles; private final Network network; @@ -48,7 +48,7 @@ public void handleEvent(CarrierShipmentPickupEndEvent event) { @Override public void reset(int iteration) { - FreightShipmentPickupEndEventHandler.super.reset(iteration); + FreightShipmentPickupEventHandler.super.reset(iteration); } @Override From 2b6b6ed3013482c78c0858546496613d690fe8e3 Mon Sep 17 00:00:00 2001 From: nixlaos Date: Mon, 16 Oct 2023 12:52:19 +0200 Subject: [PATCH 07/13] fixing error --- .../carriers/CarrierEventsReadersTest.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java index a299877ec30..b418cf800cf 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java @@ -1,20 +1,19 @@ -package org.matsim.contrib.freight.carrier; +package org.matsim.freight.carriers; +import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.matsim.contrib.freight.events.*; import org.matsim.core.api.experimental.events.EventsManager; -import org.matsim.core.config.groups.ControlerConfigGroup; +import org.matsim.core.config.groups.ControllerConfigGroup; import org.matsim.core.events.EventsUtils; import org.matsim.core.events.algorithms.EventWriterXML; +import org.matsim.freight.carriers.events.CarrierEventsReaders; import org.matsim.testcases.MatsimTestUtils; import org.matsim.testcases.utils.EventsCollector; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import static org.assertj.core.api.Assertions.*; - public class CarrierEventsReadersTest { @Rule @@ -41,11 +40,10 @@ public void testWriteReadServiceBasedEvents() { eventsManager2.addHandler(collector2); eventsManager2.initProcessing(); CarrierEventsReaders.createEventsReader(eventsManager2) - .readStream(new ByteArrayInputStream(outputStream.toByteArray()), ControlerConfigGroup.EventsFileFormat.xml); + .readStream(new ByteArrayInputStream(outputStream.toByteArray()), ControllerConfigGroup.EventsFileFormat.xml); eventsManager2.finishProcessing(); - assertThat(collector1.getEvents()).usingRecursiveFieldByFieldElementComparator() - .containsExactlyElementsOf(collector2.getEvents()); + Assert.assertEquals(collector1.getEvents(), collector2.getEvents()); } @Test @@ -69,11 +67,10 @@ public void testWriteReadShipmentBasedEvents() { eventsManager2.addHandler(collector2); eventsManager2.initProcessing(); CarrierEventsReaders.createEventsReader(eventsManager2) - .readStream(new ByteArrayInputStream(outputStream.toByteArray()), ControlerConfigGroup.EventsFileFormat.xml); + .readStream(new ByteArrayInputStream(outputStream.toByteArray()), ControllerConfigGroup.EventsFileFormat.xml); eventsManager2.finishProcessing(); - assertThat(collector1.getEvents()).usingRecursiveFieldByFieldElementComparator() - .containsExactlyElementsOf(collector2.getEvents()); + Assert.assertEquals(collector1.getEvents(), collector2.getEvents()); } } From 77516570df3c045724458556d9e9122afabbc166 Mon Sep 17 00:00:00 2001 From: nixlaos Date: Mon, 16 Oct 2023 13:00:45 +0200 Subject: [PATCH 08/13] moved test input --- .../carriers}/CarrierEventsReadersTest/serviceBasedEvents.xml | 0 .../carriers}/CarrierEventsReadersTest/shipmentBasedEvents.xml | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename contribs/freight/test/input/org/matsim/{contrib/freight/carrier => freight/carriers}/CarrierEventsReadersTest/serviceBasedEvents.xml (100%) rename contribs/freight/test/input/org/matsim/{contrib/freight/carrier => freight/carriers}/CarrierEventsReadersTest/shipmentBasedEvents.xml (100%) diff --git a/contribs/freight/test/input/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest/serviceBasedEvents.xml b/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/serviceBasedEvents.xml similarity index 100% rename from contribs/freight/test/input/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest/serviceBasedEvents.xml rename to contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/serviceBasedEvents.xml diff --git a/contribs/freight/test/input/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest/shipmentBasedEvents.xml b/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/shipmentBasedEvents.xml similarity index 100% rename from contribs/freight/test/input/org/matsim/contrib/freight/carrier/CarrierEventsReadersTest/shipmentBasedEvents.xml rename to contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/shipmentBasedEvents.xml From 23d99e65379f0792c9c7a9a4352e7d18b8f8006b Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Thu, 19 Oct 2023 14:38:48 +0200 Subject: [PATCH 09/13] fix wrong attribute in event convertion --- .../carriers/events/CarrierShipmentDeliveryEndEvent.java | 2 +- .../carriers/events/CarrierShipmentDeliveryStartEvent.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryEndEvent.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryEndEvent.java index c49c04aa533..c02717031fa 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryEndEvent.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryEndEvent.java @@ -84,7 +84,7 @@ public static CarrierShipmentDeliveryEndEvent convert(GenericEvent event) { Id shipmentTo = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); int size = Integer.parseInt(attributes.get(CarrierEventAttributes.ATTRIBUTE_CAPACITYDEMAND)); CarrierShipment shipment = CarrierShipment.Builder.newInstance(shipmentId, null, shipmentTo, size) - .setDeliveryServiceTime(Double.parseDouble(attributes.get(CarrierEventAttributes.ATTRIBUTE_SERVICE_DURATION))) + .setDeliveryServiceTime(Double.parseDouble(attributes.get(CarrierEventAttributes.ATTRIBUTE_DROPOFF_DURATION))) .build(); Id vehicleId = Id.createVehicleId(attributes.get(ATTRIBUTE_VEHICLE)); return new CarrierShipmentDeliveryEndEvent(time, carrierId, shipment, vehicleId); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryStartEvent.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryStartEvent.java index e12222973c1..43cf21fc752 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryStartEvent.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/CarrierShipmentDeliveryStartEvent.java @@ -85,7 +85,7 @@ public static CarrierShipmentDeliveryStartEvent convert(GenericEvent event) { Id shipmentTo = Id.createLinkId(attributes.get(ATTRIBUTE_LINK)); int size = Integer.parseInt(attributes.get(ATTRIBUTE_CAPACITYDEMAND)); CarrierShipment shipment = CarrierShipment.Builder.newInstance(shipmentId, null, shipmentTo, size) - .setDeliveryServiceTime(Double.parseDouble(attributes.get(ATTRIBUTE_SERVICE_DURATION))) + .setDeliveryServiceTime(Double.parseDouble(attributes.get(ATTRIBUTE_DROPOFF_DURATION))) .build(); Id vehicleId = Id.createVehicleId(attributes.get(ATTRIBUTE_VEHICLE)); return new CarrierShipmentDeliveryStartEvent(time, carrierId, shipment, vehicleId); From 1e8be707ae3f0ec85b9a3769926bb0e6ad57bc85 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Thu, 19 Oct 2023 14:45:11 +0200 Subject: [PATCH 10/13] add missing events handlers and rename existing one. We have two events per dropoff / pickup: start and end. --- ...eightShipmentDeliveryEndEventHandler.java} | 2 +- ...ightShipmentDeliveryStartEventHandler.java | 37 +++++++++++++++++++ ...FreightShipmentPickupEndEventHandler.java} | 2 +- ...reightShipmentPickupStartEventHandler.java | 35 ++++++++++++++++++ .../analysis/FreightAnalysisEventHandler.java | 6 +-- .../MyShipmentTrackerEventHandler.java | 8 ++-- 6 files changed, 81 insertions(+), 9 deletions(-) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightShipmentDeliveryEventHandler.java => FreightShipmentDeliveryEndEventHandler.java} (95%) create mode 100644 contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightShipmentPickupEventHandler.java => FreightShipmentPickupEndEventHandler.java} (95%) create mode 100644 contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupStartEventHandler.java diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java similarity index 95% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java index 858a91fdca5..da7c2f805e3 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java @@ -30,7 +30,7 @@ * @author sschroeder * */ -public interface FreightShipmentDeliveryEventHandler extends EventHandler { +public interface FreightShipmentDeliveryEndEventHandler extends EventHandler { void handleEvent(CarrierShipmentDeliveryEndEvent event); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java new file mode 100644 index 00000000000..1d0dc74c0f6 --- /dev/null +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java @@ -0,0 +1,37 @@ +/* + * *********************************************************************** * + * project: org.matsim.* + * *********************************************************************** * + * * + * copyright : (C) by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** + * + */ + +package org.matsim.freight.carriers.events.eventhandler; + +import org.matsim.core.events.handler.EventHandler; +import org.matsim.freight.carriers.events.CarrierShipmentDeliveryStartEvent; + +/** + * Interface to listen to shipmentDeliveredEvents. + * + * @author sschroeder + * + */ +public interface FreightShipmentDeliveryStartEventHandler extends EventHandler { + + void handleEvent(CarrierShipmentDeliveryStartEvent event); + +} diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEndEventHandler.java similarity index 95% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEndEventHandler.java index 126942b432f..aeca9d324d8 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEndEventHandler.java @@ -30,6 +30,6 @@ * @author sschroeder * */ -public interface FreightShipmentPickupEventHandler extends EventHandler { +public interface FreightShipmentPickupEndEventHandler extends EventHandler { void handleEvent(CarrierShipmentPickupEndEvent event); } diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupStartEventHandler.java new file mode 100644 index 00000000000..e0b13e5cbcc --- /dev/null +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupStartEventHandler.java @@ -0,0 +1,35 @@ +/* + * *********************************************************************** * + * project: org.matsim.* + * *********************************************************************** * + * * + * copyright : (C) by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** + * + */ + +package org.matsim.freight.carriers.events.eventhandler; + +import org.matsim.core.events.handler.EventHandler; +import org.matsim.freight.carriers.events.CarrierShipmentPickupStartEvent; + +/** + * Interface to listen to shipmentPickedUpEvents. + * + * @author sschroeder + * + */ +public interface FreightShipmentPickupStartEventHandler extends EventHandler { + void handleEvent(CarrierShipmentPickupStartEvent event); +} diff --git a/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java b/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java index 5a9daccf1cf..89f50649dd9 100644 --- a/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java +++ b/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java @@ -38,8 +38,8 @@ import org.matsim.freight.carriers.events.CarrierShipmentPickupEndEvent; import org.matsim.freight.carriers.events.eventhandler.FreightServiceEndEventHandler; import org.matsim.freight.carriers.events.eventhandler.FreightServiceStartEventHandler; -import org.matsim.freight.carriers.events.eventhandler.FreightShipmentDeliveryEventHandler; -import org.matsim.freight.carriers.events.eventhandler.FreightShipmentPickupEventHandler; +import org.matsim.freight.carriers.events.eventhandler.FreightShipmentDeliveryEndEventHandler; +import org.matsim.freight.carriers.events.eventhandler.FreightShipmentPickupEndEventHandler; import org.matsim.core.network.NetworkUtils; import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.Vehicles; @@ -59,7 +59,7 @@ * */ @Deprecated(since = "apr23") -class FreightAnalysisEventHandler implements ActivityStartEventHandler, LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, FreightShipmentPickupEventHandler, FreightShipmentDeliveryEventHandler, FreightServiceStartEventHandler, FreightServiceEndEventHandler { +class FreightAnalysisEventHandler implements ActivityStartEventHandler, LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, FreightShipmentPickupEndEventHandler, FreightShipmentDeliveryEndEventHandler, FreightServiceStartEventHandler, FreightServiceEndEventHandler { private final static Logger log = LogManager.getLogger(FreightAnalysisEventHandler.class); private final Vehicles vehicles; diff --git a/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyShipmentTrackerEventHandler.java b/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyShipmentTrackerEventHandler.java index 35b455b8944..3ff13bfa29a 100644 --- a/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyShipmentTrackerEventHandler.java +++ b/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyShipmentTrackerEventHandler.java @@ -29,11 +29,11 @@ import org.matsim.freight.carriers.Carriers; import org.matsim.freight.carriers.events.CarrierShipmentDeliveryEndEvent; import org.matsim.freight.carriers.events.CarrierShipmentPickupEndEvent; -import org.matsim.freight.carriers.events.eventhandler.FreightShipmentDeliveryEventHandler; -import org.matsim.freight.carriers.events.eventhandler.FreightShipmentPickupEventHandler; +import org.matsim.freight.carriers.events.eventhandler.FreightShipmentDeliveryEndEventHandler; +import org.matsim.freight.carriers.events.eventhandler.FreightShipmentPickupEndEventHandler; import org.matsim.vehicles.Vehicles; -public class MyShipmentTrackerEventHandler implements ActivityStartEventHandler, FreightShipmentPickupEventHandler, FreightShipmentDeliveryEventHandler { +public class MyShipmentTrackerEventHandler implements ActivityStartEventHandler, FreightShipmentPickupEndEventHandler, FreightShipmentDeliveryEndEventHandler { private final Vehicles vehicles; private final Network network; @@ -69,7 +69,7 @@ public void handleEvent(CarrierShipmentPickupEndEvent event) { @Override public void reset(int iteration) { - FreightShipmentPickupEventHandler.super.reset(iteration); + FreightShipmentPickupEndEventHandler.super.reset(iteration); } @Override From 54a353eb97290d1dcfdbeda2e0802564129b91ad Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Thu, 19 Oct 2023 14:46:52 +0200 Subject: [PATCH 11/13] Update test (and input). Now it will also (at least) count the number of corresponding events. --- .../carriers/CarrierEventsReadersTest.java | 96 +++- .../serviceBasedEvents.xml | 396 ++++++++-------- .../shipmentBasedEvents.xml | 430 ++++++++---------- 3 files changed, 490 insertions(+), 432 deletions(-) diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java index b418cf800cf..7495ddfc0fd 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java @@ -3,16 +3,20 @@ import org.junit.Assert; import org.junit.Rule; import org.junit.Test; +import org.matsim.api.core.v01.events.Event; import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.config.groups.ControllerConfigGroup; import org.matsim.core.events.EventsUtils; import org.matsim.core.events.algorithms.EventWriterXML; -import org.matsim.freight.carriers.events.CarrierEventsReaders; +import org.matsim.freight.carriers.events.*; +import org.matsim.freight.carriers.events.eventhandler.*; import org.matsim.testcases.MatsimTestUtils; import org.matsim.testcases.utils.EventsCollector; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.List; public class CarrierEventsReadersTest { @@ -46,6 +50,25 @@ public void testWriteReadServiceBasedEvents() { Assert.assertEquals(collector1.getEvents(), collector2.getEvents()); } + + @Test + public void testReadServiceBasedEvents() { + + EventsManager eventsManager = EventsUtils.createEventsManager(); + TestEventHandlerTours eventHandlerTours = new TestEventHandlerTours(); + TestEventHandlerServices eventHandlerServices = new TestEventHandlerServices(); + + eventsManager.addHandler(eventHandlerTours); + eventsManager.addHandler(eventHandlerServices); + eventsManager.initProcessing(); + CarrierEventsReaders.createEventsReader(eventsManager) + .readFile(utils.getClassInputDirectory() + "serviceBasedEvents.xml"); + eventsManager.finishProcessing(); + + Assert.assertEquals("Number of tour related carrier events is not correct", 4 , eventHandlerTours.handledEvents.size()); + Assert.assertEquals("Number of service related carrier events is not correct", 14 , eventHandlerServices.handledEvents.size()); + } + @Test public void testWriteReadShipmentBasedEvents() { EventsManager eventsManager1 = EventsUtils.createEventsManager(); @@ -56,7 +79,7 @@ public void testWriteReadShipmentBasedEvents() { eventsManager1.addHandler(collector1); eventsManager1.initProcessing(); CarrierEventsReaders.createEventsReader(eventsManager1) - .readFile(utils.getClassInputDirectory() + "shipmentBasedEvents.xml"); + .readFile(utils.getClassInputDirectory() + "shipmentBasedEvents.xml"); eventsManager1.finishProcessing(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); @@ -67,10 +90,77 @@ public void testWriteReadShipmentBasedEvents() { eventsManager2.addHandler(collector2); eventsManager2.initProcessing(); CarrierEventsReaders.createEventsReader(eventsManager2) - .readStream(new ByteArrayInputStream(outputStream.toByteArray()), ControllerConfigGroup.EventsFileFormat.xml); + .readStream(new ByteArrayInputStream(outputStream.toByteArray()), ControllerConfigGroup.EventsFileFormat.xml); eventsManager2.finishProcessing(); Assert.assertEquals(collector1.getEvents(), collector2.getEvents()); } + @Test + public void testReadShipmentBasedEvents() { + + EventsManager eventsManager = EventsUtils.createEventsManager(); + TestEventHandlerTours eventHandlerTours = new TestEventHandlerTours(); + TestEventHandlerShipments testEventHandlerShipments = new TestEventHandlerShipments(); + + eventsManager.addHandler(eventHandlerTours); + eventsManager.addHandler(testEventHandlerShipments); + eventsManager.initProcessing(); + CarrierEventsReaders.createEventsReader(eventsManager) + .readFile(utils.getClassInputDirectory() + "shipmentBasedEvents.xml"); + eventsManager.finishProcessing(); + + Assert.assertEquals("Number of tour related carrier events is not correct", 2 , eventHandlerTours.handledEvents.size()); + Assert.assertEquals("Number of shipments related carrier events is not correct", 20 , testEventHandlerShipments.handledEvents.size()); + } + + private static class TestEventHandlerTours + implements FreightTourStartEventHandler, FreightTourEndEventHandler { + private final List handledEvents = new ArrayList<>(); + + + @Override public void handleEvent(CarrierTourEndEvent event) { + handledEvents.add(event); + } + + @Override public void handleEvent(CarrierTourStartEvent event) { + handledEvents.add(event); + } + } + + private static class TestEventHandlerServices + implements FreightServiceStartEventHandler, FreightServiceEndEventHandler { + private final List handledEvents = new ArrayList<>(); + + @Override public void handleEvent(CarrierServiceEndEvent event) { + handledEvents.add(event); + } + + @Override public void handleEvent(CarrierServiceStartEvent event) { + handledEvents.add(event); + } + + } + + private static class TestEventHandlerShipments + implements FreightShipmentDeliveryStartEventHandler, FreightShipmentDeliveryEndEventHandler, FreightShipmentPickupStartEventHandler, FreightShipmentPickupEndEventHandler { + private final List handledEvents = new ArrayList<>(); + + + @Override public void handleEvent(CarrierShipmentDeliveryEndEvent event) { + handledEvents.add(event); + } + + @Override public void handleEvent(CarrierShipmentPickupEndEvent event) { + handledEvents.add(event); + } + + @Override public void handleEvent(CarrierShipmentDeliveryStartEvent event) { + handledEvents.add(event); + } + + @Override public void handleEvent(CarrierShipmentPickupStartEvent event) { + handledEvents.add(event); + } + } } diff --git a/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/serviceBasedEvents.xml b/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/serviceBasedEvents.xml index f2bb0c1175e..b4121096264 100644 --- a/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/serviceBasedEvents.xml +++ b/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/serviceBasedEvents.xml @@ -1,195 +1,213 @@ + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/shipmentBasedEvents.xml b/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/shipmentBasedEvents.xml index 82c90c41829..ca675a9bcbf 100644 --- a/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/shipmentBasedEvents.xml +++ b/contribs/freight/test/input/org/matsim/freight/carriers/CarrierEventsReadersTest/shipmentBasedEvents.xml @@ -1,243 +1,193 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From d888d9a7836f9f5d331355dc36fe93d5f3e169e0 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Thu, 19 Oct 2023 14:49:09 +0200 Subject: [PATCH 12/13] rename "Freight" eventsHandler to "Carrier" eventsHandler --- ...Handler.java => CarrierServiceEndEventHandler.java} | 2 +- ...ndler.java => CarrierServiceStartEventHandler.java} | 2 +- ...ava => CarrierShipmentDeliveryEndEventHandler.java} | 2 +- ...a => CarrierShipmentDeliveryStartEventHandler.java} | 2 +- ....java => CarrierShipmentPickupEndEventHandler.java} | 2 +- ...ava => CarrierShipmentPickupStartEventHandler.java} | 2 +- ...entHandler.java => CarrierTourEndEventHandler.java} | 2 +- ...tHandler.java => CarrierTourStartEventHandler.java} | 2 +- .../eventhandler/Vehicle2CarrierEventHandler.java | 2 +- .../freight/carriers/CarrierEventsReadersTest.java | 6 +++--- .../carriers/analysis/FreightAnalysisEventHandler.java | 10 +++++----- .../analysis/MyServiceTrackerEventHandler.java | 6 +++--- .../analysis/MyShipmentTrackerEventHandler.java | 8 ++++---- 13 files changed, 24 insertions(+), 24 deletions(-) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightServiceEndEventHandler.java => CarrierServiceEndEventHandler.java} (95%) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightServiceStartEventHandler.java => CarrierServiceStartEventHandler.java} (96%) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightShipmentDeliveryEndEventHandler.java => CarrierShipmentDeliveryEndEventHandler.java} (96%) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightShipmentDeliveryStartEventHandler.java => CarrierShipmentDeliveryStartEventHandler.java} (96%) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightShipmentPickupEndEventHandler.java => CarrierShipmentPickupEndEventHandler.java} (96%) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightShipmentPickupStartEventHandler.java => CarrierShipmentPickupStartEventHandler.java} (96%) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightTourEndEventHandler.java => CarrierTourEndEventHandler.java} (95%) rename contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/{FreightTourStartEventHandler.java => CarrierTourStartEventHandler.java} (95%) diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightServiceEndEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierServiceEndEventHandler.java similarity index 95% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightServiceEndEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierServiceEndEventHandler.java index 65db8298b92..11ccfde0372 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightServiceEndEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierServiceEndEventHandler.java @@ -25,7 +25,7 @@ import org.matsim.core.events.handler.EventHandler; import org.matsim.freight.carriers.events.CarrierServiceEndEvent; -public interface FreightServiceEndEventHandler extends EventHandler{ +public interface CarrierServiceEndEventHandler extends EventHandler{ void handleEvent( CarrierServiceEndEvent event ); } diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightServiceStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierServiceStartEventHandler.java similarity index 96% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightServiceStartEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierServiceStartEventHandler.java index 78534b0337e..a8ea55c13e8 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightServiceStartEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierServiceStartEventHandler.java @@ -25,7 +25,7 @@ import org.matsim.freight.carriers.events.CarrierServiceStartEvent; -public interface FreightServiceStartEventHandler extends EventHandler { +public interface CarrierServiceStartEventHandler extends EventHandler { void handleEvent( CarrierServiceStartEvent event ); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentDeliveryEndEventHandler.java similarity index 96% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentDeliveryEndEventHandler.java index da7c2f805e3..b2cc8ff31dc 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryEndEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentDeliveryEndEventHandler.java @@ -30,7 +30,7 @@ * @author sschroeder * */ -public interface FreightShipmentDeliveryEndEventHandler extends EventHandler { +public interface CarrierShipmentDeliveryEndEventHandler extends EventHandler { void handleEvent(CarrierShipmentDeliveryEndEvent event); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentDeliveryStartEventHandler.java similarity index 96% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentDeliveryStartEventHandler.java index 1d0dc74c0f6..df8a7b9785a 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentDeliveryStartEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentDeliveryStartEventHandler.java @@ -30,7 +30,7 @@ * @author sschroeder * */ -public interface FreightShipmentDeliveryStartEventHandler extends EventHandler { +public interface CarrierShipmentDeliveryStartEventHandler extends EventHandler { void handleEvent(CarrierShipmentDeliveryStartEvent event); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEndEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentPickupEndEventHandler.java similarity index 96% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEndEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentPickupEndEventHandler.java index aeca9d324d8..4c7282c29c7 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupEndEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentPickupEndEventHandler.java @@ -30,6 +30,6 @@ * @author sschroeder * */ -public interface FreightShipmentPickupEndEventHandler extends EventHandler { +public interface CarrierShipmentPickupEndEventHandler extends EventHandler { void handleEvent(CarrierShipmentPickupEndEvent event); } diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentPickupStartEventHandler.java similarity index 96% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupStartEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentPickupStartEventHandler.java index e0b13e5cbcc..79c2426f023 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightShipmentPickupStartEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierShipmentPickupStartEventHandler.java @@ -30,6 +30,6 @@ * @author sschroeder * */ -public interface FreightShipmentPickupStartEventHandler extends EventHandler { +public interface CarrierShipmentPickupStartEventHandler extends EventHandler { void handleEvent(CarrierShipmentPickupStartEvent event); } diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightTourEndEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierTourEndEventHandler.java similarity index 95% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightTourEndEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierTourEndEventHandler.java index 7a91f767c4d..2d30ce4d70c 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightTourEndEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierTourEndEventHandler.java @@ -25,7 +25,7 @@ import org.matsim.freight.carriers.events.CarrierTourEndEvent; -public interface FreightTourEndEventHandler extends EventHandler { +public interface CarrierTourEndEventHandler extends EventHandler { void handleEvent( CarrierTourEndEvent event ); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightTourStartEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierTourStartEventHandler.java similarity index 95% rename from contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightTourStartEventHandler.java rename to contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierTourStartEventHandler.java index 21b14f86ce0..5f4b26ce4bb 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/FreightTourStartEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/CarrierTourStartEventHandler.java @@ -25,7 +25,7 @@ import org.matsim.freight.carriers.events.CarrierTourStartEvent; -public interface FreightTourStartEventHandler extends EventHandler { +public interface CarrierTourStartEventHandler extends EventHandler { void handleEvent( CarrierTourStartEvent event ); diff --git a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/Vehicle2CarrierEventHandler.java b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/Vehicle2CarrierEventHandler.java index e116ab1493e..bc9236decbf 100644 --- a/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/Vehicle2CarrierEventHandler.java +++ b/contribs/freight/src/main/java/org/matsim/freight/carriers/events/eventhandler/Vehicle2CarrierEventHandler.java @@ -36,7 +36,7 @@ * * @author kturner */ -public final class Vehicle2CarrierEventHandler implements FreightTourStartEventHandler, FreightTourEndEventHandler { +public final class Vehicle2CarrierEventHandler implements CarrierTourStartEventHandler, CarrierTourEndEventHandler { // Comment from Janek (in https://github.com/matsim-org/matsim-libs/pull/2128) diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java index 7495ddfc0fd..d3c3d81eea0 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java @@ -115,7 +115,7 @@ public void testReadShipmentBasedEvents() { } private static class TestEventHandlerTours - implements FreightTourStartEventHandler, FreightTourEndEventHandler { + implements CarrierTourStartEventHandler, CarrierTourEndEventHandler { private final List handledEvents = new ArrayList<>(); @@ -129,7 +129,7 @@ private static class TestEventHandlerTours } private static class TestEventHandlerServices - implements FreightServiceStartEventHandler, FreightServiceEndEventHandler { + implements CarrierServiceStartEventHandler, CarrierServiceEndEventHandler { private final List handledEvents = new ArrayList<>(); @Override public void handleEvent(CarrierServiceEndEvent event) { @@ -143,7 +143,7 @@ private static class TestEventHandlerServices } private static class TestEventHandlerShipments - implements FreightShipmentDeliveryStartEventHandler, FreightShipmentDeliveryEndEventHandler, FreightShipmentPickupStartEventHandler, FreightShipmentPickupEndEventHandler { + implements CarrierShipmentDeliveryStartEventHandler, CarrierShipmentDeliveryEndEventHandler, CarrierShipmentPickupStartEventHandler, CarrierShipmentPickupEndEventHandler { private final List handledEvents = new ArrayList<>(); diff --git a/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java b/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java index 89f50649dd9..2f322e8640f 100644 --- a/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java +++ b/contribs/vsp/src/main/java/org/matsim/freight/carriers/analysis/FreightAnalysisEventHandler.java @@ -36,10 +36,10 @@ import org.matsim.freight.carriers.events.CarrierServiceStartEvent; import org.matsim.freight.carriers.events.CarrierShipmentDeliveryEndEvent; import org.matsim.freight.carriers.events.CarrierShipmentPickupEndEvent; -import org.matsim.freight.carriers.events.eventhandler.FreightServiceEndEventHandler; -import org.matsim.freight.carriers.events.eventhandler.FreightServiceStartEventHandler; -import org.matsim.freight.carriers.events.eventhandler.FreightShipmentDeliveryEndEventHandler; -import org.matsim.freight.carriers.events.eventhandler.FreightShipmentPickupEndEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierServiceEndEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierServiceStartEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierShipmentDeliveryEndEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierShipmentPickupEndEventHandler; import org.matsim.core.network.NetworkUtils; import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.Vehicles; @@ -59,7 +59,7 @@ * */ @Deprecated(since = "apr23") -class FreightAnalysisEventHandler implements ActivityStartEventHandler, LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, FreightShipmentPickupEndEventHandler, FreightShipmentDeliveryEndEventHandler, FreightServiceStartEventHandler, FreightServiceEndEventHandler { +class FreightAnalysisEventHandler implements ActivityStartEventHandler, LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, PersonLeavesVehicleEventHandler, CarrierShipmentPickupEndEventHandler, CarrierShipmentDeliveryEndEventHandler, CarrierServiceStartEventHandler, CarrierServiceEndEventHandler { private final static Logger log = LogManager.getLogger(FreightAnalysisEventHandler.class); private final Vehicles vehicles; diff --git a/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyServiceTrackerEventHandler.java b/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyServiceTrackerEventHandler.java index 43c9dd2d524..ae51676c57b 100644 --- a/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyServiceTrackerEventHandler.java +++ b/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyServiceTrackerEventHandler.java @@ -29,11 +29,11 @@ import org.matsim.freight.carriers.Carriers; import org.matsim.freight.carriers.events.CarrierServiceEndEvent; import org.matsim.freight.carriers.events.CarrierServiceStartEvent; -import org.matsim.freight.carriers.events.eventhandler.FreightServiceEndEventHandler; -import org.matsim.freight.carriers.events.eventhandler.FreightServiceStartEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierServiceEndEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierServiceStartEventHandler; import org.matsim.vehicles.Vehicles; - class MyServiceTrackerEventHandler implements ActivityStartEventHandler, FreightServiceStartEventHandler, FreightServiceEndEventHandler { + class MyServiceTrackerEventHandler implements ActivityStartEventHandler, CarrierServiceStartEventHandler, CarrierServiceEndEventHandler { private final Vehicles vehicles; private final Network network; private final Carriers carriers; diff --git a/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyShipmentTrackerEventHandler.java b/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyShipmentTrackerEventHandler.java index 3ff13bfa29a..178652c1c7d 100644 --- a/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyShipmentTrackerEventHandler.java +++ b/contribs/vsp/src/test/java/org/matsim/freight/carriers/analysis/MyShipmentTrackerEventHandler.java @@ -29,11 +29,11 @@ import org.matsim.freight.carriers.Carriers; import org.matsim.freight.carriers.events.CarrierShipmentDeliveryEndEvent; import org.matsim.freight.carriers.events.CarrierShipmentPickupEndEvent; -import org.matsim.freight.carriers.events.eventhandler.FreightShipmentDeliveryEndEventHandler; -import org.matsim.freight.carriers.events.eventhandler.FreightShipmentPickupEndEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierShipmentDeliveryEndEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierShipmentPickupEndEventHandler; import org.matsim.vehicles.Vehicles; -public class MyShipmentTrackerEventHandler implements ActivityStartEventHandler, FreightShipmentPickupEndEventHandler, FreightShipmentDeliveryEndEventHandler { +public class MyShipmentTrackerEventHandler implements ActivityStartEventHandler, CarrierShipmentPickupEndEventHandler, CarrierShipmentDeliveryEndEventHandler { private final Vehicles vehicles; private final Network network; @@ -69,7 +69,7 @@ public void handleEvent(CarrierShipmentPickupEndEvent event) { @Override public void reset(int iteration) { - FreightShipmentPickupEndEventHandler.super.reset(iteration); + CarrierShipmentPickupEndEventHandler.super.reset(iteration); } @Override From 376a7ec6a95d83ee42ca2cd77403f71bc1b02239 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 20 Oct 2023 16:09:23 +0200 Subject: [PATCH 13/13] add in-code created test as well. add copyright --- .../carriers/CarrierEventsReadersTest.java | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java index d3c3d81eea0..37a4cabaf82 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierEventsReadersTest.java @@ -1,9 +1,31 @@ +/* + * *********************************************************************** * + * project: org.matsim.* + * *********************************************************************** * + * * + * copyright : (C) 2023 by the members listed in the COPYING, * + * LICENSE and WARRANTY file. * + * email : info at matsim dot org * + * * + * *********************************************************************** * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * See also COPYING, LICENSE and WARRANTY file * + * * + * *********************************************************************** * + */ + package org.matsim.freight.carriers; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; +import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.events.Event; +import org.matsim.api.core.v01.network.Link; import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.config.groups.ControllerConfigGroup; import org.matsim.core.events.EventsUtils; @@ -12,17 +34,44 @@ import org.matsim.freight.carriers.events.eventhandler.*; import org.matsim.testcases.MatsimTestUtils; import org.matsim.testcases.utils.EventsCollector; +import org.matsim.vehicles.Vehicle; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.util.ArrayList; import java.util.List; + +/** + * @author Kai Martins-Turner (kturner) + * @author Niclas Richter (nixlaos) + */ public class CarrierEventsReadersTest { + @Rule public final MatsimTestUtils utils = new MatsimTestUtils(); + private final Id linkId = Id.createLinkId("demoLink"); + private final Id linkId2 = Id.createLinkId("demoLink2"); + private final Id carrierId = Id.create("testCarrier", Carrier.class); + private final Id vehicleId = Id.createVehicleId("myVehicle"); + + private final Id tourId = Id.create("myCarrierTour", Tour.class); + private final CarrierService service = CarrierService.Builder.newInstance(Id.create("service42", CarrierService.class), linkId2 ).build(); + private final CarrierShipment shipment = CarrierShipment.Builder.newInstance(Id.create("shipment11", CarrierShipment.class), linkId, linkId2,7 ).build(); + + private final List carrierEvents = List.of( + new CarrierTourStartEvent(10, carrierId, linkId, vehicleId, tourId), + new CarrierTourEndEvent(500, carrierId, linkId, vehicleId, tourId), + new CarrierServiceStartEvent(20, carrierId, service, vehicleId), + new CarrierServiceEndEvent(25, carrierId, service, vehicleId), + new CarrierShipmentPickupStartEvent(100, carrierId, shipment, vehicleId), + new CarrierShipmentPickupEndEvent(115, carrierId, shipment, vehicleId), + new CarrierShipmentDeliveryStartEvent(210, carrierId, shipment, vehicleId), + new CarrierShipmentDeliveryEndEvent(225, carrierId, shipment, vehicleId) + ); + @Test public void testWriteReadServiceBasedEvents() { EventsManager eventsManager1 = EventsUtils.createEventsManager(); @@ -114,6 +163,42 @@ public void testReadShipmentBasedEvents() { Assert.assertEquals("Number of shipments related carrier events is not correct", 20 , testEventHandlerShipments.handledEvents.size()); } + + /** + * This test is testing the reader with some locally created events (see above). + * This test is inspired by the DrtEventsReaderTest from michalm. + */ + @Test + public void testReader() { + var outputStream = new ByteArrayOutputStream(); + EventWriterXML writer = new EventWriterXML(outputStream); + carrierEvents.forEach(writer::handleEvent); + writer.closeFile(); + + EventsManager eventsManager = EventsUtils.createEventsManager(); + TestEventHandlerTours eventHandlerTours = new TestEventHandlerTours(); + TestEventHandlerServices eventHandlerServices = new TestEventHandlerServices(); + TestEventHandlerShipments eventHandlerShipments = new TestEventHandlerShipments(); + + eventsManager.addHandler(eventHandlerTours); + eventsManager.addHandler(eventHandlerServices); + eventsManager.addHandler(eventHandlerShipments); + + eventsManager.initProcessing(); + CarrierEventsReaders.createEventsReader(eventsManager) + .readStream(new ByteArrayInputStream(outputStream.toByteArray()), + ControllerConfigGroup.EventsFileFormat.xml); + eventsManager.finishProcessing(); + + var handledEvents = new ArrayList(); + handledEvents.addAll(eventHandlerTours.handledEvents); + handledEvents.addAll(eventHandlerServices.handledEvents); + handledEvents.addAll(eventHandlerShipments.handledEvents); + + //Please note: This test is sensitive to the order of events as they are added in carrierEvents (input) and the resukts of the handler... + Assert.assertArrayEquals(carrierEvents.toArray(), handledEvents.toArray()); + } + private static class TestEventHandlerTours implements CarrierTourStartEventHandler, CarrierTourEndEventHandler { private final List handledEvents = new ArrayList<>();