From 9b2e27cf95d91b67729c3f84b99f56d17aefdd6f Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Wed, 14 Aug 2024 13:57:11 +0200 Subject: [PATCH] rename tuple to lspShipment, because the tuple "ShipmentWithTime" no longer exists --- .../CollectionCarrierScheduler.java | 83 +++++++++--------- .../DistributionCarrierScheduler.java | 85 +++++++++++-------- .../MainRunCarrierScheduler.java | 76 ++++++++--------- .../TransshipmentHubScheduler.java | 28 +++--- 4 files changed, 144 insertions(+), 128 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 c2c721b7..abc6c317 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java @@ -74,42 +74,42 @@ public void initializeValues(LSPResource resource) { @Override public void scheduleResource() { - for (LspShipment tupleToBeAssigned : lspShipmentsToSchedule) { - CarrierService carrierService = convertToCarrierService(tupleToBeAssigned); + for (LspShipment lspShipmentToBeAssigned : lspShipmentsToSchedule) { + CarrierService carrierService = convertToCarrierService(lspShipmentToBeAssigned); carrier.getServices().put(carrierService.getId(), carrierService); } CarrierSchedulerUtils.solveVrpWithJsprit(carrier, scenario); } - private CarrierService convertToCarrierService(LspShipment tuple) { + private CarrierService convertToCarrierService(LspShipment lspShipment) { Id serviceId = - Id.create(tuple.getId().toString(), CarrierService.class); + Id.create(lspShipment.getId().toString(), CarrierService.class); CarrierService.Builder builder = - CarrierService.Builder.newInstance(serviceId, tuple.getFrom()); - builder.setServiceStartTimeWindow(tuple.getPickupTimeWindow()); - builder.setCapacityDemand(tuple.getSize()); - builder.setServiceDuration(tuple.getDeliveryServiceTime()); + CarrierService.Builder.newInstance(serviceId, lspShipment.getFrom()); + builder.setServiceStartTimeWindow(lspShipment.getPickupTimeWindow()); + builder.setCapacityDemand(lspShipment.getSize()); + builder.setServiceDuration(lspShipment.getDeliveryServiceTime()); CarrierService carrierService = builder.build(); - pairs.add(new LSPCarrierPair(tuple, carrierService)); + pairs.add(new LSPCarrierPair(lspShipment, carrierService)); return carrierService; } @Override protected void updateShipments() { - for (LspShipment tuple : lspShipmentsToSchedule) { + for (LspShipment lspShipment : lspShipmentsToSchedule) { 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(tuple, serviceActivity.getService()); + LSPCarrierPair carrierPair = new LSPCarrierPair(lspShipment, serviceActivity.getService()); for (LSPCarrierPair pair : pairs) { - if (pair.tuple == carrierPair.tuple + if (pair.lspShipment == carrierPair.lspShipment && pair.carrierService.getId() == carrierPair.carrierService.getId()) { - addShipmentLoadElement(tuple, tour, serviceActivity); - addShipmentTransportElement(tuple, tour, serviceActivity); - addShipmentUnloadElement(tuple, tour, serviceActivity); - addCollectionTourEndEventHandler(pair.carrierService, tuple, resource, tour); - addCollectionServiceEventHandler(pair.carrierService, tuple, resource); + addShipmentLoadElement(lspShipment, tour, serviceActivity); + addShipmentTransportElement(lspShipment, tour, serviceActivity); + addShipmentUnloadElement(lspShipment, tour, serviceActivity); + addCollectionTourEndEventHandler(pair.carrierService, lspShipment, resource, tour); + addCollectionServiceEventHandler(pair.carrierService, lspShipment, resource); } } } @@ -119,47 +119,52 @@ protected void updateShipments() { } private void addShipmentLoadElement( - LspShipment tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipmentUtils.ScheduledShipmentLoadBuilder builder = LspShipmentUtils.ScheduledShipmentLoadBuilder.newInstance(); builder.setResourceId(resource.getId()); + for (LogisticChainElement element : resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticChainElement(element); } } + int serviceIndex = tour.getTourElements().indexOf(serviceActivity); Leg legBeforeService = (Leg) tour.getTourElements().get(serviceIndex - 1); double startTimeOfLoading = legBeforeService.getExpectedDepartureTime() + legBeforeService.getExpectedTransportTime(); builder.setStartTime(startTimeOfLoading); - builder.setEndTime(startTimeOfLoading + tuple.getDeliveryServiceTime()); + builder.setEndTime(startTimeOfLoading + lspShipment.getDeliveryServiceTime()); LspShipmentPlanElement load = builder.build(); String idString = load.getResourceId() + "" + load.getLogisticChainElement().getId() + load.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, load); } private void addShipmentTransportElement( - LspShipment tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipmentUtils.ScheduledShipmentTransportBuilder builder = LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance(); builder.setResourceId(resource.getId()); + for (LogisticChainElement element : resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticChainElement(element); } } + int serviceIndex = tour.getTourElements().indexOf(serviceActivity); Leg legAfterService = (Leg) tour.getTourElements().get(serviceIndex + 1); double startTimeOfTransport = legAfterService.getExpectedDepartureTime(); builder.setStartTime(startTimeOfTransport); Leg lastLeg = (Leg) tour.getTourElements().getLast(); - double endTimeOfTransport = - lastLeg.getExpectedDepartureTime() + lastLeg.getExpectedTransportTime(); + double endTimeOfTransport = lastLeg.getExpectedDepartureTime() + lastLeg.getExpectedTransportTime(); builder.setEndTime(endTimeOfTransport); builder.setCarrierId(carrier.getId()); builder.setFromLinkId(serviceActivity.getLocation()); @@ -172,18 +177,19 @@ private void addShipmentTransportElement( + transport.getLogisticChainElement().getId() + transport.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, transport); } private void addCollectionServiceEventHandler( - CarrierService carrierService, LspShipment tuple, LSPCarrierResource resource) { + CarrierService carrierService, LspShipment lspShipment, LSPCarrierResource resource) { + for (LogisticChainElement element : this.resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { CollectionServiceEndEventHandler endHandler = new CollectionServiceEndEventHandler( - carrierService, tuple, element, resource); - tuple.addSimulationTracker(endHandler); + carrierService, lspShipment, element, resource); + lspShipment.addSimulationTracker(endHandler); break; } } @@ -191,27 +197,28 @@ private void addCollectionServiceEventHandler( private void addCollectionTourEndEventHandler( CarrierService carrierService, - LspShipment tuple, + LspShipment lspShipment, LSPCarrierResource resource, Tour tour) { for (LogisticChainElement element : this.resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { LSPTourEndEventHandler handler = new LSPTourEndEventHandler( - tuple, carrierService, element, resource, tour); - tuple.addSimulationTracker(handler); + lspShipment, carrierService, element, resource, tour); + lspShipment.addSimulationTracker(handler); break; } } } private void addShipmentUnloadElement( - LspShipment tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipmentUtils.ScheduledShipmentUnloadBuilder builder = LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance(); builder.setResourceId(resource.getId()); for (LogisticChainElement element : resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticsChainElement(element); } } @@ -227,7 +234,7 @@ private void addShipmentUnloadElement( + unload.getLogisticChainElement().getId() + unload.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, unload); } @@ -241,5 +248,5 @@ private double getUnloadEndTime(Tour tour) { return unloadEndTime; } - private record LSPCarrierPair(LspShipment tuple, CarrierService carrierService) {} + 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 c1ba5484..b78da4e1 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java @@ -89,13 +89,13 @@ protected void scheduleResource() { ArrayList shipmentsInCurrentTour = new ArrayList<>(); List scheduledPlans = new LinkedList<>(); - for (LspShipment tuple : copyOfAssignedShipments) { + for (LspShipment lspShipment : copyOfAssignedShipments) { // TODO KMT: Verstehe es nur mäßig, was er hier mit den Fahrzeugtypen macht. Er nimmt einfach // 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(); - if ((load + tuple.getSize()) + if ((load + lspShipment.getSize()) > vehicleType.getCapacity().getOther().intValue()) { load = 0; Carrier auxiliaryCarrier = @@ -107,10 +107,10 @@ protected void scheduleResource() { cumulatedLoadingTime = 0; shipmentsInCurrentTour.clear(); } - shipmentsInCurrentTour.add(tuple); - load = load + tuple.getSize(); - cumulatedLoadingTime = cumulatedLoadingTime + tuple.getDeliveryServiceTime(); - availabilityTimeOfLastShipment = tuple.getTime(); + shipmentsInCurrentTour.add(lspShipment); + load = load + lspShipment.getSize(); + cumulatedLoadingTime = cumulatedLoadingTime + lspShipment.getDeliveryServiceTime(); + availabilityTimeOfLastShipment = lspShipment.getTime(); } if (!shipmentsInCurrentTour.isEmpty()) { @@ -170,34 +170,34 @@ private Collection unifyTourIds(Collection carrierPl return scheduledToursUnified; } - private CarrierService convertToCarrierService(LspShipment tuple) { + private CarrierService convertToCarrierService(LspShipment lspShipment) { Id serviceId = - Id.create(tuple.getId().toString(), CarrierService.class); + Id.create(lspShipment.getId().toString(), CarrierService.class); CarrierService.Builder builder = - CarrierService.Builder.newInstance(serviceId, tuple.getTo()); - builder.setCapacityDemand(tuple.getSize()); - builder.setServiceDuration(tuple.getDeliveryServiceTime()); + CarrierService.Builder.newInstance(serviceId, lspShipment.getTo()); + builder.setCapacityDemand(lspShipment.getSize()); + builder.setServiceDuration(lspShipment.getDeliveryServiceTime()); CarrierService carrierService = builder.build(); - pairs.add(new LSPCarrierPair(tuple, carrierService)); + pairs.add(new LSPCarrierPair(lspShipment, carrierService)); return carrierService; } @Override protected void updateShipments() { - for (LspShipment tuple : lspShipmentsToSchedule) { + for (LspShipment lspShipment : lspShipmentsToSchedule) { for (ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()) { Tour tour = scheduledTour.getTour(); for (TourElement element : tour.getTourElements()) { if (element instanceof ServiceActivity serviceActivity) { - LSPCarrierPair carrierPair = new LSPCarrierPair(tuple, serviceActivity.getService()); + LSPCarrierPair carrierPair = new LSPCarrierPair(lspShipment, serviceActivity.getService()); for (LSPCarrierPair pair : pairs) { - if (pair.tuple == carrierPair.tuple + if (pair.lspShipment == carrierPair.lspShipment && pair.carrierService.getId() == carrierPair.carrierService.getId()) { - addShipmentLoadElement(tuple, tour, serviceActivity); - addShipmentTransportElement(tuple, tour, serviceActivity); - addShipmentUnloadElement(tuple, tour, serviceActivity); - addDistributionTourStartEventHandler(pair.carrierService, tuple, resource, tour); - addDistributionServiceEventHandler(pair.carrierService, tuple, resource); + addShipmentLoadElement(lspShipment, tour, serviceActivity); + addShipmentTransportElement(lspShipment, tour, serviceActivity); + addShipmentUnloadElement(lspShipment, tour, serviceActivity); + addDistributionTourStartEventHandler(pair.carrierService, lspShipment, resource, tour); + addDistributionServiceEventHandler(pair.carrierService, lspShipment, resource); } } } @@ -207,15 +207,18 @@ protected void updateShipments() { } private void addShipmentLoadElement( - LspShipment tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipmentUtils.ScheduledShipmentLoadBuilder builder = LspShipmentUtils.ScheduledShipmentLoadBuilder.newInstance(); builder.setResourceId(resource.getId()); + for (LogisticChainElement element : resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticChainElement(element); } } + int startIndex = tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); Leg legAfterStart = (Leg) tour.getTourElements().get(startIndex + 1); @@ -233,20 +236,23 @@ private void addShipmentLoadElement( String idString = load.getResourceId() + "" + load.getLogisticChainElement().getId() + load.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, load); } private void addShipmentTransportElement( - LspShipment tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipmentUtils.ScheduledShipmentTransportBuilder builder = LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance(); builder.setResourceId(resource.getId()); + for (LogisticChainElement element : resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticChainElement(element); } } + int startIndex = tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); final Leg legAfterStart = (Leg) tour.getTourElements().get(startIndex + 1); @@ -275,20 +281,23 @@ private void addShipmentTransportElement( + transport.getLogisticChainElement().getId() + transport.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, transport); } private void addShipmentUnloadElement( LspShipment tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipmentUtils.ScheduledShipmentUnloadBuilder builder = LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance(); builder.setResourceId(resource.getId()); + for (LogisticChainElement element : resource.getClientElements()) { if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { builder.setLogisticsChainElement(element); } } + int serviceIndex = tour.getTourElements().indexOf(serviceActivity); ServiceActivity serviceAct = (ServiceActivity) tour.getTourElements().get(serviceIndex); @@ -328,20 +337,21 @@ private Carrier createAuxiliaryCarrier(ArrayList shipmentsInCurrent auxiliaryCarrier.getCarrierCapabilities().getCarrierVehicles().put(cv.getId(), cv); auxiliaryCarrier.getCarrierCapabilities().setFleetSize(FleetSize.FINITE); - for (LspShipment tuple : shipmentsInCurrentTour) { - CarrierService carrierService = convertToCarrierService(tuple); + for (LspShipment lspShipment : shipmentsInCurrentTour) { + CarrierService carrierService = convertToCarrierService(lspShipment); auxiliaryCarrier.getServices().put(carrierService.getId(), carrierService); } return auxiliaryCarrier; } private void addDistributionServiceEventHandler( - CarrierService carrierService, LspShipment tuple, LSPCarrierResource resource) { + CarrierService carrierService, LspShipment lspShipment, LSPCarrierResource resource) { + for (LogisticChainElement element : this.resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { DistributionServiceStartEventHandler handler = - new DistributionServiceStartEventHandler(carrierService, tuple, element, resource); - tuple.addSimulationTracker(handler); + new DistributionServiceStartEventHandler(carrierService, lspShipment, element, resource); + lspShipment.addSimulationTracker(handler); break; } } @@ -349,18 +359,19 @@ private void addDistributionServiceEventHandler( private void addDistributionTourStartEventHandler( CarrierService carrierService, - LspShipment tuple, + LspShipment lspShipment, LSPCarrierResource resource, Tour tour) { + for (LogisticChainElement element : this.resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { LSPTourStartEventHandler handler = - new LSPTourStartEventHandler(tuple, carrierService, element, resource, tour); - tuple.addSimulationTracker(handler); + new LSPTourStartEventHandler(lspShipment, carrierService, element, resource, tour); + lspShipment.addSimulationTracker(handler); break; } } } - private record LSPCarrierPair(LspShipment tuple, CarrierService carrierService) {} + private record LSPCarrierPair(LspShipment lspShipment, CarrierService carrierService) {} } diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/MainRunCarrierScheduler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/MainRunCarrierScheduler.java index 40d80f73..54bc52b4 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/MainRunCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/MainRunCarrierScheduler.java @@ -83,22 +83,22 @@ protected void scheduleResource() { // ArrayList scheduledTours = new ArrayList<>(); List scheduledPlans = new LinkedList<>(); - for (LspShipment tuple : copyOfAssignedShipments) { + for (LspShipment lspShipment : copyOfAssignedShipments) { // Add job as "services" to the carrier. So the carrier has this available - CarrierService carrierService = convertToCarrierService(tuple); + CarrierService carrierService = convertToCarrierService(lspShipment); carrier.getServices().put(carrierService.getId(), carrierService); VehicleType vehicleType = ResourceImplementationUtils.getVehicleTypeCollection(carrier).iterator().next(); - if ((load + tuple.getSize()) + if ((load + lspShipment.getSize()) > vehicleType.getCapacity().getOther().intValue()) { load = 0; CarrierPlan plan = createPlan(carrier, shipmentsInCurrentTour); scheduledPlans.add(plan); shipmentsInCurrentTour.clear(); } - shipmentsInCurrentTour.add(tuple); - load = load + tuple.getSize(); + shipmentsInCurrentTour.add(lspShipment); + load = load + lspShipment.getSize(); } if (!shipmentsInCurrentTour.isEmpty()) { CarrierPlan plan = createPlan(carrier, shipmentsInCurrentTour); @@ -115,7 +115,7 @@ protected void scheduleResource() { carrier.setSelectedPlan(plan); } - private CarrierPlan createPlan(Carrier carrier, List tuples) { + private CarrierPlan createPlan(Carrier carrier, List lspShipments) { // TODO: Allgemein: Hier ist alles manuell zusammen gesetzt; es findet KEINE Tourenplanung // statt! @@ -133,14 +133,14 @@ private CarrierPlan createPlan(Carrier carrier, List tuples) { double totalLoadingTime = 0; double latestTupleTime = 0; - for (LspShipment tuple : tuples) { - totalLoadingTime = totalLoadingTime + tuple.getDeliveryServiceTime(); - if (tuple.getTime() > latestTupleTime) { - latestTupleTime = tuple.getTime(); + for (LspShipment lspShipment : lspShipments) { + totalLoadingTime = totalLoadingTime + lspShipment.getDeliveryServiceTime(); + if (lspShipment.getTime() > latestTupleTime) { + latestTupleTime = lspShipment.getTime(); } tourBuilder.addLeg(new Leg()); - CarrierService carrierService = convertToCarrierService(tuple); - pairs.add(new LSPShipmentCarrierServicePair(tuple, carrierService)); + CarrierService carrierService = convertToCarrierService(lspShipment); + pairs.add(new LSPShipmentCarrierServicePair(lspShipment, carrierService)); tourBuilder.scheduleService(carrierService); } @@ -223,13 +223,13 @@ private double scorePlanManually(CarrierPlan plan) { return (-score); // negative, because we are looking at "costs" instead of "utility" } - private CarrierService convertToCarrierService(LspShipment tuple) { + private CarrierService convertToCarrierService(LspShipment lspShipment) { Id serviceId = - Id.create(tuple.getId().toString(), CarrierService.class); + Id.create(lspShipment.getId().toString(), CarrierService.class); CarrierService.Builder builder = CarrierService.Builder.newInstance(serviceId, resource.getEndLinkId()); - builder.setCapacityDemand(tuple.getSize()); - builder.setServiceDuration(tuple.getDeliveryServiceTime()); + builder.setCapacityDemand(lspShipment.getSize()); + builder.setServiceDuration(lspShipment.getDeliveryServiceTime()); return builder.build(); } @@ -244,7 +244,7 @@ protected void updateShipments() { new LSPShipmentCarrierServicePair( LspShipment, serviceActivity.getService()); for (LSPShipmentCarrierServicePair pair : pairs) { - if (pair.tuple == carrierPair.tuple + if (pair.lspShipment == carrierPair.lspShipment && pair.carrierService.getId() == carrierPair.carrierService.getId()) { addShipmentLoadElement(LspShipment, tour); addShipmentTransportElement(LspShipment, tour, serviceActivity); @@ -259,13 +259,12 @@ protected void updateShipments() { } } - private void addShipmentLoadElement( - LspShipment tuple, Tour tour) { + private void addShipmentLoadElement(LspShipment lspShipment, Tour tour) { LspShipmentUtils.ScheduledShipmentLoadBuilder builder = LspShipmentUtils.ScheduledShipmentLoadBuilder.newInstance(); builder.setResourceId(resource.getId()); for (LogisticChainElement element : resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticChainElement(element); } } @@ -288,17 +287,16 @@ private void addShipmentLoadElement( + String.valueOf(load.getLogisticChainElement().getId()) + load.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, load); } - private void addShipmentTransportElement( - LspShipment tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + private void addShipmentTransportElement(LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { LspShipmentUtils.ScheduledShipmentTransportBuilder builder = LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance(); builder.setResourceId(resource.getId()); for (LogisticChainElement element : resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticChainElement(element); } } @@ -318,17 +316,16 @@ private void addShipmentTransportElement( + String.valueOf(transport.getLogisticChainElement().getId()) + transport.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, transport); } - private void addShipmentUnloadElement( - LspShipment tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + private void addShipmentUnloadElement(LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { LspShipmentUtils.ScheduledShipmentUnloadBuilder builder = LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance(); builder.setResourceId(resource.getId()); for (LogisticChainElement element : resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticsChainElement(element); } } @@ -354,20 +351,21 @@ private void addShipmentUnloadElement( + String.valueOf(unload.getLogisticChainElement().getId()) + unload.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, unload); } private void addMainTourRunStartEventHandler( - CarrierService carrierService, - LspShipment tuple, + CarrierService carrierService, + LspShipment lspShipment, LSPCarrierResource resource, Tour tour) { + for (LogisticChainElement element : this.resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { LSPTourStartEventHandler handler = - new LSPTourStartEventHandler(tuple, carrierService, element, resource, tour); - tuple.addSimulationTracker(handler); + new LSPTourStartEventHandler(lspShipment, carrierService, element, resource, tour); + lspShipment.addSimulationTracker(handler); break; } } @@ -375,18 +373,18 @@ private void addMainTourRunStartEventHandler( private void addMainRunTourEndEventHandler( CarrierService carrierService, - LspShipment tuple, + LspShipment lspShipment, LSPCarrierResource resource, Tour tour) { for (LogisticChainElement element : this.resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { LSPTourEndEventHandler handler = - new LSPTourEndEventHandler(tuple, carrierService, element, resource, tour); - tuple.addSimulationTracker(handler); + new LSPTourEndEventHandler(lspShipment, carrierService, element, resource, tour); + lspShipment.addSimulationTracker(handler); break; } } } - private record LSPShipmentCarrierServicePair(LspShipment tuple, CarrierService carrierService) {} + private record LSPShipmentCarrierServicePair(LspShipment lspShipment, CarrierService carrierService) {} } diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/TransshipmentHubScheduler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/TransshipmentHubScheduler.java index b2ed65fe..9d1d7348 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/TransshipmentHubScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/TransshipmentHubScheduler.java @@ -55,8 +55,8 @@ protected void initializeValues(LSPResource resource) { @Override protected void scheduleResource() { - for (LspShipment tupleToBeAssigned : lspShipmentsToSchedule) { - updateSchedule(tupleToBeAssigned); + for (LspShipment lspShipmentToBeAssigned : lspShipmentsToSchedule) { + updateSchedule(lspShipmentToBeAssigned); } } @@ -66,20 +66,20 @@ protected void updateShipments() { log.error("This method is not implemented. Nothing will happen here. "); } - private void updateSchedule(LspShipment tuple) { - addShipmentHandleElement(tuple); - addShipmentToEventHandler(tuple); + private void updateSchedule(LspShipment lspShipment) { + addShipmentHandleElement(lspShipment); + addShipmentToEventHandler(lspShipment); } - private void addShipmentHandleElement(LspShipment tuple) { + private void addShipmentHandleElement(LspShipment lspShipment) { LspShipmentUtils.ScheduledShipmentHandleBuilder builder = LspShipmentUtils.ScheduledShipmentHandleBuilder.newInstance(); - builder.setStartTime(tuple.getTime()); + builder.setStartTime(lspShipment.getTime()); builder.setEndTime( - tuple.getTime() + capacityNeedFixed + capacityNeedLinear * tuple.getSize()); + lspShipment.getTime() + capacityNeedFixed + capacityNeedLinear * lspShipment.getSize()); builder.setResourceId(transshipmentHubResource.getId()); for (LogisticChainElement element : transshipmentHubResource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { builder.setLogisticsChainElement(element); } } @@ -89,16 +89,16 @@ private void addShipmentHandleElement(LspShipment tuple) { + String.valueOf(handle.getLogisticChainElement().getId()) + handle.getElementType(); Id id = Id.create(idString, LspShipmentPlanElement.class); - LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, tuple.getId()) + LspShipmentUtils.getOrCreateShipmentPlan(super.lspPlan, lspShipment.getId()) .addPlanElement(id, handle); } - private void addShipmentToEventHandler(LspShipment tuple) { + private void addShipmentToEventHandler(LspShipment lspShipment) { for (LogisticChainElement element : transshipmentHubResource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(tuple)) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { LspShipmentPlan lspShipmentPlan = - LspShipmentUtils.getOrCreateShipmentPlan(lspPlan, tuple.getId()); - eventHandler.addShipment(tuple, element, lspShipmentPlan); + LspShipmentUtils.getOrCreateShipmentPlan(lspPlan, lspShipment.getId()); + eventHandler.addShipment(lspShipment, element, lspShipmentPlan); break; } }