From c53036c2a20f9f7eb2d9703fd0f078601930678c Mon Sep 17 00:00:00 2001 From: dziemke Date: Tue, 10 Oct 2023 17:30:12 +0200 Subject: [PATCH] make bicycle example use inputs from the examples module, add dependency to examples module --- contribs/bicycle/pom.xml | 6 +++++ .../bicycle/run/RunBicycleExample.java | 23 ++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/contribs/bicycle/pom.xml b/contribs/bicycle/pom.xml index e49da35da22..3fd58fd6208 100644 --- a/contribs/bicycle/pom.xml +++ b/contribs/bicycle/pom.xml @@ -26,5 +26,11 @@ 16.0-SNAPSHOT compile + + org.matsim + matsim-examples + 16.0-SNAPSHOT + compile + diff --git a/contribs/bicycle/src/main/java/org/matsim/contrib/bicycle/run/RunBicycleExample.java b/contribs/bicycle/src/main/java/org/matsim/contrib/bicycle/run/RunBicycleExample.java index 134f8bf421e..f6b6c497005 100644 --- a/contribs/bicycle/src/main/java/org/matsim/contrib/bicycle/run/RunBicycleExample.java +++ b/contribs/bicycle/src/main/java/org/matsim/contrib/bicycle/run/RunBicycleExample.java @@ -39,6 +39,7 @@ import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.examples.ExamplesUtils; import org.matsim.vehicles.VehicleType; import org.matsim.vehicles.VehicleUtils; import org.matsim.vehicles.VehiclesFactory; @@ -59,22 +60,20 @@ public static void main(String[] args) { config = ConfigUtils.loadConfig(args[0], new BicycleConfigGroup()); fillConfigWithBicycleStandardValues(config); } else if (args.length == 0) { - 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()); + LOG.info("No config.xml file was provided. Using 'standard' example files given in examples module."); + config = ConfigUtils.createConfig(new BicycleConfigGroup()); fillConfigWithBicycleStandardValues(config); - config.network().setInputFile("network_lane.xml"); // Modify this - config.plans().setInputFile("population_1200.xml"); + config.network().setInputFile(ExamplesUtils.getTestScenarioURL("bicycle_example") + "/network_lane.xml"); + config.plans().setInputFile(ExamplesUtils.getTestScenarioURL("bicycle_example") + "population_1200.xml"); } else { - throw new RuntimeException("More than one argument was provided. There is no procedure for this situation. Thus aborting!" - + " Provide either (1) only a suitable config file or (2) no argument at all to run example with given example of resources folder."); + throw new RuntimeException("More than one argument was provided. This situation is not configured. Thus aborting!" + + " Provide either (1) only a suitable config file or (2) no argument at all to run example of the examples module."); } config.controler().setLastIteration(100); // Modify if motorized interaction is used boolean considerMotorizedInteraction = false; - new RunBicycleExample().run(config ); + new RunBicycleExample().run(config); } static void fillConfigWithBicycleStandardValues(Config config) { @@ -90,7 +89,6 @@ static void fillConfigWithBicycleStandardValues(Config config) { bicycleConfigGroup.setMaxBicycleSpeedForRouting(4.16666666); - List mainModeList = new ArrayList<>(); mainModeList.add( bicycleConfigGroup.getBicycleMode() ); mainModeList.add(TransportMode.car); @@ -135,6 +133,7 @@ public void run(Config config ) { controler.run(); } + public void runWithOwnScoring(Config config, boolean considerMotorizedInteraction) { config.global().setNumberOfThreads(1); config.controler().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); @@ -168,7 +167,6 @@ public void runWithOwnScoring(Config config, boolean considerMotorizedInteractio } private static class MyAdditionalBicycleLinkScore implements AdditionalBicycleLinkScore { - private final AdditionalBicycleLinkScore delegate; @Inject MyAdditionalBicycleLinkScore( Scenario scenario ) { this.delegate = BicycleUtils.createDefaultBicycleLinkScore( scenario ); @@ -179,9 +177,6 @@ private static class MyAdditionalBicycleLinkScore implements AdditionalBicycleLi double amount = delegate.computeLinkBasedScore( link ); return amount + result ; // or some other way to augment the score - } } - - }