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 e0dda3a commit 5a86078
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 55 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;

/**
* The LSP have to possibilities to send the goods from the first depot to the recipients: A) via
Expand Down Expand Up @@ -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<VehicleType> 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(
Expand Down Expand Up @@ -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<LspShipment> createInitialLSPShipments(Network network) {
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.CommandLine;
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;

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

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 ExampleTwoEchelonGrid() {} // so it cannot be instantiated

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

Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Link> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Link> DEPOT_SOUTH_LINK_ID = Id.createLinkId("i(1,0)");
private static final Id<Link> 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;
Expand Down

0 comments on commit 5a86078

Please sign in to comment.