From b8b0c07cdd4d65ade14e58604065506d9fefa0e3 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Wed, 14 Aug 2024 15:32:07 +0200 Subject: [PATCH 1/4] minor internal simplification --- .../CollectionCarrierScheduler.java | 24 +++++++++---------- .../DistributionCarrierScheduler.java | 17 ++++++------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java index 4d8c35b3..c3448994 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java @@ -29,6 +29,7 @@ import org.matsim.freight.carriers.ScheduledTour; import org.matsim.freight.carriers.Tour; import org.matsim.freight.carriers.Tour.Leg; +import org.matsim.freight.carriers.Tour.ServiceActivity; import org.matsim.freight.carriers.Tour.TourElement; import org.matsim.freight.logistics.*; import org.matsim.freight.logistics.shipment.LspShipment; @@ -82,14 +83,12 @@ public void scheduleResource() { } private CarrierService convertToCarrierService(LspShipment lspShipment) { - Id serviceId = - Id.create(lspShipment.getId().toString(), CarrierService.class); - CarrierService.Builder builder = - CarrierService.Builder.newInstance(serviceId, lspShipment.getFrom()); - builder.setServiceStartTimeWindow(lspShipment.getPickupTimeWindow()); - builder.setCapacityDemand(lspShipment.getSize()); - builder.setServiceDuration(lspShipment.getDeliveryServiceTime()); - CarrierService carrierService = builder.build(); + Id serviceId = Id.create(lspShipment.getId().toString(), CarrierService.class); + CarrierService carrierService = CarrierService.Builder.newInstance(serviceId, lspShipment.getFrom()) + .setServiceStartTimeWindow(lspShipment.getPickupTimeWindow()) + .setCapacityDemand(lspShipment.getSize()) + .setServiceDuration(lspShipment.getDeliveryServiceTime()) + .build(); pairs.add(new LSPCarrierPair(lspShipment, carrierService)); return carrierService; } @@ -100,11 +99,10 @@ protected void updateShipments() { for (ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()) { Tour tour = scheduledTour.getTour(); for (TourElement element : tour.getTourElements()) { - if (element instanceof Tour.ServiceActivity serviceActivity) { - LSPCarrierPair carrierPair = new LSPCarrierPair(lspShipment, serviceActivity.getService()); + if (element instanceof ServiceActivity serviceActivity) { for (LSPCarrierPair pair : pairs) { - if (pair.lspShipment == carrierPair.lspShipment - && pair.carrierService.getId() == carrierPair.carrierService.getId()) { + if (pair.lspShipment == lspShipment + && pair.carrierService.getId() == serviceActivity.getService().getId()) { addShipmentLoadElement(lspShipment, tour, serviceActivity); addShipmentTransportElement(lspShipment, tour, serviceActivity); addShipmentUnloadElement(lspShipment, tour); @@ -119,7 +117,7 @@ protected void updateShipments() { } private void addShipmentLoadElement( - LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipment lspShipment, Tour tour, ServiceActivity serviceActivity) { LspShipmentUtils.ScheduledShipmentLoadBuilder builder = LspShipmentUtils.ScheduledShipmentLoadBuilder.newInstance(); diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java index 16aae7ca..2dc40979 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java @@ -171,13 +171,11 @@ private Collection unifyTourIds(Collection carrierPl } private CarrierService convertToCarrierService(LspShipment lspShipment) { - Id serviceId = - Id.create(lspShipment.getId().toString(), CarrierService.class); - CarrierService.Builder builder = - CarrierService.Builder.newInstance(serviceId, lspShipment.getTo()); - builder.setCapacityDemand(lspShipment.getSize()); - builder.setServiceDuration(lspShipment.getDeliveryServiceTime()); - CarrierService carrierService = builder.build(); + Id serviceId = Id.create(lspShipment.getId().toString(), CarrierService.class); + CarrierService carrierService = CarrierService.Builder.newInstance(serviceId, lspShipment.getTo()) + .setCapacityDemand(lspShipment.getSize()) + .setServiceDuration(lspShipment.getDeliveryServiceTime()) + .build(); pairs.add(new LSPCarrierPair(lspShipment, carrierService)); return carrierService; } @@ -189,10 +187,9 @@ protected void updateShipments() { Tour tour = scheduledTour.getTour(); for (TourElement element : tour.getTourElements()) { if (element instanceof ServiceActivity serviceActivity) { - LSPCarrierPair carrierPair = new LSPCarrierPair(lspShipment, serviceActivity.getService()); for (LSPCarrierPair pair : pairs) { - if (pair.lspShipment == carrierPair.lspShipment - && pair.carrierService.getId() == carrierPair.carrierService.getId()) { + if (pair.lspShipment == lspShipment + && pair.carrierService.getId() == serviceActivity.getService().getId()) { addShipmentLoadElement(lspShipment, tour); addShipmentTransportElement(lspShipment, tour, serviceActivity); addShipmentUnloadElement(lspShipment, tour, serviceActivity); From 2057918e3f3c199ed12d20354669e0f4cbc47e2f Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 16 Aug 2024 15:27:48 +0200 Subject: [PATCH 2/4] remove LSPCarrierPair and the list storing it. This is not needed in leads only to more complex code. --- .../CollectionCarrierScheduler.java | 122 ++++++------- .../DistributionCarrierScheduler.java | 169 +++++++++--------- 2 files changed, 147 insertions(+), 144 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java index c3448994..8e19d993 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java @@ -1,27 +1,30 @@ /* - *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2022 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 * - * * - * *********************************************************************** + *********************************************************************** * + * project: org.matsim.* + * * + * *********************************************************************** * + * * + * copyright : (C) 2022 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.logistics.resourceImplementations; -import java.util.ArrayList; +import java.util.Objects; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.freight.carriers.Carrier; @@ -45,9 +48,10 @@ */ /*package-private*/ class CollectionCarrierScheduler extends LSPResourceScheduler { + Logger log = LogManager.getLogger(CollectionCarrierScheduler.class); + private Carrier carrier; private CollectionCarrierResource resource; - private ArrayList pairs; private final Scenario scenario; /** @@ -57,13 +61,11 @@ * @param scenario the road pricing scheme */ CollectionCarrierScheduler(Scenario scenario) { - this.pairs = new ArrayList<>(); this.scenario = scenario; } @Override public void initializeValues(LSPResource resource) { - this.pairs = new ArrayList<>(); if (resource.getClass() == CollectionCarrierResource.class) { this.resource = (CollectionCarrierResource) resource; this.carrier = this.resource.getCarrier(); @@ -89,7 +91,11 @@ private CarrierService convertToCarrierService(LspShipment lspShipment) { .setCapacityDemand(lspShipment.getSize()) .setServiceDuration(lspShipment.getDeliveryServiceTime()) .build(); - pairs.add(new LSPCarrierPair(lspShipment, carrierService)); + //ensure that the ids of the lspShipment and the carrierService are the same. This is needed for updating the LSPShipmentPlan + if (! Objects.equals(lspShipment.getId().toString(), carrierService.getId().toString())) { + log.error("Id of LspShipment: {} and CarrierService: {} do not match", lspShipment.getId().toString(), carrierService.getId().toString(), + new IllegalStateException("Id of LspShipment and CarrierService do not match")); + } return carrierService; } @@ -100,15 +106,12 @@ protected void updateShipments() { Tour tour = scheduledTour.getTour(); for (TourElement element : tour.getTourElements()) { if (element instanceof ServiceActivity serviceActivity) { - for (LSPCarrierPair pair : pairs) { - if (pair.lspShipment == lspShipment - && pair.carrierService.getId() == serviceActivity.getService().getId()) { - addShipmentLoadElement(lspShipment, tour, serviceActivity); - addShipmentTransportElement(lspShipment, tour, serviceActivity); - addShipmentUnloadElement(lspShipment, tour); - addCollectionTourEndEventHandler(pair.carrierService, lspShipment, resource, tour); - addCollectionServiceEventHandler(pair.carrierService, lspShipment, resource); - } + if (Objects.equals(lspShipment.getId().toString(), serviceActivity.getService().getId().toString())) { + addShipmentLoadElement(lspShipment, tour, serviceActivity); + addShipmentTransportElement(lspShipment, tour, serviceActivity); + addShipmentUnloadElement(lspShipment, tour); + addCollectionTourEndEventHandler(serviceActivity.getService(), lspShipment, resource, tour); + addCollectionServiceEventHandler(serviceActivity.getService(), lspShipment, resource); } } } @@ -117,10 +120,10 @@ protected void updateShipments() { } private void addShipmentLoadElement( - LspShipment lspShipment, Tour tour, ServiceActivity serviceActivity) { + LspShipment lspShipment, Tour tour, ServiceActivity serviceActivity) { LspShipmentUtils.ScheduledShipmentLoadBuilder builder = - LspShipmentUtils.ScheduledShipmentLoadBuilder.newInstance(); + LspShipmentUtils.ScheduledShipmentLoadBuilder.newInstance(); builder.setResourceId(resource.getId()); for (LogisticChainElement element : resource.getClientElements()) { @@ -132,23 +135,23 @@ private void addShipmentLoadElement( int serviceIndex = tour.getTourElements().indexOf(serviceActivity); Leg legBeforeService = (Leg) tour.getTourElements().get(serviceIndex - 1); double startTimeOfLoading = - legBeforeService.getExpectedDepartureTime() + legBeforeService.getExpectedTransportTime(); + legBeforeService.getExpectedDepartureTime() + legBeforeService.getExpectedTransportTime(); builder.setStartTime(startTimeOfLoading); builder.setEndTime(startTimeOfLoading + lspShipment.getDeliveryServiceTime()); LspShipmentPlanElement load = builder.build(); String idString = - load.getResourceId() + "" + load.getLogisticChainElement().getId() + load.getElementType(); + load.getResourceId() + "" + load.getLogisticChainElement().getId() + load.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) - .addPlanElement(id, load); + .addPlanElement(id, load); } private void addShipmentTransportElement( - LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { LspShipmentUtils.ScheduledShipmentTransportBuilder builder = - LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance(); + LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance(); builder.setResourceId(resource.getId()); for (LogisticChainElement element : resource.getClientElements()) { @@ -170,23 +173,23 @@ private void addShipmentTransportElement( builder.setCarrierService(serviceActivity.getService()); LspShipmentPlanElement transport = builder.build(); String idString = - transport.getResourceId() - + "" - + transport.getLogisticChainElement().getId() - + transport.getElementType(); + transport.getResourceId() + + "" + + transport.getLogisticChainElement().getId() + + transport.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) - .addPlanElement(id, transport); + .addPlanElement(id, transport); } private void addCollectionServiceEventHandler( - CarrierService carrierService, LspShipment lspShipment, LSPCarrierResource resource) { + CarrierService carrierService, LspShipment lspShipment, LSPCarrierResource resource) { for (LogisticChainElement element : this.resource.getClientElements()) { if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { CollectionServiceEndEventHandler endHandler = - new CollectionServiceEndEventHandler( - carrierService, lspShipment, element, resource); + new CollectionServiceEndEventHandler( + carrierService, lspShipment, element, resource); lspShipment.addSimulationTracker(endHandler); break; } @@ -194,15 +197,15 @@ private void addCollectionServiceEventHandler( } private void addCollectionTourEndEventHandler( - CarrierService carrierService, - LspShipment lspShipment, - LSPCarrierResource resource, - Tour tour) { + CarrierService carrierService, + LspShipment lspShipment, + LSPCarrierResource resource, + Tour tour) { for (LogisticChainElement element : this.resource.getClientElements()) { if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { LSPTourEndEventHandler handler = - new LSPTourEndEventHandler( - lspShipment, carrierService, element, resource, tour); + new LSPTourEndEventHandler( + lspShipment, carrierService, element, resource, tour); lspShipment.addSimulationTracker(handler); break; } @@ -212,7 +215,7 @@ private void addCollectionTourEndEventHandler( private void addShipmentUnloadElement(LspShipment lspShipment, Tour tour) { LspShipmentUtils.ScheduledShipmentUnloadBuilder builder = - LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance(); + LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance(); builder.setResourceId(resource.getId()); for (LogisticChainElement element : resource.getClientElements()) { if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { @@ -226,13 +229,13 @@ private void addShipmentUnloadElement(LspShipment lspShipment, Tour tour) { LspShipmentPlanElement unload = builder.build(); String idString = - unload.getResourceId() - + "" - + unload.getLogisticChainElement().getId() - + unload.getElementType(); + unload.getResourceId() + + "" + + unload.getLogisticChainElement().getId() + + unload.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) - .addPlanElement(id, unload); + .addPlanElement(id, unload); } private double getUnloadEndTime(Tour tour) { @@ -245,5 +248,4 @@ private double getUnloadEndTime(Tour tour) { return unloadEndTime; } - private record LSPCarrierPair(LspShipment lspShipment, CarrierService carrierService) {} } diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java index 2dc40979..5a3de136 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java @@ -1,30 +1,30 @@ /* - *********************************************************************** * - * project: org.matsim.* - * * - * *********************************************************************** * - * * - * copyright : (C) 2022 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 * - * * - * *********************************************************************** + *********************************************************************** * + * project: org.matsim.* + * * + * *********************************************************************** * + * * + * copyright : (C) 2022 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.logistics.resourceImplementations; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; +import java.util.*; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.locationtech.jts.util.Assert; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; @@ -50,9 +50,10 @@ */ /*package-private*/ class DistributionCarrierScheduler extends LSPResourceScheduler { + Logger log = LogManager.getLogger(DistributionCarrierScheduler.class); + private Carrier carrier; private DistributionCarrierResource resource; - private ArrayList pairs; private int carrierCnt = 1; private final Scenario scenario; @@ -64,13 +65,11 @@ * @param scenario the scenario */ DistributionCarrierScheduler(Scenario scenario) { - this.pairs = new ArrayList<>(); this.scenario = scenario; } @Override protected void initializeValues(LSPResource resource) { - this.pairs = new ArrayList<>(); if (resource.getClass() == DistributionCarrierResource.class) { this.resource = (DistributionCarrierResource) resource; this.carrier = this.resource.getCarrier(); @@ -94,14 +93,14 @@ protected void scheduleResource() { // das erste/nächste(?) und schaut ob es da rein passt... Aber was ist, wenn es mehrere // gibt??? VehicleType vehicleType = - ResourceImplementationUtils.getVehicleTypeCollection(carrier).iterator().next(); + ResourceImplementationUtils.getVehicleTypeCollection(carrier).iterator().next(); if ((load + lspShipment.getSize()) - > vehicleType.getCapacity().getOther().intValue()) { + > vehicleType.getCapacity().getOther().intValue()) { load = 0; Carrier auxiliaryCarrier = - CarrierSchedulerUtils.solveVrpWithJsprit( - createAuxiliaryCarrier(shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime), - scenario); + CarrierSchedulerUtils.solveVrpWithJsprit( + createAuxiliaryCarrier(shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime), + scenario); scheduledPlans.add(auxiliaryCarrier.getSelectedPlan()); carrier.getServices().putAll(auxiliaryCarrier.getServices()); cumulatedLoadingTime = 0; @@ -115,10 +114,10 @@ protected void scheduleResource() { if (!shipmentsInCurrentTour.isEmpty()) { Carrier auxiliaryCarrier = - CarrierSchedulerUtils.solveVrpWithJsprit( - createAuxiliaryCarrier( - shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime), - scenario); + CarrierSchedulerUtils.solveVrpWithJsprit( + createAuxiliaryCarrier( + shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime), + scenario); scheduledPlans.add(auxiliaryCarrier.getSelectedPlan()); carrier.getServices().putAll(auxiliaryCarrier.getServices()); shipmentsInCurrentTour.clear(); @@ -157,13 +156,13 @@ private Collection unifyTourIds(Collection carrierPl for (CarrierPlan carrierPlan : carrierPlans) { for (ScheduledTour scheduledTour : carrierPlan.getScheduledTours()) { var newTour = - scheduledTour - .getTour() - .duplicateWithNewId(Id.create("dist_" + tourIdIndex, Tour.class)); + scheduledTour + .getTour() + .duplicateWithNewId(Id.create("dist_" + tourIdIndex, Tour.class)); tourIdIndex++; var newScheduledTour = - ScheduledTour.newInstance( - newTour, scheduledTour.getVehicle(), scheduledTour.getDeparture()); + ScheduledTour.newInstance( + newTour, scheduledTour.getVehicle(), scheduledTour.getDeparture()); scheduledToursUnified.add(newScheduledTour); } } @@ -176,7 +175,11 @@ private CarrierService convertToCarrierService(LspShipment lspShipment) { .setCapacityDemand(lspShipment.getSize()) .setServiceDuration(lspShipment.getDeliveryServiceTime()) .build(); - pairs.add(new LSPCarrierPair(lspShipment, carrierService)); + //ensure that the ids of the lspShipment and the carrierService are the same. This is needed for updating the LSPShipmentPlan + if (! Objects.equals(lspShipment.getId().toString(), carrierService.getId().toString())) { + log.error("Id of LspShipment: {} and CarrierService: {} do not match", lspShipment.getId().toString(), carrierService.getId().toString(), + new IllegalStateException("Id of LspShipment and CarrierService do not match")); + } return carrierService; } @@ -187,15 +190,12 @@ protected void updateShipments() { Tour tour = scheduledTour.getTour(); for (TourElement element : tour.getTourElements()) { if (element instanceof ServiceActivity serviceActivity) { - for (LSPCarrierPair pair : pairs) { - if (pair.lspShipment == lspShipment - && pair.carrierService.getId() == serviceActivity.getService().getId()) { - addShipmentLoadElement(lspShipment, tour); - addShipmentTransportElement(lspShipment, tour, serviceActivity); - addShipmentUnloadElement(lspShipment, tour, serviceActivity); - addDistributionTourStartEventHandler(pair.carrierService, lspShipment, resource, tour); - addDistributionServiceEventHandler(pair.carrierService, lspShipment, resource); - } + if (Objects.equals(lspShipment.getId().toString(), serviceActivity.getService().getId().toString())) { + addShipmentLoadElement(lspShipment, tour); + addShipmentTransportElement(lspShipment, tour, serviceActivity); + addShipmentUnloadElement(lspShipment, tour, serviceActivity); + addDistributionTourStartEventHandler(serviceActivity.getService(), lspShipment, resource, tour); + addDistributionServiceEventHandler(serviceActivity.getService(), lspShipment, resource); } } } @@ -205,7 +205,7 @@ protected void updateShipments() { private void addShipmentLoadElement(LspShipment lspShipment, Tour tour) { LspShipmentUtils.ScheduledShipmentLoadBuilder builder = - LspShipmentUtils.ScheduledShipmentLoadBuilder.newInstance(); + LspShipmentUtils.ScheduledShipmentLoadBuilder.newInstance(); builder.setResourceId(resource.getId()); for (LogisticChainElement element : resource.getClientElements()) { @@ -228,17 +228,17 @@ private void addShipmentLoadElement(LspShipment lspShipment, Tour tour) { LspShipmentPlanElement load = builder.build(); String idString = - load.getResourceId() + "" + load.getLogisticChainElement().getId() + load.getElementType(); + load.getResourceId() + "" + load.getLogisticChainElement().getId() + load.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) - .addPlanElement(id, load); + .addPlanElement(id, load); } private void addShipmentTransportElement( - LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { LspShipmentUtils.ScheduledShipmentTransportBuilder builder = - LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance(); + LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance(); builder.setResourceId(resource.getId()); for (LogisticChainElement element : resource.getClientElements()) { @@ -253,13 +253,13 @@ private void addShipmentTransportElement( final Leg legBeforeService = (Leg) tour.getTourElements().get(serviceIndex - 1); final double startTimeOfTransport = legAfterStart.getExpectedDepartureTime(); final double endTimeOfTransport = - legBeforeService.getExpectedTransportTime() + legBeforeService.getExpectedDepartureTime(); + legBeforeService.getExpectedTransportTime() + legBeforeService.getExpectedDepartureTime(); Assert.isTrue( - endTimeOfTransport >= startTimeOfTransport, - "latest End must be later than earliest start. start: " - + startTimeOfTransport - + " ; end: " - + endTimeOfTransport); + endTimeOfTransport >= startTimeOfTransport, + "latest End must be later than earliest start. start: " + + startTimeOfTransport + + " ; end: " + + endTimeOfTransport); builder.setStartTime(startTimeOfTransport); builder.setEndTime(endTimeOfTransport); @@ -269,20 +269,20 @@ private void addShipmentTransportElement( builder.setCarrierService(serviceActivity.getService()); LspShipmentPlanElement transport = builder.build(); String idString = - transport.getResourceId() - + "" - + transport.getLogisticChainElement().getId() - + transport.getElementType(); + transport.getResourceId() + + "" + + transport.getLogisticChainElement().getId() + + transport.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) - .addPlanElement(id, transport); + .addPlanElement(id, transport); } private void addShipmentUnloadElement( - LspShipment tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipment tuple, Tour tour, Tour.ServiceActivity serviceActivity) { LspShipmentUtils.ScheduledShipmentUnloadBuilder builder = - LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance(); + LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance(); builder.setResourceId(resource.getId()); for (LogisticChainElement element : resource.getClientElements()) { @@ -297,20 +297,20 @@ private void addShipmentUnloadElement( final double startTime = serviceAct.getExpectedArrival(); final double endTime = startTime + serviceAct.getDuration(); Assert.isTrue( - endTime >= startTime, - "latest End must be later than earliest start. start: " + startTime + " ; end: " + endTime); + endTime >= startTime, + "latest End must be later than earliest start. start: " + startTime + " ; end: " + endTime); builder.setStartTime(startTime); builder.setEndTime(endTime); LspShipmentPlanElement unload = builder.build(); String idString = - unload.getResourceId() - + String.valueOf(unload.getLogisticChainElement().getId()) - + unload.getElementType(); + unload.getResourceId() + + String.valueOf(unload.getLogisticChainElement().getId()) + + unload.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getId()) - .addPlanElement(id, unload); + .addPlanElement(id, unload); } private Carrier createAuxiliaryCarrier(ArrayList shipmentsInCurrentTour, double startTime) { @@ -318,12 +318,12 @@ private Carrier createAuxiliaryCarrier(ArrayList shipmentsInCurrent carrierCnt++; Carrier auxiliaryCarrier = CarriersUtils.createCarrier(carrierId); CarrierVehicle carrierVehicle = - carrier.getCarrierCapabilities().getCarrierVehicles().values().iterator().next(); + carrier.getCarrierCapabilities().getCarrierVehicles().values().iterator().next(); final VehicleType vehicleType = carrierVehicle.getType(); CarrierVehicle.Builder vBuilder = - CarrierVehicle.Builder.newInstance( - carrierVehicle.getId(), carrierVehicle.getLinkId(), vehicleType); + CarrierVehicle.Builder.newInstance( + carrierVehicle.getId(), carrierVehicle.getLinkId(), vehicleType); vBuilder.setEarliestStart(startTime); vBuilder.setLatestEnd(24 * 60 * 60); CarrierVehicle cv = vBuilder.build(); @@ -338,12 +338,14 @@ private Carrier createAuxiliaryCarrier(ArrayList shipmentsInCurrent } private void addDistributionServiceEventHandler( - CarrierService carrierService, LspShipment lspShipment, LSPCarrierResource resource) { + CarrierService carrierService, + LspShipment lspShipment, + LSPCarrierResource resource) { for (LogisticChainElement element : this.resource.getClientElements()) { if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { DistributionServiceStartEventHandler handler = - new DistributionServiceStartEventHandler(carrierService, lspShipment, element, resource); + new DistributionServiceStartEventHandler(carrierService, lspShipment, element, resource); lspShipment.addSimulationTracker(handler); break; } @@ -351,20 +353,19 @@ private void addDistributionServiceEventHandler( } private void addDistributionTourStartEventHandler( - CarrierService carrierService, - LspShipment lspShipment, - LSPCarrierResource resource, - Tour tour) { + CarrierService carrierService, + LspShipment lspShipment, + LSPCarrierResource resource, + Tour tour) { for (LogisticChainElement element : this.resource.getClientElements()) { if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { LSPTourStartEventHandler handler = - new LSPTourStartEventHandler(lspShipment, carrierService, element, resource, tour); + new LSPTourStartEventHandler(lspShipment, carrierService, element, resource, tour); lspShipment.addSimulationTracker(handler); break; } } } - private record LSPCarrierPair(LspShipment lspShipment, CarrierService carrierService) {} } From 1293b86ee11c474147b2c3dfa5813773a73d59de Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 16 Aug 2024 15:40:13 +0200 Subject: [PATCH 3/4] build new object instead of just handing over the object. --- .../CollectionCarrierScheduler.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java index 8e19d993..708f5797 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java @@ -27,10 +27,7 @@ import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; -import org.matsim.freight.carriers.Carrier; -import org.matsim.freight.carriers.CarrierService; -import org.matsim.freight.carriers.ScheduledTour; -import org.matsim.freight.carriers.Tour; +import org.matsim.freight.carriers.*; import org.matsim.freight.carriers.Tour.Leg; import org.matsim.freight.carriers.Tour.ServiceActivity; import org.matsim.freight.carriers.Tour.TourElement; @@ -87,7 +84,7 @@ public void scheduleResource() { private CarrierService convertToCarrierService(LspShipment lspShipment) { Id serviceId = Id.create(lspShipment.getId().toString(), CarrierService.class); CarrierService carrierService = CarrierService.Builder.newInstance(serviceId, lspShipment.getFrom()) - .setServiceStartTimeWindow(lspShipment.getPickupTimeWindow()) + .setServiceStartTimeWindow(TimeWindow.newInstance(lspShipment.getPickupTimeWindow().getStart(), lspShipment.getPickupTimeWindow().getEnd())) .setCapacityDemand(lspShipment.getSize()) .setServiceDuration(lspShipment.getDeliveryServiceTime()) .build(); From 37d94efb0febf8c5ffcc2ea1389617649b03fe02 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 16 Aug 2024 15:51:13 +0200 Subject: [PATCH 4/4] test for values instead of objects --- .../CollectionLSPSchedulingTest.java | 10 ++++++++-- .../CompleteLSPSchedulingTest.java | 6 ++++-- .../FirstReloadLSPSchedulingTest.java | 6 ++++-- .../MainRunLSPSchedulingTest.java | 6 ++++-- ...leShipmentsCollectionLSPSchedulingTest.java | 6 ++++-- ...ipleShipmentsCompleteLSPSchedulingTest.java | 6 ++++-- ...eShipmentsFirstReloadLSPSchedulingTest.java | 6 ++++-- ...tipleShipmentsMainRunLSPSchedulingTest.java | 6 ++++-- ...ShipmentsSecondReloadLSPSchedulingTest.java | 17 ++++++++++++----- .../SecondReloadLSPSchedulingTest.java | 18 ++++++++++++------ 10 files changed, 60 insertions(+), 27 deletions(-) diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/CollectionLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/CollectionLSPSchedulingTest.java index 4064ef67..400ab067 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/CollectionLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/CollectionLSPSchedulingTest.java @@ -192,29 +192,35 @@ public void testCollectionLSPScheduling() { assertEquals(2, shipment.getSimulationTrackers().size()); ArrayList eventHandlers = new ArrayList<>(shipment.getSimulationTrackers()); + { assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); LSPTourEndEventHandler endHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(endHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(endHandler.getLogisticChainElement(), planElements.get(2).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), collectionLSP.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements().iterator().next()); assertSame(endHandler.getLspShipment(), shipment); assertSame(endHandler.getResourceId(), planElements.get(2).getResourceId()); assertSame(endHandler.getResourceId(), collectionLSP.getResources().iterator().next().getId()); + } + { assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler serviceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(serviceHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(serviceHandler.getElement(), planElements.get(1).getLogisticChainElement()); assertSame(serviceHandler.getElement(), collectionLSP.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements().iterator().next()); assertSame(serviceHandler.getLspShipment(), shipment); assertSame(serviceHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(serviceHandler.getResourceId(), collectionLSP.getResources().iterator().next().getId()); + } } for (LogisticChain solution : collectionLSP.getSelectedPlan().getLogisticChains()) { diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/CompleteLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/CompleteLSPSchedulingTest.java index e4227cbd..885a2d4f 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/CompleteLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/CompleteLSPSchedulingTest.java @@ -488,7 +488,8 @@ public void testCompletedLSPScheduling() { assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(endHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(endHandler.getLogisticChainElement(), planElements.get(0).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), planElements.get(1).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), planElements.get(2).getLogisticChainElement()); @@ -505,7 +506,8 @@ public void testCompletedLSPScheduling() { assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(serviceHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(serviceHandler.getElement(), planElements.get(0).getLogisticChainElement()); assertSame(serviceHandler.getElement(), planElements.get(1).getLogisticChainElement()); assertSame(serviceHandler.getElement(), planElements.get(2).getLogisticChainElement()); diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/FirstReloadLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/FirstReloadLSPSchedulingTest.java index 8ad0b1c4..90254732 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/FirstReloadLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/FirstReloadLSPSchedulingTest.java @@ -285,7 +285,8 @@ public void testFirstReloadLSPScheduling() { assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(endHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(endHandler.getLogisticChainElement(), planElements.get(2).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), lsp.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements().iterator().next()); assertSame(endHandler.getLspShipment(), shipment); @@ -297,7 +298,8 @@ public void testFirstReloadLSPScheduling() { assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(serviceHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(serviceHandler.getElement(), planElements.getFirst().getLogisticChainElement()); assertSame(serviceHandler.getElement(), lsp.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements().iterator().next()); assertSame(serviceHandler.getLspShipment(), shipment); diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MainRunLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MainRunLSPSchedulingTest.java index 7f6900e6..de0c1643 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MainRunLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MainRunLSPSchedulingTest.java @@ -353,7 +353,8 @@ public void testMainRunLSPScheduling() { assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(endHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(endHandler.getLogisticChainElement(), planElements.get(0).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), planElements.get(1).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), planElements.get(2).getLogisticChainElement()); @@ -370,7 +371,8 @@ public void testMainRunLSPScheduling() { assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(serviceHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(serviceHandler.getElement(), planElements.get(0).getLogisticChainElement()); assertSame(serviceHandler.getElement(), planElements.get(1).getLogisticChainElement()); assertSame(serviceHandler.getElement(), planElements.get(2).getLogisticChainElement()); diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCollectionLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCollectionLSPSchedulingTest.java index 458a833b..173fa089 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCollectionLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCollectionLSPSchedulingTest.java @@ -200,7 +200,8 @@ public void testCollectionLSPScheduling() { assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(endHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(endHandler.getLogisticChainElement(), planElements.get(2).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), collectionLSP.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements().iterator().next()); assertSame(endHandler.getLspShipment(), shipment); @@ -212,7 +213,8 @@ public void testCollectionLSPScheduling() { assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(serviceHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(serviceHandler.getElement(), planElements.get(1).getLogisticChainElement()); assertSame(serviceHandler.getElement(), collectionLSP.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements().iterator().next()); assertSame(serviceHandler.getLspShipment(), shipment); diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCompleteLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCompleteLSPSchedulingTest.java index 8b09edd0..6994d171 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCompleteLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCompleteLSPSchedulingTest.java @@ -491,7 +491,8 @@ public void testCompletedLSPScheduling() { assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(endHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(endHandler.getLogisticChainElement(), planElements.get(0).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), planElements.get(1).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), planElements.get(2).getLogisticChainElement()); @@ -508,7 +509,8 @@ public void testCompletedLSPScheduling() { assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(serviceHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(serviceHandler.getElement(), planElements.get(0).getLogisticChainElement()); assertSame(serviceHandler.getElement(), planElements.get(1).getLogisticChainElement()); assertSame(serviceHandler.getElement(), planElements.get(2).getLogisticChainElement()); diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsFirstReloadLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsFirstReloadLSPSchedulingTest.java index d101b4c9..2b6a2e60 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsFirstReloadLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsFirstReloadLSPSchedulingTest.java @@ -284,7 +284,8 @@ public void testFirstReloadLSPScheduling() { assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(endHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(endHandler.getLogisticChainElement(), planElements.get(2).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), lsp.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements().iterator().next()); assertSame(endHandler.getLspShipment(), shipment); @@ -296,7 +297,8 @@ public void testFirstReloadLSPScheduling() { assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(serviceHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(serviceHandler.getElement(), planElements.getFirst().getLogisticChainElement()); assertSame(serviceHandler.getElement(), lsp.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements().iterator().next()); assertSame(serviceHandler.getLspShipment(), shipment); diff --git a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsMainRunLSPSchedulingTest.java b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsMainRunLSPSchedulingTest.java index 4f0605cf..6c8bd2fe 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsMainRunLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsMainRunLSPSchedulingTest.java @@ -353,7 +353,8 @@ public void testMainRunLSPScheduling() { assertSame(endHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(endHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(endHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(endHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(endHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(endHandler.getLogisticChainElement(), planElements.get(0).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), planElements.get(1).getLogisticChainElement()); assertSame(endHandler.getLogisticChainElement(), planElements.get(2).getLogisticChainElement()); @@ -370,7 +371,8 @@ public void testMainRunLSPScheduling() { assertSame(serviceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(serviceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(serviceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(serviceHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(serviceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(serviceHandler.getElement(), planElements.get(0).getLogisticChainElement()); assertSame(serviceHandler.getElement(), planElements.get(1).getLogisticChainElement()); assertSame(serviceHandler.getElement(), planElements.get(2).getLogisticChainElement()); 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 4766d616..236e1dd2 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java @@ -427,12 +427,14 @@ public void testSecondReloadLSPScheduling() { ArrayList resources = new ArrayList<>(lsp.getResources()); //CollectionTourEnd + { assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); LSPTourEndEventHandler collectionEndHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); assertSame(collectionEndHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(collectionEndHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(collectionEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(collectionEndHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(collectionEndHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(collectionEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(collectionEndHandler.getLogisticChainElement(), planElements.get(0).getLogisticChainElement()); assertSame(collectionEndHandler.getLogisticChainElement(), planElements.get(1).getLogisticChainElement()); assertSame(collectionEndHandler.getLogisticChainElement(), planElements.get(2).getLogisticChainElement()); @@ -442,14 +444,16 @@ public void testSecondReloadLSPScheduling() { assertSame(collectionEndHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(collectionEndHandler.getResourceId(), planElements.get(2).getResourceId()); assertSame(collectionEndHandler.getResourceId(), resources.getFirst().getId()); + } - //CollectionServiceEnd + {//CollectionServiceEnd assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler collectionServiceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); assertSame(collectionServiceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(collectionServiceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(collectionServiceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(collectionServiceHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(collectionServiceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(collectionServiceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(collectionServiceHandler.getElement(), planElements.get(0).getLogisticChainElement()); assertSame(collectionServiceHandler.getElement(), planElements.get(1).getLogisticChainElement()); assertSame(collectionServiceHandler.getElement(), planElements.get(2).getLogisticChainElement()); @@ -459,8 +463,9 @@ public void testSecondReloadLSPScheduling() { assertSame(collectionServiceHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(collectionServiceHandler.getResourceId(), planElements.get(2).getResourceId()); assertSame(collectionServiceHandler.getResourceId(), resources.getFirst().getId()); + } - //MainRunStart + {//MainRunStart assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(2)); LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2); assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId); @@ -477,8 +482,9 @@ public void testSecondReloadLSPScheduling() { assertSame(mainRunStartHandler.getResourceId(), planElements.get(5).getResourceId()); assertSame(mainRunStartHandler.getResourceId(), planElements.get(6).getResourceId()); assertSame(mainRunStartHandler.getResourceId(), resources.get(2).getId()); + } - //MainRunEnd + {//MainRunEnd assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.get(3)); LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3); assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId); @@ -495,6 +501,7 @@ public void testSecondReloadLSPScheduling() { assertSame(mainRunEndHandler.getResourceId(), planElements.get(5).getResourceId()); assertSame(mainRunEndHandler.getResourceId(), planElements.get(6).getResourceId()); assertSame(mainRunEndHandler.getResourceId(), resources.get(2).getId()); + } } for (LogisticChain solution : lsp.getSelectedPlan().getLogisticChains()) { 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 f7a32ede..e158884b 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java @@ -434,13 +434,14 @@ public void testSecondReloadLSPScheduling() { ArrayList solutionElements = new ArrayList<>(lsp.getSelectedPlan().getLogisticChains().iterator().next().getLogisticChainElements()); ArrayList resources = new ArrayList<>(lsp.getResources()); - //CollectionTourEnd + {//CollectionTourEnd assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.getFirst()); LSPTourEndEventHandler collectionEndHandler = (LSPTourEndEventHandler) eventHandlers.getFirst(); assertSame(collectionEndHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(collectionEndHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(collectionEndHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(collectionEndHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(collectionEndHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(collectionEndHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(collectionEndHandler.getLogisticChainElement(), planElements.get(0).getLogisticChainElement()); assertSame(collectionEndHandler.getLogisticChainElement(), planElements.get(1).getLogisticChainElement()); assertSame(collectionEndHandler.getLogisticChainElement(), planElements.get(2).getLogisticChainElement()); @@ -450,14 +451,16 @@ public void testSecondReloadLSPScheduling() { assertSame(collectionEndHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(collectionEndHandler.getResourceId(), planElements.get(2).getResourceId()); assertSame(collectionEndHandler.getResourceId(), resources.getFirst().getId()); + } - //CollectionServiceEnd + {//CollectionServiceEnd assertInstanceOf(CollectionServiceEndEventHandler.class, eventHandlers.get(1)); CollectionServiceEndEventHandler collectionServiceHandler = (CollectionServiceEndEventHandler) eventHandlers.get(1); assertSame(collectionServiceHandler.getCarrierService().getLocationLinkId(), shipment.getFrom()); assertEquals(collectionServiceHandler.getCarrierService().getCapacityDemand(), shipment.getSize()); assertEquals(collectionServiceHandler.getCarrierService().getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); - assertSame(collectionServiceHandler.getCarrierService().getServiceStartTimeWindow(), shipment.getPickupTimeWindow()); + assertEquals(collectionServiceHandler.getCarrierService().getServiceStartTimeWindow().getStart(), shipment.getPickupTimeWindow().getStart(), 0.0); + assertEquals(collectionServiceHandler.getCarrierService().getServiceStartTimeWindow().getEnd(), shipment.getPickupTimeWindow().getEnd(), 0.0); assertSame(collectionServiceHandler.getElement(), planElements.get(0).getLogisticChainElement()); assertSame(collectionServiceHandler.getElement(), planElements.get(1).getLogisticChainElement()); assertSame(collectionServiceHandler.getElement(), planElements.get(2).getLogisticChainElement()); @@ -467,8 +470,9 @@ public void testSecondReloadLSPScheduling() { assertSame(collectionServiceHandler.getResourceId(), planElements.get(1).getResourceId()); assertSame(collectionServiceHandler.getResourceId(), planElements.get(2).getResourceId()); assertSame(collectionServiceHandler.getResourceId(), resources.getFirst().getId()); + } - //MainRunStart + {//MainRunStart assertInstanceOf(LSPTourStartEventHandler.class, eventHandlers.get(2)); LSPTourStartEventHandler mainRunStartHandler = (LSPTourStartEventHandler) eventHandlers.get(2); assertSame(mainRunStartHandler.getCarrierService().getLocationLinkId(), toLinkId); @@ -485,8 +489,9 @@ public void testSecondReloadLSPScheduling() { assertSame(mainRunStartHandler.getResourceId(), planElements.get(5).getResourceId()); assertSame(mainRunStartHandler.getResourceId(), planElements.get(6).getResourceId()); assertSame(mainRunStartHandler.getResourceId(), resources.get(2).getId()); + } - //MainRunEnd + {//MainRunEnd assertInstanceOf(LSPTourEndEventHandler.class, eventHandlers.get(3)); LSPTourEndEventHandler mainRunEndHandler = (LSPTourEndEventHandler) eventHandlers.get(3); assertSame(mainRunEndHandler.getCarrierService().getLocationLinkId(), toLinkId); @@ -503,6 +508,7 @@ public void testSecondReloadLSPScheduling() { assertSame(mainRunEndHandler.getResourceId(), planElements.get(5).getResourceId()); assertSame(mainRunEndHandler.getResourceId(), planElements.get(6).getResourceId()); assertSame(mainRunEndHandler.getResourceId(), resources.get(2).getId()); + } } for (LogisticChain solution : lsp.getSelectedPlan().getLogisticChains()) {