From bcfb579dfe854a3936408d22548c6e6c14c141d6 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Wed, 21 Aug 2024 13:03:46 +0200 Subject: [PATCH 01/18] comment --- .../resourceImplementations/CarrierSchedulerUtils.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java index bb668d07..f5a9ca62 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java @@ -43,6 +43,10 @@ public class CarrierSchedulerUtils { * @return Carrier with the solution of the VehicleRoutingProblem and the routed plan. */ public static Carrier solveVrpWithJsprit(Carrier carrier, Scenario scenario) { + // Maybe it make sense to store this object instead of rebuilding it for each carrier (in each iteration) ??? + // pro: save computation time + // con: interdependencies, if something changes in the network (load), the object is not up-to-date & it is not clear, if the object is thread safe + // Decision for the time being: rebuild it for each carrier to have a clear state KMT/KN Aug'24 NetworkBasedTransportCosts netbasedTransportCosts; Network network = scenario.getNetwork(); RoadPricingScheme roadPricingScheme = null; From 17eee39e95a73a9c0542f34e6115f95d386fbb85 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 23 Aug 2024 15:50:09 +0200 Subject: [PATCH 02/18] towards using shipments for the delivery carrier. --- .../CarrierSchedulerUtils.java | 10 +- .../DistributionCarrierScheduler.java | 93 ++++++++++++++----- 2 files changed, 78 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java index f5a9ca62..022b41db 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java @@ -130,10 +130,16 @@ public static void setVrpLogic(Carrier carrier, LSPUtils.LogicOfVrp logicOfVrp){ * This decides later, whether the VRP is build base on {@link org.matsim.freight.carriers.CarrierService}s or {@link org.matsim.freight.carriers.CarrierShipment}s. * * @param carrier The carrier for which the setting should be got. - * @return the logic of the VRP + * @return the logic of the VRP, returns {@link LSPUtils.LogicOfVrp#serviceBased} if not set. */ public static LSPUtils.LogicOfVrp getVrpLogic(Carrier carrier){ - return (LSPUtils.LogicOfVrp) carrier.getAttributes().getAttribute(LOGIC_OF_VRP); + LSPUtils.LogicOfVrp result = (LSPUtils.LogicOfVrp) carrier.getAttributes().getAttribute(LOGIC_OF_VRP); + if (result == null){ + log.error("VRPLogic not found for carrier {}. Will return {}", carrier.getId(), LSPUtils.LogicOfVrp.serviceBased); + return LSPUtils.LogicOfVrp.serviceBased; + } else { + return result ; + } } } 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 5a3de136..c724e547 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java @@ -92,17 +92,21 @@ protected void scheduleResource() { // 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 + lspShipment.getSize()) - > vehicleType.getCapacity().getOther().intValue()) { + VehicleType vehicleType = ResourceImplementationUtils.getVehicleTypeCollection(carrier).iterator().next(); + if ((load + lspShipment.getSize()) > vehicleType.getCapacity().getOther().intValue()) { load = 0; Carrier auxiliaryCarrier = CarrierSchedulerUtils.solveVrpWithJsprit( createAuxiliaryCarrier(shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime), scenario); scheduledPlans.add(auxiliaryCarrier.getSelectedPlan()); - carrier.getServices().putAll(auxiliaryCarrier.getServices()); + var vrpLogic = CarrierSchedulerUtils.getVrpLogic(carrier); + switch (vrpLogic) { + case serviceBased -> { carrier.getServices().putAll(auxiliaryCarrier.getServices()); } + case shipmentBased -> { carrier.getShipments().putAll(auxiliaryCarrier.getShipments()); } + default -> throw new IllegalStateException("Unexpected value: " + vrpLogic); + } + cumulatedLoadingTime = 0; shipmentsInCurrentTour.clear(); } @@ -115,11 +119,19 @@ protected void scheduleResource() { if (!shipmentsInCurrentTour.isEmpty()) { Carrier auxiliaryCarrier = CarrierSchedulerUtils.solveVrpWithJsprit( - createAuxiliaryCarrier( - shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime), + createAuxiliaryCarrier(shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime), scenario); scheduledPlans.add(auxiliaryCarrier.getSelectedPlan()); - carrier.getServices().putAll(auxiliaryCarrier.getServices()); + + switch (CarrierSchedulerUtils.getVrpLogic(carrier)) { + case serviceBased -> { carrier.getServices().putAll(auxiliaryCarrier.getServices()); } + case shipmentBased -> { carrier.getShipments().putAll(auxiliaryCarrier.getShipments()); + //TODO: When using shipmentbased, only ONE Vrp should be created and solved. -> No need for the auxiliary carrier(s). KMT'Aug 24 + //Then we can also just pass all the vehicles over :) + //And need the TimeWindows for the Shipments... + } + default -> throw new IllegalStateException("Unexpected value: " + CarrierSchedulerUtils.getVrpLogic(carrier)); + } shipmentsInCurrentTour.clear(); } @@ -172,6 +184,8 @@ private Collection unifyTourIds(Collection carrierPl private CarrierService convertToCarrierService(LspShipment lspShipment) { Id serviceId = Id.create(lspShipment.getId().toString(), CarrierService.class); CarrierService carrierService = CarrierService.Builder.newInstance(serviceId, lspShipment.getTo()) + //TODO TimeWindows are not set. This seems to be a problem. KMT'Aug'24 + //If added here, we also need to decide what happens, if the vehicles StartTime (plus TT) is > TimeWindowEnd .... .setCapacityDemand(lspShipment.getSize()) .setServiceDuration(lspShipment.getDeliveryServiceTime()) .build(); @@ -183,6 +197,29 @@ private CarrierService convertToCarrierService(LspShipment lspShipment) { return carrierService; } +/** +* This method converts a LspShipment to a CarrierShipment. + * Please note: This method may get removed in the future, in case that the LSPShipment and the CarrierShipment are merged. KMT'Aug'24 + + * @param lspShipment the LspShipment to convert + * @return a CarrierShipment +*/ + private CarrierShipment convertToCarrierShipment(LspShipment lspShipment) { + Id serviceId = Id.create(lspShipment.getId().toString(), CarrierShipment.class); + CarrierShipment carrierShipment = CarrierShipment.Builder.newInstance(serviceId, lspShipment.getFrom(), lspShipment.getTo(), lspShipment.getSize()) + //TODO TimeWindows are not set. This seems to be a problem. KMT'Aug'24 + //If added here, we also need to decide what happens, if the vehicles StartTime (plus TT) is > TimeWindowEnd .... + .setDeliveryServiceTime(lspShipment.getDeliveryServiceTime()) + .build(); + //ensure that the ids of the lspShipment and the carrierShipment are the same. This is needed for updating the LSPShipmentPlan + if (! Objects.equals(lspShipment.getId().toString(), carrierShipment.getId().toString())) { + log.error("Id of LspShipment: {} and CarrierService: {} do not match", lspShipment.getId().toString(), carrierShipment.getId().toString(), + new IllegalStateException("Id of LspShipment and CarrierService do not match")); + } + return carrierShipment; + } + + @Override protected void updateShipments() { for (LspShipment lspShipment : lspShipmentsToSchedule) { @@ -235,7 +272,7 @@ private void addShipmentLoadElement(LspShipment lspShipment, Tour tour) { } private void addShipmentTransportElement( - LspShipment lspShipment, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipment lspShipment, Tour tour, ServiceActivity serviceActivity) { LspShipmentUtils.ScheduledShipmentTransportBuilder builder = LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance(); @@ -279,7 +316,7 @@ private void addShipmentTransportElement( } private void addShipmentUnloadElement( - LspShipment tuple, Tour tour, Tour.ServiceActivity serviceActivity) { + LspShipment tuple, Tour tour, ServiceActivity serviceActivity) { LspShipmentUtils.ScheduledShipmentUnloadBuilder builder = LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance(); @@ -316,24 +353,34 @@ private void addShipmentUnloadElement( private Carrier createAuxiliaryCarrier(ArrayList shipmentsInCurrentTour, double startTime) { final Id carrierId = Id.create(carrier.getId().toString() + carrierCnt, Carrier.class); carrierCnt++; + + CarrierVehicle carrierVehicle = carrier.getCarrierCapabilities().getCarrierVehicles().values().iterator().next(); + CarrierVehicle cv = CarrierVehicle.Builder.newInstance( + carrierVehicle.getId(), carrierVehicle.getLinkId(), carrierVehicle.getType()) + .setEarliestStart(startTime) + .setLatestEnd(24 * 60 * 60) + .build(); Carrier auxiliaryCarrier = CarriersUtils.createCarrier(carrierId); - CarrierVehicle carrierVehicle = - carrier.getCarrierCapabilities().getCarrierVehicles().values().iterator().next(); - final VehicleType vehicleType = carrierVehicle.getType(); - - CarrierVehicle.Builder vBuilder = - CarrierVehicle.Builder.newInstance( - carrierVehicle.getId(), carrierVehicle.getLinkId(), vehicleType); - vBuilder.setEarliestStart(startTime); - vBuilder.setLatestEnd(24 * 60 * 60); - CarrierVehicle cv = vBuilder.build(); auxiliaryCarrier.getCarrierCapabilities().getCarrierVehicles().put(cv.getId(), cv); auxiliaryCarrier.getCarrierCapabilities().setFleetSize(FleetSize.FINITE); - for (LspShipment lspShipment : shipmentsInCurrentTour) { - CarrierService carrierService = convertToCarrierService(lspShipment); - auxiliaryCarrier.getServices().put(carrierService.getId(), carrierService); + switch (CarrierSchedulerUtils.getVrpLogic(carrier)) { + case serviceBased -> { + for (LspShipment lspShipment : shipmentsInCurrentTour) { + CarrierService carrierService = convertToCarrierService(lspShipment); + auxiliaryCarrier.getServices().put(carrierService.getId(), carrierService); + } + } + case shipmentBased -> { + for (LspShipment lspShipment : shipmentsInCurrentTour) { + CarrierShipment carrierShipment = convertToCarrierShipment(lspShipment); + auxiliaryCarrier.getShipments().put(carrierShipment.getId(), carrierShipment); + } + } + default -> throw new IllegalStateException("Unexpected value: " + CarrierSchedulerUtils.getVrpLogic(carrier)); } + + return auxiliaryCarrier; } From c95d98540a8a05da041ceb042653f3bc12befa9e Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 23 Aug 2024 17:00:52 +0200 Subject: [PATCH 03/18] not working now.. needs infrastructure for EventHandling.. --- .../ExampleTwoLspsGroceryDeliveryMultipleChains.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java index 0895684c..9fe959ce 100644 --- a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java +++ b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java @@ -67,6 +67,7 @@ import org.matsim.freight.carriers.controler.CarrierStrategyManager; import org.matsim.freight.logistics.*; import org.matsim.freight.logistics.examples.ExampleConstants; +import org.matsim.freight.logistics.resourceImplementations.CarrierSchedulerUtils; import org.matsim.freight.logistics.resourceImplementations.ResourceImplementationUtils; import org.matsim.freight.logistics.shipment.LspShipment; import org.matsim.vehicles.VehicleType; @@ -119,9 +120,9 @@ public static void main(String[] args) { log.info("Add LSP(s) to the scenario"); Collection lsps = new LinkedList<>(); - lsps.add(createLspWithTwoChains(scenario, "Edeka", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierEdeka), getDepotLinkFromVehicle(carrierEdeka), HUB_LINK_ID_NEUKOELLN, vehicleTypes, vehicleTypes, vehicleTypes)); - lsps.add(createLspWithTwoChains(scenario, "Kaufland", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierKaufland), getDepotLinkFromVehicle(carrierKaufland), HUB_LINK_ID_NEUKOELLN, vehicleTypes, vehicleTypes, vehicleTypes)); - lsps.add(createLspWithDirectChain(scenario, "Edeka_DIRECT", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierEdeka), getDepotLinkFromVehicle(carrierEdeka), vehicleTypes)); +// lsps.add(createLspWithTwoChains(scenario, "Edeka", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierEdeka), getDepotLinkFromVehicle(carrierEdeka), HUB_LINK_ID_NEUKOELLN, vehicleTypes, vehicleTypes, vehicleTypes)); +// lsps.add(createLspWithTwoChains(scenario, "Kaufland", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierKaufland), getDepotLinkFromVehicle(carrierKaufland), HUB_LINK_ID_NEUKOELLN, vehicleTypes, vehicleTypes, vehicleTypes)); +// lsps.add(createLspWithDirectChain(scenario, "Edeka_DIRECT", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierEdeka), getDepotLinkFromVehicle(carrierEdeka), vehicleTypes)); lsps.add(createLspWithDirectChain(scenario, "Kaufland_DIRECT", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierKaufland), getDepotLinkFromVehicle(carrierKaufland), vehicleTypes)); LSPUtils.addLSPs(scenario, new LSPs(lsps)); @@ -325,6 +326,7 @@ private static LogisticChain createTwoEchelonChain(Scenario scenario, String lsp distributionCarrier .getCarrierCapabilities() .setFleetSize(CarrierCapabilities.FleetSize.INFINITE); + CarrierSchedulerUtils.setVrpLogic(distributionCarrier, LSPUtils.LogicOfVrp.shipmentBased); CarriersUtils.addCarrierVehicle( distributionCarrier, @@ -400,6 +402,7 @@ private static LogisticChain createDirectChain(Scenario scenario, String lspName LogisticChain directChain; Carrier directCarrier = CarriersUtils.createCarrier(Id.create(lspName +"_directCarrier", Carrier.class)); directCarrier.getCarrierCapabilities().setFleetSize(CarrierCapabilities.FleetSize.INFINITE); + CarrierSchedulerUtils.setVrpLogic(directCarrier, LSPUtils.LogicOfVrp.shipmentBased); CarriersUtils.addCarrierVehicle(directCarrier, CarrierVehicle.newInstance( From bd80bfa1493e2731160afbea8bd29701bdc8b3f4 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 30 Aug 2024 14:34:53 +0200 Subject: [PATCH 04/18] WIP commiting just to change the workspace.. --- .../DistributionCarrierScheduler.java | 70 +++++++++++------ .../DistributionServiceStartEventHandler.java | 75 +++++++++++-------- .../logistics/shipment/LspShipmentUtils.java | 6 ++ .../ScheduledLspShipmentTransport.java | 7 ++ 4 files changed, 104 insertions(+), 54 deletions(-) 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 c724e547..814cf83b 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java @@ -102,9 +102,9 @@ protected void scheduleResource() { scheduledPlans.add(auxiliaryCarrier.getSelectedPlan()); var vrpLogic = CarrierSchedulerUtils.getVrpLogic(carrier); switch (vrpLogic) { - case serviceBased -> { carrier.getServices().putAll(auxiliaryCarrier.getServices()); } - case shipmentBased -> { carrier.getShipments().putAll(auxiliaryCarrier.getShipments()); } - default -> throw new IllegalStateException("Unexpected value: " + vrpLogic); + case serviceBased -> { carrier.getServices().putAll(auxiliaryCarrier.getServices()); } + case shipmentBased -> { carrier.getShipments().putAll(auxiliaryCarrier.getShipments()); } + default -> throw new IllegalStateException("Unexpected value: " + vrpLogic); } cumulatedLoadingTime = 0; @@ -129,7 +129,7 @@ protected void scheduleResource() { //TODO: When using shipmentbased, only ONE Vrp should be created and solved. -> No need for the auxiliary carrier(s). KMT'Aug 24 //Then we can also just pass all the vehicles over :) //And need the TimeWindows for the Shipments... - } + } default -> throw new IllegalStateException("Unexpected value: " + CarrierSchedulerUtils.getVrpLogic(carrier)); } shipmentsInCurrentTour.clear(); @@ -197,13 +197,13 @@ private CarrierService convertToCarrierService(LspShipment lspShipment) { return carrierService; } -/** -* This method converts a LspShipment to a CarrierShipment. - * Please note: This method may get removed in the future, in case that the LSPShipment and the CarrierShipment are merged. KMT'Aug'24 + /** + * This method converts a LspShipment to a CarrierShipment. + * Please note: This method may get removed in the future, in case that the LSPShipment and the CarrierShipment are merged. KMT'Aug'24 - * @param lspShipment the LspShipment to convert - * @return a CarrierShipment -*/ + * @param lspShipment the LspShipment to convert + * @return a CarrierShipment + */ private CarrierShipment convertToCarrierShipment(LspShipment lspShipment) { Id serviceId = Id.create(lspShipment.getId().toString(), CarrierShipment.class); CarrierShipment carrierShipment = CarrierShipment.Builder.newInstance(serviceId, lspShipment.getFrom(), lspShipment.getTo(), lspShipment.getSize()) @@ -225,16 +225,38 @@ protected void updateShipments() { for (LspShipment lspShipment : lspShipmentsToSchedule) { for (ScheduledTour scheduledTour : carrier.getSelectedPlan().getScheduledTours()) { Tour tour = scheduledTour.getTour(); - for (TourElement element : tour.getTourElements()) { - if (element instanceof ServiceActivity serviceActivity) { - 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); + + switch (CarrierSchedulerUtils.getVrpLogic(carrier)) { + case serviceBased -> { + for (TourElement element : tour.getTourElements()) { + if (element instanceof ServiceActivity serviceActivity) { + 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); + } + } } } + case shipmentBased -> { + //TODO needs fixture + for (TourElement element : tour.getTourElements()) { + if (element instanceof Tour.Delivery deliveryActivity) { + if (Objects.equals(lspShipment.getId().toString(), deliveryActivity.getShipment().getId().toString())) { + addShipmentLoadElement(lspShipment, tour); + addShipmentTransportElement(lspShipment, tour, deliveryActivity); + addShipmentUnloadElement(lspShipment, tour, deliveryActivity); + addDistributionTourStartEventHandler(deliveryActivity.getShipment(), lspShipment, resource, tour); + addDistributionServiceEventHandler(deliveryActivity.getShipment(), lspShipment, resource); + } + } + } + } + default -> + throw new IllegalStateException( + "Unexpected value: " + CarrierSchedulerUtils.getVrpLogic(carrier)); } } } @@ -272,7 +294,7 @@ private void addShipmentLoadElement(LspShipment lspShipment, Tour tour) { } private void addShipmentTransportElement( - LspShipment lspShipment, Tour tour, ServiceActivity serviceActivity) { + LspShipment lspShipment, Tour tour, Tour.TourActivity tourActivity) { LspShipmentUtils.ScheduledShipmentTransportBuilder builder = LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance(); @@ -286,7 +308,7 @@ private void addShipmentTransportElement( int startIndex = tour.getTourElements().indexOf(tour.getTourElements().indexOf(tour.getStart())); final Leg legAfterStart = (Leg) tour.getTourElements().get(startIndex + 1); - final int serviceIndex = tour.getTourElements().indexOf(serviceActivity); + final int serviceIndex = tour.getTourElements().indexOf(tourActivity); final Leg legBeforeService = (Leg) tour.getTourElements().get(serviceIndex - 1); final double startTimeOfTransport = legAfterStart.getExpectedDepartureTime(); final double endTimeOfTransport = @@ -302,8 +324,8 @@ private void addShipmentTransportElement( builder.setEndTime(endTimeOfTransport); builder.setCarrierId(carrier.getId()); builder.setFromLinkId(tour.getStartLinkId()); - builder.setToLinkId(serviceActivity.getLocation()); - builder.setCarrierService(serviceActivity.getService()); + builder.setToLinkId(tourActivity.getLocation()); + builder.setCarrierService(tourActivity.getService()); LspShipmentPlanElement transport = builder.build(); String idString = transport.getResourceId() @@ -366,11 +388,11 @@ private Carrier createAuxiliaryCarrier(ArrayList shipmentsInCurrent switch (CarrierSchedulerUtils.getVrpLogic(carrier)) { case serviceBased -> { - for (LspShipment lspShipment : shipmentsInCurrentTour) { + for (LspShipment lspShipment : shipmentsInCurrentTour) { CarrierService carrierService = convertToCarrierService(lspShipment); auxiliaryCarrier.getServices().put(carrierService.getId(), carrierService); - } } + } case shipmentBased -> { for (LspShipment lspShipment : shipmentsInCurrentTour) { CarrierShipment carrierShipment = convertToCarrierShipment(lspShipment); diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionServiceStartEventHandler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionServiceStartEventHandler.java index 80e04fc5..b885a5aa 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionServiceStartEventHandler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionServiceStartEventHandler.java @@ -1,22 +1,22 @@ /* - *********************************************************************** * - * 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; @@ -25,8 +25,11 @@ import org.matsim.core.controler.events.AfterMobsimEvent; import org.matsim.core.controler.listener.AfterMobsimListener; import org.matsim.freight.carriers.CarrierService; +import org.matsim.freight.carriers.CarrierShipment; import org.matsim.freight.carriers.events.CarrierServiceStartEvent; +import org.matsim.freight.carriers.events.CarrierShipmentDeliveryStartEvent; import org.matsim.freight.carriers.events.eventhandler.CarrierServiceStartEventHandler; +import org.matsim.freight.carriers.events.eventhandler.CarrierShipmentDeliveryStartEventHandler; import org.matsim.freight.logistics.LSPCarrierResource; import org.matsim.freight.logistics.LSPSimulationTracker; import org.matsim.freight.logistics.LogisticChainElement; @@ -36,20 +39,23 @@ import org.matsim.freight.logistics.shipment.LspShipmentUtils; /*package-private*/ class DistributionServiceStartEventHandler - implements AfterMobsimListener, + implements AfterMobsimListener, CarrierServiceStartEventHandler, + CarrierShipmentDeliveryStartEventHandler, LSPSimulationTracker { private final CarrierService carrierService; + private final CarrierShipment carrierShipment; private final LogisticChainElement logisticChainElement; private final LSPCarrierResource resource; private LspShipment lspShipment; DistributionServiceStartEventHandler( - CarrierService carrierService, - LspShipment lspShipment, - LogisticChainElement element, - LSPCarrierResource resource) { + CarrierService carrierService, + LspShipment lspShipment, + LogisticChainElement element, + LSPCarrierResource resource) { + this.carrierShipment = carrierShipment; this.carrierService = carrierService; this.lspShipment = lspShipment; this.logisticChainElement = element; @@ -65,7 +71,16 @@ public void reset(int iteration) { @Override public void handleEvent(CarrierServiceStartEvent event) { if (event.getServiceId() == carrierService.getId() - && event.getCarrierId() == resource.getCarrier().getId()) { + && event.getCarrierId() == resource.getCarrier().getId()) { + logTransport(event); + logUnload(event); + } + } + + @Override + public void handleEvent(CarrierShipmentDeliveryStartEvent event) { + if (event.getShipmentId() == this.carrierShipment.getId() + && event.getCarrierId() == resource.getCarrier().getId()) { logTransport(event); logUnload(event); } @@ -75,7 +90,7 @@ private void logTransport(CarrierServiceStartEvent event) { String idString = resource.getId() + "" + logisticChainElement.getId() + "TRANSPORT"; Id id = Id.create(idString, LspShipmentPlanElement.class); LspShipmentPlanElement abstractPlanElement = - lspShipment.getShipmentLog().getPlanElements().get(id); + lspShipment.getShipmentLog().getPlanElements().get(id); if (abstractPlanElement instanceof LspShipmentLeg transport) { transport.setEndTime(event.getTime()); } @@ -83,7 +98,7 @@ private void logTransport(CarrierServiceStartEvent event) { private void logUnload(CarrierServiceStartEvent event) { LspShipmentUtils.LoggedShipmentUnloadBuilder builder = - LspShipmentUtils.LoggedShipmentUnloadBuilder.newInstance(); + LspShipmentUtils.LoggedShipmentUnloadBuilder.newInstance(); builder.setCarrierId(event.getCarrierId()); builder.setLinkId(event.getLinkId()); builder.setLogisticChainElement(logisticChainElement); @@ -92,10 +107,10 @@ private void logUnload(CarrierServiceStartEvent event) { builder.setEndTime(event.getTime() + event.getServiceDuration()); LspShipmentPlanElement unload = builder.build(); String idString = - unload.getResourceId() - + "" - + unload.getLogisticChainElement().getId() - + unload.getElementType(); + unload.getResourceId() + + "" + + unload.getLogisticChainElement().getId() + + unload.getElementType(); Id unloadId = Id.create(idString, LspShipmentPlanElement.class); lspShipment.getShipmentLog().addPlanElement(unloadId, unload); } diff --git a/src/main/java/org/matsim/freight/logistics/shipment/LspShipmentUtils.java b/src/main/java/org/matsim/freight/logistics/shipment/LspShipmentUtils.java index 01efd96b..3b2c46e8 100644 --- a/src/main/java/org/matsim/freight/logistics/shipment/LspShipmentUtils.java +++ b/src/main/java/org/matsim/freight/logistics/shipment/LspShipmentUtils.java @@ -27,6 +27,7 @@ import org.matsim.api.core.v01.network.Link; import org.matsim.freight.carriers.Carrier; import org.matsim.freight.carriers.CarrierService; +import org.matsim.freight.carriers.CarrierShipment; import org.matsim.freight.carriers.TimeWindow; import org.matsim.freight.logistics.LSPPlan; import org.matsim.freight.logistics.LSPResource; @@ -420,6 +421,7 @@ public static final class ScheduledShipmentTransportBuilder { Id fromLinkId; Id toLinkId; CarrierService carrierService; + CarrierShipment carrierShipment; //TODO: Put CarrierShipment and CarrieTask behind one interface and use that here (CarrierTask...) private ScheduledShipmentTransportBuilder() {} @@ -459,6 +461,10 @@ public void setCarrierService(CarrierService carrierService) { this.carrierService = carrierService; } + public void setCarrierShipment(CarrierShipment carrierShipment) { + this.carrierShipment = carrierShipment; + } + public ScheduledLspShipmentTransport build() { return new ScheduledLspShipmentTransport(this); } diff --git a/src/main/java/org/matsim/freight/logistics/shipment/ScheduledLspShipmentTransport.java b/src/main/java/org/matsim/freight/logistics/shipment/ScheduledLspShipmentTransport.java index d4f69efa..71b084e2 100644 --- a/src/main/java/org/matsim/freight/logistics/shipment/ScheduledLspShipmentTransport.java +++ b/src/main/java/org/matsim/freight/logistics/shipment/ScheduledLspShipmentTransport.java @@ -24,6 +24,7 @@ import org.matsim.api.core.v01.network.Link; import org.matsim.freight.carriers.Carrier; import org.matsim.freight.carriers.CarrierService; +import org.matsim.freight.carriers.CarrierShipment; import org.matsim.freight.logistics.LSPResource; import org.matsim.freight.logistics.LogisticChainElement; @@ -37,6 +38,7 @@ final class ScheduledLspShipmentTransport implements LspShipmentLeg { private final Id fromLinkId; private final Id toLinkId; private final CarrierService carrierService; + private final CarrierShipment carrierShipment; //TODO: Put CarrierShipment and CarrieTask behind one interface and use that here (CarrierTask...) ScheduledLspShipmentTransport(LspShipmentUtils.ScheduledShipmentTransportBuilder builder) { this.startTime = builder.startTime; @@ -47,6 +49,7 @@ final class ScheduledLspShipmentTransport implements LspShipmentLeg { this.fromLinkId = builder.fromLinkId; this.toLinkId = builder.toLinkId; this.carrierService = builder.carrierService; + this.carrierShipment = builder.carrierShipment; } @Override @@ -103,4 +106,8 @@ public Id getFromLinkId() { public CarrierService getCarrierService() { return carrierService; } + + public CarrierShipment getCarrierShipment() { + return carrierShipment; + } } From 6ddf8ea509dc5b69a3d85bce7861bb1f165e652c Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Mon, 2 Sep 2024 12:26:56 +0200 Subject: [PATCH 05/18] renaming --- src/main/java/doxyfilter.sh | 0 .../TransshipmentHubTourEndEventHandler.java | 6 +++--- .../resourceImplementations/CompleteLSPSchedulingTest.java | 4 ++-- .../FirstReloadLSPSchedulingTest.java | 2 +- .../resourceImplementations/MainRunLSPSchedulingTest.java | 2 +- .../MultipleShipmentsCompleteLSPSchedulingTest.java | 4 ++-- .../MultipleShipmentsFirstReloadLSPSchedulingTest.java | 2 +- .../MultipleShipmentsMainRunLSPSchedulingTest.java | 2 +- .../MultipleShipmentsSecondReloadLSPSchedulingTest.java | 4 ++-- .../SecondReloadLSPSchedulingTest.java | 4 ++-- 10 files changed, 15 insertions(+), 15 deletions(-) mode change 100755 => 100644 src/main/java/doxyfilter.sh diff --git a/src/main/java/doxyfilter.sh b/src/main/java/doxyfilter.sh old mode 100755 new mode 100644 diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/TransshipmentHubTourEndEventHandler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/TransshipmentHubTourEndEventHandler.java index 4250e867..bd476a54 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/TransshipmentHubTourEndEventHandler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/TransshipmentHubTourEndEventHandler.java @@ -213,7 +213,7 @@ private void logHandlingInHub( .setResourceId(resourceId) .setStartTime(startTime) .setEndTime(endTime) - .setLogisticsChainElement(servicesWaitedFor.get(carrierService).element) + .setLogisticsChainElement(servicesWaitedFor.get(carrierService).logisticChainElement) .build(); Id loadId = Id.create( @@ -268,11 +268,11 @@ public Id getLinkId() { public static class TransshipmentHubEventHandlerPair { public final LspShipment lspShipment; - public final LogisticChainElement element; + public final LogisticChainElement logisticChainElement; public TransshipmentHubEventHandlerPair(LspShipment lspShipment, LogisticChainElement element) { this.lspShipment = lspShipment; - this.element = element; + this.logisticChainElement = element; } } } 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 885a2d4f..5665c4cf 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/CompleteLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/CompleteLSPSchedulingTest.java @@ -433,7 +433,7 @@ public void testCompletedLSPScheduling() { Entry entry = iter.next(); CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; + LogisticChainElement element = entry.getValue().logisticChainElement; assertSame(service.getLocationLinkId(), shipment.getFrom()); assertEquals(service.getCapacityDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -460,7 +460,7 @@ public void testCompletedLSPScheduling() { Entry entry = iter.next(); CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; + LogisticChainElement element = entry.getValue().logisticChainElement; assertSame(service.getLocationLinkId(), toLinkId); assertEquals(service.getCapacityDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); 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 90254732..145f8777 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/FirstReloadLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/FirstReloadLSPSchedulingTest.java @@ -257,7 +257,7 @@ public void testFirstReloadLSPScheduling() { for (Entry entry : reloadEventHandler.getServicesWaitedFor().entrySet()) { CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; + LogisticChainElement element = entry.getValue().logisticChainElement; assertSame(service.getLocationLinkId(), shipment.getFrom()); assertEquals(service.getCapacityDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); 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 de0c1643..95002e79 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MainRunLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MainRunLSPSchedulingTest.java @@ -323,7 +323,7 @@ public void testMainRunLSPScheduling() { for (Entry entry : reloadEventHandler.getServicesWaitedFor().entrySet()) { CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; + LogisticChainElement element = entry.getValue().logisticChainElement; assertSame(service.getLocationLinkId(), shipment.getFrom()); assertEquals(service.getCapacityDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); 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 6994d171..fcbe5c90 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCompleteLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsCompleteLSPSchedulingTest.java @@ -436,7 +436,7 @@ public void testCompletedLSPScheduling() { Entry entry = iter.next(); CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; + LogisticChainElement element = entry.getValue().logisticChainElement; assertSame(service.getLocationLinkId(), shipment.getFrom()); assertEquals(service.getCapacityDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -463,7 +463,7 @@ public void testCompletedLSPScheduling() { Entry entry = iter.next(); CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; + LogisticChainElement element = entry.getValue().logisticChainElement; assertSame(service.getLocationLinkId(), toLinkId); assertEquals(service.getCapacityDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); 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 2b6a2e60..10d237c6 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsFirstReloadLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsFirstReloadLSPSchedulingTest.java @@ -256,7 +256,7 @@ public void testFirstReloadLSPScheduling() { for (Entry entry : reloadEventHandler.getServicesWaitedFor().entrySet()) { CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; + LogisticChainElement element = entry.getValue().logisticChainElement; assertSame(service.getLocationLinkId(), shipment.getFrom()); assertEquals(service.getCapacityDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); 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 6c8bd2fe..1b82cf09 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsMainRunLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsMainRunLSPSchedulingTest.java @@ -323,7 +323,7 @@ public void testMainRunLSPScheduling() { for (Entry entry : reloadEventHandler.getServicesWaitedFor().entrySet()) { CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; + LogisticChainElement element = entry.getValue().logisticChainElement; assertSame(service.getLocationLinkId(), shipment.getFrom()); assertEquals(service.getCapacityDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); 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 236e1dd2..97d44970 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/MultipleShipmentsSecondReloadLSPSchedulingTest.java @@ -367,7 +367,7 @@ public void testSecondReloadLSPScheduling() { entry = iter.next(); CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; + LogisticChainElement element = entry.getValue().logisticChainElement; assertSame(service.getLocationLinkId(), shipment.getFrom()); assertEquals(service.getCapacityDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -399,7 +399,7 @@ public void testSecondReloadLSPScheduling() { Entry entry = iter.next(); CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; + LogisticChainElement element = entry.getValue().logisticChainElement; assertSame(service.getLocationLinkId(), toLinkId); assertEquals(service.getCapacityDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); 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 e158884b..cccd4153 100644 --- a/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java +++ b/src/test/java/org/matsim/freight/logistics/resourceImplementations/SecondReloadLSPSchedulingTest.java @@ -367,7 +367,7 @@ public void testSecondReloadLSPScheduling() { entry = iter.next(); CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; + LogisticChainElement element = entry.getValue().logisticChainElement; assertSame(service.getLocationLinkId(), shipment.getFrom()); assertEquals(service.getCapacityDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); @@ -405,7 +405,7 @@ public void testSecondReloadLSPScheduling() { entry = iter.next(); CarrierService service = entry.getKey(); LspShipment shipment = entry.getValue().lspShipment; - LogisticChainElement element = entry.getValue().element; + LogisticChainElement element = entry.getValue().logisticChainElement; assertSame(service.getLocationLinkId(), toLinkId); assertEquals(service.getCapacityDemand(), shipment.getSize()); assertEquals(service.getServiceDuration(), shipment.getDeliveryServiceTime(), 0.0); From 6569879092cceb639e56bdbc4a1078ea26be66eb Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Mon, 2 Sep 2024 12:28:12 +0200 Subject: [PATCH 06/18] pom to shnapshot --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 539b2a3f..68d6cbde 100644 --- a/pom.xml +++ b/pom.xml @@ -15,8 +15,8 @@ org.matsim matsim-all - 2025.0-2024w34 - + + 2025.0-SNAPSHOT From 89283a35c51c1dd84ab8509e9bd6793a3faad991 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Thu, 10 Oct 2024 11:01:58 +0200 Subject: [PATCH 07/18] some minor adaptions towards Shipment-based solving. some comments --- .../DistributionCarrierScheduler.java | 37 ++++++++++++++++++- .../DistributionServiceStartEventHandler.java | 33 ++++++++++++++++- 2 files changed, 67 insertions(+), 3 deletions(-) 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 6e4b03be..4e3b4639 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java @@ -295,7 +295,8 @@ private void addShipmentLoadElement(LspShipment lspShipment, Tour tour) { } private void addShipmentTransportElement( - LspShipment lspShipment, Tour tour, Tour.TourActivity tourActivity) { +// LspShipment lspShipment, Tour tour, Tour.TourActivity tourActivity) { + LspShipment lspShipment, Tour tour, Tour.ServiceActivity tourActivity) { LspShipmentUtils.ScheduledShipmentTransportBuilder builder = LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance(); @@ -415,7 +416,23 @@ private void addDistributionServiceEventHandler( 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, null); + lspShipment.addSimulationTracker(handler); + break; + } + } + } + + //TODO: Kann man das wieder zusammenfassen mitt der Methode fpr die Services? + private void addDistributionServiceEventHandler( + CarrierShipment carrierShipment, + LspShipment lspShipment, + LSPCarrierResource resource) { + + for (LogisticChainElement element : this.resource.getClientElements()) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { + DistributionServiceStartEventHandler handler = + new DistributionServiceStartEventHandler(null, lspShipment, element, resource, carrierShipment); lspShipment.addSimulationTracker(handler); break; } @@ -438,4 +455,20 @@ private void addDistributionTourStartEventHandler( } } + private void addDistributionTourStartEventHandler( + CarrierShipment carrierShipment, + LspShipment lspShipment, + LSPCarrierResource resource, + Tour tour) { + + for (LogisticChainElement element : this.resource.getClientElements()) { + if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { + LSPTourStartEventHandler handler = + new LSPTourStartEventHandler(lspShipment, null, element, resource, tour); //FIXME: Hier müsste eigentlich das CarrierShipment übergeben werden in anaolger Logic zu Services... arghhh. + lspShipment.addSimulationTracker(handler); + break; + } + } + } + } diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionServiceStartEventHandler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionServiceStartEventHandler.java index b885a5aa..0436a116 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionServiceStartEventHandler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionServiceStartEventHandler.java @@ -54,7 +54,7 @@ CarrierService carrierService, LspShipment lspShipment, LogisticChainElement element, - LSPCarrierResource resource) { + LSPCarrierResource resource, CarrierShipment carrierShipment) { this.carrierShipment = carrierShipment; this.carrierService = carrierService; this.lspShipment = lspShipment; @@ -96,6 +96,17 @@ private void logTransport(CarrierServiceStartEvent event) { } } + //TODO: Inahltlich ansehen, was hier passiert. Ist aktuell nur Copy und Paste aus Service-Variante + private void logTransport(CarrierShipmentDeliveryStartEvent event) { + String idString = resource.getId() + "" + logisticChainElement.getId() + "TRANSPORT"; + Id id = Id.create(idString, LspShipmentPlanElement.class); + LspShipmentPlanElement abstractPlanElement = + lspShipment.getShipmentLog().getPlanElements().get(id); + if (abstractPlanElement instanceof LspShipmentLeg transport) { + transport.setEndTime(event.getTime()); + } + } + private void logUnload(CarrierServiceStartEvent event) { LspShipmentUtils.LoggedShipmentUnloadBuilder builder = LspShipmentUtils.LoggedShipmentUnloadBuilder.newInstance(); @@ -115,6 +126,26 @@ private void logUnload(CarrierServiceStartEvent event) { lspShipment.getShipmentLog().addPlanElement(unloadId, unload); } + //TODO: Inahltlich ansehen, was hier passiert. Ist aktuell nur Copy und Paste aus Service-Variante + private void logUnload(CarrierShipmentDeliveryStartEvent event) { + LspShipmentUtils.LoggedShipmentUnloadBuilder builder = + LspShipmentUtils.LoggedShipmentUnloadBuilder.newInstance(); + builder.setCarrierId(event.getCarrierId()); + builder.setLinkId(event.getLinkId()); + builder.setLogisticChainElement(logisticChainElement); + builder.setResourceId(resource.getId()); + builder.setStartTime(event.getTime()); + builder.setEndTime(event.getTime() + event.getDeliveryDuration()); + LspShipmentPlanElement unload = builder.build(); + String idString = + unload.getResourceId() + + "" + + unload.getLogisticChainElement().getId() + + unload.getElementType(); + Id unloadId = Id.create(idString, LspShipmentPlanElement.class); + lspShipment.getShipmentLog().addPlanElement(unloadId, unload); + } + public CarrierService getCarrierService() { return carrierService; } From c79b3f4245ad01a1cecb03450f29e1836bc734f7 Mon Sep 17 00:00:00 2001 From: Kai Nagel Date: Thu, 10 Oct 2024 11:57:40 +0200 Subject: [PATCH 08/18] towards using instanceof --- .../DistributionCarrierScheduler.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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 4e3b4639..fb775818 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java @@ -31,7 +31,6 @@ import org.matsim.freight.carriers.*; import org.matsim.freight.carriers.CarrierCapabilities.FleetSize; 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; @@ -230,7 +229,7 @@ protected void updateShipments() { switch (CarrierSchedulerUtils.getVrpLogic(carrier)) { case serviceBased -> { for (TourElement element : tour.getTourElements()) { - if (element instanceof ServiceActivity serviceActivity) { + if (element instanceof Tour.ServiceActivity serviceActivity) { if (Objects.equals(lspShipment.getId().toString(), serviceActivity.getService().getId().toString())) { addShipmentLoadElement(lspShipment, tour); addShipmentTransportElement(lspShipment, tour, serviceActivity); @@ -296,7 +295,8 @@ private void addShipmentLoadElement(LspShipment lspShipment, Tour tour) { private void addShipmentTransportElement( // LspShipment lspShipment, Tour tour, Tour.TourActivity tourActivity) { - LspShipment lspShipment, Tour tour, Tour.ServiceActivity tourActivity) { +// LspShipment lspShipment, Tour tour, Tour.ServiceActivity tourActivity) { + LspShipment lspShipment, Tour tour, Tour.TourActivity tourActivity) { LspShipmentUtils.ScheduledShipmentTransportBuilder builder = LspShipmentUtils.ScheduledShipmentTransportBuilder.newInstance(); @@ -327,7 +327,15 @@ private void addShipmentTransportElement( builder.setCarrierId(carrier.getId()); builder.setFromLinkId(tour.getStartLinkId()); builder.setToLinkId(tourActivity.getLocation()); - builder.setCarrierService(tourActivity.getService()); + switch( tourActivity ){ + case Tour.ServiceActivity serviceActivity -> builder.setCarrierService( serviceActivity.getService() ); + case Tour.ShipmentBasedActivity shipment -> builder.setCarrierShipment( shipment.getShipment() ); + case null, default -> { + } + // yyyy: At the jsprit level, it makes sense to have these different since services run about 10x faster than shipments. However, + // at the matsim level we could consider to either only have shipments (from depot to xx for what used to be services), or only have + // services. kai/kai, oct'24 + } LspShipmentPlanElement transport = builder.build(); String idString = transport.getResourceId() From 1ea559bba1c0089434596179adbe8fd8831f7a41 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 11 Oct 2024 09:28:20 +0200 Subject: [PATCH 09/18] some more work, check that serviceBased still works --- ...eTwoLspsGroceryDeliveryMultipleChains.java | 10 ++--- .../DistributionCarrierScheduler.java | 37 +++++++++++++------ 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java index c8f6d436..3c63b4d3 100644 --- a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java +++ b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java @@ -122,9 +122,9 @@ public static void main(String[] args) { log.info("Add LSP(s) to the scenario"); Collection lsps = new LinkedList<>(); -// lsps.add(createLspWithTwoChains(scenario, "Edeka", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierEdeka), getDepotLinkFromVehicle(carrierEdeka), HUB_LINK_ID_NEUKOELLN, vehicleTypes, vehicleTypes, vehicleTypes)); -// lsps.add(createLspWithTwoChains(scenario, "Kaufland", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierKaufland), getDepotLinkFromVehicle(carrierKaufland), HUB_LINK_ID_NEUKOELLN, vehicleTypes, vehicleTypes, vehicleTypes)); -// lsps.add(createLspWithDirectChain(scenario, "Edeka_DIRECT", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierEdeka), getDepotLinkFromVehicle(carrierEdeka), vehicleTypes)); + lsps.add(createLspWithTwoChains(scenario, "Edeka", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierEdeka), getDepotLinkFromVehicle(carrierEdeka), HUB_LINK_ID_NEUKOELLN, vehicleTypes, vehicleTypes, vehicleTypes)); + lsps.add(createLspWithTwoChains(scenario, "Kaufland", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierKaufland), getDepotLinkFromVehicle(carrierKaufland), HUB_LINK_ID_NEUKOELLN, vehicleTypes, vehicleTypes, vehicleTypes)); + lsps.add(createLspWithDirectChain(scenario, "Edeka_DIRECT", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierEdeka), getDepotLinkFromVehicle(carrierEdeka), vehicleTypes)); lsps.add(createLspWithDirectChain(scenario, "Kaufland_DIRECT", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierKaufland), getDepotLinkFromVehicle(carrierKaufland), vehicleTypes)); LSPUtils.addLSPs(scenario, new LSPs(lsps)); @@ -343,7 +343,7 @@ private static LogisticChain createTwoEchelonChain(Scenario scenario, String lsp .getCarrierCapabilities() //.setNumberOfJspritIterations // TODO Das mal hier einbauen. --> Ist aktuell in CarrierUtils. .setFleetSize(CarrierCapabilities.FleetSize.INFINITE); - CarrierSchedulerUtils.setVrpLogic(distributionCarrier, LSPUtils.LogicOfVrp.shipmentBased); + CarrierSchedulerUtils.setVrpLogic(distributionCarrier, LSPUtils.LogicOfVrp.serviceBased); CarriersUtils.addCarrierVehicle( distributionCarrier, @@ -418,7 +418,7 @@ private static LogisticChain createDirectChain(Scenario scenario, String lspName LogisticChain directChain; Carrier directCarrier = CarriersUtils.createCarrier(Id.create(lspName +"_directCarrier", Carrier.class)); directCarrier.getCarrierCapabilities().setFleetSize(CarrierCapabilities.FleetSize.INFINITE); - CarrierSchedulerUtils.setVrpLogic(directCarrier, LSPUtils.LogicOfVrp.shipmentBased); + CarrierSchedulerUtils.setVrpLogic(directCarrier, LSPUtils.LogicOfVrp.serviceBased); CarriersUtils.addCarrierVehicle(directCarrier, CarrierVehicle.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 fb775818..5e474e56 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java @@ -278,7 +278,7 @@ private void addShipmentLoadElement(LspShipment lspShipment, Tour tour) { double startTimeOfTransport = legAfterStart.getExpectedDepartureTime(); double cumulatedLoadingTime = 0; for (TourElement element : tour.getTourElements()) { - if (element instanceof ServiceActivity activity) { + if (element instanceof Tour.ServiceActivity activity) { cumulatedLoadingTime = cumulatedLoadingTime + activity.getDuration(); } } @@ -294,8 +294,6 @@ private void addShipmentLoadElement(LspShipment lspShipment, Tour tour) { } private void addShipmentTransportElement( -// LspShipment lspShipment, Tour tour, Tour.TourActivity tourActivity) { -// LspShipment lspShipment, Tour tour, Tour.ServiceActivity tourActivity) { LspShipment lspShipment, Tour tour, Tour.TourActivity tourActivity) { LspShipmentUtils.ScheduledShipmentTransportBuilder builder = @@ -330,11 +328,10 @@ private void addShipmentTransportElement( switch( tourActivity ){ case Tour.ServiceActivity serviceActivity -> builder.setCarrierService( serviceActivity.getService() ); case Tour.ShipmentBasedActivity shipment -> builder.setCarrierShipment( shipment.getShipment() ); - case null, default -> { - } - // yyyy: At the jsprit level, it makes sense to have these different since services run about 10x faster than shipments. However, + default -> throw new IllegalStateException("Unexpected value: " + tourActivity); + // yyyy: At the jsprit level, it makes sense to have these different since services run about 10x faster than shipments. However, // at the matsim level we could consider to either only have shipments (from depot to xx for what used to be services), or only have - // services. kai/kai, oct'24 + // services. See also MATSim issue #3510 kai/kai, oct'24 } LspShipmentPlanElement transport = builder.build(); String idString = @@ -348,7 +345,7 @@ private void addShipmentTransportElement( } private void addShipmentUnloadElement( - LspShipment tuple, Tour tour, ServiceActivity serviceActivity) { + LspShipment tuple, Tour tour, Tour.TourActivity tourActivity) { LspShipmentUtils.ScheduledShipmentUnloadBuilder builder = LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance(); @@ -360,11 +357,27 @@ private void addShipmentUnloadElement( } } - int serviceIndex = tour.getTourElements().indexOf(serviceActivity); - ServiceActivity serviceAct = (ServiceActivity) tour.getTourElements().get(serviceIndex); + final double startTime = tourActivity.getExpectedArrival(); + final double endTime = startTime + tourActivity.getDuration(); + //Todo: Check if it also works with shipmentBased activity, or if we in that case need the way with the switch-case and the data from the shipmentBasedActivity. KMT Oct'24 + +// switch( tourActivity ){ +// case Tour.ServiceActivity serviceActivity -> { +// startTime = tourActivity.getExpectedArrival(); +// endTime = startTime + tourActivity.getDuration(); +// +//// startTime = serviceActivity.getExpectedArrival(); //Why is there also a arrivalTime in the Tour.ServiceActivity? Why do not take the date in TourActivity.getExpectedArrivalTime()? KMT Oct'24 +//// endTime = startTime + serviceActivity.getDuration(); +// } +// case Tour.ShipmentBasedActivity shipmentBasedActivity -> { +// //Todo: Not tested ; maybe we need to take the data from the shipment itself (as is was originally done with the service: serviceActivity.getService() ,..... KMT Oct'24 +// startTime = shipmentBasedActivity.getExpectedArrival(); //Why is there also a arrivalTime in the Tour.ServiceActivity? Why do not take the date in TourActivity.getExpectedArrivalTime()? KMT Oct'24 +// endTime = startTime + shipmentBasedActivity.getDuration(); +// +// } +// default -> {} +// } - 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); From a087058fbcd96faa2b9f567db9204bf27aa74950 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 11 Oct 2024 09:45:50 +0200 Subject: [PATCH 10/18] more forward --- .../DistributionCarrierScheduler.java | 76 ++++++++----------- .../DistributionServiceStartEventHandler.java | 9 ++- .../LSPTourStartEventHandler.java | 11 ++- .../MainRunCarrierScheduler.java | 2 +- 4 files changed, 46 insertions(+), 52 deletions(-) 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 5e474e56..249b5a76 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java @@ -233,23 +233,23 @@ protected void updateShipments() { 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); + addShipmentUnloadElement(lspShipment, serviceActivity); + addDistributionTourStartEventHandler(serviceActivity, lspShipment, resource, tour); + addDistributionServiceEventHandler(serviceActivity, lspShipment, resource); } } } } case shipmentBased -> { - //TODO needs fixture + //TODO needs to get fixed. KMT'Aug'24 for (TourElement element : tour.getTourElements()) { if (element instanceof Tour.Delivery deliveryActivity) { if (Objects.equals(lspShipment.getId().toString(), deliveryActivity.getShipment().getId().toString())) { addShipmentLoadElement(lspShipment, tour); addShipmentTransportElement(lspShipment, tour, deliveryActivity); - addShipmentUnloadElement(lspShipment, tour, deliveryActivity); - addDistributionTourStartEventHandler(deliveryActivity.getShipment(), lspShipment, resource, tour); - addDistributionServiceEventHandler(deliveryActivity.getShipment(), lspShipment, resource); + addShipmentUnloadElement(lspShipment, deliveryActivity); + addDistributionTourStartEventHandler(deliveryActivity, lspShipment, resource, tour); + addDistributionServiceEventHandler(deliveryActivity, lspShipment, resource); } } } @@ -344,8 +344,7 @@ private void addShipmentTransportElement( .addPlanElement(id, transport); } - private void addShipmentUnloadElement( - LspShipment tuple, Tour tour, Tour.TourActivity tourActivity) { + private void addShipmentUnloadElement(LspShipment tuple, Tour.TourActivity tourActivity) { LspShipmentUtils.ScheduledShipmentUnloadBuilder builder = LspShipmentUtils.ScheduledShipmentUnloadBuilder.newInstance(); @@ -430,30 +429,23 @@ private Carrier createAuxiliaryCarrier(ArrayList shipmentsInCurrent } private void addDistributionServiceEventHandler( - CarrierService carrierService, + Tour.TourActivity tourActivity, LspShipment lspShipment, LSPCarrierResource resource) { for (LogisticChainElement element : this.resource.getClientElements()) { if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { - DistributionServiceStartEventHandler handler = - new DistributionServiceStartEventHandler(carrierService, lspShipment, element, resource, null); - lspShipment.addSimulationTracker(handler); - break; - } - } - } - - //TODO: Kann man das wieder zusammenfassen mitt der Methode fpr die Services? - private void addDistributionServiceEventHandler( - CarrierShipment carrierShipment, - LspShipment lspShipment, - LSPCarrierResource resource) { + DistributionServiceStartEventHandler handler; + switch (tourActivity) { + case Tour.ServiceActivity serviceActivity-> { + handler = new DistributionServiceStartEventHandler(serviceActivity.getService(), lspShipment, element, resource, null); + } + case Tour.ShipmentBasedActivity shipmentBasedActivity-> { + handler = new DistributionServiceStartEventHandler(null, lspShipment, element, resource, shipmentBasedActivity.getShipment()); + } + default -> throw new IllegalStateException("Unexpected value: " + tourActivity); + } - for (LogisticChainElement element : this.resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { - DistributionServiceStartEventHandler handler = - new DistributionServiceStartEventHandler(null, lspShipment, element, resource, carrierShipment); lspShipment.addSimulationTracker(handler); break; } @@ -461,35 +453,29 @@ private void addDistributionServiceEventHandler( } private void addDistributionTourStartEventHandler( - CarrierService carrierService, + Tour.TourActivity tourActivity, 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); - lspShipment.addSimulationTracker(handler); - break; - } - } - } - - private void addDistributionTourStartEventHandler( - CarrierShipment carrierShipment, - LspShipment lspShipment, - LSPCarrierResource resource, - Tour tour) { + LSPTourStartEventHandler handler; + switch (tourActivity) { + case Tour.ServiceActivity serviceActivity-> { + handler = new LSPTourStartEventHandler(lspShipment, serviceActivity.getService(), element, resource, tour, null); + } + case Tour.ShipmentBasedActivity shipmentBasedActivity-> { + handler = new LSPTourStartEventHandler(lspShipment, null , element, resource, tour, shipmentBasedActivity.getShipment()); + } + default -> throw new IllegalStateException("Unexpected value: " + tourActivity); + } - for (LogisticChainElement element : this.resource.getClientElements()) { - if (element.getIncomingShipments().getLspShipmentsWTime().contains(lspShipment)) { - LSPTourStartEventHandler handler = - new LSPTourStartEventHandler(lspShipment, null, element, resource, tour); //FIXME: Hier müsste eigentlich das CarrierShipment übergeben werden in anaolger Logic zu Services... arghhh. lspShipment.addSimulationTracker(handler); break; } } } + } diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionServiceStartEventHandler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionServiceStartEventHandler.java index 0436a116..047ade24 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionServiceStartEventHandler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionServiceStartEventHandler.java @@ -54,7 +54,8 @@ CarrierService carrierService, LspShipment lspShipment, LogisticChainElement element, - LSPCarrierResource resource, CarrierShipment carrierShipment) { + LSPCarrierResource resource, + CarrierShipment carrierShipment) { this.carrierShipment = carrierShipment; this.carrierService = carrierService; this.lspShipment = lspShipment; @@ -96,7 +97,7 @@ private void logTransport(CarrierServiceStartEvent event) { } } - //TODO: Inahltlich ansehen, was hier passiert. Ist aktuell nur Copy und Paste aus Service-Variante + //TODO: Inhaltlich ansehen, was hier passiert. Ist aktuell nur Copy und Paste aus Service-Variante private void logTransport(CarrierShipmentDeliveryStartEvent event) { String idString = resource.getId() + "" + logisticChainElement.getId() + "TRANSPORT"; Id id = Id.create(idString, LspShipmentPlanElement.class); @@ -126,7 +127,7 @@ private void logUnload(CarrierServiceStartEvent event) { lspShipment.getShipmentLog().addPlanElement(unloadId, unload); } - //TODO: Inahltlich ansehen, was hier passiert. Ist aktuell nur Copy und Paste aus Service-Variante + //TODO: Inhaltlich ansehen, was hier passiert. Ist aktuell nur Copy und Paste aus Service-Variante private void logUnload(CarrierShipmentDeliveryStartEvent event) { LspShipmentUtils.LoggedShipmentUnloadBuilder builder = LspShipmentUtils.LoggedShipmentUnloadBuilder.newInstance(); @@ -146,6 +147,8 @@ private void logUnload(CarrierShipmentDeliveryStartEvent event) { lspShipment.getShipmentLog().addPlanElement(unloadId, unload); } + //Todo: Wird das auch inhaltlich irgendwo genutzt,oder ist das nur für die Tests da? + //todo ctd. Brauchen wir den CarrierService hier eigentlich wirklich oder kann das zurück gebaut werden? KMT Okt'24 public CarrierService getCarrierService() { return carrierService; } diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java index cd6d94ed..d38569a6 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java @@ -25,6 +25,7 @@ import org.matsim.api.core.v01.network.Link; import org.matsim.freight.carriers.Carrier; import org.matsim.freight.carriers.CarrierService; +import org.matsim.freight.carriers.CarrierShipment; import org.matsim.freight.carriers.Tour; import org.matsim.freight.carriers.Tour.ServiceActivity; import org.matsim.freight.carriers.Tour.TourElement; @@ -44,6 +45,7 @@ private final Tour tour; private final CarrierService carrierService; + private final CarrierShipment carrierShipment; private final LogisticChainElement logisticChainElement; private final LSPCarrierResource resource; private LspShipment lspShipment; @@ -53,9 +55,12 @@ public LSPTourStartEventHandler( CarrierService carrierService, LogisticChainElement logisticChainElement, LSPCarrierResource resource, - Tour tour) { + Tour tour, + CarrierShipment carrierShipment) + { this.lspShipment = lspShipment; this.carrierService = carrierService; + this.carrierShipment = carrierShipment; this.logisticChainElement = logisticChainElement; this.resource = resource; this.tour = tour; @@ -68,6 +73,7 @@ public void reset(int iteration) { @Override public void handleEvent(CarrierTourStartEvent event) { + //Todo: Ablauf für CarrierShipment einbauen. Das fehlt aktuell noch. if (event.getTourId().equals(tour.getId())) { for (TourElement tourElement : tour.getTourElements()) { if (tourElement instanceof ServiceActivity serviceActivity) { @@ -99,8 +105,7 @@ public void handleEvent(CarrierTourStartEvent event) { } } - private void logLoad(Id carrierId, Id linkId, - double startTime, double endTime) { + private void logLoad(Id carrierId, Id linkId, double startTime, double endTime) { LspShipmentUtils.LoggedShipmentLoadBuilder builder = LspShipmentUtils.LoggedShipmentLoadBuilder.newInstance(); builder.setCarrierId(carrierId); 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 9e1f13c8..8dcde45f 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/MainRunCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/MainRunCarrierScheduler.java @@ -362,7 +362,7 @@ private void addMainTourRunStartEventHandler( 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, null); lspShipment.addSimulationTracker(handler); break; } From 92b13f125268073db1b27542326e63eaa18d8b5d Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 11 Oct 2024 23:36:25 +0200 Subject: [PATCH 11/18] replace if by switch --- .../LSPTourStartEventHandler.java | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java index d38569a6..aff1195a 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java @@ -76,31 +76,43 @@ public void handleEvent(CarrierTourStartEvent event) { //Todo: Ablauf für CarrierShipment einbauen. Das fehlt aktuell noch. if (event.getTourId().equals(tour.getId())) { for (TourElement tourElement : tour.getTourElements()) { - if (tourElement instanceof ServiceActivity serviceActivity) { - if (serviceActivity.getService().getId() == carrierService.getId() - && event.getCarrierId() == resource.getCarrier().getId()) { - if (resource instanceof DistributionCarrierResource) { //DistributionTourStarts - logLoad( - event.getCarrierId(), - event.getLinkId(), - event.getTime() - getCumulatedLoadingTime(tour), - event.getTime()); - logTransport( - event.getCarrierId(), - event.getLinkId(), tour.getEndLinkId(), - event.getTime()); - } else if (resource instanceof MainRunCarrierResource) { //MainRunTourStarts - logLoad(event.getCarrierId(), - event.getLinkId(), - event.getTime() - getCumulatedLoadingTime(tour), - event.getTime()); - logTransport(event.getCarrierId(), - event.getLinkId(), - tour.getEndLinkId(), - event.getTime()); - } + switch (tourElement) { + case ServiceActivity serviceActivity -> { + if (serviceActivity.getService().getId() == carrierService.getId() + && event.getCarrierId() == resource.getCarrier().getId()) { + switch (resource) { + case DistributionCarrierResource ignored -> { //DistributionTourStarts + logLoad( + event.getCarrierId(), + event.getLinkId(), + event.getTime() - getCumulatedLoadingTime(tour), + event.getTime()); + logTransport( + event.getCarrierId(), + event.getLinkId(), + tour.getEndLinkId(), + event.getTime()); + } + case MainRunCarrierResource ignored -> { //MainRunTourStarts + logLoad(event.getCarrierId(), + event.getLinkId(), + event.getTime() - getCumulatedLoadingTime(tour), + event.getTime()); + logTransport(event.getCarrierId(), + event.getLinkId(), + tour.getEndLinkId(), + event.getTime()); + } + default -> {} + } + } + } + case Tour.ShipmentBasedActivity shipmentBasedActivity -> { + //Todo: Implement ShipmentBasedActivity + } + case null, default -> { + } } - } } } } From f358399e7c686737b71abdb6e56a41ab0b4c1311 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 11 Oct 2024 23:43:42 +0200 Subject: [PATCH 12/18] implement ShipmentBased --- .../LSPTourStartEventHandler.java | 128 ++++++++---------- 1 file changed, 58 insertions(+), 70 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java index aff1195a..a76cce43 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java @@ -1,22 +1,22 @@ /* - *********************************************************************** * - * 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; @@ -40,8 +40,10 @@ import org.matsim.freight.logistics.shipment.LspShipmentPlanElement; import org.matsim.freight.logistics.shipment.LspShipmentUtils; +import java.util.Objects; + /*package-private*/ class LSPTourStartEventHandler - implements CarrierTourStartEventHandler, LSPSimulationTracker { + implements CarrierTourStartEventHandler, LSPSimulationTracker { private final Tour tour; private final CarrierService carrierService; @@ -51,12 +53,12 @@ private LspShipment lspShipment; public LSPTourStartEventHandler( - LspShipment lspShipment, - CarrierService carrierService, - LogisticChainElement logisticChainElement, - LSPCarrierResource resource, - Tour tour, - CarrierShipment carrierShipment) + LspShipment lspShipment, + CarrierService carrierService, + LogisticChainElement logisticChainElement, + LSPCarrierResource resource, + Tour tour, + CarrierShipment carrierShipment) { this.lspShipment = lspShipment; this.carrierService = carrierService; @@ -76,50 +78,36 @@ public void handleEvent(CarrierTourStartEvent event) { //Todo: Ablauf für CarrierShipment einbauen. Das fehlt aktuell noch. if (event.getTourId().equals(tour.getId())) { for (TourElement tourElement : tour.getTourElements()) { - switch (tourElement) { - case ServiceActivity serviceActivity -> { - if (serviceActivity.getService().getId() == carrierService.getId() - && event.getCarrierId() == resource.getCarrier().getId()) { - switch (resource) { - case DistributionCarrierResource ignored -> { //DistributionTourStarts - logLoad( - event.getCarrierId(), - event.getLinkId(), - event.getTime() - getCumulatedLoadingTime(tour), - event.getTime()); - logTransport( - event.getCarrierId(), - event.getLinkId(), - tour.getEndLinkId(), - event.getTime()); - } - case MainRunCarrierResource ignored -> { //MainRunTourStarts - logLoad(event.getCarrierId(), - event.getLinkId(), - event.getTime() - getCumulatedLoadingTime(tour), - event.getTime()); - logTransport(event.getCarrierId(), - event.getLinkId(), - tour.getEndLinkId(), - event.getTime()); - } - default -> {} - } - } - } - case Tour.ShipmentBasedActivity shipmentBasedActivity -> { - //Todo: Implement ShipmentBasedActivity + switch (tourElement) { + case ServiceActivity serviceActivity -> { + if (serviceActivity.getService().getId() == carrierService.getId() + && event.getCarrierId() == resource.getCarrier().getId()) { + if (resource instanceof DistributionCarrierResource || resource instanceof MainRunCarrierResource) { + logLoad(event.getCarrierId(),event.getLinkId(), event.getTime() - getCumulatedLoadingTime(tour), event.getTime()); + logTransport(event.getCarrierId(), event.getLinkId(), tour.getEndLinkId(), event.getTime()); } - case null, default -> { + } + } + case Tour.ShipmentBasedActivity shipmentBasedActivity -> { + if (Objects.equals(shipmentBasedActivity.getShipment().getId().toString(), carrierService.getId().toString()) + && event.getCarrierId() == resource.getCarrier().getId()) { + + //Todo: This should be possibly even shorter, because it does the same es in the ServiceBased case... + if (resource instanceof DistributionCarrierResource || resource instanceof MainRunCarrierResource) { + logLoad(event.getCarrierId(),event.getLinkId(), event.getTime() - getCumulatedLoadingTime(tour), event.getTime()); + logTransport(event.getCarrierId(), event.getLinkId(), tour.getEndLinkId(), event.getTime()); } + } } + case null, default -> {} + } } } } private void logLoad(Id carrierId, Id linkId, double startTime, double endTime) { LspShipmentUtils.LoggedShipmentLoadBuilder builder = - LspShipmentUtils.LoggedShipmentLoadBuilder.newInstance(); + LspShipmentUtils.LoggedShipmentLoadBuilder.newInstance(); builder.setCarrierId(carrierId); builder.setLinkId(linkId); builder.setLogisticsChainElement(logisticChainElement); @@ -128,18 +116,18 @@ private void logLoad(Id carrierId, Id linkId, double startTime, d builder.setEndTime(endTime); LspShipmentPlanElement loggedShipmentLoad = builder.build(); String idString = - loggedShipmentLoad.getResourceId() - + "" - + loggedShipmentLoad.getLogisticChainElement().getId() - + loggedShipmentLoad.getElementType(); + loggedShipmentLoad.getResourceId() + + "" + + loggedShipmentLoad.getLogisticChainElement().getId() + + loggedShipmentLoad.getElementType(); Id loadId = Id.create(idString, LspShipmentPlanElement.class); lspShipment.getShipmentLog().addPlanElement(loadId, loggedShipmentLoad); } private void logTransport(Id carrierId, Id fromLinkId, - Id toLinkId, double startTime) { + Id toLinkId, double startTime) { LspShipmentUtils.LoggedShipmentTransportBuilder builder = - LspShipmentUtils.LoggedShipmentTransportBuilder.newInstance(); + LspShipmentUtils.LoggedShipmentTransportBuilder.newInstance(); builder.setCarrierId(carrierId); builder.setFromLinkId(fromLinkId); builder.setToLinkId(toLinkId); @@ -148,10 +136,10 @@ private void logTransport(Id carrierId, Id fromLinkId, builder.setStartTime(startTime); LspShipmentLeg transport = builder.build(); String idString = - transport.getResourceId() - + "" - + transport.getLogisticChainElement().getId() - + transport.getElementType(); + transport.getResourceId() + + "" + + transport.getLogisticChainElement().getId() + + transport.getElementType(); Id transportId = Id.create(idString, LspShipmentPlanElement.class); lspShipment.getShipmentLog().addPlanElement(transportId, transport); } From 04f95eef76e9bbfc45024f6e986954096cdfad1c Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 11 Oct 2024 23:53:35 +0200 Subject: [PATCH 13/18] extract method, comment --- .../LSPTourStartEventHandler.java | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java index a76cce43..4b3ff6a8 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/LSPTourStartEventHandler.java @@ -75,28 +75,18 @@ public void reset(int iteration) { @Override public void handleEvent(CarrierTourStartEvent event) { - //Todo: Ablauf für CarrierShipment einbauen. Das fehlt aktuell noch. - if (event.getTourId().equals(tour.getId())) { + if (event.getTourId().equals(tour.getId()) && event.getCarrierId() == resource.getCarrier().getId()) { for (TourElement tourElement : tour.getTourElements()) { switch (tourElement) { + //This could even be short, if the Id would be available already on the level of Tour.TourActivity. KMT Oct'24 case ServiceActivity serviceActivity -> { - if (serviceActivity.getService().getId() == carrierService.getId() - && event.getCarrierId() == resource.getCarrier().getId()) { - if (resource instanceof DistributionCarrierResource || resource instanceof MainRunCarrierResource) { - logLoad(event.getCarrierId(),event.getLinkId(), event.getTime() - getCumulatedLoadingTime(tour), event.getTime()); - logTransport(event.getCarrierId(), event.getLinkId(), tour.getEndLinkId(), event.getTime()); - } + if (serviceActivity.getService().getId() == carrierService.getId()) { + logLoadAndTransport(event); } } case Tour.ShipmentBasedActivity shipmentBasedActivity -> { - if (Objects.equals(shipmentBasedActivity.getShipment().getId().toString(), carrierService.getId().toString()) - && event.getCarrierId() == resource.getCarrier().getId()) { - - //Todo: This should be possibly even shorter, because it does the same es in the ServiceBased case... - if (resource instanceof DistributionCarrierResource || resource instanceof MainRunCarrierResource) { - logLoad(event.getCarrierId(),event.getLinkId(), event.getTime() - getCumulatedLoadingTime(tour), event.getTime()); - logTransport(event.getCarrierId(), event.getLinkId(), tour.getEndLinkId(), event.getTime()); - } + if (Objects.equals(shipmentBasedActivity.getShipment().getId().toString(), carrierService.getId().toString())) { + logLoadAndTransport(event); } } case null, default -> {} @@ -105,6 +95,13 @@ public void handleEvent(CarrierTourStartEvent event) { } } + private void logLoadAndTransport(CarrierTourStartEvent event) { + if (resource instanceof DistributionCarrierResource || resource instanceof MainRunCarrierResource) { + logLoad(event.getCarrierId(), event.getLinkId(), event.getTime() - getCumulatedLoadingTime(tour), event.getTime()); + logTransport(event.getCarrierId(), event.getLinkId(), tour.getEndLinkId(), event.getTime()); + } + } + private void logLoad(Id carrierId, Id linkId, double startTime, double endTime) { LspShipmentUtils.LoggedShipmentLoadBuilder builder = LspShipmentUtils.LoggedShipmentLoadBuilder.newInstance(); From 7082b91bceb6d0aafb1cee686f1daffc38fd8164 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 11 Oct 2024 23:57:00 +0200 Subject: [PATCH 14/18] move setting to config setup --- ...ExampleSchedulingOfTransportChainHubsVsDirect.java | 10 ++++------ .../ExampleTwoLspsGroceryDeliveryMultipleChains.java | 11 ++++------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/examples/initialPlans/ExampleSchedulingOfTransportChainHubsVsDirect.java b/src/main/java/org/matsim/freight/logistics/examples/initialPlans/ExampleSchedulingOfTransportChainHubsVsDirect.java index 6c359b32..17ddf16c 100644 --- a/src/main/java/org/matsim/freight/logistics/examples/initialPlans/ExampleSchedulingOfTransportChainHubsVsDirect.java +++ b/src/main/java/org/matsim/freight/logistics/examples/initialPlans/ExampleSchedulingOfTransportChainHubsVsDirect.java @@ -101,6 +101,9 @@ public static void main(String[] args) { .controller() .setOverwriteFileSetting( OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); + // The VSP default settings are designed for person transport simulation. After talking to Kai, + // they will be set to WARN here. Kai MT may'23 + config.vspExperimental().setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.warn); var freightConfig = ConfigUtils.addOrGetModule(config, FreightCarriersConfigGroup.class); freightConfig.setTimeWindowHandling(FreightCarriersConfigGroup.TimeWindowHandling.ignore); @@ -168,12 +171,7 @@ public void install() { }); log.info("Run MATSim"); - // The VSP default settings are designed for person transport simulation. After talking to Kai, - // they will be set to WARN here. Kai MT may'23 - controler - .getConfig() - .vspExperimental() - .setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.warn); + controler.run(); // print the schedules for the assigned LSPShipments diff --git a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java index 3c63b4d3..3ad5fd77 100644 --- a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java +++ b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java @@ -128,17 +128,10 @@ public static void main(String[] args) { lsps.add(createLspWithDirectChain(scenario, "Kaufland_DIRECT", MultipleChainsUtils.createLSPShipmentsFromCarrierShipments(carrierKaufland), getDepotLinkFromVehicle(carrierKaufland), vehicleTypes)); LSPUtils.addLSPs(scenario, new LSPs(lsps)); - Controler controler = prepareControler(scenario); log.info("Run MATSim"); - // The VSP default settings are designed for person transport simulation. After talking to Kai, - // they will be set to WARN here. Kai MT may'23 - controler - .getConfig() - .vspExperimental() - .setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.warn); controler.run(); runCarrierAnalysis(controler.getControlerIO().getOutputPath(), config); @@ -163,6 +156,10 @@ private static Config prepareConfig(String[] args) { config.global().setRandomSeed(4177); config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); + // The VSP default settings are designed for person transport simulation. After talking to Kai, + // they will be set to WARN here. Kai MT may'23 + config.vspExperimental().setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.warn); + FreightCarriersConfigGroup freightConfig = ConfigUtils.addOrGetModule(config, FreightCarriersConfigGroup.class); freightConfig.setTimeWindowHandling(FreightCarriersConfigGroup.TimeWindowHandling.ignore); From 23bd646c3e33bffce10d2d05ece7633a1b865102 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 15 Nov 2024 15:25:59 +0100 Subject: [PATCH 15/18] comments after Kai/Kai mtg --- src/main/java/org/matsim/freight/logistics/LSPUtils.java | 2 ++ .../ExampleTwoLspsGroceryDeliveryMultipleChains.java | 1 + 2 files changed, 3 insertions(+) diff --git a/src/main/java/org/matsim/freight/logistics/LSPUtils.java b/src/main/java/org/matsim/freight/logistics/LSPUtils.java index 2821a8a0..e40c44e9 100644 --- a/src/main/java/org/matsim/freight/logistics/LSPUtils.java +++ b/src/main/java/org/matsim/freight/logistics/LSPUtils.java @@ -237,6 +237,8 @@ public LogisticChainBuilder addTracker(LSPSimulationTracker track } public LogisticChain build() { + //TODO: Prüfe of das alle Elemente Verbunden sind (in irgendeiner Art). Plus Hinweis auf die Änderung. + return new LogisticChainImpl(this); } } diff --git a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java index 3ad5fd77..71c9ac4f 100644 --- a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java +++ b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java @@ -365,6 +365,7 @@ private static LogisticChain createTwoEchelonChain(Scenario scenario, String lsp mainCarrierElement.connectWithNextElement(hubElement); hubElement.connectWithNextElement(distributionCarrierElement); + //TODO: Hier das Verbinden einfügen und in der Reihenfolge ist es. KMT Nov'24 hubChain = LSPUtils.LogisticChainBuilder.newInstance(Id.create("hubChain", LogisticChain.class)) .addLogisticChainElement(mainCarrierElement) From 5bcdeafd61512951f5260086e05685ace092f85d Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 15 Nov 2024 15:27:21 +0100 Subject: [PATCH 16/18] remove dependency to vsp contrib, as it is no longer needed --- pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pom.xml b/pom.xml index ffa13b01..3e938dc1 100644 --- a/pom.xml +++ b/pom.xml @@ -37,12 +37,6 @@ ${project.parent.version} - - org.matsim.contrib - vsp - ${project.parent.version} - - org.matsim From 198861cd31320515b988c2224ccca11637ae2367 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 15 Nov 2024 15:41:20 +0100 Subject: [PATCH 17/18] update import for annotation --- .../ExampleTwoLspsGroceryDeliveryMultipleChains.java | 2 +- .../ExampleTwoLspsGroceryDeliveryMultipleChainsWithToll.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java index d3424b98..b43f4fbc 100644 --- a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java +++ b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java @@ -45,9 +45,9 @@ import java.io.IOException; import java.util.*; +import jakarta.validation.constraints.NotNull; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.jetbrains.annotations.NotNull; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.TransportMode; diff --git a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChainsWithToll.java b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChainsWithToll.java index c1d277be..adb7ae41 100644 --- a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChainsWithToll.java +++ b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChainsWithToll.java @@ -24,9 +24,9 @@ import java.io.IOException; import java.util.*; +import jakarta.validation.constraints.NotNull; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.jetbrains.annotations.NotNull; import org.matsim.analysis.personMoney.PersonMoneyEventsAnalysisModule; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; From aed7adad16bb295edee99e4b76f89b12916c2dbd Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Fri, 15 Nov 2024 15:45:44 +0100 Subject: [PATCH 18/18] remove NotNull annotation --- .../ExampleTwoLspsGroceryDeliveryMultipleChains.java | 3 +-- .../ExampleTwoLspsGroceryDeliveryMultipleChainsWithToll.java | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java index b43f4fbc..57231be2 100644 --- a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java +++ b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java @@ -45,7 +45,6 @@ import java.io.IOException; import java.util.*; -import jakarta.validation.constraints.NotNull; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; @@ -171,7 +170,7 @@ private static Config prepareConfig(String[] args) { return config; } - private static @NotNull Controler prepareControler(Scenario scenario) { + private static Controler prepareControler(Scenario scenario) { log.info("Prepare controler"); Controler controler = new Controler(scenario); controler.addOverridingModule( diff --git a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChainsWithToll.java b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChainsWithToll.java index adb7ae41..e27b2e27 100644 --- a/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChainsWithToll.java +++ b/src/main/java/org/matsim/freight/logistics/examples/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChainsWithToll.java @@ -24,7 +24,6 @@ import java.io.IOException; import java.util.*; -import jakarta.validation.constraints.NotNull; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.matsim.analysis.personMoney.PersonMoneyEventsAnalysisModule; @@ -159,7 +158,7 @@ private static Config prepareConfig(String[] args) { return config; } - private static @NotNull Controler prepareControler(Scenario scenario, RoadPricingScheme rpScheme) { + private static Controler prepareControler(Scenario scenario, RoadPricingScheme rpScheme) { log.info("Prepare controler"); Controler controler = new Controler(scenario); controler.addOverridingModule(