From 44f71bbd451a0423f6c2b2a860dd3630ab07e813 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Thu, 1 Aug 2024 13:46:44 +0200 Subject: [PATCH 1/4] use tolled version for planning. --- .../CarrierSchedulerUtils.java | 16 ++++++++-------- .../CollectionCarrierScheduler.java | 2 +- .../DistributionCarrierScheduler.java | 8 ++++---- 3 files changed, 13 insertions(+), 13 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 6eb57410..993c3af2 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java @@ -31,16 +31,16 @@ public class CarrierSchedulerUtils { * This looks for me (KMT) similar to what is done in {@link org.matsim.freight.carriers.CarriersUtils#runJsprit(Scenario)}. * So, maybe this can be more simplify. *

- * @Todo: include toll in the NetbasedCosts (if set), so it is also pat of the VRP - * @Todo: Find a way to reuse the netbasedCosts over the iterations(?) to avoid re-setting this up??? - *

  • Pro: saves computation times, - *
  • Con: There is now update of the costs if the network (load) changes. - *
  • --> do it at least per Carrier or generally or stay as it is? --> Discuss with KN - * @Todo: Make the number of jsprit-Iterations configurable * - * @param carrier Carrier for which the problem should be solved - * @param network the underlying network to create the network based transport costs + * @param carrier Carrier for which the problem should be solved + * @param network the underlying network to create the network based transport costs * @return Carrier with the solution of the VehicleRoutingProblem and the routed plan. + * @Todo: include toll in the NetbasedCosts (if set), so it is also pat of the VRP + * @Todo: Find a way to reuse the netbasedCosts over the iterations(?) to avoid re-setting this up??? + *
  • Pro: saves computation times, + *
  • Con: There is now update of the costs if the network (load) changes. + *
  • --> do it at least per Carrier or generally or stay as it is? --> Discuss with KN + * @Todo: Make the number of jsprit-Iterations configurable */ public static Carrier solveVrpWithJsprit(Carrier carrier, Network network) { NetworkBasedTransportCosts netbasedTransportCosts = diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java index b0103bf2..9e0fbf96 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java @@ -69,7 +69,7 @@ public void scheduleResource() { CarrierService carrierService = convertToCarrierService(tupleToBeAssigned); carrier.getServices().put(carrierService.getId(), carrierService); } - carrier = CarrierSchedulerUtils.solveVrpWithJsprit(carrier, resource.getNetwork()); + carrier = CarrierSchedulerUtils.solveVrpWithJspritWithToll(carrier, resource.getNetwork(), null); } private CarrierService convertToCarrierService(LspShipmentWithTime tuple) { 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 031495e7..a31c2fad 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java @@ -88,10 +88,10 @@ protected void scheduleResource() { > vehicleType.getCapacity().getOther().intValue()) { load = 0; Carrier auxiliaryCarrier = - CarrierSchedulerUtils.solveVrpWithJsprit( + CarrierSchedulerUtils.solveVrpWithJspritWithToll( createAuxiliaryCarrier( shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime), - resource.getNetwork()); + resource.getNetwork(), null); scheduledPlans.add(auxiliaryCarrier.getSelectedPlan()); carrier.getServices().putAll(auxiliaryCarrier.getServices()); cumulatedLoadingTime = 0; @@ -105,10 +105,10 @@ protected void scheduleResource() { if (!shipmentsInCurrentTour.isEmpty()) { Carrier auxiliaryCarrier = - CarrierSchedulerUtils.solveVrpWithJsprit( + CarrierSchedulerUtils.solveVrpWithJspritWithToll( createAuxiliaryCarrier( shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime), - resource.getNetwork()); + resource.getNetwork(), null); scheduledPlans.add(auxiliaryCarrier.getSelectedPlan()); carrier.getServices().putAll(auxiliaryCarrier.getServices()); shipmentsInCurrentTour.clear(); From 4e23da5bf210ae8524302006e05b374de7e5e3d9 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Wed, 7 Aug 2024 09:24:59 +0200 Subject: [PATCH 2/4] Todos nach KN - Meeting --- .../ExampleTwoLspsGroceryDeliveryMultipleChainsWithToll.java | 1 + .../logistics/resourceImplementations/CarrierSchedulerUtils.java | 1 + 2 files changed, 2 insertions(+) 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 7ec09a44..4277b034 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 @@ -352,6 +352,7 @@ private static LogisticChain createTwoEchelonChain(Scenario scenario, String lsp CarriersUtils.createCarrier(Id.create(lspName +"_distributionCarrier", Carrier.class)); distributionCarrier .getCarrierCapabilities() + //.setNumberOfJspritIterations // TODO Das mal hier einbauen. --> Ist aktuell in CarrierUtils. .setFleetSize(CarrierCapabilities.FleetSize.INFINITE); CarriersUtils.addCarrierVehicle( 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 993c3af2..80897290 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java @@ -89,6 +89,7 @@ public static Carrier solveVrpWithJspritWithToll(Carrier carrier, Network networ .build(); //Setting jspritIterations to use central infrastructure -> should go more up in the code + //TODO: If not set, setze es auf 1. CarriersUtils.setJspritIterations(carrier, 1); VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); From 5cdcf9424d4d0efd29daac57fbed222a9f005702 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Wed, 7 Aug 2024 09:26:14 +0200 Subject: [PATCH 3/4] Update pom: Use official RoadpricingScheme in Freight --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5e2b066f..ee05d468 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ org.matsim matsim-all - 2025.0-PR3386 + 2025.0-PR3390 From 39c406ea34e99d309133f1dcafb6433f602b45bb Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Wed, 7 Aug 2024 09:36:32 +0200 Subject: [PATCH 4/4] fix compile errors after updating MATSim --- .../CarrierSchedulerUtils.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 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 80897290..88ec931e 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CarrierSchedulerUtils.java @@ -9,13 +9,13 @@ import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.roadpricing.RoadPricingScheme; import org.matsim.freight.carriers.Carrier; import org.matsim.freight.carriers.CarrierPlan; import org.matsim.freight.carriers.CarriersUtils; import org.matsim.freight.carriers.jsprit.MatsimJspritFactory; import org.matsim.freight.carriers.jsprit.NetworkBasedTransportCosts; import org.matsim.freight.carriers.jsprit.NetworkRouter; -import org.matsim.freight.carriers.jsprit.VehicleTypeDependentRoadPricingCalculator; /** * This class contains some code fragments, that are used in the different *CarrierScheduler @@ -70,17 +70,18 @@ public static Carrier solveVrpWithJsprit(Carrier carrier, Network network) { /** * First try with tolls. * Rest is the same as {@link #solveVrpWithJsprit(Carrier, Network)}. - * @param carrier Carrier for which the problem should be solved - * @param network the underlying network to create the network based transport costs - * @param roadPricingCalculator the road pricing calculator to calculate the tolls + * //TODO: Combine this method with the untolled version {@link #solveVrpWithJsprit(Carrier, Network)}. + * @param carrier Carrier for which the problem should be solved + * @param network the underlying network to create the network based transport costs + * @param roadPricingScheme (MATSim's) road pricing scheme from the roadpricing contrib * @return Carrier with the solution of the VehicleRoutingProblem and the routed plan. */ - public static Carrier solveVrpWithJspritWithToll(Carrier carrier, Network network, VehicleTypeDependentRoadPricingCalculator roadPricingCalculator) { - if (roadPricingCalculator != null) { + public static Carrier solveVrpWithJspritWithToll(Carrier carrier, Network network, RoadPricingScheme roadPricingScheme) { + if (roadPricingScheme != null) { NetworkBasedTransportCosts netbasedTransportCosts = NetworkBasedTransportCosts.Builder.newInstance( network, ResourceImplementationUtils.getVehicleTypeCollection(carrier)) - .setRoadPricingCalculator(roadPricingCalculator) + .setRoadPricingScheme(roadPricingScheme) .build(); VehicleRoutingProblem vrp =