diff --git a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java
index f4277404..433b6733 100644
--- a/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java
+++ b/src/main/java/org/matsim/freight/logistics/example/lsp/multipleChains/ExampleTwoLspsGroceryDeliveryMultipleChains.java
@@ -62,7 +62,11 @@ final class ExampleTwoLspsGroceryDeliveryMultipleChains {
private static final Logger log = LogManager.getLogger(ExampleTwoLspsGroceryDeliveryMultipleChains.class);
private static final Id 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() {}
@@ -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 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);
@@ -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;
@@ -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 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 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 depotLinkFromShipments =
- // carrier.getShipments().values().iterator().next().getFrom();
- Id depotLinkFromVehicles = carrier
- .getCarrierCapabilities()
- .getCarrierVehicles()
- .values()
- .iterator()
- .next()
- .getLinkId();
+ Carrier carrier = carriers.getCarriers().get(Id.create(carrierIdString, CarrierImpl.class));
+ Id 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 lspPlans = new ArrayList<>();
- lspPlans.add(multipleMixedEchelonChainsPlan);
+ List 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(
@@ -241,6 +223,16 @@ private static LSP createLspWithTwoChains(Scenario scenario, String lspName, Str
return lsp;
}
+ private static Id getDepotLinkFromVehicle(Carrier carrier) {
+ return carrier
+ .getCarrierCapabilities()
+ .getCarrierVehicles()
+ .values()
+ .iterator()
+ .next()
+ .getLinkId();
+ }
+
private static LogisticChain createTwoEchelonChain(Scenario scenario, String lspName, Id hubLinkId, Id depotLinkFromVehicles, CarrierVehicleTypes vehicleTypes) {
LogisticChain hubChain;
Carrier mainCarrier = CarriersUtils.createCarrier(Id.create(lspName +"_mainCarrier", Carrier.class));
@@ -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) {
@@ -349,15 +341,8 @@ private static LSP createLspWithDirectChain(Scenario scenario, String lspName, S
Carrier carrier = carriers.getCarriers()
.get(Id.create(carrierIdString, CarrierImpl.class));
- // Id depotLinkFromShipments =
- // carrier.getShipments().values().iterator().next().getFrom();
- Id depotLinkFromVehicles = carrier
- .getCarrierCapabilities()
- .getCarrierVehicles()
- .values()
- .iterator()
- .next()
- .getLinkId();
+
+ Id depotLinkFromVehicles = getDepotLinkFromVehicle(carrier);
log.info("create LSP");
@@ -372,8 +357,7 @@ private static LSP createLspWithDirectChain(Scenario scenario, String lspName, S
.setInitialShipmentAssigner(MultipleChainsUtils.createRandomLogisticChainShipmentAssigner());
}
- List lspPlans = new ArrayList<>();
- lspPlans.add(lspPlan);
+ List lspPlans = List.of(lspPlan);
LSP lsp =
LSPUtils.LSPBuilder.getInstance(Id.create(lspName, LSP.class))
@@ -395,6 +379,7 @@ private static LSP createLspWithDirectChain(Scenario scenario, String lspName, S
return lsp;
}
+
private static LogisticChain createDirectChain(Scenario scenario, String lspName, Id depotLinkFromVehicles, CarrierVehicleTypes vehicleTypes) {
LogisticChain directChain;
Carrier directCarrier = CarriersUtils.createCarrier(Id.create(lspName +"_directCarrier", Carrier.class));