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

Commit

Permalink
Merge pull request #160 from matsim-vsp/2821-rename-freight-contrib-2
Browse files Browse the repository at this point in the history
Adapt to changes in MATSim-libs: Reorganisation in freight contrib
  • Loading branch information
kt86 authored Oct 13, 2023
2 parents 4c952e4 + 4e81458 commit 557cf7c
Show file tree
Hide file tree
Showing 126 changed files with 752 additions and 799 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<parent>
<groupId>org.matsim</groupId>
<artifactId>matsim-all</artifactId>
<!-- <version>16.0-2023w24</version>-->
<version>16.0-2023w41</version>
<version>16.0-PR2857</version>
<!-- <version>16.0-2023w41</version>-->
<!-- <version>16.0-2023w23</version>-->
<!-- <version>16.0-SNAPSHOT</version>-->
<relativePath/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.freight.carrier.*;
import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize;
import org.matsim.core.config.Config;
import org.matsim.core.network.io.MatsimNetworkReader;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.freight.carriers.*;
import org.matsim.freight.carriers.CarrierCapabilities.FleetSize;
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleType;

Expand Down Expand Up @@ -68,7 +68,7 @@ private static LSP createInitialLSP(Network network) {
capabilitiesBuilder.setFleetSize(FleetSize.INFINITE);
CarrierCapabilities capabilities = capabilitiesBuilder.build();

Carrier carrier = CarrierUtils.createCarrier(carrierId);
Carrier carrier = CarriersUtils.createCarrier(carrierId);
carrier.setCarrierCapabilities(capabilities);

//The Resource i.e. the Resource is created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.freight.carrier.*;
import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize;
import org.matsim.core.config.Config;
import org.matsim.core.network.io.MatsimNetworkReader;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.freight.carriers.*;
import org.matsim.freight.carriers.CarrierCapabilities.FleetSize;
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleType;

Expand Down Expand Up @@ -77,7 +77,7 @@ private static LSP createInitialLSP(Scenario scenario) {
capabilitiesBuilder.setFleetSize(FleetSize.INFINITE);
CarrierCapabilities capabilities = capabilitiesBuilder.build();

Carrier collectionCarrier = CarrierUtils.createCarrier(collectionCarrierId);
Carrier collectionCarrier = CarriersUtils.createCarrier(collectionCarrierId);
collectionCarrier.setCarrierCapabilities(capabilities);

//The collection adapter i.e. the Resource is created
Expand Down Expand Up @@ -134,7 +134,7 @@ private static LSP createInitialLSP(Scenario scenario) {
.addVehicle(mainRunCarrierVehicle)
.setFleetSize(FleetSize.INFINITE)
.build();
Carrier mainRunCarrier = CarrierUtils.createCarrier(mainRunCarrierId);
Carrier mainRunCarrier = CarriersUtils.createCarrier(mainRunCarrierId);
mainRunCarrier.setCarrierCapabilities(mainRunCapabilities);

//The adapter i.e. the main run resource is created
Expand Down Expand Up @@ -191,7 +191,7 @@ private static LSP createInitialLSP(Scenario scenario) {
distributionCapabilitiesBuilder.addVehicle(distributionCarrierVehicle);
distributionCapabilitiesBuilder.setFleetSize(FleetSize.INFINITE);
CarrierCapabilities distributionCapabilities = distributionCapabilitiesBuilder.build();
Carrier distributionCarrier = CarrierUtils.createCarrier(distributionCarrierId);
Carrier distributionCarrier = CarriersUtils.createCarrier(distributionCarrierId);
distributionCarrier.setCarrierCapabilities(distributionCapabilities);

//The distribution adapter i.e. the Resource is created
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.freight.FreightConfigGroup;
import org.matsim.contrib.freight.carrier.*;
import org.matsim.contrib.freight.carrier.CarrierCapabilities.FleetSize;
import org.matsim.contrib.freight.controler.CarrierStrategyManager;
import org.matsim.contrib.freight.controler.FreightUtils;
import org.matsim.contrib.freight.events.CarrierServiceEndEvent;
import org.matsim.contrib.freight.events.CarrierTourEndEvent;
import org.matsim.contrib.freight.events.eventhandler.FreightServiceEndEventHandler;
import org.matsim.contrib.freight.events.eventhandler.FreightTourEndEventHandler;
import org.matsim.core.config.CommandLine;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
Expand All @@ -53,6 +44,14 @@
import org.matsim.core.replanning.GenericPlanStrategyImpl;
import org.matsim.core.replanning.selectors.RandomPlanSelector;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.freight.carriers.*;
import org.matsim.freight.carriers.CarrierCapabilities.FleetSize;
import org.matsim.freight.carriers.controler.CarrierControlerUtils;
import org.matsim.freight.carriers.controler.CarrierStrategyManager;
import org.matsim.freight.carriers.events.CarrierServiceEndEvent;
import org.matsim.freight.carriers.events.CarrierTourEndEvent;
import org.matsim.freight.carriers.events.eventhandler.FreightServiceEndEventHandler;
import org.matsim.freight.carriers.events.eventhandler.FreightTourEndEventHandler;
import org.matsim.vehicles.VehicleType;

import java.util.*;
Expand Down Expand Up @@ -99,14 +98,14 @@ public static void main(String[] args) {
} else {
solutionType = SolutionType.onePlan_direct;
log.warn("SolutionType was set in code to: " + solutionType);
config.controler().setOutputDirectory("output/ChainVsDirect/" + solutionType);
config.controler().setLastIteration(2);
config.controller().setOutputDirectory("output/ChainVsDirect/" + solutionType);
config.controller().setLastIteration(2);

}
config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);
config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);

var freightConfig = ConfigUtils.addOrGetModule(config, FreightConfigGroup.class);
freightConfig.setTimeWindowHandling(FreightConfigGroup.TimeWindowHandling.ignore);
var freightConfig = ConfigUtils.addOrGetModule(config, FreightCarriersConfigGroup.class);
freightConfig.setTimeWindowHandling(FreightCarriersConfigGroup.TimeWindowHandling.ignore);

log.warn("solutionType= " + solutionType);

Expand Down Expand Up @@ -151,7 +150,7 @@ public static void main(String[] args) {
return strategyManager;
});
bind( CarrierStrategyManager.class ).toProvider(() -> {
CarrierStrategyManager strategyManager = FreightUtils.createDefaultCarrierStrategyManager();
CarrierStrategyManager strategyManager = CarrierControlerUtils.createDefaultCarrierStrategyManager();
strategyManager.addStrategy(new GenericPlanStrategyImpl<>(new RandomPlanSelector<>()), null, 1);
return strategyManager;
});
Expand All @@ -165,7 +164,7 @@ public static void main(String[] args) {

//print the schedules for the assigned LSPShipments
log.info("print the schedules for the assigned LSPShipments");
ResourceImplementationUtils.printResults_shipmentPlan(config.controler().getOutputDirectory(), lsp);
ResourceImplementationUtils.printResults_shipmentPlan(config.controller().getOutputDirectory(), lsp);

log.info("Done.");

Expand Down Expand Up @@ -217,7 +216,7 @@ private static LSP createInitialLSP(Scenario scenario, SolutionType solutionType

log.info("");
log.info("The Carrier for the main run is created");
Carrier mainRunCarrier = CarrierUtils.createCarrier(Id.create("MainRunCarrier", Carrier.class));
Carrier mainRunCarrier = CarriersUtils.createCarrier(Id.create("MainRunCarrier", Carrier.class));

VehicleType mainRunVehicleType = CarrierVehicleType.Builder.newInstance(Id.create("MainRunCarrierVehicleType", VehicleType.class))
.setCapacity(30)
Expand Down Expand Up @@ -280,7 +279,7 @@ private static LSP createInitialLSP(Scenario scenario, SolutionType solutionType

CarrierVehicle distributionCarrierVehicle = CarrierVehicle.Builder.newInstance(Id.createVehicleId("DistributionVehicle"), hubLinkId, distributionVehicleType).build();

Carrier distributionCarrier = CarrierUtils.createCarrier(Id.create("DistributionCarrier", Carrier.class));
Carrier distributionCarrier = CarriersUtils.createCarrier(Id.create("DistributionCarrier", Carrier.class));
distributionCarrier.setCarrierCapabilities(
CarrierCapabilities.Builder.newInstance()
.addType(distributionVehicleType)
Expand Down Expand Up @@ -319,7 +318,7 @@ private static LSP createInitialLSP(Scenario scenario, SolutionType solutionType
.addVehicle(directDistributionCarrierVehicle)
.setFleetSize(FleetSize.INFINITE)
.build();
Carrier directDistributionCarrier = CarrierUtils.createCarrier(Id.create("DirectDistributionCarrier", Carrier.class));
Carrier directDistributionCarrier = CarriersUtils.createCarrier(Id.create("DirectDistributionCarrier", Carrier.class));
directDistributionCarrier.setCarrierCapabilities(directDistributionCarrierCapabilities);

//The distribution adapter i.e. the Resource is created
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/example/lsp/initialPlans/ExampleTestOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public static void main( String[] args ){

Config config = ConfigUtils.loadConfig( IOUtils.extendUrl( ExamplesUtils.getTestScenarioURL( "equil" ), "config.xml" ) );

config.controler().setOverwriteFileSetting( OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists );
config.controler().setLastIteration( 1 );
config.controller().setOverwriteFileSetting( OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists );
config.controller().setLastIteration( 1 );

Scenario scenario = ScenarioUtils.loadScenario( config );

Expand Down
35 changes: 17 additions & 18 deletions src/main/java/example/lsp/initialPlans/ExampleTwoEchelonGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.freight.FreightConfigGroup;
import org.matsim.contrib.freight.carrier.*;
import org.matsim.contrib.freight.controler.CarrierScoringFunctionFactory;
import org.matsim.contrib.freight.controler.CarrierStrategyManager;
import org.matsim.contrib.freight.controler.FreightUtils;
import org.matsim.core.config.CommandLine;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
Expand All @@ -51,6 +46,10 @@
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.examples.ExamplesUtils;
import org.matsim.freight.carriers.*;
import org.matsim.freight.carriers.controler.CarrierControlerUtils;
import org.matsim.freight.carriers.controler.CarrierScoringFunctionFactory;
import org.matsim.freight.carriers.controler.CarrierStrategyManager;
import org.matsim.vehicles.VehicleType;

import java.util.*;
Expand Down Expand Up @@ -134,7 +133,7 @@ public void install() {

bind( CarrierScoringFunctionFactory.class ).toInstance(carrierScorer);
bind( CarrierStrategyManager.class ).toProvider(() -> {
CarrierStrategyManager strategyManager = FreightUtils.createDefaultCarrierStrategyManager();
CarrierStrategyManager strategyManager = CarrierControlerUtils.createDefaultCarrierStrategyManager();
strategyManager.addStrategy(new GenericPlanStrategyImpl<>(new BestPlanSelector<>()), null, 1);
return strategyManager;
});
Expand Down Expand Up @@ -175,16 +174,16 @@ private static Config prepareConfig(String[] args) {

CommandLine cmd = ConfigUtils.getCommandLine(args);
} else {
config.controler().setOutputDirectory("output/2echelon_"+demandSetting + "_" + costSetting + "_" + HUBCOSTS_FIX+ "_" + TOLL_VALUE);
config.controler().setLastIteration(2);
config.controller().setOutputDirectory("output/2echelon_"+demandSetting + "_" + costSetting + "_" + HUBCOSTS_FIX+ "_" + TOLL_VALUE);
config.controller().setLastIteration(2);
}

config.network().setInputFile(String.valueOf(IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("freight-chessboard-9x9"), "grid9x9.xml")));
config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);
config.controler().setWriteEventsInterval(1);
config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);
config.controller().setWriteEventsInterval(1);

FreightConfigGroup freightConfig = ConfigUtils.addOrGetModule(config, FreightConfigGroup.class);
freightConfig.setTimeWindowHandling(FreightConfigGroup.TimeWindowHandling.ignore);
FreightCarriersConfigGroup freightConfig = ConfigUtils.addOrGetModule(config, FreightCarriersConfigGroup.class);
freightConfig.setTimeWindowHandling(FreightCarriersConfigGroup.TimeWindowHandling.ignore);

return config;
}
Expand Down Expand Up @@ -212,10 +211,10 @@ private static LSP createLSP(Scenario scenario) {
{
log.info("Create lspPlan for direct delivery");

Carrier directCarrier = CarrierUtils.createCarrier(Id.create("directCarrier", Carrier.class));
Carrier directCarrier = CarriersUtils.createCarrier(Id.create("directCarrier", Carrier.class));
directCarrier.getCarrierCapabilities().setFleetSize(CarrierCapabilities.FleetSize.INFINITE);

CarrierUtils.addCarrierVehicle(directCarrier, CarrierVehicle.newInstance(Id.createVehicleId("directTruck"), DEPOT_LINK_ID, VEH_TYPE_LARGE_50));
CarriersUtils.addCarrierVehicle(directCarrier, CarrierVehicle.newInstance(Id.createVehicleId("directTruck"), DEPOT_LINK_ID, VEH_TYPE_LARGE_50));
LSPResource directCarrierRessource = DistributionCarrierUtils.DistributionCarrierResourceBuilder.newInstance(directCarrier, network)
.setDistributionScheduler(DistributionCarrierUtils.createDefaultDistributionCarrierScheduler())
.build();
Expand All @@ -239,10 +238,10 @@ private static LSP createLSP(Scenario scenario) {
{
log.info("Create lspPlan with Hub");

Carrier mainCarrier = CarrierUtils.createCarrier(Id.create("mainCarrier", Carrier.class));
Carrier mainCarrier = CarriersUtils.createCarrier(Id.create("mainCarrier", Carrier.class));
mainCarrier.getCarrierCapabilities().setFleetSize(CarrierCapabilities.FleetSize.INFINITE);

CarrierUtils.addCarrierVehicle(mainCarrier, CarrierVehicle.newInstance(Id.createVehicleId("mainTruck"), DEPOT_LINK_ID, VEH_TYPE_LARGE_50));
CarriersUtils.addCarrierVehicle(mainCarrier, CarrierVehicle.newInstance(Id.createVehicleId("mainTruck"), DEPOT_LINK_ID, VEH_TYPE_LARGE_50));
LSPResource mainCarrierRessource = MainRunCarrierUtils.MainRunCarrierResourceBuilder.newInstance(mainCarrier, network)
.setFromLinkId(DEPOT_LINK_ID)
.setMainRunCarrierScheduler(MainRunCarrierUtils.createDefaultMainRunCarrierScheduler())
Expand Down Expand Up @@ -270,7 +269,7 @@ private static LSP createLSP(Scenario scenario) {
.setResource(hubResource)
.build(); //Nicht unbedingt nötig, aber nehme den alten Hub nun als Depot. Waren werden dann dort "Zusammengestellt".

Carrier distributionCarrier = CarrierUtils.createCarrier(Id.create("distributionCarrier", Carrier.class));
Carrier distributionCarrier = CarriersUtils.createCarrier(Id.create("distributionCarrier", Carrier.class));
distributionCarrier.getCarrierCapabilities().setFleetSize(CarrierCapabilities.FleetSize.INFINITE);

final VehicleType vehType;
Expand All @@ -279,7 +278,7 @@ private static LSP createLSP(Scenario scenario) {
case lowerCost4LastMile -> vehType = VEH_TYPE_SMALL_05;
default -> throw new IllegalStateException("Unexpected value: " + costSetting);
}
CarrierUtils.addCarrierVehicle(distributionCarrier, CarrierVehicle.newInstance(Id.createVehicleId("distributionTruck"), HUB_LINK_ID, vehType));
CarriersUtils.addCarrierVehicle(distributionCarrier, CarrierVehicle.newInstance(Id.createVehicleId("distributionTruck"), HUB_LINK_ID, vehType));
LSPResource distributionCarrierRessource = DistributionCarrierUtils.DistributionCarrierResourceBuilder.newInstance(distributionCarrier, network)
.setDistributionScheduler(DistributionCarrierUtils.createDefaultDistributionCarrierScheduler())
.build();
Expand Down
Loading

0 comments on commit 557cf7c

Please sign in to comment.