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

Commit

Permalink
Merge branch 'main' into uniqueResourceIds
Browse files Browse the repository at this point in the history
  • Loading branch information
kt86 authored Jul 5, 2024
2 parents 9868b3b + f049ae2 commit 2c00ae6
Showing 1 changed file with 43 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ final class ExampleTwoLspsGroceryDeliveryMultipleChains {
private static final Logger log = LogManager.getLogger(ExampleTwoLspsGroceryDeliveryMultipleChains.class);
private static final Id<Link> HUB_LINK_ID_NEUKOELLN = Id.createLinkId("91085");
private static final double TOLL_VALUE = 1000;
static double HUBCOSTS_FIX = 100;
private static final double HUBCOSTS_FIX = 100;
private static final String CARRIER_PLAN_FILE = "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/berlin/projects/freight/foodRetailing_wo_rangeConstraint/input/CarrierLEH_v2_withFleet_Shipment_OneTW_PickupTime_ICEVandBEV.xml";
private static final String VEHICLE_TYPE_FILE = "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/berlin/projects/freight/foodRetailing_wo_rangeConstraint/input/vehicleTypesBVWP100_DC_noTax.xml";
public static final String EDEKA_SUPERMARKT_TROCKEN = "edeka_SUPERMARKT_TROCKEN";
public static final String KAUFLAND_VERBRAUCHERMARKT_TROCKEN = "kaufland_VERBRAUCHERMARKT_TROCKEN";

private ExampleTwoLspsGroceryDeliveryMultipleChains() {}

Expand All @@ -71,7 +75,16 @@ public static void main(String[] args) {
Config config = prepareConfig(args);

log.info("Prepare scenario");
Scenario scenario = prepareScenario(config);
Scenario scenario = ScenarioUtils.loadScenario(config);

log.info("Add LSP(s) to the scenario");
Collection<LSP> lsps = new LinkedList<>();
lsps.add(createLspWithTwoChains(scenario, "myLSP2", EDEKA_SUPERMARKT_TROCKEN, HUB_LINK_ID_NEUKOELLN));
lsps.add(createLspWithTwoChains(scenario, "myLSP1", KAUFLAND_VERBRAUCHERMARKT_TROCKEN, HUB_LINK_ID_NEUKOELLN));
lsps.add(createLspWithDirectChain(scenario, "myLSP2_DIRECT", EDEKA_SUPERMARKT_TROCKEN));
lsps.add(createLspWithDirectChain(scenario, "myLSP1_DIRECT", KAUFLAND_VERBRAUCHERMARKT_TROCKEN));
LSPUtils.addLSPs(scenario, new LSPs(lsps));


log.info("Prepare controler");
Controler controler = new Controler(scenario);
Expand Down Expand Up @@ -106,11 +119,7 @@ public void install() {
() -> {
LSPStrategyManager strategyManager = new LSPStrategyManagerImpl();
strategyManager.addStrategy(new GenericPlanStrategyImpl<>(new ExpBetaPlanSelector<>(new ScoringConfigGroup())), null, 1);
// strategyManager.addStrategy(new
// RebalancingShipmentsStrategyFactory().createStrategy(), null, 2);
strategyManager.addStrategy(new RandomShiftingStrategyFactory().createStrategy(), null, 4);
// strategyManager.addStrategy(new
// ProximityStrategyFactory(scenario.getNetwork()).createStrategy(), null, 1);
strategyManager.addStrategy(RandomShiftingStrategyFactory.createStrategy(), null, 4);
strategyManager.setMaxPlansPerAgent(5);
strategyManager.setPlanSelectorForRemoval(new GenericWorstPlanForRemovalSelector<>());
return strategyManager;
Expand Down Expand Up @@ -156,73 +165,46 @@ private static Config prepareConfig(String[] args) {
return config;
}

private static Scenario prepareScenario(Config config) {
Scenario scenario = ScenarioUtils.loadScenario(config);

log.info("Add LSP to the scenario");
Collection<LSP> lsps = new LinkedList<>();
lsps.add(createLspWithTwoChains(scenario, "myLSP2", "edeka_SUPERMARKT_TROCKEN", HUB_LINK_ID_NEUKOELLN));
lsps.add(createLspWithTwoChains(scenario, "myLSP1", "kaufland_VERBRAUCHERMARKT_TROCKEN", HUB_LINK_ID_NEUKOELLN));
lsps.add(createLspWithDirectChain(scenario, "myLSP2_DIRECT", "edeka_SUPERMARKT_TROCKEN"));
lsps.add(createLspWithDirectChain(scenario, "myLSP1_DIRECT", "kaufland_VERBRAUCHERMARKT_TROCKEN"));
LSPUtils.addLSPs(scenario, new LSPs(lsps));

return scenario;
}

/**
* Creates an LSP with two chains:
* - direct delivery
* - 2-echelon delivery
*
* @param scenario the scenria, used e.g. for getting the network and register some stuff
* @param scenario the scenario, used e.g. for getting the network and register some stuff
* @param lspName String of LSP's Id
* @param carrierIdString Name of the carrier, the (lsp's) demand (shipments) are created from.
* @param carrierIdString Name of the carrier, the (LSP's) demand (shipments) are created from.
* @param hubLinkId location of the hub
* @return the LSP
*/
private static LSP createLspWithTwoChains(Scenario scenario, String lspName, String carrierIdString, Id<Link> hubLinkId) {
String carrierPlanFile = "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/berlin/projects/freight/foodRetailing_wo_rangeConstraint/input/CarrierLEH_v2_withFleet_Shipment_OneTW_PickupTime_ICEVandBEV.xml";
String vehicleTypeFile = "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/berlin/projects/freight/foodRetailing_wo_rangeConstraint/input/vehicleTypesBVWP100_DC_noTax.xml";

CarrierVehicleTypes vehicleTypes = new CarrierVehicleTypes();
CarrierVehicleTypeReader vehicleTypeReader = new CarrierVehicleTypeReader(vehicleTypes);
vehicleTypeReader.readFile(vehicleTypeFile);
vehicleTypeReader.readFile(VEHICLE_TYPE_FILE);


Carriers carriers = new Carriers();
CarrierPlanXmlReader carrierReader = new CarrierPlanXmlReader(carriers, vehicleTypes);
carrierReader.readFile(carrierPlanFile);
carrierReader.readFile(CARRIER_PLAN_FILE);

Carrier carrier = carriers.getCarriers()
.get(Id.create(carrierIdString, CarrierImpl.class));
// Id<Link> depotLinkFromShipments =
// carrier.getShipments().values().iterator().next().getFrom();
Id<Link> depotLinkFromVehicles = carrier
.getCarrierCapabilities()
.getCarrierVehicles()
.values()
.iterator()
.next()
.getLinkId();
Carrier carrier = carriers.getCarriers().get(Id.create(carrierIdString, CarrierImpl.class));
Id<Link> depotLinkFromVehicle = getDepotLinkFromVehicle(carrier);

log.info("create LSP");

//Chains
LogisticChain directChain = createDirectChain(scenario, lspName, depotLinkFromVehicles, vehicleTypes);
LogisticChain twoEchelonChain = createTwoEchelonChain(scenario, lspName, hubLinkId, depotLinkFromVehicles, vehicleTypes);
LogisticChain directChain = createDirectChain(scenario, lspName, depotLinkFromVehicle, vehicleTypes);
LogisticChain twoEchelonChain = createTwoEchelonChain(scenario, lspName, hubLinkId, depotLinkFromVehicle, vehicleTypes);

LSPPlan multipleMixedEchelonChainsPlan =
LSPUtils.createLSPPlan()
.addLogisticChain(directChain)
.addLogisticChain(twoEchelonChain)
.addLogisticChain(twoEchelonChain)
.setInitialShipmentAssigner(MultipleChainsUtils.createRandomLogisticChainShipmentAssigner());

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

LSP lsp =
LSPUtils.LSPBuilder.getInstance(Id.create(lspName, LSP.class))
LSP lsp = LSPUtils.LSPBuilder.getInstance(Id.create(lspName, LSP.class))
.setInitialPlan(multipleMixedEchelonChainsPlan)
.setLogisticChainScheduler(
ResourceImplementationUtils.createDefaultSimpleForwardLogisticChainScheduler(
Expand All @@ -241,6 +223,16 @@ private static LSP createLspWithTwoChains(Scenario scenario, String lspName, Str
return lsp;
}

private static Id<Link> getDepotLinkFromVehicle(Carrier carrier) {
return carrier
.getCarrierCapabilities()
.getCarrierVehicles()
.values()
.iterator()
.next()
.getLinkId();
}

private static LogisticChain createTwoEchelonChain(Scenario scenario, String lspName, Id<Link> hubLinkId, Id<Link> depotLinkFromVehicles, CarrierVehicleTypes vehicleTypes) {
LogisticChain hubChain;
Carrier mainCarrier = CarriersUtils.createCarrier(Id.create(lspName +"_mainCarrier", Carrier.class));
Expand Down Expand Up @@ -330,9 +322,9 @@ private static LogisticChain createTwoEchelonChain(Scenario scenario, String lsp
/**
* Creates an LSP with direct chains:
*
* @param scenario the scenria, used e.g. for getting the network and register some stuff
* @param scenario the scenario, used e.g. for getting the network and register some stuff
* @param lspName String of LSP's Id
* @param carrierIdString Name of the carrier, the (lsp's) demand (shipments) are created from.
* @param carrierIdString Name of the carrier, the (LSP's) demand (shipments) are created from.
* @return the LSP
*/
private static LSP createLspWithDirectChain(Scenario scenario, String lspName, String carrierIdString) {
Expand All @@ -349,15 +341,8 @@ private static LSP createLspWithDirectChain(Scenario scenario, String lspName, S

Carrier carrier = carriers.getCarriers()
.get(Id.create(carrierIdString, CarrierImpl.class));
// Id<Link> depotLinkFromShipments =
// carrier.getShipments().values().iterator().next().getFrom();
Id<Link> depotLinkFromVehicles = carrier
.getCarrierCapabilities()
.getCarrierVehicles()
.values()
.iterator()
.next()
.getLinkId();

Id<Link> depotLinkFromVehicles = getDepotLinkFromVehicle(carrier);

log.info("create LSP");

Expand All @@ -372,8 +357,7 @@ private static LSP createLspWithDirectChain(Scenario scenario, String lspName, S
.setInitialShipmentAssigner(MultipleChainsUtils.createRandomLogisticChainShipmentAssigner());
}

List<LSPPlan> lspPlans = new ArrayList<>();
lspPlans.add(lspPlan);
List<LSPPlan> lspPlans = List.of(lspPlan);

LSP lsp =
LSPUtils.LSPBuilder.getInstance(Id.create(lspName, LSP.class))
Expand All @@ -395,6 +379,7 @@ private static LSP createLspWithDirectChain(Scenario scenario, String lspName, S
return lsp;
}


private static LogisticChain createDirectChain(Scenario scenario, String lspName, Id<Link> depotLinkFromVehicles, CarrierVehicleTypes vehicleTypes) {
LogisticChain directChain;
Carrier directCarrier = CarriersUtils.createCarrier(Id.create(lspName +"_directCarrier", Carrier.class));
Expand Down

0 comments on commit 2c00ae6

Please sign in to comment.