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

Commit

Permalink
add networkMode to vehicleType. Do not use CarrierVehicleType.Builder…
Browse files Browse the repository at this point in the history
… any more.
  • Loading branch information
kt86 committed Nov 12, 2024
1 parent 5a86078 commit c6e9c6c
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
* This is an academic example for the 2-echelon problem. It uses the 9x9-grid network from the
Expand Down Expand Up @@ -83,22 +85,33 @@ final class ExampleTwoEchelonGrid_NR {

private static final Id<Link> DEPOT_LINK_ID = Id.createLinkId("i(5,0)");
private static final Id<Link> 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 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;
}

private ExampleTwoEchelonGrid_NR() {} // so it cannot be instantiated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.Config;
Expand All @@ -44,6 +45,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;

/* Example for customized scoring. Each customer that is visited will give a random tip between zero and five
*
Expand All @@ -57,24 +59,18 @@ private ExampleLSPScoring() {}
private static LSP createLSPWithScorer(Scenario scenario) {

// The Carrier for the resource of the sole LogisticsSolutionElement of the LSP is created
var carrierVehicleType =
CarrierVehicleType.Builder.newInstance(
Id.create("CollectionCarrierVehicleType", VehicleType.class))
.setCapacity(10)
.setCostPerDistanceUnit(0.0004)
.setCostPerTimeUnit(0.38)
.setFixCost(49)
.setMaxVelocity(50 / 3.6)
.build();
final VehicleType carrierVehType = VehicleUtils.createVehicleType( Id.create("CollectionCarrierVehicleType", VehicleType.class), TransportMode.car);
carrierVehType.getCapacity().setOther(10);
carrierVehType.getCostInformation().setCostsPerMeter(0.0004);
carrierVehType.getCostInformation().setCostsPerSecond(0.38);
carrierVehType.getCostInformation().setFixedCost(49.);
carrierVehType.setMaximumVelocity(50 / 3.6);

Id<Link> collectionLinkId = Id.createLinkId("(4 2) (4 3)");

CarrierCapabilities capabilities =
CarrierCapabilities.Builder.newInstance()
// .addType(carrierVehicleType )
.addVehicle(
CarrierVehicle.newInstance(
Id.createVehicleId("CollectionVehicle"), collectionLinkId, carrierVehicleType))
.addVehicle(CarrierVehicle.newInstance(Id.createVehicleId("CollectionVehicle"), collectionLinkId, carrierVehType))
.setFleetSize(FleetSize.INFINITE)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.Config;
Expand All @@ -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;

final class ExampleMultipleMixedEchelonChains {

Expand All @@ -58,22 +60,32 @@ final class ExampleMultipleMixedEchelonChains {
private static final double TOLL_VALUE = 1000;
private static final Id<Link> DEPOT_LINK_ID = Id.createLinkId("i(5,0)");
private static final Id<Link> HUB_LINK_ID = Id.createLinkId("j(5,3)");
private static final VehicleType VEH_TYPE_SMALL_05 =
CarrierVehicleType.Builder.newInstance(Id.create("small05", VehicleType.class))
.setCapacity(5)
.setMaxVelocity(10)
.setFixCost(5)
.setCostPerDistanceUnit(0.001)
.setCostPerTimeUnit(0.01)
.build();
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 final VehicleType VEH_TYPE_SMALL_05 = createVehTypeSmall05();

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;
}

private ExampleMultipleMixedEchelonChains() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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.Config;
Expand All @@ -51,29 +52,41 @@
import org.matsim.freight.logistics.shipment.LspShipment;
import org.matsim.freight.logistics.shipment.LspShipmentUtils;
import org.matsim.vehicles.VehicleType;
import org.matsim.vehicles.VehicleUtils;

final class ExampleMultipleOneEchelonChains {

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

private static final DemandSetting demandSetting = DemandSetting.fiveUnits;
private static final Id<Link> DEPOT_LINK_ID = Id.createLinkId("i(5,0)");
private static final VehicleType VEH_TYPE_SMALL_05 =
CarrierVehicleType.Builder.newInstance(Id.create("small05", VehicleType.class))
.setCapacity(5)
.setMaxVelocity(10)
.setFixCost(5)
.setCostPerDistanceUnit(0.001)
.setCostPerTimeUnit(0.01)
.build();
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 final VehicleType VEH_TYPE_SMALL_05 = createVehTypeSmall05();

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;
}


private ExampleMultipleOneEchelonChains() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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.Config;
Expand All @@ -54,6 +55,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;

final class ExampleMultipleOneEchelonChainsReplanning {

Expand All @@ -62,23 +64,32 @@ final class ExampleMultipleOneEchelonChainsReplanning {

private static final Id<Link> DEPOT_LINK_ID = Id.createLinkId("i(5,0)");

private static final VehicleType VEH_TYPE_SMALL_05 =
CarrierVehicleType.Builder.newInstance(Id.create("small05", VehicleType.class))
.setCapacity(5)
.setMaxVelocity(10)
.setFixCost(5)
.setCostPerDistanceUnit(0.001)
.setCostPerTimeUnit(0.01)
.build();

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 final VehicleType VEH_TYPE_SMALL_05 = createVehTypeSmall05();

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;
}

private ExampleMultipleOneEchelonChainsReplanning() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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.Config;
Expand All @@ -54,6 +55,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;

final class ExampleMultipleTwoEchelonChainsReplanning {

Expand All @@ -64,23 +66,32 @@ final class ExampleMultipleTwoEchelonChainsReplanning {
private static final Id<Link> HUB_LEFT_LINK_ID = Id.createLinkId("i(1,5)R");
private static final Id<Link> HUB_RIGHT_LINK_ID = Id.createLinkId("j(9,5)");

private static final VehicleType VEH_TYPE_SMALL_05 =
CarrierVehicleType.Builder.newInstance(Id.create("small05", VehicleType.class))
.setCapacity(5)
.setMaxVelocity(10)
.setFixCost(5)
.setCostPerDistanceUnit(0.001)
.setCostPerTimeUnit(0.01)
.build();

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 final VehicleType VEH_TYPE_SMALL_05 = createVehTypeSmall05();

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;
}

private ExampleMultipleTwoEchelonChainsReplanning() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ public void initialize() {
.setResource(firstTransshipmentHubBuilder.build())
.build();

VehicleType mainRunType = CarrierVehicleType.Builder
.newInstance(collectionVehTypeId)
.setCapacity(30)
.setCostPerDistanceUnit(0.0002)
.setCostPerTimeUnit(0.38)
.setFixCost(120).setMaxVelocity(50 / 3.6)
.build();

final VehicleType mainRunType = VehicleUtils.createVehicleType(Id.create("small05", VehicleType.class), TransportMode.car);
mainRunType.getCapacity().setOther(30);
mainRunType.getCostInformation().setCostsPerMeter(0.0002);
mainRunType.getCostInformation().setCostsPerSecond(0.38);
mainRunType.getCostInformation().setFixedCost(120.);
mainRunType.setMaximumVelocity(50 / 3.6);
mainRunType.setNetworkMode(TransportMode.car);

final Id<Link> fromLinkId = Id.createLinkId("(4 2) (4 3)");
CarrierVehicle mainRunCarrierVehicle = CarrierVehicle.newInstance(Id.createVehicleId("MainRunVehicle"), fromLinkId, mainRunType);
Expand Down

0 comments on commit c6e9c6c

Please sign in to comment.