From 6fb3020f6df78d01c4583681bd8646e075410668 Mon Sep 17 00:00:00 2001 From: xinxin-git <82400603+xinxin-git@users.noreply.github.com> Date: Tue, 17 Oct 2023 15:53:44 +0200 Subject: [PATCH 1/2] update matsim to most recent version, adapted API --- pom.xml | 6 ++--- .../PotentialServiceAreaAnalysis.java | 25 +++++++++---------- ...rPollutionAnalysisByEngineInformation.java | 4 +-- .../drt/DrtServiceQualityAnalysis.java | 6 ++--- .../org/matsim/run/KelheimPtFareModule.java | 4 +-- .../matsim/run/RunKelheimRealDrtDemands.java | 12 ++++----- .../org/matsim/run/RunKelheimScenario.java | 10 ++++---- .../matsim/run/prepare/DrtStopsWriter.java | 3 +-- .../matsim/run/RunKelheimIntegrationTest.java | 8 +++--- 9 files changed, 38 insertions(+), 40 deletions(-) diff --git a/pom.xml b/pom.xml index 132d2965..94f2729f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ matsim-all - 16.0-PR2750 + 16.0-PR2878 @@ -181,13 +181,13 @@ one.util streamex - 0.8.1 + 0.8.2 commons-io commons-io - 2.11.0 + 2.13.0 diff --git a/src/main/java/org/matsim/analysis/PotentialServiceAreaAnalysis.java b/src/main/java/org/matsim/analysis/PotentialServiceAreaAnalysis.java index 97556667..0e33859d 100644 --- a/src/main/java/org/matsim/analysis/PotentialServiceAreaAnalysis.java +++ b/src/main/java/org/matsim/analysis/PotentialServiceAreaAnalysis.java @@ -35,15 +35,13 @@ import org.matsim.api.core.v01.network.Network; import org.matsim.api.core.v01.network.Node; import org.matsim.api.core.v01.population.Person; -import org.matsim.contrib.freight.carrier.*; -import org.matsim.contrib.freight.controler.FreightUtils; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.OutputDirectoryHierarchy; import org.matsim.core.network.NetworkUtils; import org.matsim.core.network.algorithms.TransportModeNetworkFilter; import org.matsim.core.population.routes.NetworkRoute; -import org.matsim.core.router.FastAStarLandmarksFactory; +import org.matsim.core.router.speedy.SpeedyALTFactory; import org.matsim.core.router.util.LeastCostPathCalculator; import org.matsim.core.router.util.TravelDisutility; import org.matsim.core.scenario.ScenarioUtils; @@ -54,6 +52,7 @@ import org.matsim.core.utils.geometry.transformations.TransformationFactory; import org.matsim.core.utils.gis.ShapeFileReader; import org.matsim.core.utils.io.IOUtils; +import org.matsim.freight.carriers.*; import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleType; import org.matsim.vehicles.VehicleUtils; @@ -130,7 +129,7 @@ public static void main(String[] args) { private static void writeStats(Network network, Map serviceAreas, Map> area2Stops, Carriers carriers, Map, Id>, Integer> relations) { String outputFileName = INPUT_SERVICE_AREAS_SHAPE.substring(0, INPUT_SERVICE_AREAS_SHAPE.lastIndexOf(".")) + "_stats.csv"; - LeastCostPathCalculator router = new FastAStarLandmarksFactory(4).createPathCalculator(network, new TravelDisutility() { + LeastCostPathCalculator router = new SpeedyALTFactory().createPathCalculator(network, new TravelDisutility() { @Override public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) { return link.getLength(); @@ -211,23 +210,23 @@ private static double getLongestRouteDistanceBetweenStops(Collection stops @SuppressWarnings("IllegalCatch") private static Carriers getCarriersWithPlannedRoundTours(Network network, Map serviceAreas, Map> area2Stops) { Config config = ConfigUtils.createConfig(); - config.controler().setLastIteration(0); + config.controller().setLastIteration(0); config.network().setInputFile(INPUT_NETWORK); - config.controler().setOutputDirectory("D:/KelRide-test/testServiceAreaTours/"); - config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles); + config.controller().setOutputDirectory("D:/KelRide-test/testServiceAreaTours/"); + config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles); Scenario scenario = ScenarioUtils.loadScenario(config); //container - Carriers carriers = FreightUtils.addOrGetCarriers(scenario); + Carriers carriers = CarriersUtils.addOrGetCarriers(scenario); VehicleType type = createVehicleType(); - FreightUtils.getCarrierVehicleTypes(scenario).getVehicleTypes().put(type.getId(), type); + CarriersUtils.getCarrierVehicleTypes(scenario).getVehicleTypes().put(type.getId(), type); //iterate over service areas and create carrier serviceAreas.forEach((areaName, geom) -> carriers.addCarrier(buildCarrier(areaName, area2Stops.get(geom), network, type))); try { - FreightUtils.runJsprit(scenario); + CarriersUtils.runJsprit(scenario); } catch (Exception e) { log.error(e); } @@ -281,9 +280,9 @@ private static boolean isLinkInsideGeom(Link l, PreparedGeometry geom) { private static Carrier buildCarrier(String areaName, Collection stops, Network network, VehicleType vehicleType) { //carrier - Carrier carrier = CarrierUtils.createCarrier(Id.create(areaName, Carrier.class)); - CarrierUtils.setCarrierMode(carrier, TransportMode.car); - CarrierUtils.setJspritIterations(carrier, 10000); + Carrier carrier = CarriersUtils.createCarrier(Id.create(areaName, Carrier.class)); + CarriersUtils.setCarrierMode(carrier, TransportMode.car); + CarriersUtils.setJspritIterations(carrier, 10000); //we will specify one vehicle and only want one tour carrier.getCarrierCapabilities().setFleetSize(CarrierCapabilities.FleetSize.FINITE); carrier.getCarrierCapabilities().getVehicleTypes().add(vehicleType); diff --git a/src/main/java/org/matsim/analysis/emissions/KelheimOfflineAirPollutionAnalysisByEngineInformation.java b/src/main/java/org/matsim/analysis/emissions/KelheimOfflineAirPollutionAnalysisByEngineInformation.java index 2ecf06a6..ee32cc66 100644 --- a/src/main/java/org/matsim/analysis/emissions/KelheimOfflineAirPollutionAnalysisByEngineInformation.java +++ b/src/main/java/org/matsim/analysis/emissions/KelheimOfflineAirPollutionAnalysisByEngineInformation.java @@ -173,8 +173,8 @@ private Config prepareConfig() { config.transit().setVehiclesFile( runDirectory + runId + ".output_transitVehicles.xml.gz"); config.global().setCoordinateSystem("EPSG:25832"); config.plans().setInputFile(null); - config.parallelEventHandling().setNumberOfThreads(null); - config.parallelEventHandling().setEstimatedNumberOfEvents(null); + config.eventsManager().setNumberOfThreads(null); + config.eventsManager().setEstimatedNumberOfEvents(null); config.global().setNumberOfThreads(1); EmissionsConfigGroup eConfig = ConfigUtils.addOrGetModule(config, EmissionsConfigGroup.class); diff --git a/src/main/java/org/matsim/analysis/postAnalysis/drt/DrtServiceQualityAnalysis.java b/src/main/java/org/matsim/analysis/postAnalysis/drt/DrtServiceQualityAnalysis.java index db49ee7f..061685ea 100644 --- a/src/main/java/org/matsim/analysis/postAnalysis/drt/DrtServiceQualityAnalysis.java +++ b/src/main/java/org/matsim/analysis/postAnalysis/drt/DrtServiceQualityAnalysis.java @@ -80,8 +80,8 @@ public Integer call() throws Exception { } Config config = ConfigUtils.loadConfig(configPath.toString(), new MultiModeDrtConfigGroup(DrtWithExtensionsConfigGroup::new)); - int lastIteration = config.controler().getLastIteration(); - String runId = config.controler().getRunId(); + int lastIteration = config.controller().getLastIteration(); + String runId = config.controller().getRunId(); Path folderOfLastIteration = Path.of(directory.toString() + "/ITERS/it." + lastIteration); MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class); List modes = new ArrayList<>(); @@ -99,7 +99,7 @@ public Integer call() throws Exception { network = NetworkUtils.readNetwork(networkPath.toString()); travelTime = TrafficAnalysis.analyzeTravelTimeFromEvents(network, eventPath.toString()); - config.plansCalcRoute().setRoutingRandomness(0); + config.routing().setRoutingRandomness(0); TravelDisutility travelDisutility = new RandomizingTimeDistanceTravelDisutilityFactory(TransportMode.car, config) .createTravelDisutility(travelTime); router = new SpeedyALTFactory(). diff --git a/src/main/java/org/matsim/run/KelheimPtFareModule.java b/src/main/java/org/matsim/run/KelheimPtFareModule.java index be9a2e2e..2f823747 100644 --- a/src/main/java/org/matsim/run/KelheimPtFareModule.java +++ b/src/main/java/org/matsim/run/KelheimPtFareModule.java @@ -15,8 +15,8 @@ public class KelheimPtFareModule extends AbstractModule { @Override public void install() { // Set the money related thing in the config (planCalcScore) file to 0. - getConfig().planCalcScore().getModes().get(TransportMode.pt).setDailyMonetaryConstant(0); - getConfig().planCalcScore().getModes().get(TransportMode.pt).setMarginalUtilityOfDistance(0); + getConfig().scoring().getModes().get(TransportMode.pt).setDailyMonetaryConstant(0); + getConfig().scoring().getModes().get(TransportMode.pt).setMarginalUtilityOfDistance(0); // Initialize config group (and also write in the output config) PtFareConfigGroup ptFareConfigGroup = ConfigUtils.addOrGetModule(this.getConfig(), PtFareConfigGroup.class); diff --git a/src/main/java/org/matsim/run/RunKelheimRealDrtDemands.java b/src/main/java/org/matsim/run/RunKelheimRealDrtDemands.java index d0609db0..74b805d4 100644 --- a/src/main/java/org/matsim/run/RunKelheimRealDrtDemands.java +++ b/src/main/java/org/matsim/run/RunKelheimRealDrtDemands.java @@ -14,7 +14,7 @@ import org.matsim.contrib.dvrp.run.DvrpQSimComponents; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; -import org.matsim.core.config.groups.PlansCalcRouteConfigGroup; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.VspExperimentalConfigGroup; import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy; @@ -59,17 +59,17 @@ public Integer call() throws Exception { config.plans().setInputFile("./real-drt-demands/" + date + "-drt.plans.xml"); log.info("Setting input plans file to: " + config.plans().getInputFile()); - String outputDirectory = Path.of(config.controler().getOutputDirectory()).getParent().toString() + "/" + date; - config.controler().setOutputDirectory(outputDirectory); - log.info("Setting output directory to: " + config.controler().getOutputDirectory()); + String outputDirectory = Path.of(config.controller().getOutputDirectory()).getParent().toString() + "/" + date; + config.controller().setOutputDirectory(outputDirectory); + log.info("Setting output directory to: " + config.controller().getOutputDirectory()); config.vspExperimental().setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.info); - config.plansCalcRoute().setAccessEgressType(PlansCalcRouteConfigGroup.AccessEgressType.accessEgressModeToLink); + config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.accessEgressModeToLink); if (!networkChangeEventsFile.equals("")) { config.network().setTimeVariantNetwork(true); config.network().setChangeEventsInputFile(networkChangeEventsFile); } - config.controler() + config.controller() .setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles); Scenario scenario = DrtControlerCreator.createScenarioWithDrtRouteFactory(config); diff --git a/src/main/java/org/matsim/run/RunKelheimScenario.java b/src/main/java/org/matsim/run/RunKelheimScenario.java index b4995552..6523be91 100644 --- a/src/main/java/org/matsim/run/RunKelheimScenario.java +++ b/src/main/java/org/matsim/run/RunKelheimScenario.java @@ -44,7 +44,7 @@ import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; -import org.matsim.core.config.groups.PlansCalcRouteConfigGroup; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.VspExperimentalConfigGroup; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; @@ -146,15 +146,15 @@ protected Config prepareConfig(Config config) { SnzActivities.addScoringParams(config); - config.controler().setOutputDirectory(sample.adjustName(config.controler().getOutputDirectory())); + config.controller().setOutputDirectory(sample.adjustName(config.controller().getOutputDirectory())); config.plans().setInputFile(sample.adjustName(config.plans().getInputFile())); - config.controler().setRunId(sample.adjustName(config.controler().getRunId())); + config.controller().setRunId(sample.adjustName(config.controller().getRunId())); config.qsim().setFlowCapFactor(sample.getSize() / 100.0); config.qsim().setStorageCapFactor(sample.getSize() / 100.0); config.vspExperimental().setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.abort); - config.plansCalcRoute().setAccessEgressType(PlansCalcRouteConfigGroup.AccessEgressType.accessEgressModeToLink); + config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.accessEgressModeToLink); config.global().setRandomSeed(randomSeed); @@ -184,7 +184,7 @@ protected Config prepareConfig(Config config) { } ConfigUtils.addOrGetModule(config, DvrpConfigGroup.class); - DrtConfigs.adjustMultiModeDrtConfig(multiModeDrtConfig, config.planCalcScore(), config.plansCalcRoute()); + DrtConfigs.adjustMultiModeDrtConfig(multiModeDrtConfig, config.scoring(), config.routing()); } // Config is always needed diff --git a/src/main/java/org/matsim/run/prepare/DrtStopsWriter.java b/src/main/java/org/matsim/run/prepare/DrtStopsWriter.java index 6b59ba95..71ac293d 100644 --- a/src/main/java/org/matsim/run/prepare/DrtStopsWriter.java +++ b/src/main/java/org/matsim/run/prepare/DrtStopsWriter.java @@ -17,7 +17,6 @@ import org.matsim.core.utils.geometry.geotools.MGC; import org.matsim.core.utils.io.IOUtils; import org.matsim.core.utils.io.MatsimXmlWriter; -import org.matsim.core.utils.io.UncheckedIOException; import org.matsim.run.RunKelheimScenario; import org.opengis.feature.simple.SimpleFeature; @@ -65,7 +64,7 @@ public final class DrtStopsWriter extends MatsimXmlWriter { /** * Write content to specified folder. */ - public void write() throws UncheckedIOException, IOException { + public void write() throws IOException { this.openFile(outputFolder + "/" + mode + "-stops.xml"); this.writeXmlHead(); this.writeDoctype("transitSchedule", "http://www.matsim.org/files/dtd/transitSchedule_v1.dtd"); diff --git a/src/test/java/org/matsim/run/RunKelheimIntegrationTest.java b/src/test/java/org/matsim/run/RunKelheimIntegrationTest.java index 872f32e4..60bee285 100644 --- a/src/test/java/org/matsim/run/RunKelheimIntegrationTest.java +++ b/src/test/java/org/matsim/run/RunKelheimIntegrationTest.java @@ -16,10 +16,10 @@ public class RunKelheimIntegrationTest { @Test public final void runExamplePopulationTest() { Config config = ConfigUtils.loadConfig("input/test.config.xml"); - config.controler().setLastIteration(1); + config.controller().setLastIteration(1); config.global().setNumberOfThreads(1); config.qsim().setNumberOfThreads(1); - config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); + config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled; @@ -30,8 +30,8 @@ public final void runExamplePopulationTest() { @Test public final void runDrtExamplePopulationTest() { Config config = ConfigUtils.loadConfig("input/test.with-drt.config.xml"); - config.controler().setLastIteration(1); - config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); + config.controller().setLastIteration(1); + config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled; From 66c5d4e6d0ced506728361f6475320e9b42ab4e9 Mon Sep 17 00:00:00 2001 From: xinxin-git <82400603+xinxin-git@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:58:41 +0200 Subject: [PATCH 2/2] update config for 3.1 --- Makefile | 2 +- input/test.config.xml | 12 +- input/test.with-drt.config.xml | 12 +- input/v3.1/kelheim-v3.1-25pct.kexi.config.xml | 343 ++++++++++++++++++ input/v3.1/kelheim-v3.1-config.xml | 234 ++++++++++++ .../org/matsim/run/RunKelheimScenario.java | 2 +- 6 files changed, 591 insertions(+), 14 deletions(-) create mode 100644 input/v3.1/kelheim-v3.1-25pct.kexi.config.xml create mode 100644 input/v3.1/kelheim-v3.1-config.xml diff --git a/Makefile b/Makefile index b74fa5fc..7887d84e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -V := v3.0 +V := v3.1 CRS := EPSG:25832 MEMORY ?= 20G diff --git a/input/test.config.xml b/input/test.config.xml index a9f7e502..4d4855c6 100644 --- a/input/test.config.xml +++ b/input/test.config.xml @@ -1,11 +1,11 @@ - + - + @@ -43,7 +43,7 @@ - + @@ -73,7 +73,7 @@ - + @@ -87,7 +87,7 @@ - + @@ -157,7 +157,7 @@ - + diff --git a/input/test.with-drt.config.xml b/input/test.with-drt.config.xml index d32dc581..20e47754 100644 --- a/input/test.with-drt.config.xml +++ b/input/test.with-drt.config.xml @@ -1,11 +1,11 @@ - + - + @@ -42,7 +42,7 @@ - + @@ -72,7 +72,7 @@ - + @@ -86,7 +86,7 @@ - + @@ -156,7 +156,7 @@ - + diff --git a/input/v3.1/kelheim-v3.1-25pct.kexi.config.xml b/input/v3.1/kelheim-v3.1-25pct.kexi.config.xml new file mode 100644 index 00000000..c2ea1d77 --- /dev/null +++ b/input/v3.1/kelheim-v3.1-25pct.kexi.config.xml @@ -0,0 +1,343 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/input/v3.1/kelheim-v3.1-config.xml b/input/v3.1/kelheim-v3.1-config.xml new file mode 100644 index 00000000..14b50330 --- /dev/null +++ b/input/v3.1/kelheim-v3.1-config.xml @@ -0,0 +1,234 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/org/matsim/run/RunKelheimScenario.java b/src/main/java/org/matsim/run/RunKelheimScenario.java index 6523be91..6a8d4dcd 100644 --- a/src/main/java/org/matsim/run/RunKelheimScenario.java +++ b/src/main/java/org/matsim/run/RunKelheimScenario.java @@ -78,7 +78,7 @@ }) public class RunKelheimScenario extends MATSimApplication { - public static final String VERSION = "3.0"; + public static final String VERSION = "3.1"; private static final double WEIGHT_1_PASSENGER = 16517.; private static final double WEIGHT_2_PASSENGER = 2084.; private static final double WEIGHT_3_PASSENGER = 532.;