From 79337361ba72bd1c4ead4c5749c547528d4e0b0d Mon Sep 17 00:00:00 2001 From: Paul Heinrich Date: Thu, 2 May 2024 16:14:17 +0200 Subject: [PATCH 1/9] switch to matsim 2025 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 90544046..7061986d 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ Therefore we need to use a fixed value here and then refer to the matsim version with ${project.parent.version} --> - 16.0-2024w15 + 2025.0-PR3238 @@ -24,7 +24,7 @@ ${project.parent.version} - 17 + 21 UTF-8 UTF-8 From 40a6edb04f521fc39056f65a56addda4f7fd99b7 Mon Sep 17 00:00:00 2001 From: Paul Heinrich Date: Thu, 2 May 2024 16:16:53 +0200 Subject: [PATCH 2/9] switch to java 21 --- .github/workflows/mvn-verify.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mvn-verify.yml b/.github/workflows/mvn-verify.yml index 68f41eec..7f290d61 100644 --- a/.github/workflows/mvn-verify.yml +++ b/.github/workflows/mvn-verify.yml @@ -20,7 +20,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3 with: - java-version: 17 + java-version: 21 distribution: 'temurin' cache: maven - name: Build with Maven From 2cb32eb12c4db749119531984a7ca3a652e46761 Mon Sep 17 00:00:00 2001 From: Paul Heinrich Date: Thu, 2 May 2024 16:27:50 +0200 Subject: [PATCH 3/9] fix error --- .../mobsim/ownMobsimAgent/RunAddAgentSourceExample.java | 2 +- .../RunOwnMobsimAgentUsingRouterExample.java | 2 +- .../RunOwnMobsimAgentWithPerceptionExample.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/matsim/codeexamples/mobsim/ownMobsimAgent/RunAddAgentSourceExample.java b/src/main/java/org/matsim/codeexamples/mobsim/ownMobsimAgent/RunAddAgentSourceExample.java index f3fe04be..019b8e6a 100644 --- a/src/main/java/org/matsim/codeexamples/mobsim/ownMobsimAgent/RunAddAgentSourceExample.java +++ b/src/main/java/org/matsim/codeexamples/mobsim/ownMobsimAgent/RunAddAgentSourceExample.java @@ -78,7 +78,7 @@ public void insertAgentsIntoMobsim(){ qsim.insertAgentIntoMobsim( ag ); // insert vehicle: - final Vehicle vehicle = VehicleUtils.getFactory().createVehicle( Id.create( ag.getId(), Vehicle.class ), VehicleUtils.getDefaultVehicleType() ); + final Vehicle vehicle = VehicleUtils.getFactory().createVehicle( Id.create( ag.getId(), Vehicle.class ), VehicleUtils.createDefaultVehicleType() ); QVehicleImpl qVeh = new QVehicleImpl( vehicle ); qsim.addParkedVehicle( qVeh, ag.getCurrentLinkId() ); diff --git a/src/main/java/org/matsim/codeexamples/mobsim/ownMobsimAgentUsingRouter/RunOwnMobsimAgentUsingRouterExample.java b/src/main/java/org/matsim/codeexamples/mobsim/ownMobsimAgentUsingRouter/RunOwnMobsimAgentUsingRouterExample.java index 36187c22..2c7e5563 100644 --- a/src/main/java/org/matsim/codeexamples/mobsim/ownMobsimAgentUsingRouter/RunOwnMobsimAgentUsingRouterExample.java +++ b/src/main/java/org/matsim/codeexamples/mobsim/ownMobsimAgentUsingRouter/RunOwnMobsimAgentUsingRouterExample.java @@ -79,7 +79,7 @@ public void insertAgentsIntoMobsim() { qsim.insertAgentIntoMobsim(ag); // insert vehicle: - final Vehicle vehicle = VehicleUtils.getFactory().createVehicle(Id.create(ag.getId(), Vehicle.class), VehicleUtils.getDefaultVehicleType()); + final Vehicle vehicle = VehicleUtils.getFactory().createVehicle(Id.create(ag.getId(), Vehicle.class), VehicleUtils.createDefaultVehicleType()); final Id linkId4VehicleInsertion = Id.createLinkId(1); // qsim.createAndParkVehicleOnLink(vehicle, linkId4VehicleInsertion); final QVehicle qVeh = new QVehicleImpl( vehicle ) ; diff --git a/src/main/java/org/matsim/codeexamples/mobsim/ownMobsimAgentWithPerception/RunOwnMobsimAgentWithPerceptionExample.java b/src/main/java/org/matsim/codeexamples/mobsim/ownMobsimAgentWithPerception/RunOwnMobsimAgentWithPerceptionExample.java index 0d8c2da4..fa9bbdd4 100644 --- a/src/main/java/org/matsim/codeexamples/mobsim/ownMobsimAgentWithPerception/RunOwnMobsimAgentWithPerceptionExample.java +++ b/src/main/java/org/matsim/codeexamples/mobsim/ownMobsimAgentWithPerception/RunOwnMobsimAgentWithPerceptionExample.java @@ -103,7 +103,7 @@ public void insertAgentsIntoMobsim() { // insert vehicle: final Id vehId = Id.create("myVeh", Vehicle.class); - final VehicleType vehType = VehicleUtils.getDefaultVehicleType(); + final VehicleType vehType = VehicleUtils.createDefaultVehicleType(); final VehiclesFactory vehFactory = VehicleUtils.getFactory(); final Vehicle vehicle = vehFactory.createVehicle(vehId, vehType); // qsim.createAndParkVehicleOnLink(vehicle, startingLinkId); From d2a13722dc11b80db7c8cd3e1d34f476cecdae2a Mon Sep 17 00:00:00 2001 From: Paul Heinrich Date: Mon, 6 May 2024 12:58:17 +0200 Subject: [PATCH 4/9] update to latest matsim PR --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7061986d..ff434596 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ Therefore we need to use a fixed value here and then refer to the matsim version with ${project.parent.version} --> - 2025.0-PR3238 + 2025.0-PR3235 From a41172c7b6aafd1cba265ba5fdb2e6401bfb760b Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Fri, 17 May 2024 12:44:28 +0200 Subject: [PATCH 5/9] Add jogamp repo for gluegen dependency --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index ff434596..469e30f0 100644 --- a/pom.xml +++ b/pom.xml @@ -50,6 +50,11 @@ jzy3d https://maven.jzy3d.org/releases/ + + + jogamp + https://jogamp.org/deployment/maven + From ef25586fe45b81bbfcf022281e81d8827663b1ba Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Fri, 17 May 2024 13:06:01 +0200 Subject: [PATCH 6/9] update latest matsim geotools update drt optimization constraints dvrp travel time zones --- pom.xml | 2 +- .../extensions/drt/RunMelunPrebooking.java | 17 ++++---- .../extensions/dvrp/RunDrtExample.java | 42 ++++++++----------- .../network/RunCreateNetworkSHP.java | 7 ++-- .../CreateDemand.java | 7 ++-- .../demand/CreateDemand.java | 5 ++- 6 files changed, 39 insertions(+), 41 deletions(-) diff --git a/pom.xml b/pom.xml index ff434596..bf77d693 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ Therefore we need to use a fixed value here and then refer to the matsim version with ${project.parent.version} --> - 2025.0-PR3235 + 2025.0-PR3272 diff --git a/src/main/java/org/matsim/codeexamples/extensions/drt/RunMelunPrebooking.java b/src/main/java/org/matsim/codeexamples/extensions/drt/RunMelunPrebooking.java index 2cdeb01c..7be7dbe6 100644 --- a/src/main/java/org/matsim/codeexamples/extensions/drt/RunMelunPrebooking.java +++ b/src/main/java/org/matsim/codeexamples/extensions/drt/RunMelunPrebooking.java @@ -14,6 +14,7 @@ import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.population.Person; +import org.matsim.contrib.common.zones.systems.grid.square.SquareGridZoneSystemParams; import org.matsim.contrib.drt.extension.insertion.DrtInsertionModule; import org.matsim.contrib.drt.optimizer.insertion.DrtInsertionSearchParams; import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams; @@ -21,11 +22,8 @@ import org.matsim.contrib.drt.prebooking.logic.ProbabilityBasedPrebookingLogic; import org.matsim.contrib.drt.routing.DrtRoute; import org.matsim.contrib.drt.routing.DrtRouteFactory; -import org.matsim.contrib.drt.run.DrtConfigGroup; +import org.matsim.contrib.drt.run.*; import org.matsim.contrib.drt.run.DrtConfigGroup.OperationalScheme; -import org.matsim.contrib.drt.run.DrtConfigs; -import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; -import org.matsim.contrib.drt.run.MultiModeDrtModule; import org.matsim.contrib.dvrp.fleet.DvrpVehicle; import org.matsim.contrib.dvrp.fleet.FleetSpecification; import org.matsim.contrib.dvrp.fleet.FleetSpecificationImpl; @@ -81,7 +79,9 @@ public static class RunSettings { public static void runSingle(File populationPath, File networkPath, File outputPath, RunSettings settings) { // configuration - Config config = ConfigUtils.createConfig(new MultiModeDrtConfigGroup(), new DvrpConfigGroup()); + DvrpConfigGroup dvrpConfigGroup = new DvrpConfigGroup(); + dvrpConfigGroup.getTravelTimeMatrixParams().addParameterSet(new SquareGridZoneSystemParams()); + Config config = ConfigUtils.createConfig(new MultiModeDrtConfigGroup(), dvrpConfigGroup); config.qsim().setSimStarttimeInterpretation(StarttimeInterpretation.onlyUseStarttime); config.qsim().setStartTime(0.0); @@ -117,9 +117,10 @@ public static void runSingle(File populationPath, File networkPath, File outputP drtConfig.mode = "drt"; drtConfig.operationalScheme = OperationalScheme.door2door; drtConfig.stopDuration = 60.0; - drtConfig.maxWaitTime = settings.maxWaitTime; - drtConfig.maxTravelTimeAlpha = settings.maxTravelTimeAlpha; - drtConfig.maxTravelTimeBeta = settings.maxWaitTime; + DrtOptimizationConstraintsParams constraintsParam = drtConfig.getDrtOptimizationConstraintsParam(); + constraintsParam.maxWaitTime = settings.maxWaitTime; + constraintsParam.maxTravelTimeAlpha = settings.maxTravelTimeAlpha; + constraintsParam.maxTravelTimeBeta = settings.maxWaitTime; DrtInsertionSearchParams insertionSearchParams = new ExtensiveInsertionSearchParams(); drtConfig.addDrtInsertionSearchParams(insertionSearchParams); diff --git a/src/main/java/org/matsim/codeexamples/extensions/dvrp/RunDrtExample.java b/src/main/java/org/matsim/codeexamples/extensions/dvrp/RunDrtExample.java index 37607a7e..87c4272b 100644 --- a/src/main/java/org/matsim/codeexamples/extensions/dvrp/RunDrtExample.java +++ b/src/main/java/org/matsim/codeexamples/extensions/dvrp/RunDrtExample.java @@ -1,37 +1,29 @@ package org.matsim.codeexamples.extensions.dvrp; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.TransportMode; -import org.matsim.api.core.v01.events.Event; +import org.matsim.contrib.common.zones.systems.grid.square.SquareGridZoneSystemParams; import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams; import org.matsim.contrib.drt.routing.DrtRoute; import org.matsim.contrib.drt.routing.DrtRouteFactory; -import org.matsim.contrib.drt.run.DrtConfigGroup; -import org.matsim.contrib.drt.run.DrtConfigs; -import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; -import org.matsim.contrib.drt.run.MultiModeDrtModule; +import org.matsim.contrib.drt.run.*; import org.matsim.contrib.dvrp.run.DvrpConfigGroup; import org.matsim.contrib.dvrp.run.DvrpModule; import org.matsim.contrib.dvrp.run.DvrpQSimComponents; import org.matsim.contrib.otfvis.OTFVisLiveModule; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; -import org.matsim.core.config.groups.ScoringConfigGroup.ModeParams; import org.matsim.core.config.groups.QSimConfigGroup; import org.matsim.core.config.groups.QSimConfigGroup.SnapshotStyle; import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings; -import org.matsim.core.controler.AbstractModule; +import org.matsim.core.config.groups.ScoringConfigGroup.ModeParams; import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; -import org.matsim.core.events.handler.BasicEventHandler; -import org.matsim.core.events.handler.EventHandler; import org.matsim.core.replanning.strategies.DefaultPlanStrategiesModule.DefaultSelector; import org.matsim.core.replanning.strategies.DefaultPlanStrategiesModule.DefaultStrategy; import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.core.utils.io.IOUtils; -import org.matsim.examples.ExamplesUtils; import org.matsim.vis.otfvis.OTFVisConfigGroup; class RunDrtExample{ @@ -71,6 +63,7 @@ public static void run(boolean otfvis, String... args ){ @SuppressWarnings("unused") DvrpConfigGroup dvrpConfig = ConfigUtils.addOrGetModule( config, DvrpConfigGroup.class ); + dvrpConfig.getTravelTimeMatrixParams().addParameterSet(new SquareGridZoneSystemParams()); // (config group needs to be "materialized") MultiModeDrtConfigGroup multiModeDrtCfg = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class); @@ -78,10 +71,10 @@ public static void run(boolean otfvis, String... args ){ DrtConfigGroup drtConfig = new DrtConfigGroup(); drtConfig.mode = DRT_A; drtConfig.stopDuration = 60.; - drtConfig.maxWaitTime=900; - drtConfig.maxTravelTimeAlpha = 1.3; - drtConfig.maxTravelTimeBeta=10. * 60.; - drtConfig.rejectRequestIfMaxWaitOrTravelTimeViolated= false ; + drtConfig.getDrtOptimizationConstraintsParam().maxWaitTime=900; + drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; + drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeBeta=10. * 60.; + drtConfig.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated= false ; drtConfig.vehiclesFile="one_shared_taxi_vehicles_A.xml"; drtConfig.changeStartLinkToLastLinkInSchedule=true; drtConfig.addParameterSet( new ExtensiveInsertionSearchParams() ); @@ -91,10 +84,10 @@ public static void run(boolean otfvis, String... args ){ DrtConfigGroup drtConfig = new DrtConfigGroup(); drtConfig.mode = DRT_B; drtConfig.stopDuration = 60.; - drtConfig.maxWaitTime=900; - drtConfig.maxTravelTimeAlpha = 1.3; - drtConfig.maxTravelTimeBeta=10. * 60.; - drtConfig.rejectRequestIfMaxWaitOrTravelTimeViolated= false ; + drtConfig.getDrtOptimizationConstraintsParam().maxWaitTime=900; + drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3; + drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeBeta=10. * 60.; + drtConfig.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated= false ; drtConfig.vehiclesFile="one_shared_taxi_vehicles_B.xml"; drtConfig.changeStartLinkToLastLinkInSchedule=true; drtConfig.addParameterSet( new ExtensiveInsertionSearchParams() ); @@ -104,10 +97,11 @@ public static void run(boolean otfvis, String... args ){ DrtConfigGroup drtConfig = new DrtConfigGroup(); drtConfig.mode = DRT_C; drtConfig.stopDuration = 60.; - drtConfig.maxWaitTime=900; - drtConfig.maxTravelTimeAlpha = 1.3; - drtConfig.maxTravelTimeBeta=10. * 60.; - drtConfig.rejectRequestIfMaxWaitOrTravelTimeViolated= false ; + DrtOptimizationConstraintsParams constraintsParam = drtConfig.getDrtOptimizationConstraintsParam(); + constraintsParam.maxWaitTime=900; + constraintsParam.maxTravelTimeAlpha = 1.3; + constraintsParam.maxTravelTimeBeta=10. * 60.; + constraintsParam.rejectRequestIfMaxWaitOrTravelTimeViolated= false ; drtConfig.vehiclesFile="one_shared_taxi_vehicles_C.xml"; drtConfig.changeStartLinkToLastLinkInSchedule=true; drtConfig.addParameterSet( new ExtensiveInsertionSearchParams() ); diff --git a/src/main/java/org/matsim/codeexamples/network/RunCreateNetworkSHP.java b/src/main/java/org/matsim/codeexamples/network/RunCreateNetworkSHP.java index 2d1ae2df..67524fae 100644 --- a/src/main/java/org/matsim/codeexamples/network/RunCreateNetworkSHP.java +++ b/src/main/java/org/matsim/codeexamples/network/RunCreateNetworkSHP.java @@ -19,6 +19,8 @@ package org.matsim.codeexamples.network; +import org.geotools.api.feature.simple.SimpleFeature; +import org.geotools.api.referencing.crs.CoordinateReferenceSystem; import org.locationtech.jts.geom.Coordinate; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; @@ -29,11 +31,10 @@ import org.matsim.core.network.NetworkUtils; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.core.utils.geometry.geotools.MGC; +import org.matsim.core.utils.gis.GeoFileWriter; import org.matsim.core.utils.gis.PointFeatureFactory; import org.matsim.core.utils.gis.PolylineFeatureFactory; import org.matsim.core.utils.gis.ShapeFileWriter; -import org.opengis.feature.simple.SimpleFeature; -import org.opengis.referencing.crs.CoordinateReferenceSystem; import java.util.ArrayList; import java.util.Collection; @@ -70,7 +71,7 @@ public static void main(String[] args) { new Object[]{link.getId().toString(), link.getFromNode().getId().toString(), link.getToNode().getId().toString(), link.getLength(), NetworkUtils.getType(link), link.getCapacity(), link.getFreespeed()}, null); features.add(ft); } - ShapeFileWriter.writeGeometries(features, "output/network_links.shp"); + GeoFileWriter.writeGeometries(features, "output/network_links.shp"); features = new ArrayList<>(); PointFeatureFactory nodeFactory = new PointFeatureFactory.Builder(). diff --git a/src/main/java/org/matsim/codeexamples/population/demandGenerationFromShapefile/CreateDemand.java b/src/main/java/org/matsim/codeexamples/population/demandGenerationFromShapefile/CreateDemand.java index e4e42702..270b6dcc 100644 --- a/src/main/java/org/matsim/codeexamples/population/demandGenerationFromShapefile/CreateDemand.java +++ b/src/main/java/org/matsim/codeexamples/population/demandGenerationFromShapefile/CreateDemand.java @@ -7,6 +7,7 @@ import org.apache.commons.math3.util.Pair; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.geotools.api.feature.simple.SimpleFeature; import org.locationtech.jts.geom.*; import org.matsim.api.core.v01.Coord; import org.matsim.api.core.v01.Id; @@ -14,8 +15,8 @@ import org.matsim.api.core.v01.population.*; import org.matsim.core.config.ConfigUtils; import org.matsim.core.population.PopulationUtils; +import org.matsim.core.utils.gis.GeoFileReader; import org.matsim.core.utils.gis.ShapeFileReader; -import org.opengis.feature.simple.SimpleFeature; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -80,14 +81,14 @@ class CreateDemand { // read in the shape file and store the geometries according to their region identifier stored as 'RS' in the // shape file - regions = ShapeFileReader.getAllFeatures(sampleFolder.resolve("thueringen-kreise.shp").toString()).stream() + regions = GeoFileReader.getAllFeatures(sampleFolder.resolve("thueringen-kreise.shp").toString()).stream() .collect(Collectors.toMap(feature -> (String) feature.getAttribute("RS"), feature -> (Geometry) feature.getDefaultGeometry())); // Read in landcover data to make people stay in populated areas // we are using a weighted distribution by area-size, so that small areas receive less inhabitants than more // populated ones. List> weightedGeometries = new ArrayList<>(); - for (SimpleFeature feature : ShapeFileReader.getAllFeatures(sampleFolder.resolve("landcover.shp").toString())) { + for (SimpleFeature feature : GeoFileReader.getAllFeatures(sampleFolder.resolve("landcover.shp").toString())) { Geometry geometry = (Geometry) feature.getDefaultGeometry(); weightedGeometries.add(new Pair<>(geometry, geometry.getArea())); } diff --git a/src/main/java/org/matsim/codeexamples/programming/example21tutorialTUBclass/demand/CreateDemand.java b/src/main/java/org/matsim/codeexamples/programming/example21tutorialTUBclass/demand/CreateDemand.java index 103419f4..3d62ab85 100644 --- a/src/main/java/org/matsim/codeexamples/programming/example21tutorialTUBclass/demand/CreateDemand.java +++ b/src/main/java/org/matsim/codeexamples/programming/example21tutorialTUBclass/demand/CreateDemand.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.Random; +import org.geotools.api.feature.simple.SimpleFeature; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.GeometryFactory; import org.locationtech.jts.geom.Point; @@ -43,11 +44,11 @@ import org.matsim.core.utils.geometry.CoordinateTransformation; import org.matsim.core.utils.geometry.geotools.MGC; import org.matsim.core.utils.geometry.transformations.GeotoolsTransformation; +import org.matsim.core.utils.gis.GeoFileReader; import org.matsim.core.utils.gis.ShapeFileReader; import org.matsim.core.utils.io.tabularFileParser.TabularFileHandler; import org.matsim.core.utils.io.tabularFileParser.TabularFileParser; import org.matsim.core.utils.io.tabularFileParser.TabularFileParserConfig; -import org.opengis.feature.simple.SimpleFeature; /** * @author jbischoff @@ -161,7 +162,7 @@ public Map readShapeFile(String filename, String attrString){ Map shapeMap = new HashMap(); - for (SimpleFeature ft : ShapeFileReader.getAllFeatures(filename)) { + for (SimpleFeature ft : GeoFileReader.getAllFeatures(filename)) { GeometryFactory geometryFactory= new GeometryFactory(); WKTReader wktReader = new WKTReader(geometryFactory); From a7fed54ef85c890c63d48652eb0ed391695d4497 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 May 2024 22:49:40 +0000 Subject: [PATCH 7/9] --- updated-dependencies: - dependency-name: org.matsim:matsim-all dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim:matsim dependency-type: direct:development dependency-group: java-dependencies - dependency-name: org.matsim:matsim-examples dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:minibus dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:otfvis dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:roadpricing dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:taxi dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:av dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:freight dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:vsp dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:dvrp dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:drt dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:drt-extensions dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:bicycle dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:osm dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:emissions dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:discrete_mode_choice dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:locationchoice dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:application dependency-type: direct:production dependency-group: java-dependencies - dependency-name: org.matsim.contrib:decongestion dependency-type: direct:production dependency-group: java-dependencies ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0b0df5cf..6dee58cc 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ Therefore we need to use a fixed value here and then refer to the matsim version with ${project.parent.version} --> - 2025.0-PR3272 + 2025.0-2024w21 From d04e35bf04c14d1748ec241f93a7494d2ae8c6af Mon Sep 17 00:00:00 2001 From: Paul Heinrich Date: Thu, 27 Jun 2024 11:18:31 +0200 Subject: [PATCH 8/9] add vehicles source option to example --- .../integration/RunMultipleModesExample.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/org/matsim/codeexamples/integration/RunMultipleModesExample.java b/src/main/java/org/matsim/codeexamples/integration/RunMultipleModesExample.java index 363cbf7c..5851247f 100644 --- a/src/main/java/org/matsim/codeexamples/integration/RunMultipleModesExample.java +++ b/src/main/java/org/matsim/codeexamples/integration/RunMultipleModesExample.java @@ -2,21 +2,26 @@ import org.apache.logging.log4j.LogManager; 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.population.Person; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.QSimConfigGroup; import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy; import org.matsim.core.replanning.strategies.DefaultPlanStrategiesModule; import org.matsim.core.router.util.TravelTime; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.core.utils.io.IOUtils; import org.matsim.examples.ExamplesUtils; import org.matsim.vehicles.Vehicle; +import org.matsim.vehicles.VehicleType; +import org.matsim.vehicles.VehicleUtils; import java.net.URL; import java.util.Arrays; @@ -60,6 +65,16 @@ static Scenario prepareScenario( Config config ){ Set modes = new LinkedHashSet<>( Arrays.asList( TransportMode.car, TransportMode.bike )); link.setAllowedModes( modes ); } + + // add vehicle types for both modes (they are only used, if the vehicles source is set correspondingly) + scenario.getVehicles().addVehicleType( VehicleUtils.getFactory().createVehicleType(Id.create("car", VehicleType.class)) ); + + VehicleType bike = VehicleUtils.getFactory().createVehicleType(Id.create("bike", VehicleType.class)) + .setNetworkMode("bike") + .setMaximumVelocity(5.); + + scenario.getVehicles().addVehicleType(bike); + return scenario; } @@ -67,6 +82,10 @@ static Config prepareConfig(){ final URL url = IOUtils.extendUrl( ExamplesUtils.getTestScenarioURL( "equil" ), "config.xml" ); log.warn("url=" + url) ; Config config = ConfigUtils.loadConfig( url ); + config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); + + // in case you want the different modes to use different vehicle types, you need to set this + config.qsim().setVehiclesSource(QSimConfigGroup.VehiclesSource.modeVehicleTypesFromVehiclesData); { // add strategy that switches between car and bike: StrategySettings stratSets = new StrategySettings( ) ; From e3552ad0c124ed0bc7edc6132fe207bc8c2c1ab6 Mon Sep 17 00:00:00 2001 From: Kai Nagel Date: Thu, 27 Jun 2024 13:33:31 +0200 Subject: [PATCH 9/9] make bicycle example work; improve it --- .../bicycle/RunBicycleContribExample.java | 78 +++++++++++++------ 1 file changed, 54 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/matsim/codeexamples/extensions/bicycle/RunBicycleContribExample.java b/src/main/java/org/matsim/codeexamples/extensions/bicycle/RunBicycleContribExample.java index 5edcb77a..c3093dfe 100644 --- a/src/main/java/org/matsim/codeexamples/extensions/bicycle/RunBicycleContribExample.java +++ b/src/main/java/org/matsim/codeexamples/extensions/bicycle/RunBicycleContribExample.java @@ -5,8 +5,13 @@ 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.population.Leg; +import org.matsim.api.core.v01.population.Plan; import org.matsim.contrib.bicycle.BicycleConfigGroup; import org.matsim.contrib.bicycle.BicycleModule; +import org.matsim.contrib.bicycle.BicycleUtils; +import org.matsim.contrib.otfvis.OTFVisLiveModule; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.ScoringConfigGroup; @@ -14,57 +19,66 @@ import org.matsim.core.config.groups.ReplanningConfigGroup; import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy; +import org.matsim.core.router.TripStructureUtils; import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.core.utils.io.IOUtils; +import org.matsim.examples.ExamplesUtils; import org.matsim.vehicles.VehicleType; import org.matsim.vehicles.VehicleUtils; import org.matsim.vehicles.VehiclesFactory; +import org.matsim.vis.otfvis.OTFVisConfigGroup; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.net.URL; +import java.util.*; public final class RunBicycleContribExample{ private static final Logger LOG = LogManager.getLogger( RunBicycleContribExample.class ); + private static final String BICYCLE_MODE = "bicycle"; + public static void main(String[] args) { Config config; if (args.length >= 1) { LOG.info("A user-specified config.xml file was provided. Using it..."); config = ConfigUtils.loadConfig(args, new BicycleConfigGroup() ); } else { - LOG.info("No config.xml file was provided. Using 'standard' example files given in this contrib's resources folder."); - // Setting the context like this works when the data is stored under "/matsim/contribs/bicycle/src/main/resources/bicycle_example" - config = ConfigUtils.createConfig("bicycle_example/"); - config.addModule(new BicycleConfigGroup()); - config.network().setInputFile("network_lane.xml"); // Modify this - config.plans().setInputFile("population_1200.xml"); + LOG.info("No config.xml file was provided. Using bicycle_example from ExamplesUtils."); + + config = ConfigUtils.createConfig( ExamplesUtils.getTestScenarioURL( "bicycle_example" ) ); + + config.qsim().setLinkDynamics( QSimConfigGroup.LinkDynamics.PassingQ ); + config.qsim().setTrafficDynamics( QSimConfigGroup.TrafficDynamics.kinematicWaves ); + + config.network().setInputFile("network_normal.xml"); // change this to any of the others that are provided + config.plans().setInputFile("population_3.xml"); - config.replanning().addStrategySettings( new ReplanningConfigGroup.StrategySettings().setStrategyName("ChangeExpBeta" ).setWeight(0.8 ) ); - config.replanning().addStrategySettings( new ReplanningConfigGroup.StrategySettings().setStrategyName("ReRoute" ).setWeight(0.2 ) ); +// config.replanning().addStrategySettings( new ReplanningConfigGroup.StrategySettings().setStrategyName("ChangeExpBeta" ).setWeight(0.8 ) ); +// config.replanning().addStrategySettings( new ReplanningConfigGroup.StrategySettings().setStrategyName("ReRoute" ).setWeight(0.2 ) ); config.scoring().addActivityParams( new ScoringConfigGroup.ActivityParams("home").setTypicalDuration(12*60*60 ) ); config.scoring().addActivityParams( new ScoringConfigGroup.ActivityParams("work").setTypicalDuration(8*60*60 ) ); - config.scoring().addModeParams( new ScoringConfigGroup.ModeParams("bicycle").setConstant(0. ).setMarginalUtilityOfDistance(-0.0004 ).setMarginalUtilityOfTraveling(-6.0 ).setMonetaryDistanceRate(0. ) ); + config.scoring().addModeParams( new ScoringConfigGroup.ModeParams( + BICYCLE_MODE ).setConstant(0. ).setMarginalUtilityOfDistance(-0.0004 ).setMarginalUtilityOfTraveling(-6.0 ).setMonetaryDistanceRate(0. ) ); config.global().setNumberOfThreads(1 ); config.controller().setOverwriteFileSetting( OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists ); - config.controller().setLastIteration(100); // Modify if motorized interaction is used + config.controller().setLastIteration(0); } - BicycleConfigGroup bicycleConfigGroup = ConfigUtils.addOrGetModule( config, BicycleConfigGroup.class ); - bicycleConfigGroup.setBicycleMode( "bicycle" ); - bicycleConfigGroup.setMarginalUtilityOfInfrastructure_m(-0.0002); - bicycleConfigGroup.setMarginalUtilityOfComfort_m(-0.0002); - bicycleConfigGroup.setMarginalUtilityOfGradient_m_100m(-0.02); - bicycleConfigGroup.setMaxBicycleSpeedForRouting(4.16666666); + BicycleConfigGroup bicycleConfig = ConfigUtils.addOrGetModule( config, BicycleConfigGroup.class ); + bicycleConfig.setBicycleMode( BICYCLE_MODE ); +// bicycleConfig.setMarginalUtilityOfInfrastructure_m(-0.0002); +// bicycleConfig.setMarginalUtilityOfComfort_m(-0.0002); +// bicycleConfig.setMarginalUtilityOfGradient_m_100m(-0.02); +// bicycleConfig.setMaxBicycleSpeedForRouting(4.16666666); - List mainModeList = Arrays.asList( "bicycle", TransportMode.car); + Set mainModeSet = new LinkedHashSet<>( Arrays.asList( BICYCLE_MODE, TransportMode.car ) ); - config.qsim().setMainModes(mainModeList ); + config.qsim().setMainModes(mainModeSet ); - config.routing().setNetworkModes(mainModeList ); + config.routing().setNetworkModes(mainModeSet ); // === @@ -73,16 +87,32 @@ public static void main(String[] args) { // set config such that the mode vehicles come from vehicles data: scenario.getConfig().qsim().setVehiclesSource( QSimConfigGroup.VehiclesSource.modeVehicleTypesFromVehiclesData ); - // now put hte mode vehicles into the vehicles data: + // now put the mode vehicles into the vehicles data: final VehiclesFactory vf = VehicleUtils.getFactory(); scenario.getVehicles().addVehicleType( vf.createVehicleType( Id.create(TransportMode.car, VehicleType.class ) ).setNetworkMode( TransportMode.car ) ); - scenario.getVehicles().addVehicleType( vf.createVehicleType(Id.create("bicycle", VehicleType.class ) ).setNetworkMode( "bicycle" ).setMaximumVelocity(4.16666666 ).setPcuEquivalents(0.25 ) ); + scenario.getVehicles().addVehicleType( vf.createVehicleType(Id.create( BICYCLE_MODE, VehicleType.class ) ).setNetworkMode( BICYCLE_MODE ).setMaximumVelocity(4.16666666 ).setPcuEquivalents(0.25 ) ); + +// // create a bicycle expressway +// scenario.getNetwork().getLinks().get( Id.createLinkId( 2 ) ).getAttributes().putAttribute( BicycleUtils.BICYCLE_INFRASTRUCTURE_SPEED_FACTOR, 10. ); + +// // allow cars on all links ... and switch one person to car: +// for( Link link : scenario.getNetwork().getLinks().values() ){ +// link.setAllowedModes( mainModeSet ); +// } +// Plan plan = scenario.getPopulation().getPersons().get( Id.createPersonId( 1 ) ).getSelectedPlan(); +// for( Leg leg : TripStructureUtils.getLegs( plan ) ){ +// leg.setMode( TransportMode.car ); +// } // === Controler controler = new Controler(scenario); controler.addOverridingModule(new BicycleModule() ); + controler.addOverridingModule( new OTFVisLiveModule() ); + OTFVisConfigGroup otfConfig = ConfigUtils.addOrGetModule( config, OTFVisConfigGroup.class ); + otfConfig.setAgentSize( otfConfig.getAgentSize()*2 ); + controler.run(); }