Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
pass the scenario through to the *CarrierScheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
kt86 committed Aug 13, 2024
1 parent 2ee697c commit 5790244
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,7 +49,7 @@
private Carrier carrier;
private CollectionCarrierResource resource;
private ArrayList<LSPCarrierPair> pairs;
private RoadPricingScheme rpscheme = null;
private Scenario scenario;

CollectionCarrierScheduler() {
this.pairs = new ArrayList<>();
Expand All @@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -53,7 +56,7 @@
private DistributionCarrierResource resource;
private ArrayList<LSPCarrierPair> pairs;
private int carrierCnt = 1;
private RoadPricingScheme rpscheme = null;
private Scenario scenario;

DistributionCarrierScheduler() {
this.pairs = new ArrayList<>();
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 5790244

Please sign in to comment.