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

Commit

Permalink
remove network from MainRunCarrierResource and its Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
kt86 committed Aug 13, 2024
1 parent ce44ec7 commit 2db8f74
Show file tree
Hide file tree
Showing 37 changed files with 54 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private static LSP createInitialLSP(Scenario scenario) {
ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainRunCarrier, network)
.setFromLinkId(Id.createLinkId("(4 2) (4 3)"))
.setToLinkId(Id.createLinkId("(14 2) (14 3)"))
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.build();

// The LogisticsSolutionElement for the main run Resource is created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private static LSP createInitialLSP(Scenario scenario, SolutionType solutionType
.setFromLinkId(depotLinkId)
.setToLinkId(hubLinkId)
.setMainRunCarrierScheduler(
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.build();

mainRunElement =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private static LSP createLSP(Scenario scenario) {
ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainCarrier, network)
.setFromLinkId(DEPOT_LINK_ID)
.setMainRunCarrierScheduler(
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setToLinkId(HUB_LINK_ID)
.setVehicleReturn(ResourceImplementationUtils.VehicleReturn.returnToFromLink)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private static LSP createLSP(Scenario scenario) {
ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainCarrier, network)
.setFromLinkId(DEPOT_LINK_ID)
.setMainRunCarrierScheduler(
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setToLinkId(HUB_LINK_ID)
.setVehicleReturn(ResourceImplementationUtils.VehicleReturn.returnToFromLink)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private static LSP createInitialLSP(Scenario scenario) {
ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainRunCarrier, network)
.setFromLinkId(Id.createLinkId("(4 2) (4 3)"))
.setToLinkId(Id.createLinkId("(14 2) (14 3)"))
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.build();

// The LogisticsSolutionElement for the main run Resource is created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private static LSP createLSP(Scenario scenario) {
mainCarrier, scenario.getNetwork())
.setFromLinkId(depotLinkFromVehicles)
.setMainRunCarrierScheduler(
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setToLinkId(HUB_LINK_ID)
.setVehicleReturn(ResourceImplementationUtils.VehicleReturn.returnToFromLink)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private static LSP createLSP(Scenario scenario) {
mainCarrier1, network)
.setFromLinkId(DEPOT_LINK_ID)
.setMainRunCarrierScheduler(
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setToLinkId(HUB_LINK_ID)
.setVehicleReturn(ResourceImplementationUtils.VehicleReturn.returnToFromLink)
.build();
Expand Down Expand Up @@ -319,7 +319,7 @@ private static LSP createLSP(Scenario scenario) {
mainCarrier, network)
.setFromLinkId(DEPOT_LINK_ID)
.setMainRunCarrierScheduler(
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setToLinkId(HUB_LINK_ID)
.setVehicleReturn(ResourceImplementationUtils.VehicleReturn.returnToFromLink)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private static LSP createLSP(Scenario scenario) {
ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainCarrierLeft, network)
.setFromLinkId(DEPOT_LINK_ID)
.setMainRunCarrierScheduler(
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setToLinkId(HUB_LEFT_LINK_ID)
.setVehicleReturn(ResourceImplementationUtils.VehicleReturn.returnToFromLink)
.build();
Expand Down Expand Up @@ -284,7 +284,7 @@ private static LSP createLSP(Scenario scenario) {
ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainCarrier, network)
.setFromLinkId(DEPOT_LINK_ID)
.setMainRunCarrierScheduler(
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setToLinkId(HUB_RIGHT_LINK_ID)
.setVehicleReturn(ResourceImplementationUtils.VehicleReturn.returnToFromLink)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ private static LogisticChain createTwoEchelonChain(Scenario scenario, String lsp
mainCarrier, scenario.getNetwork())
.setFromLinkId(depotLinkFromVehicles)
.setMainRunCarrierScheduler(
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setToLinkId(hubLinkId)
.setVehicleReturn(ResourceImplementationUtils.VehicleReturn.returnToFromLink)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ private static LogisticChain createTwoEchelonChain(Scenario scenario, String lsp
mainCarrier, scenario.getNetwork())
.setFromLinkId(depotLinkFromVehicles)
.setMainRunCarrierScheduler(
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setToLinkId(hubLinkId)
.setVehicleReturn(ResourceImplementationUtils.VehicleReturn.returnToFromLink)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void endTag(String name, String content, Stack<String> context) {
case mainRunCarrier -> lspResource =
ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(currentCarrier, null)
.setMainRunCarrierScheduler(
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(null))
.build();
case distributionCarrier -> lspResource =
ResourceImplementationUtils.DistributionCarrierResourceBuilder.newInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.freight.carriers.Carrier;
import org.matsim.freight.logistics.*;
import org.matsim.freight.logistics.resourceImplementations.ResourceImplementationUtils.MainRunCarrierResourceBuilder;
Expand All @@ -43,7 +42,6 @@
private final MainRunCarrierScheduler mainRunScheduler;

private final ResourceImplementationUtils.VehicleReturn vehicleReturn;
private final Network network;

MainRunCarrierResource(MainRunCarrierResourceBuilder builder) {
super(builder.getId());
Expand All @@ -58,7 +56,6 @@
log.warn("Return behaviour was not specified. Using the following setting as default: {}", ResourceImplementationUtils.VehicleReturn.endAtToLink);
this.vehicleReturn = ResourceImplementationUtils.VehicleReturn.endAtToLink;
}
this.network = builder.getNetwork();
}

@Override
Expand All @@ -85,10 +82,6 @@ public Carrier getCarrier() {
return carrier;
}

public Network getNetwork() {
return network;
}

public ResourceImplementationUtils.VehicleReturn getVehicleReturn() {
return vehicleReturn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.*;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
import org.matsim.core.population.routes.NetworkRoute;
import org.matsim.freight.carriers.*;
Expand All @@ -48,14 +49,16 @@
* shipments into the vehicle * has passed.
*/
/*package-private*/ class MainRunCarrierScheduler extends LSPResourceScheduler {

private Carrier carrier;
private MainRunCarrierResource resource;
private ArrayList<LSPShipmentCarrierServicePair> pairs;
private final Scenario scenario;
private int tourIdIndex = 1; // Have unique TourIds for the MainRun.

/*package-private*/ MainRunCarrierScheduler() {
/*package-private*/ MainRunCarrierScheduler(Scenario scenario) {
this.pairs = new ArrayList<>();
this.scenario = scenario;
}

@Override
Expand Down Expand Up @@ -117,7 +120,7 @@ private CarrierPlan createPlan(Carrier carrier, List<LspShipmentWithTime> tuples
// statt!
NetworkBasedTransportCosts.Builder tpcostsBuilder =
NetworkBasedTransportCosts.Builder.newInstance(
resource.getNetwork(),
scenario.getNetwork(),
ResourceImplementationUtils.getVehicleTypeCollection(resource.getCarrier()));
NetworkBasedTransportCosts netbasedTransportcosts = tpcostsBuilder.build();
Collection<ScheduledTour> tours = new ArrayList<>();
Expand Down Expand Up @@ -193,14 +196,14 @@ private double scorePlanManually(CarrierPlan plan) {
// distance
NetworkRoute route = (NetworkRoute) leg.getRoute();
for (Id<Link> linkId : route.getLinkIds()) {
distance = distance + resource.getNetwork().getLinks().get(linkId).getLength();
distance = distance + scenario.getNetwork().getLinks().get(linkId).getLength();
}
if (route.getEndLinkId()
!= route
.getStartLinkId()) { // Do not calculate any distance, if start and endpoint are
// identical
distance =
distance + resource.getNetwork().getLinks().get(route.getEndLinkId()).getLength();
distance + scenario.getNetwork().getLinks().get(route.getEndLinkId()).getLength();
}

// travel time (exp.)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public static void setCarrierType(Carrier carrier, CARRIER_TYPE carrierType) {
}

/**
* Utils method to create a DistributionCarrierScheduler
* Utils method to create a DistributionCarrierScheduler
* 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
Expand All @@ -224,7 +224,7 @@ public static DistributionCarrierScheduler createDefaultDistributionCarrierSched
}

/**
* Utils method to create a Collection CarrierScheduler
* Utils method to create a CollectionCarrierScheduler
* 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
Expand All @@ -233,8 +233,14 @@ public static CollectionCarrierScheduler createDefaultCollectionCarrierScheduler
return new CollectionCarrierScheduler(scenario);
}

public static MainRunCarrierScheduler createDefaultMainRunCarrierScheduler() {
return new MainRunCarrierScheduler();
/**
* Utils method to create a MainRunCarrierScheduler
* 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
*/
public static MainRunCarrierScheduler createDefaultMainRunCarrierScheduler(Scenario scenario) {
return new MainRunCarrierScheduler(scenario);
}

public enum VehicleReturn {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void initialize() {
carrier.setCarrierCapabilities(capabilities);

mainRunResource = ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(carrier, network)
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setFromLinkId(Id.createLinkId("(4 2) (4 3)")).setToLinkId(Id.createLinkId("(14 2) (14 3)"))
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void initialize() {
mainRunCarrierResourceBuilder.setCarrierCapabilities(capabilities);

mainRunResource = ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainRunCarrierResourceBuilder, network)
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setFromLinkId(Id.createLinkId("(4 2) (4 3)"))
.setToLinkId(Id.createLinkId("(14 2) (14 3)"))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void initialize() {
mainRunCarrier.setCarrierCapabilities(mainRunCapabilities);

LSPResource mainRunResource = ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainRunCarrier, network)
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setFromLinkId(Id.createLinkId("(4 2) (4 3)"))
.setToLinkId(Id.createLinkId("(14 2) (14 3)"))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void initialize() {


LSPResource mainRunResource = ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainRunCarrier, network)
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setFromLinkId(Id.createLinkId("(4 2) (4 3)"))
.setToLinkId(Id.createLinkId("(14 2) (14 3)"))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void initialize() {


LSPResource mainRunResource = ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainRunCarrier, network)
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setFromLinkId(Id.createLinkId("(4 2) (4 3)"))
.setToLinkId(Id.createLinkId("(14 2) (14 3)"))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void initialize() {


LSPResource mainRunResource = ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainRunCarrier, network)
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setFromLinkId(Id.createLinkId("(4 2) (4 3)"))
.setToLinkId(Id.createLinkId("(14 2) (14 3)"))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void initialize() {


LSPResource mainRunResource = ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainRunCarrier, network)
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setFromLinkId(Id.createLinkId("(4 2) (4 3)"))
.setToLinkId(Id.createLinkId("(14 2) (14 3)"))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void initialize() {


LSPResource mainRunResource = ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainRunCarrier, network)
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setFromLinkId(Id.createLinkId("(4 2) (4 3)"))
.setToLinkId(Id.createLinkId("(14 2) (14 3)"))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void initialize() {


LSPResource mainRunResource = ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainRunCarrier, network)
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setFromLinkId(Id.createLinkId("(4 2) (4 3)"))
.setToLinkId(Id.createLinkId("(14 2) (14 3)"))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void initialize() {


LSPResource mainRunResource = ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainRunCarrier, network)
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setFromLinkId(Id.createLinkId("(4 2) (4 3)"))
.setToLinkId(Id.createLinkId("(14 2) (14 3)"))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void initialize() {


LSPResource mainRunResource = ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainRunCarrier, network)
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setFromLinkId(Id.createLinkId("(4 2) (4 3)"))
.setToLinkId(Id.createLinkId("(14 2) (14 3)"))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void initialize() {


LSPResource mainRunResource = ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainRunCarrier, network)
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setFromLinkId(Id.createLinkId("(4 2) (4 3)"))
.setToLinkId(Id.createLinkId("(14 2) (14 3)"))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void initialize() {


LSPResource mainRunResource = ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainRunCarrier, network)
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setFromLinkId(Id.createLinkId("(4 2) (4 3)"))
.setToLinkId(Id.createLinkId("(14 2) (14 3)"))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void initialize() {


LSPResource mainRunResource = ResourceImplementationUtils.MainRunCarrierResourceBuilder.newInstance(mainRunCarrier, network)
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler())
.setMainRunCarrierScheduler(ResourceImplementationUtils.createDefaultMainRunCarrierScheduler(scenario))
.setFromLinkId(Id.createLinkId("(4 2) (4 3)"))
.setToLinkId(Id.createLinkId("(14 2) (14 3)"))
.build();
Expand Down
Loading

0 comments on commit 2db8f74

Please sign in to comment.