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 ad0967f8..6c00ce74 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/CollectionCarrierScheduler.java @@ -23,7 +23,9 @@ import java.util.ArrayList; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; import org.matsim.contrib.roadpricing.RoadPricingScheme; +import org.matsim.contrib.roadpricing.RoadPricingUtils; import org.matsim.freight.carriers.Carrier; import org.matsim.freight.carriers.CarrierService; import org.matsim.freight.carriers.ScheduledTour; @@ -47,7 +49,7 @@ private Carrier carrier; private CollectionCarrierResource resource; private ArrayList pairs; - private RoadPricingScheme rpscheme = null; + private Scenario scenario; CollectionCarrierScheduler() { this.pairs = new ArrayList<>(); @@ -56,13 +58,14 @@ /** * Constructor for the CollectionCarrierScheduler. * TODO: In the future, the road pricing scheme should come from some the scenario: RoadPricingUtils.getRoadPricingScheme(scenario). This here is only a dirty workaround. KMT'Aug'24 + * + * @param scenario the road pricing scheme * @deprecated This is only a dirty workaround. KMT'Aug'24 - * @param rpscheme the road pricing scheme */ @Deprecated - CollectionCarrierScheduler(RoadPricingScheme rpscheme) { + CollectionCarrierScheduler(Scenario scenario) { this.pairs = new ArrayList<>(); - this.rpscheme = rpscheme; + this.scenario = scenario; } @Override @@ -83,7 +86,7 @@ public void scheduleResource() { CarrierService carrierService = convertToCarrierService(tupleToBeAssigned); carrier.getServices().put(carrierService.getId(), carrierService); } - carrier = CarrierSchedulerUtils.solveVrpWithJsprit(carrier, resource.getNetwork(), rpscheme); + carrier = CarrierSchedulerUtils.solveVrpWithJsprit(carrier, resource.getNetwork(), RoadPricingUtils.getRoadPricingScheme(scenario)); } 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 80902b88..060bbbca 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/DistributionCarrierScheduler.java @@ -27,7 +27,10 @@ import java.util.List; import org.locationtech.jts.util.Assert; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Scenario; import org.matsim.contrib.roadpricing.RoadPricingScheme; +import org.matsim.contrib.roadpricing.RoadPricingUtils; +import org.matsim.core.scenario.ScenarioUtils; import org.matsim.freight.carriers.*; import org.matsim.freight.carriers.CarrierCapabilities.FleetSize; import org.matsim.freight.carriers.Tour.Leg; @@ -53,7 +56,7 @@ private DistributionCarrierResource resource; private ArrayList pairs; private int carrierCnt = 1; - private RoadPricingScheme rpscheme = null; + private Scenario scenario; DistributionCarrierScheduler() { this.pairs = new ArrayList<>(); @@ -62,13 +65,14 @@ /** * Constructor for the DistributionCarrierScheduler. * TODO: In the future, the road pricing scheme should come from some the scenario: RoadPricingUtils.getRoadPricingScheme(scenario). This here is only a dirty workaround. KMT'Aug'24 + * + * @param scenario the scenario * @deprecated This is only a dirty workaround. KMT'Aug'24 - * @param rpscheme the road pricing scheme */ @Deprecated - DistributionCarrierScheduler(RoadPricingScheme rpscheme) { + DistributionCarrierScheduler(Scenario scenario) { this.pairs = new ArrayList<>(); - this.rpscheme = rpscheme; + this.scenario = scenario; } @Override @@ -105,7 +109,7 @@ protected void scheduleResource() { CarrierSchedulerUtils.solveVrpWithJsprit( createAuxiliaryCarrier( shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime), - resource.getNetwork(), rpscheme); + resource.getNetwork(), RoadPricingUtils.getRoadPricingScheme(scenario)); scheduledPlans.add(auxiliaryCarrier.getSelectedPlan()); carrier.getServices().putAll(auxiliaryCarrier.getServices()); cumulatedLoadingTime = 0; @@ -122,7 +126,7 @@ protected void scheduleResource() { CarrierSchedulerUtils.solveVrpWithJsprit( createAuxiliaryCarrier( shipmentsInCurrentTour, availabilityTimeOfLastShipment + cumulatedLoadingTime), - resource.getNetwork(), rpscheme); + resource.getNetwork(), RoadPricingUtils.getRoadPricingScheme(scenario)); scheduledPlans.add(auxiliaryCarrier.getSelectedPlan()); carrier.getServices().putAll(auxiliaryCarrier.getServices()); shipmentsInCurrentTour.clear(); diff --git a/src/main/java/org/matsim/freight/logistics/resourceImplementations/ResourceImplementationUtils.java b/src/main/java/org/matsim/freight/logistics/resourceImplementations/ResourceImplementationUtils.java index b3a82f17..304223a6 100644 --- a/src/main/java/org/matsim/freight/logistics/resourceImplementations/ResourceImplementationUtils.java +++ b/src/main/java/org/matsim/freight/logistics/resourceImplementations/ResourceImplementationUtils.java @@ -29,7 +29,6 @@ import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.roadpricing.RoadPricingScheme; import org.matsim.core.utils.io.IOUtils; import org.matsim.freight.carriers.Carrier; import org.matsim.freight.carriers.CarrierVehicle; @@ -224,22 +223,24 @@ public static CollectionCarrierScheduler createDefaultCollectionCarrierScheduler /** * Utils method to create a DistributionCarrierScheduler with Roadpricing. - * TODO: In the future, the road pricing scheme should come from some the scenario: RoadPricingUtils.getRoadPricingScheme(scenario). This here is only a dirty workaround. KMT'Aug'24 + * TODO: In the future, the scheduler should get the scenario via injection. This here is only a dirty workaround. KMT'Aug'24 + * + * @param scenario the scenario * @deprecated This is only a dirty workaround. KMT'Aug'24 - * @param roadPricingScheme the road pricing scheme */ - public static DistributionCarrierScheduler createDefaultDistributionCarrierSchedulerWithRoadPricing(RoadPricingScheme roadPricingScheme) { - return new DistributionCarrierScheduler(roadPricingScheme); + public static DistributionCarrierScheduler createDefaultDistributionCarrierSchedulerWithRoadPricing(Scenario scenario) { + return new DistributionCarrierScheduler(scenario); } /** * Utils method to create a Collection CarrierScheduler with Roadpricing. - * TODO: In the future, the road pricing scheme should come from some the scenario: RoadPricingUtils.getRoadPricingScheme(scenario). This here is only a dirty workaround. KMT'Aug'24 + * TODO: In the future, the scheduler should get the scenario via injection. This here is only a dirty workaround. KMT'Aug'24 + * + * @param scenario the scenario * @deprecated This is only a dirty workaround. KMT'Aug'24 - * @param roadPricingScheme the road pricing scheme */ - public static CollectionCarrierScheduler createDefaultCollectionCarrierSchedulerWithRoadPricing(RoadPricingScheme roadPricingScheme) { - return new CollectionCarrierScheduler(roadPricingScheme); + public static CollectionCarrierScheduler createDefaultCollectionCarrierSchedulerWithRoadPricing(Scenario scenario) { + return new CollectionCarrierScheduler(scenario); } public static MainRunCarrierScheduler createDefaultMainRunCarrierScheduler() {