From 28217d0dd5f38c01e012c0d6c6e3abea993e15c3 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Wed, 14 Aug 2024 14:26:28 +0200 Subject: [PATCH] some encapsulation. fix and comment test --- ...hipmentsSecondReloadLSPSchedulingTest.java | 104 ++++++++-------- .../SecondReloadLSPSchedulingTest.java | 112 ++++++++++-------- 2 files changed, 122 insertions(+), 94 deletions(-) diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java index 42425002..4766d616 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java @@ -354,63 +354,73 @@ public void testSecondReloadLSPScheduling() { assertSame(planElements.getFirst().getLogisticChainElement(), collectionElement); } - assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size()); - ArrayList eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers()); - assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); - TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); - Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while (iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; - assertSame(service.getLocationLinkId(), shipment.getFrom()); - assertEquals(service.getCapacityDemand(), shipment.getSize()); - assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - boolean handledByTranshipmentHub = false; - for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { - if (clientElement == element) { - handledByTranshipmentHub = true; - break; + { + assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size()); + ArrayList eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers()); + assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); + TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); + Iterator> + iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while (iter.hasNext()) { + Entry + entry = iter.next(); + CarrierService service = entry.getKey(); + LspShipment shipment = entry.getValue().lspShipment; + LogisticChainElement element = entry.getValue().element; + assertSame(service.getLocationLinkId(), shipment.getFrom()); + assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); + boolean handledByTranshipmentHub = false; + for (LogisticChainElement clientElement : + reloadEventHandler.getTranshipmentHub().getClientElements()) { + if (clientElement == element) { + handledByTranshipmentHub = true; + break; + } } - } - assertTrue(handledByTranshipmentHub); + assertTrue(handledByTranshipmentHub); - assertTrue(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); - assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); + //There IS a next element following the 1st hub, so the outgoing shipments does NOT contain the shipment anymore (got handled). + assertFalse(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); + assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); + } } - assertEquals(1, secondTranshipmentHubResource.getSimulationTrackers().size()); - eventHandlers = new ArrayList<>(secondTranshipmentHubResource.getSimulationTrackers()); - assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); - reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); - iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while (iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; - assertSame(service.getLocationLinkId(), toLinkId); - assertEquals(service.getCapacityDemand(), shipment.getSize()); - assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - boolean handledByTranshipmentHub = false; - for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { - if (clientElement == element) { - handledByTranshipmentHub = true; - break; + { + assertEquals(1, secondTranshipmentHubResource.getSimulationTrackers().size()); + ArrayList eventHandlers = new ArrayList<>(secondTranshipmentHubResource.getSimulationTrackers()); + assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); + TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); + Iterator> + iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while (iter.hasNext()) { + Entry entry = iter.next(); + CarrierService service = entry.getKey(); + LspShipment shipment = entry.getValue().lspShipment; + LogisticChainElement element = entry.getValue().element; + assertSame(service.getLocationLinkId(), toLinkId); + assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); + boolean handledByTranshipmentHub = false; + for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { + if (clientElement == element) { + handledByTranshipmentHub = true; + break; + } } - } - assertTrue(handledByTranshipmentHub); + assertTrue(handledByTranshipmentHub); - assertTrue(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); - assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); + //There is NO next element following the 2nd hub, so the outgoing shipments remain in the list of the 2nd hub. + assertTrue(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); + assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); + } } for (LspShipment shipment : lsp.getLspShipments()) { assertEquals(4, shipment.getSimulationTrackers().size()); - eventHandlers = new ArrayList<>(shipment.getSimulationTrackers()); + ArrayList> eventHandlers = new ArrayList<>(shipment.getSimulationTrackers()); ArrayList planElements = new ArrayList<>(LspShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId()).getPlanElements().values()); planElements.sort(LspShipmentUtils.createShipmentPlanElementComparator()); ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements()); diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java index 69d5e998..f7a32ede 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java @@ -354,63 +354,81 @@ public void testSecondReloadLSPScheduling() { assertSame(planElements.getFirst().getLogisticChainElement(), collectionElement); } - assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size()); - ArrayList eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers()); - assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); - TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); - Iterator> iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while (iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; - assertSame(service.getLocationLinkId(), shipment.getFrom()); - assertEquals(service.getCapacityDemand(), shipment.getSize()); - assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - boolean handledByTranshipmentHub = false; - for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { - if (clientElement == element) { - handledByTranshipmentHub = true; - break; + { + assertEquals(1, firstTranshipmentHubResource.getSimulationTrackers().size()); + ArrayList eventHandlers = new ArrayList<>(firstTranshipmentHubResource.getSimulationTrackers()); + assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); + TransshipmentHubTourEndEventHandler reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); + Iterator> + iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while (iter.hasNext()) { + Entry + entry = iter.next(); + CarrierService service = entry.getKey(); + LspShipment shipment = entry.getValue().lspShipment; + LogisticChainElement element = entry.getValue().element; + assertSame(service.getLocationLinkId(), shipment.getFrom()); + assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); + boolean handledByTranshipmentHub = false; + for (LogisticChainElement clientElement : + reloadEventHandler.getTranshipmentHub().getClientElements()) { + if (clientElement == element) { + handledByTranshipmentHub = true; + break; + } } - } - assertTrue(handledByTranshipmentHub); + assertTrue(handledByTranshipmentHub); - assertTrue(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); - assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); + //There IS a next element following the 1st hub, so the outgoing shipments does NOT contain the shipment anymore (got handled). + assertFalse(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); + assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); + } } - assertEquals(1, secondTranshipmentHubResource.getSimulationTrackers().size()); - eventHandlers = new ArrayList<>(secondTranshipmentHubResource.getSimulationTrackers()); - assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); - reloadEventHandler = (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); - iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); - - while (iter.hasNext()) { - Entry entry = iter.next(); - CarrierService service = entry.getKey(); - LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; - assertSame(service.getLocationLinkId(), toLinkId); - assertEquals(service.getCapacityDemand(), shipment.getSize()); - assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - boolean handledByTranshipmentHub = false; - for (LogisticChainElement clientElement : reloadEventHandler.getTranshipmentHub().getClientElements()) { - if (clientElement == element) { - handledByTranshipmentHub = true; - break; + { + assertEquals(1, secondTranshipmentHubResource.getSimulationTrackers().size()); + ArrayList eventHandlers = + new ArrayList<>(secondTranshipmentHubResource.getSimulationTrackers()); + assertInstanceOf(TransshipmentHubTourEndEventHandler.class, eventHandlers.getFirst()); + TransshipmentHubTourEndEventHandler reloadEventHandler = + (TransshipmentHubTourEndEventHandler) eventHandlers.getFirst(); + Iterator< + Entry< + CarrierService, + TransshipmentHubTourEndEventHandler.TransshipmentHubEventHandlerPair>> + iter = reloadEventHandler.getServicesWaitedFor().entrySet().iterator(); + + while (iter.hasNext()) { + Entry + entry = iter.next(); + CarrierService service = entry.getKey(); + LspShipment shipment = entry.getValue().lspShipment; + LogisticChainElement element = entry.getValue().element; + assertSame(service.getLocationLinkId(), toLinkId); + assertEquals(service.getCapacityDemand(), shipment.getSize()); + assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); + boolean handledByTranshipmentHub = false; + for (LogisticChainElement clientElement : + reloadEventHandler.getTranshipmentHub().getClientElements()) { + if (clientElement == element) { + handledByTranshipmentHub = true; + break; + } } - } - assertTrue(handledByTranshipmentHub); + assertTrue(handledByTranshipmentHub); - assertTrue(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); - assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); + //There is NO next element following the 2nd hub, so the outgoing shipments remain in the list of the 2nd hub. + assertTrue(element.getOutgoingShipments().getLspShipmentsWTime().contains(shipment)); + assertFalse(element.getIncomingShipments().getLspShipmentsWTime().contains(shipment)); + } } + for (LspShipment shipment : lsp.getLspShipments()) { assertEquals(4, shipment.getSimulationTrackers().size()); - eventHandlers = new ArrayList<>(shipment.getSimulationTrackers()); + ArrayList eventHandlers = new ArrayList<>(shipment.getSimulationTrackers()); ArrayList planElements = new ArrayList<>(LspShipmentUtils.getOrCreateShipmentPlan(lsp.getSelectedPlan(), shipment.getId()).getPlanElements().values()); planElements.sort(LspShipmentUtils.createShipmentPlanElementComparator()); ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements());