From 5a860785b7886958b59dabb9da71e724a602aae6 Mon Sep 17 00:00:00 2001 From: Kai Martins-Turner Date: Tue, 12 Nov 2024 15:52:30 +0100 Subject: [PATCH] add networkMode to vehicleType. Do not use CarrierVehicleType.Builder any more. --- ...chedulingOfTransportChainHubsVsDirect.java | 35 +++++++------- .../initialPlans/ExampleTwoEchelonGrid.java | 46 ++++++++++++------- .../lspScoring/CollectionLSPScoringTest.java | 13 +++++- .../MultipleChainsReplanningTest.java | 23 +++++++--- .../multipleChains/WorstPlanSelectorTest.java | 30 ++++++------ 5 files changed, 92 insertions(+), 55 deletions(-) diff --git a/src/main/java/org/matsim/freight/logistics/examples/initialPlans/ExampleSchedulingOfTransportChainHubsVsDirect.java b/src/main/java/org/matsim/freight/logistics/examples/initialPlans/ExampleSchedulingOfTransportChainHubsVsDirect.java index 392845d6..d76277d6 100644 --- a/src/main/java/org/matsim/freight/logistics/examples/initialPlans/ExampleSchedulingOfTransportChainHubsVsDirect.java +++ b/src/main/java/org/matsim/freight/logistics/examples/initialPlans/ExampleSchedulingOfTransportChainHubsVsDirect.java @@ -26,6 +26,7 @@ import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.CommandLine; @@ -52,6 +53,7 @@ import org.matsim.freight.logistics.shipment.LspShipment; import org.matsim.freight.logistics.shipment.LspShipmentUtils; import org.matsim.vehicles.VehicleType; +import org.matsim.vehicles.VehicleUtils; /** * The LSP have to possibilities to send the goods from the first depot to the recipients: A) via @@ -240,15 +242,14 @@ private static LSP createInitialLSP(Scenario scenario, SolutionType solutionType Carrier mainRunCarrier = CarriersUtils.createCarrier(Id.create("MainRunCarrier", Carrier.class)); - VehicleType mainRunVehType = - CarrierVehicleType.Builder.newInstance( - Id.create("MainRunCarrierVehicleType", VehicleType.class)) - .setCapacity(30) - .setCostPerDistanceUnit(0.0002) - .setCostPerTimeUnit(0.38) - .setFixCost(120) - .setMaxVelocity(50 / 3.6) - .build(); + Id mainRunCarrierVehicleType = Id.create("MainRunCarrierVehicleType", VehicleType.class); + VehicleType mainRunVehType = VehicleUtils.createVehicleType(mainRunCarrierVehicleType, TransportMode.car); + mainRunVehType.getCapacity().setOther(30); + mainRunVehType.getCostInformation().setCostsPerMeter(0.0002); + mainRunVehType.getCostInformation().setCostsPerSecond(0.38); + mainRunVehType.getCostInformation().setFixedCost(120.); + mainRunVehType.setMaximumVelocity(50 / 3.6); + mainRunVehType.setNetworkMode(TransportMode.car); CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.Builder.newInstance( @@ -533,13 +534,15 @@ private static LSPPlan createLSPPlan_reloading( } private static VehicleType createCarrierVehicleType(String vehicleTypeId) { - return CarrierVehicleType.Builder.newInstance(Id.create(vehicleTypeId, VehicleType.class)) - .setCapacity(10) - .setCostPerDistanceUnit(0.0004) - .setCostPerTimeUnit(0.38) - .setFixCost(49) - .setMaxVelocity(50 / 3.6) - .build(); + VehicleType vehicleType = VehicleUtils.createVehicleType(Id.create(vehicleTypeId, VehicleType.class), TransportMode.car); + vehicleType.getCapacity().setOther(10); + vehicleType.getCostInformation().setCostsPerMeter(0.0004); + vehicleType.getCostInformation().setCostsPerSecond(0.38); + vehicleType.getCostInformation().setFixedCost(49.); + vehicleType.setMaximumVelocity(50 / 3.6); + vehicleType.setNetworkMode(TransportMode.car); + + return vehicleType; } private static Collection createInitialLSPShipments(Network network) { diff --git a/src/main/java/org/matsim/freight/logistics/examples/initialPlans/ExampleTwoEchelonGrid.java b/src/main/java/org/matsim/freight/logistics/examples/initialPlans/ExampleTwoEchelonGrid.java index 37714938..a776131e 100644 --- a/src/main/java/org/matsim/freight/logistics/examples/initialPlans/ExampleTwoEchelonGrid.java +++ b/src/main/java/org/matsim/freight/logistics/examples/initialPlans/ExampleTwoEchelonGrid.java @@ -26,6 +26,7 @@ import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.CommandLine; @@ -50,6 +51,7 @@ import org.matsim.freight.logistics.shipment.LspShipment; import org.matsim.freight.logistics.shipment.LspShipmentUtils; import org.matsim.vehicles.VehicleType; +import org.matsim.vehicles.VehicleUtils; /** * This is an academic example for the 2-echelon problem. It uses the 9x9-grid network from the @@ -81,22 +83,9 @@ final class ExampleTwoEchelonGrid { private static final Id DEPOT_LINK_ID = Id.createLinkId("i(5,0)"); private static final Id HUB_LINK_ID = Id.createLinkId("j(5,3)"); - private static final VehicleType VEH_TYPE_LARGE_50 = - CarrierVehicleType.Builder.newInstance(Id.create("large50", VehicleType.class)) - .setCapacity(50) - .setMaxVelocity(10) - .setFixCost(150) - .setCostPerDistanceUnit(0.01) - .setCostPerTimeUnit(0.01) - .build(); - private static final VehicleType VEH_TYPE_SMALL_05 = - CarrierVehicleType.Builder.newInstance(Id.create("small05", VehicleType.class)) - .setCapacity(5) - .setMaxVelocity(10) - .setFixCost(25) - .setCostPerDistanceUnit(0.001) - .setCostPerTimeUnit(0.005) - .build(); + private static final VehicleType VEH_TYPE_LARGE_50 = createVehTypeLarge50(); + private static final VehicleType VEH_TYPE_SMALL_05 = createVehTypeSmall05(); + private ExampleTwoEchelonGrid() {} // so it cannot be instantiated @@ -490,6 +479,31 @@ enum CarrierCostSetting { lowerCost4LastMile } + + private static VehicleType createVehTypeLarge50() { + VehicleType vehicleType = VehicleUtils.createVehicleType(Id.create("large50", VehicleType.class), TransportMode.car); + vehicleType.getCapacity().setOther(50); + vehicleType.getCostInformation().setCostsPerMeter(0.01); + vehicleType.getCostInformation().setCostsPerSecond(0.01); + vehicleType.getCostInformation().setFixedCost(150.); + vehicleType.setMaximumVelocity(10); + vehicleType.setNetworkMode(TransportMode.car); + + return vehicleType; + } + + private static VehicleType createVehTypeSmall05() { + VehicleType vehicleType = VehicleUtils.createVehicleType(Id.create("small05", VehicleType.class), TransportMode.car); + vehicleType.getCapacity().setOther(5); + vehicleType.getCostInformation().setCostsPerMeter(0.001); + vehicleType.getCostInformation().setCostsPerSecond(0.005); + vehicleType.getCostInformation().setFixedCost(25.); + vehicleType.setMaximumVelocity(10); + vehicleType.setNetworkMode(TransportMode.car); + + return vehicleType; + } + // @Override public ScoringFunction createScoringFunction(Carrier carrier ){ // // return new ScoringFunction(){ diff --git a/src/test/java/org/matsim/freight/logistics/examples/lspScoring/CollectionLSPScoringTest.java b/src/test/java/org/matsim/freight/logistics/examples/lspScoring/CollectionLSPScoringTest.java index 50431487..2e06a80c 100644 --- a/src/test/java/org/matsim/freight/logistics/examples/lspScoring/CollectionLSPScoringTest.java +++ b/src/test/java/org/matsim/freight/logistics/examples/lspScoring/CollectionLSPScoringTest.java @@ -32,6 +32,7 @@ import org.junit.jupiter.api.Test; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.Config; @@ -49,6 +50,7 @@ import org.matsim.freight.logistics.shipment.LspShipmentUtils; import org.matsim.testcases.MatsimTestUtils; import org.matsim.vehicles.VehicleType; +import org.matsim.vehicles.VehicleUtils; public class CollectionLSPScoringTest { @@ -69,8 +71,15 @@ public void initialize() { Scenario scenario = ScenarioUtils.loadScenario(config); Network network = scenario.getNetwork(); - VehicleType collectionVehType = CarrierVehicleType.Builder.newInstance(Id.create("CollectionCarrierVehicleType", VehicleType.class)) - .setCapacity(10).setCostPerDistanceUnit(0.0004).setCostPerTimeUnit(0.38).setFixCost(49).setMaxVelocity(50 / 3.6).build(); + + VehicleType collectionVehType = VehicleUtils.createVehicleType(Id.create("CollectionCarrierVehicleType", VehicleType.class), TransportMode.car); + collectionVehType.getCapacity().setOther(10); + collectionVehType.getCostInformation().setCostsPerMeter(0.0004); + collectionVehType.getCostInformation().setCostsPerSecond(0.38); + collectionVehType.getCostInformation().setFixedCost(49.); + collectionVehType.setMaximumVelocity(50 / 3.6); + collectionVehType.setNetworkMode(TransportMode.car); + Link collectionLink = network.getLinks().get(Id.createLinkId("(4 2) (4 3)")); // (make sure that the link exists) diff --git a/src/test/java/org/matsim/freight/logistics/examples/multipleChains/MultipleChainsReplanningTest.java b/src/test/java/org/matsim/freight/logistics/examples/multipleChains/MultipleChainsReplanningTest.java index 9dd5cc58..501e710b 100644 --- a/src/test/java/org/matsim/freight/logistics/examples/multipleChains/MultipleChainsReplanningTest.java +++ b/src/test/java/org/matsim/freight/logistics/examples/multipleChains/MultipleChainsReplanningTest.java @@ -32,6 +32,7 @@ import org.junit.jupiter.api.Test; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Link; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; @@ -55,17 +56,25 @@ import org.matsim.freight.logistics.shipment.LspShipmentUtils; import org.matsim.testcases.MatsimTestUtils; import org.matsim.vehicles.VehicleType; +import org.matsim.vehicles.VehicleUtils; public class MultipleChainsReplanningTest { private static final Id DEPOT_LINK_ID = Id.createLinkId("i(5,0)"); - private static final VehicleType VEH_TYPE_LARGE_50 = CarrierVehicleType.Builder.newInstance(Id.create("large50", VehicleType.class)) - .setCapacity(50) - .setMaxVelocity(10) - .setFixCost(150) - .setCostPerDistanceUnit(0.01) - .setCostPerTimeUnit(0.01) - .build(); + private static final VehicleType VEH_TYPE_LARGE_50 = createVehTypeLarge50(); + + private static VehicleType createVehTypeLarge50() { + VehicleType vehicleType = VehicleUtils.createVehicleType(Id.create("large50", VehicleType.class), TransportMode.car); + vehicleType.getCapacity().setOther(50); + vehicleType.getCostInformation().setCostsPerMeter(0.01); + vehicleType.getCostInformation().setCostsPerSecond(0.01); + vehicleType.getCostInformation().setFixedCost(150.); + vehicleType.setMaximumVelocity(10); + vehicleType.setNetworkMode(TransportMode.car); + + return vehicleType; + } + @RegisterExtension public final MatsimTestUtils utils = new MatsimTestUtils(); int initialPlanCount; diff --git a/src/test/java/org/matsim/freight/logistics/examples/multipleChains/WorstPlanSelectorTest.java b/src/test/java/org/matsim/freight/logistics/examples/multipleChains/WorstPlanSelectorTest.java index 47ad17c8..fccfa68e 100644 --- a/src/test/java/org/matsim/freight/logistics/examples/multipleChains/WorstPlanSelectorTest.java +++ b/src/test/java/org/matsim/freight/logistics/examples/multipleChains/WorstPlanSelectorTest.java @@ -29,6 +29,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; +import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; import org.matsim.core.config.Config; @@ -56,25 +57,26 @@ import org.matsim.freight.logistics.shipment.LspShipmentUtils; import org.matsim.testcases.MatsimTestUtils; import org.matsim.vehicles.VehicleType; +import org.matsim.vehicles.VehicleUtils; public class WorstPlanSelectorTest { private static final Id DEPOT_SOUTH_LINK_ID = Id.createLinkId("i(1,0)"); private static final Id DEPOT_NORTH_LINK_ID = Id.createLinkId("i(1,8)"); - private static final VehicleType VEH_TYPE_CHEAP = CarrierVehicleType.Builder.newInstance(Id.create("cheap", VehicleType.class)) - .setCapacity(50) - .setMaxVelocity(10) - .setFixCost(1) - .setCostPerDistanceUnit(0.001) - .setCostPerTimeUnit(0.001) - .build(); - private static final VehicleType VEH_TYPE_EXPENSIVE = CarrierVehicleType.Builder.newInstance(Id.create("expensive", VehicleType.class)) - .setCapacity(50) - .setMaxVelocity(10) - .setFixCost(100) - .setCostPerDistanceUnit(0.01) - .setCostPerTimeUnit(0.01) - .build(); + private static final VehicleType VEH_TYPE_CHEAP = createVehType("cheap", 1., 0.001, 0.001); + private static final VehicleType VEH_TYPE_EXPENSIVE = createVehType("expensive", 100., 0.01, 0.01); + + private static VehicleType createVehType(String vehicleTypeId, double fix, double perDistanceUnit, double perTimeUnit) { + VehicleType vehicleType = VehicleUtils.createVehicleType(Id.create(vehicleTypeId, VehicleType.class), TransportMode.car); + vehicleType.getCapacity().setOther(50); + vehicleType.getCostInformation().setCostsPerMeter(perDistanceUnit); + vehicleType.getCostInformation().setCostsPerSecond(perTimeUnit); + vehicleType.getCostInformation().setFixedCost(fix); + vehicleType.setMaximumVelocity(10); + + return vehicleType; + } + @RegisterExtension public final MatsimTestUtils utils = new MatsimTestUtils(); private LSP lsp;