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

Commit

Permalink
changed scenario to contain two plans instead of two different initia…
Browse files Browse the repository at this point in the history
…l assignments
  • Loading branch information
nixlaos committed Dec 4, 2023
1 parent c2ba20d commit a300f87
Showing 1 changed file with 66 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ final class ExampleMultipleMixedEchelonChains {

private static final Logger log = LogManager.getLogger(ExampleMultipleMixedEchelonChains.class);

private static final AssignerSetting assignerSetting = AssignerSetting.primary;
enum AssignerSetting {primary, roundRobin}

private static final double TOLL_VALUE = 1000;

static final double HUBCOSTS_FIX = 100;
Expand Down Expand Up @@ -119,8 +116,8 @@ private static Config prepareConfig(String[] args) {
}
ConfigUtils.applyCommandline(config,args);
} else {
config.controller().setOutputDirectory("output/multipleMixedEchelonChains_" + assignerSetting);
config.controller().setLastIteration(0);
config.controller().setOutputDirectory("output/multipleMixedEchelonChains_twoPlans");
config.controller().setLastIteration(2);
}
config.network().setInputFile(String.valueOf(IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("freight-chessboard-9x9"), "grid9x9.xml")));
config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);
Expand Down Expand Up @@ -150,6 +147,65 @@ private static LSP createLSP(Scenario scenario) {
log.info("create LSP");
Network network = scenario.getNetwork();

LSPPlan singleTwoEchelonChainPlan; {
LogisticChain hubChain1;
{
Carrier mainCarrier1 = CarriersUtils.createCarrier(Id.create("mainCarrier", Carrier.class));
mainCarrier1.getCarrierCapabilities().setFleetSize(CarrierCapabilities.FleetSize.INFINITE);

CarriersUtils.addCarrierVehicle(mainCarrier1, CarrierVehicle.newInstance(Id.createVehicleId("mainTruck"), DEPOT_LINK_ID, VEH_TYPE_LARGE_50));
LSPResource mainCarrierResource1 = MainRunCarrierUtils.MainRunCarrierResourceBuilder.newInstance(mainCarrier1, network)
.setFromLinkId(DEPOT_LINK_ID)
.setMainRunCarrierScheduler(MainRunCarrierUtils.createDefaultMainRunCarrierScheduler())
.setToLinkId(HUB_LINK_ID)
.setVehicleReturn(ResourceImplementationUtils.VehicleReturn.returnToFromLink)
.build();

LogisticChainElement mainCarrierElement1 = LSPUtils.LogisticChainElementBuilder.newInstance(Id.create("mainCarrierElement", LogisticChainElement.class))
.setResource(mainCarrierResource1)
.build();

LSPResourceScheduler hubScheduler1 = TranshipmentHubUtils.TranshipmentHubSchedulerBuilder.newInstance()
.setCapacityNeedFixed(10)
.setCapacityNeedLinear(1)
.build();

LSPResource hubResource1 = TranshipmentHubUtils.TransshipmentHubBuilder.newInstance(Id.create("Hub", LSPResource.class), HUB_LINK_ID, scenario)
.setTransshipmentHubScheduler(hubScheduler1)
.build();
LSPUtils.setFixedCost(hubResource1, HUBCOSTS_FIX);

LogisticChainElement hubElement1 = LSPUtils.LogisticChainElementBuilder.newInstance(Id.create("HubElement", LogisticChainElement.class))
.setResource(hubResource1)
.build();

Carrier distributionCarrier1 = CarriersUtils.createCarrier(Id.create("distributionCarrier", Carrier.class));
distributionCarrier1.getCarrierCapabilities().setFleetSize(CarrierCapabilities.FleetSize.INFINITE);

CarriersUtils.addCarrierVehicle(distributionCarrier1, CarrierVehicle.newInstance(Id.createVehicleId("distributionTruck"), HUB_LINK_ID, VEH_TYPE_SMALL_05));
LSPResource distributionCarrierResource1 = DistributionCarrierUtils.DistributionCarrierResourceBuilder.newInstance(distributionCarrier1, network)
.setDistributionScheduler(DistributionCarrierUtils.createDefaultDistributionCarrierScheduler())
.build();

LogisticChainElement distributionCarrierElement1 = LSPUtils.LogisticChainElementBuilder.newInstance(Id.create("distributionCarrierElement", LogisticChainElement.class))
.setResource(distributionCarrierResource1)
.build();

mainCarrierElement1.connectWithNextElement(hubElement1);
hubElement1.connectWithNextElement(distributionCarrierElement1);

hubChain1 = LSPUtils.LogisticChainBuilder.newInstance(Id.create("hubChain", LogisticChain.class))
.addLogisticChainElement(mainCarrierElement1)
.addLogisticChainElement(hubElement1)
.addLogisticChainElement(distributionCarrierElement1)
.build();
}

singleTwoEchelonChainPlan = LSPUtils.createLSPPlan()
.addLogisticChain(hubChain1)
.setAssigner(MultipleChainsUtils.createPrimaryLogisticChainShipmentAssigner());
}

// A plan with a direct chain and a hub chain is created
LSPPlan multipleMixedEchelonChainsPlan;
{
Expand Down Expand Up @@ -225,27 +281,21 @@ private static LSP createLSP(Scenario scenario) {
.build();
}

ShipmentAssigner assigner;

switch (assignerSetting) {
case primary -> assigner = MultipleChainsUtils.createPrimaryLogisticChainShipmentAssigner();
case roundRobin -> assigner = MultipleChainsUtils.createRoundRobinLogisticChainShipmentAssigner();
default -> throw new IllegalStateException("Unexpected value: " + assignerSetting);
}

multipleMixedEchelonChainsPlan = LSPUtils.createLSPPlan()
.addLogisticChain(hubChain)
.addLogisticChain(directChain)
.setAssigner(assigner);
.setAssigner(MultipleChainsUtils.createRoundRobinLogisticChainShipmentAssigner());
}

List<LSPPlan> lspPlans = new ArrayList<>();
lspPlans.add(singleTwoEchelonChainPlan);
lspPlans.add(multipleMixedEchelonChainsPlan);

LSP lsp = LSPUtils.LSPBuilder.getInstance(Id.create("myLSP", LSP.class))
.setInitialPlan(multipleMixedEchelonChainsPlan)
.setInitialPlan(singleTwoEchelonChainPlan)
.setLogisticChainScheduler(ResourceImplementationUtils.createDefaultSimpleForwardLogisticChainScheduler(createResourcesListFromLSPPlans(lspPlans)))
.build();
lsp.addPlan(multipleMixedEchelonChainsPlan);

log.info("create initial LSPShipments");
log.info("assign the shipments to the LSP");
Expand Down Expand Up @@ -323,4 +373,4 @@ private static List<LSPResource> createResourcesListFromLSPPlans(List<LSPPlan> l
return resourceList;
}

}
}

0 comments on commit a300f87

Please sign in to comment.