From 7e4a36938fe868d7763b515b4d23406ed34ec2a0 Mon Sep 17 00:00:00 2001 From: sime94 Date: Thu, 26 Sep 2024 20:11:21 +0200 Subject: [PATCH 1/4] add run class for speed reduction scenario --- .../run/LausitzSpeedReductionScenario.java | 88 +++++++++++++++++++ .../run/RunLausitzSpeedReductionScenario.java | 17 ++++ 2 files changed, 105 insertions(+) create mode 100644 src/main/java/org/matsim/run/LausitzSpeedReductionScenario.java create mode 100644 src/main/java/org/matsim/run/RunLausitzSpeedReductionScenario.java diff --git a/src/main/java/org/matsim/run/LausitzSpeedReductionScenario.java b/src/main/java/org/matsim/run/LausitzSpeedReductionScenario.java new file mode 100644 index 0000000..697ea26 --- /dev/null +++ b/src/main/java/org/matsim/run/LausitzSpeedReductionScenario.java @@ -0,0 +1,88 @@ +package org.matsim.run; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.locationtech.jts.geom.prep.PreparedGeometry; +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.controler.Controler; +import org.matsim.core.utils.io.IOUtils; +import org.matsim.utils.gis.shp2matsim.ShpGeometryUtils; +import picocli.CommandLine; + +import javax.annotation.Nullable; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Lausitz scenario including speed reductions on network links of all types except motorways. + * Speed reduction can be done relatively or by absolute value. + * All necessary configs will be made in this class. + */ +public class LausitzSpeedReductionScenario extends LausitzScenario { + Logger log = LogManager.getLogger(LausitzSpeedReductionScenario.class); + + private final LausitzScenario baseScenario = new LausitzScenario(sample, emissions); + + @CommandLine.Option(names = "--slow-speed-shp", description = "Path to shp file for adaption of link speeds.", defaultValue = "../shp/lausitz.shp") + private String slowSpeedAreaShp; + @CommandLine.Option(names = "--slow-speed-relative-change", description = "provide a value that is bigger than 0.0 and smaller than 1.0." + + "The default is set to 0.6, such that roads with an allowed speed of 50kmh are reduced to 30kmh.", defaultValue = "0.6") + private double relativeSpeedChange; + + public LausitzSpeedReductionScenario(@Nullable Config config) { + super(config); + } + + public LausitzSpeedReductionScenario(@Nullable String args) { + super(args); + } + + public LausitzSpeedReductionScenario() { + super(String.format("input/v%s/lausitz-v%s-10pct.config.xml", LausitzScenario.VERSION, LausitzScenario.VERSION)); + } + + @Nullable + @Override + protected Config prepareConfig(Config config) { + // apply all config changes from base scenario class + baseScenario.prepareConfig(config); + return config; + } + + @Override + protected void prepareScenario(Scenario scenario) { + // apply all scenario changes from base scenario class + baseScenario.prepareScenario(scenario); + + List geometries = ShpGeometryUtils.loadPreparedGeometries(IOUtils.extendUrl(scenario.getConfig().getContext(), slowSpeedAreaShp)); + + Set carLinksInArea = scenario.getNetwork().getLinks().values().stream() + //filter car links + .filter(link -> link.getAllowedModes().contains(TransportMode.car)) + //spatial filter + .filter(link -> ShpGeometryUtils.isCoordInPreparedGeometries(link.getCoord(), geometries)) + //we won't change motorways and motorway_links + .filter(link -> !((String) link.getAttributes().getAttribute("type")).contains("motorway")) + .collect(Collectors.toSet()); + + if (relativeSpeedChange >= 0.0 && relativeSpeedChange < 1.0) { + log.info("reduce speed relatively by a factor of: {}", relativeSpeedChange); + + //apply speed reduction to all roads but motorways + carLinksInArea.forEach(link -> link.setFreespeed(link.getFreespeed() * relativeSpeedChange)); + } else { + log.fatal("Speed reduction value of {} is invalid. Please put a 0.0 <= value < 1.0", relativeSpeedChange); + throw new IllegalArgumentException(); + } + } + + @Override + protected void prepareControler(Controler controler) { + // apply all controller changes from base scenario class + baseScenario.prepareControler(controler); + } +} diff --git a/src/main/java/org/matsim/run/RunLausitzSpeedReductionScenario.java b/src/main/java/org/matsim/run/RunLausitzSpeedReductionScenario.java new file mode 100644 index 0000000..1a61b8d --- /dev/null +++ b/src/main/java/org/matsim/run/RunLausitzSpeedReductionScenario.java @@ -0,0 +1,17 @@ +package org.matsim.run; + +import org.matsim.application.MATSimApplication; + +/** + * Run the Lausitz speed reduction scenario policy case. + */ +public final class RunLausitzSpeedReductionScenario { + + private RunLausitzSpeedReductionScenario() { + } + + public static void main(String[] args) { + MATSimApplication.execute(LausitzSpeedReductionScenario.class, args); + } + +} From 787dc548c876664892f43de0d408752ef467c062 Mon Sep 17 00:00:00 2001 From: sime94 Date: Thu, 26 Sep 2024 20:11:40 +0200 Subject: [PATCH 2/4] add run class for single mode scenario --- .../matsim/run/LausitzSingleModeScenario.java | 98 +++++++++++++++++++ .../run/RunLausitzSingleModeScenario.java | 17 ++++ 2 files changed, 115 insertions(+) create mode 100644 src/main/java/org/matsim/run/LausitzSingleModeScenario.java create mode 100644 src/main/java/org/matsim/run/RunLausitzSingleModeScenario.java diff --git a/src/main/java/org/matsim/run/LausitzSingleModeScenario.java b/src/main/java/org/matsim/run/LausitzSingleModeScenario.java new file mode 100644 index 0000000..8c38ce1 --- /dev/null +++ b/src/main/java/org/matsim/run/LausitzSingleModeScenario.java @@ -0,0 +1,98 @@ +package org.matsim.run; + +import com.google.common.collect.Lists; +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.population.*; +import org.matsim.core.config.Config; +import org.matsim.core.config.groups.ReplanningConfigGroup; +import org.matsim.core.controler.Controler; +import org.matsim.core.population.algorithms.TripsToLegsAlgorithm; +import org.matsim.core.router.RoutingModeMainModeIdentifier; +import picocli.CommandLine; + +import javax.annotation.Nullable; +import java.util.Collection; + +/** + * Lausitz scenario including the simulation of 1 single transport mode. + * All legs are changed to --transport-mode and mode choice is switched off. + * All necessary configs will be made in this class. + */ +public class LausitzSingleModeScenario extends LausitzScenario { + Logger log = LogManager.getLogger(LausitzSingleModeScenario.class); + + private final LausitzScenario baseScenario = new LausitzScenario(sample, emissions); + + @CommandLine.Option(names = "--transport-mode", description = "Transport mode to which all legs should be changed.", defaultValue = TransportMode.car) + private String mode; + + public LausitzSingleModeScenario(@Nullable Config config) { + super(config); + } + + public LausitzSingleModeScenario(@Nullable String args) { + super(args); + } + + public LausitzSingleModeScenario() { + super(String.format("input/v%s/lausitz-v%s-10pct.config.xml", LausitzScenario.VERSION, LausitzScenario.VERSION)); + } + + @Nullable + @Override + protected Config prepareConfig(Config config) { + // apply all config changes from base scenario class + baseScenario.prepareConfig(config); + + config.subtourModeChoice().setModes(new String[0]); + +// remove smc strategy, only one mode for this scenario + Collection settings = config.replanning().getStrategySettings(); + config.replanning().clearStrategySettings(); + + settings.stream() + .filter(setting -> !setting.getStrategyName().equals("SubtourModeChoice")) + .forEach(setting -> config.replanning().addStrategySettings(setting)); + + return config; + } + + @Override + protected void prepareScenario(Scenario scenario) { + // apply all scenario changes from base scenario class + baseScenario.prepareScenario(scenario); + +// TODO: replace code segment that selects, cleans routes and converts trips 2 legs with call of CleanPopulation PR3496 + TripsToLegsAlgorithm trips2Legs = new TripsToLegsAlgorithm(new RoutingModeMainModeIdentifier()); + + for (Person person : scenario.getPopulation().getPersons().values()) { + Plan selected = person.getSelectedPlan(); + for (Plan plan : Lists.newArrayList(person.getPlans())) { + if (plan != selected) + person.removePlan(plan); + } + + for (Plan plan : person.getPlans()) { + trips2Legs.run(plan); + + for (PlanElement el : plan.getPlanElements()) { + if (el instanceof Leg leg) { + leg.setRoute(null); + leg.setMode(mode); + } + } + } + } + log.info("For all agents: Unselected plans have been removed. Trips were converted to legs. Routes have been removed." + + " For every leg, the mode was changed to {}", mode); + } + + @Override + protected void prepareControler(Controler controler) { + // apply all controller changes from base scenario class + baseScenario.prepareControler(controler); + } +} diff --git a/src/main/java/org/matsim/run/RunLausitzSingleModeScenario.java b/src/main/java/org/matsim/run/RunLausitzSingleModeScenario.java new file mode 100644 index 0000000..47d2005 --- /dev/null +++ b/src/main/java/org/matsim/run/RunLausitzSingleModeScenario.java @@ -0,0 +1,17 @@ +package org.matsim.run; + +import org.matsim.application.MATSimApplication; + +/** + * Run the Lausitz single mode scenario policy case. + */ +public final class RunLausitzSingleModeScenario { + + private RunLausitzSingleModeScenario() { + } + + public static void main(String[] args) { + MATSimApplication.execute(LausitzSingleModeScenario.class, args); + } + +} From 4327d3442bab492bf9d80038bb0735a7a937b283 Mon Sep 17 00:00:00 2001 From: sime94 Date: Thu, 26 Sep 2024 20:11:55 +0200 Subject: [PATCH 3/4] add tests for new scenarios --- .gitignore | 1 + .../dashboards/LausitzDashboardProvider.java | 1 - .../org/matsim/run/RunIntegrationTest.java | 153 +++++++++++++----- 3 files changed, 118 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index ed46f39..6970ec7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ output/ scenarios/output test/output +runs/ *.gz *.pbf diff --git a/src/main/java/org/matsim/dashboards/LausitzDashboardProvider.java b/src/main/java/org/matsim/dashboards/LausitzDashboardProvider.java index 0092383..10ed8d8 100644 --- a/src/main/java/org/matsim/dashboards/LausitzDashboardProvider.java +++ b/src/main/java/org/matsim/dashboards/LausitzDashboardProvider.java @@ -1,7 +1,6 @@ package org.matsim.dashboards; import org.matsim.core.config.Config; -import org.matsim.core.population.PersonUtils; import org.matsim.simwrapper.Dashboard; import org.matsim.simwrapper.DashboardProvider; import org.matsim.simwrapper.SimWrapper; diff --git a/src/test/java/org/matsim/run/RunIntegrationTest.java b/src/test/java/org/matsim/run/RunIntegrationTest.java index fa3151e..fca0b6e 100644 --- a/src/test/java/org/matsim/run/RunIntegrationTest.java +++ b/src/test/java/org/matsim/run/RunIntegrationTest.java @@ -1,6 +1,7 @@ package org.matsim.run; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.io.TempDir; @@ -20,6 +21,8 @@ import org.matsim.core.network.NetworkUtils; import org.matsim.core.population.PersonUtils; import org.matsim.core.population.PopulationUtils; +import org.matsim.core.router.RoutingModeMainModeIdentifier; +import org.matsim.core.router.TripStructureUtils; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.pt.transitSchedule.api.*; import org.matsim.simwrapper.SimWrapperConfigGroup; @@ -29,18 +32,29 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.Set; import static org.matsim.application.ApplicationUtils.globFile; class RunIntegrationTest { @RegisterExtension - public MatsimTestUtils utils = new MatsimTestUtils(); + private MatsimTestUtils utils = new MatsimTestUtils(); @TempDir - public Path p; + private Path p; - private final static Id ptPersonId = Id.createPersonId("Hoyerswerda-Cottbus_PT"); + private String inputPath; + + private final static Id personId = Id.createPersonId("Hoyerswerda-Cottbus"); + + private final RoutingModeMainModeIdentifier identifier = new RoutingModeMainModeIdentifier(); + + @BeforeEach + void setUp() { + // Initialize inputPath after p is injected + inputPath = p.resolve("test-population.xml.gz").toString(); + } @Test void runScenario() { @@ -50,7 +64,7 @@ void runScenario() { assert MATSimApplication.execute(LausitzScenario.class, config, "--1pct", "--iterations", "1", - "--config:plans.inputPlansFile", "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/lausitz/input/v1.1/lausitz-v1.1-1pct.plans-initial.xml.gz", + "--config:plans.inputPlansFile", "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/lausitz/input/v1.1/lausitz-v1.1-0.1pct.plans-initial.xml.gz", "--output", utils.getOutputDirectory(), "--config:controller.overwriteFiles=deleteDirectoryIfExists", "--emissions", "DO_NOT_PERFORM_EMISSIONS_ANALYSIS") == 0 : "Must return non error code"; @@ -81,42 +95,13 @@ void runScenarioIncludingAdditionalPtLine() { Config config = ConfigUtils.loadConfig(String.format("input/v%s/lausitz-v%s-10pct.config.xml", LausitzScenario.VERSION, LausitzScenario.VERSION)); ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled; - Path inputPath = p.resolve("pt-test-population.xml.gz"); - - Population population = PopulationUtils.createPopulation(config); - PopulationFactory fac = population.getFactory(); - Person person = fac.createPerson(ptPersonId); - Plan plan = PopulationUtils.createPlan(person); - -// home in hoyerswerda - Activity home = fac.createActivityFromCoord("home_2400", new Coord(863538.13,5711028.24)); - home.setEndTime(8 * 3600); - Activity home2 = fac.createActivityFromCoord("home_2400", new Coord(863538.13,5711028.24)); - home2.setEndTime(19 * 3600); -// work in cottbus - Activity work = fac.createActivityFromCoord("work_2400", new Coord(867489.48,5746587.47)); - work.setEndTime(17 * 3600 + 25 * 60); - - Leg leg = fac.createLeg(TransportMode.pt); - - plan.addActivity(home); - plan.addLeg(leg); - plan.addActivity(work); - plan.addLeg(leg); - plan.addActivity(home2); - - person.addPlan(plan); - PersonUtils.setIncome(person, 1000.); - person.getAttributes().putAttribute("subpopulation", "person"); - population.addPerson(person); - - new PopulationWriter(population).write(inputPath.toString()); + createSinglePersonTestPopulation(config, TransportMode.pt); assert MATSimApplication.execute(LausitzPtScenario.class, config, "--1pct", "--iterations", "1", "--output", utils.getOutputDirectory(), - "--config:plans.inputPlansFile", inputPath.toString(), + "--config:plans.inputPlansFile", inputPath, "--config:controller.overwriteFiles=deleteDirectoryIfExists", "--emissions", "DO_NOT_PERFORM_EMISSIONS_ANALYSIS") == 0 : "Must return non error code"; @@ -149,12 +134,108 @@ void runScenarioIncludingAdditionalPtLine() { } + @Test + void runSpeedReductionScenario() { + Config config = ConfigUtils.loadConfig(String.format("input/v%s/lausitz-v%s-10pct.config.xml", LausitzScenario.VERSION, LausitzScenario.VERSION)); + ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled; + + assert MATSimApplication.execute(LausitzSpeedReductionScenario.class, config, + "--1pct", + "--iterations", "0", + "--config:plans.inputPlansFile", "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/lausitz/input/v1.1/lausitz-v1.1-0.1pct.plans-initial.xml.gz", + "--output", utils.getOutputDirectory(), + "--config:controller.overwriteFiles=deleteDirectoryIfExists", "--emissions", "DO_NOT_PERFORM_EMISSIONS_ANALYSIS") + == 0 : "Must return non error code"; + + Assertions.assertTrue(new File(utils.getOutputDirectory()).isDirectory()); + Assertions.assertTrue(new File(utils.getOutputDirectory()).exists()); + + Network network = NetworkUtils.readNetwork(globFile(Path.of(utils.getOutputDirectory()), "*output_network.xml.gz").toString()); + + // motorway speed should not be altered + Assertions.assertEquals(39.44, network.getLinks().get(Id.createLinkId("267472144")).getFreespeed()); + Assertions.assertEquals(27.78 * 0.6, network.getLinks().get(Id.createLinkId("-134417722")).getFreespeed()); + Assertions.assertEquals(10.4175 * 0.6, network.getLinks().get(Id.createLinkId("-67544888")).getFreespeed()); + Assertions.assertEquals(6.2475000000000005 * 0.6, network.getLinks().get(Id.createLinkId("-836484274")).getFreespeed()); + } + + @Test + void runSingleModeScenario() { + Set modes = Set.of(TransportMode.car, TransportMode.bike, TransportMode.pt, TransportMode.walk); + + for (String mode : modes){ + Config config = ConfigUtils.loadConfig(String.format("input/v%s/lausitz-v%s-10pct.config.xml", LausitzScenario.VERSION, LausitzScenario.VERSION)); + ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled; + + createSinglePersonTestPopulation(config, mode); + + assert MATSimApplication.execute(LausitzSingleModeScenario.class, config, + "--1pct", + "--iterations", "1", + "--config:plans.inputPlansFile", inputPath, + "--output", utils.getOutputDirectory(), + "--config:controller.overwriteFiles=deleteDirectoryIfExists", "--emissions", "DO_NOT_PERFORM_EMISSIONS_ANALYSIS", + "--transport-mode", mode) + == 0 : "Must return non error code"; + + Assertions.assertTrue(new File(utils.getOutputDirectory()).isDirectory()); + Assertions.assertTrue(new File(utils.getOutputDirectory()).exists()); + + Config outputConfig = ConfigUtils.loadConfig(globFile(Path.of(utils.getOutputDirectory()), "*output_config.xml").toString()); + +// config should not have any smc modes + no smc strategy + Assertions.assertEquals(1, outputConfig.subtourModeChoice().getModes().length); + Assertions.assertEquals("", outputConfig.subtourModeChoice().getModes()[0]); + Assertions.assertEquals(0, outputConfig.replanning().getStrategySettings() + .stream() + .filter(setting -> setting.getStrategyName().equals("SubtourModeChoice")) + .toList() + .size()); + + Population population = PopulationUtils.readPopulation(globFile(Path.of(utils.getOutputDirectory()), "*output_plans.xml.gz").toString()); + + TripStructureUtils.getTrips(population.getPersons().get(Id.createPersonId(personId)).getSelectedPlan()) + .forEach(t -> Assertions.assertEquals(mode, this.identifier.identifyMainMode(t.getTripElements()))); + } + } + + private void createSinglePersonTestPopulation(Config config, String mode) { + Population population = PopulationUtils.createPopulation(config); + PopulationFactory fac = population.getFactory(); + Person person = fac.createPerson(personId); + Plan plan = PopulationUtils.createPlan(person); + +// home in hoyerswerda + Activity home = fac.createActivityFromCoord("home_2400", new Coord(863538.13,5711028.24)); + home.setEndTime(8 * 3600); + Activity home2 = fac.createActivityFromCoord("home_2400", new Coord(863538.13,5711028.24)); + home2.setEndTime(19 * 3600); +// work in cottbus + Activity work = fac.createActivityFromCoord("work_2400", new Coord(867489.48,5746587.47)); + work.setEndTime(17 * 3600 + 25 * 60); + + Leg leg = fac.createLeg(mode); + + plan.addActivity(home); + plan.addLeg(leg); + plan.addActivity(work); + plan.addLeg(leg); + plan.addActivity(home2); + + person.addPlan(plan); + PersonUtils.setIncome(person, 1000.); + person.getAttributes().putAttribute("subpopulation", "person"); + population.addPerson(person); + + new PopulationWriter(population).write(this.inputPath); + } + private static final class PersonEntersPtVehicleEventHandler implements PersonEntersVehicleEventHandler { static List enterEvents = new ArrayList<>(); @Override public void handleEvent(PersonEntersVehicleEvent event) { - if (event.getPersonId().equals(ptPersonId) && event.getVehicleId().toString().contains("RE-VSP1")) { + if (event.getPersonId().equals(personId) && event.getVehicleId().toString().contains("RE-VSP1")) { enterEvents.add(event); } } From 1ebe6ebe3acaf04f4f58552645b203a2819f1743 Mon Sep 17 00:00:00 2001 From: sime94 Date: Thu, 26 Sep 2024 20:18:11 +0200 Subject: [PATCH 4/4] move scenario classes to dedicated package --- src/main/java/org/matsim/run/RunLausitzDrtScenario.java | 1 + src/main/java/org/matsim/run/RunLausitzPtScenario.java | 1 + src/main/java/org/matsim/run/RunLausitzScenario.java | 1 + .../java/org/matsim/run/RunLausitzSingleModeScenario.java | 1 + .../org/matsim/run/RunLausitzSpeedReductionScenario.java | 1 + .../run/prepare/AdaptFreightTrafficToDetailedModes.java | 2 +- src/main/java/org/matsim/run/prepare/PrepareNetwork.java | 2 +- .../org/matsim/run/{ => scenarios}/LausitzPtScenario.java | 8 ++++---- .../org/matsim/run/{ => scenarios}/LausitzScenario.java | 8 ++++---- .../run/{ => scenarios}/LausitzSingleModeScenario.java | 8 ++++---- .../{ => scenarios}/LausitzSpeedReductionScenario.java | 8 ++++---- .../matsim/run/EmissionAndNoiseAnalysisOutputTest.java | 1 + src/test/java/org/matsim/run/RunIntegrationTest.java | 4 ++++ 13 files changed, 28 insertions(+), 18 deletions(-) rename src/main/java/org/matsim/run/{ => scenarios}/LausitzPtScenario.java (98%) rename src/main/java/org/matsim/run/{ => scenarios}/LausitzScenario.java (98%) rename src/main/java/org/matsim/run/{ => scenarios}/LausitzSingleModeScenario.java (94%) rename src/main/java/org/matsim/run/{ => scenarios}/LausitzSpeedReductionScenario.java (94%) diff --git a/src/main/java/org/matsim/run/RunLausitzDrtScenario.java b/src/main/java/org/matsim/run/RunLausitzDrtScenario.java index fbec143..0d49c9b 100644 --- a/src/main/java/org/matsim/run/RunLausitzDrtScenario.java +++ b/src/main/java/org/matsim/run/RunLausitzDrtScenario.java @@ -27,6 +27,7 @@ import org.matsim.core.controler.Controler; import org.matsim.core.network.algorithms.MultimodalNetworkCleaner; import org.matsim.core.utils.geometry.geotools.MGC; +import org.matsim.run.scenarios.LausitzScenario; import org.matsim.vehicles.Vehicle; import org.matsim.vehicles.VehicleCapacity; import org.matsim.vehicles.VehicleType; diff --git a/src/main/java/org/matsim/run/RunLausitzPtScenario.java b/src/main/java/org/matsim/run/RunLausitzPtScenario.java index 0f40604..f88ee99 100644 --- a/src/main/java/org/matsim/run/RunLausitzPtScenario.java +++ b/src/main/java/org/matsim/run/RunLausitzPtScenario.java @@ -1,6 +1,7 @@ package org.matsim.run; import org.matsim.application.MATSimApplication; +import org.matsim.run.scenarios.LausitzPtScenario; /** * Run the Lausitz PT scenario policy case. diff --git a/src/main/java/org/matsim/run/RunLausitzScenario.java b/src/main/java/org/matsim/run/RunLausitzScenario.java index 7d3f2d4..005718a 100644 --- a/src/main/java/org/matsim/run/RunLausitzScenario.java +++ b/src/main/java/org/matsim/run/RunLausitzScenario.java @@ -1,6 +1,7 @@ package org.matsim.run; import org.matsim.application.MATSimApplication; +import org.matsim.run.scenarios.LausitzScenario; /** * Run the Lausitz scenario with default configuration. diff --git a/src/main/java/org/matsim/run/RunLausitzSingleModeScenario.java b/src/main/java/org/matsim/run/RunLausitzSingleModeScenario.java index 47d2005..47655f0 100644 --- a/src/main/java/org/matsim/run/RunLausitzSingleModeScenario.java +++ b/src/main/java/org/matsim/run/RunLausitzSingleModeScenario.java @@ -1,6 +1,7 @@ package org.matsim.run; import org.matsim.application.MATSimApplication; +import org.matsim.run.scenarios.LausitzSingleModeScenario; /** * Run the Lausitz single mode scenario policy case. diff --git a/src/main/java/org/matsim/run/RunLausitzSpeedReductionScenario.java b/src/main/java/org/matsim/run/RunLausitzSpeedReductionScenario.java index 1a61b8d..11d392e 100644 --- a/src/main/java/org/matsim/run/RunLausitzSpeedReductionScenario.java +++ b/src/main/java/org/matsim/run/RunLausitzSpeedReductionScenario.java @@ -1,6 +1,7 @@ package org.matsim.run; import org.matsim.application.MATSimApplication; +import org.matsim.run.scenarios.LausitzSpeedReductionScenario; /** * Run the Lausitz speed reduction scenario policy case. diff --git a/src/main/java/org/matsim/run/prepare/AdaptFreightTrafficToDetailedModes.java b/src/main/java/org/matsim/run/prepare/AdaptFreightTrafficToDetailedModes.java index 259add6..a3bdb45 100644 --- a/src/main/java/org/matsim/run/prepare/AdaptFreightTrafficToDetailedModes.java +++ b/src/main/java/org/matsim/run/prepare/AdaptFreightTrafficToDetailedModes.java @@ -21,7 +21,7 @@ import java.util.Map; import java.util.Set; -import static org.matsim.run.LausitzScenario.*; +import static org.matsim.run.scenarios.LausitzScenario.*; @CommandLine.Command( name = "adapt-freight-plans", diff --git a/src/main/java/org/matsim/run/prepare/PrepareNetwork.java b/src/main/java/org/matsim/run/prepare/PrepareNetwork.java index bb5f89f..9860434 100644 --- a/src/main/java/org/matsim/run/prepare/PrepareNetwork.java +++ b/src/main/java/org/matsim/run/prepare/PrepareNetwork.java @@ -15,7 +15,7 @@ import java.util.Set; -import static org.matsim.run.LausitzScenario.*; +import static org.matsim.run.scenarios.LausitzScenario.*; @CommandLine.Command( name = "network", diff --git a/src/main/java/org/matsim/run/LausitzPtScenario.java b/src/main/java/org/matsim/run/scenarios/LausitzPtScenario.java similarity index 98% rename from src/main/java/org/matsim/run/LausitzPtScenario.java rename to src/main/java/org/matsim/run/scenarios/LausitzPtScenario.java index 8c73028..d3dff67 100644 --- a/src/main/java/org/matsim/run/LausitzPtScenario.java +++ b/src/main/java/org/matsim/run/scenarios/LausitzPtScenario.java @@ -1,4 +1,4 @@ -package org.matsim.run; +package org.matsim.run.scenarios; import org.matsim.api.core.v01.Coord; import org.matsim.api.core.v01.Id; @@ -46,7 +46,7 @@ public static void main(String[] args) { @Nullable @Override - protected Config prepareConfig(Config config) { + public Config prepareConfig(Config config) { // apply all config changes from base scenario class baseScenario.prepareConfig(config); @@ -54,7 +54,7 @@ protected Config prepareConfig(Config config) { } @Override - protected void prepareScenario(Scenario scenario) { + public void prepareScenario(Scenario scenario) { // apply all scenario changes from base scenario class baseScenario.prepareScenario(scenario); @@ -147,7 +147,7 @@ protected void prepareScenario(Scenario scenario) { } @Override - protected void prepareControler(Controler controler) { + public void prepareControler(Controler controler) { // apply all controller changes from base scenario class baseScenario.prepareControler(controler); // TODO: add potential new Listeners here diff --git a/src/main/java/org/matsim/run/LausitzScenario.java b/src/main/java/org/matsim/run/scenarios/LausitzScenario.java similarity index 98% rename from src/main/java/org/matsim/run/LausitzScenario.java rename to src/main/java/org/matsim/run/scenarios/LausitzScenario.java index 14fefe7..d082bb2 100644 --- a/src/main/java/org/matsim/run/LausitzScenario.java +++ b/src/main/java/org/matsim/run/scenarios/LausitzScenario.java @@ -1,4 +1,4 @@ -package org.matsim.run; +package org.matsim.run.scenarios; import com.google.common.collect.Sets; import org.matsim.analysis.personMoney.PersonMoneyEventsAnalysisModule; @@ -108,7 +108,7 @@ public static void main(String[] args) { @Nullable @Override - protected Config prepareConfig(Config config) { + public Config prepareConfig(Config config) { // Add all activity types with time bins SnzActivities.addScoringParams(config); @@ -184,7 +184,7 @@ protected Config prepareConfig(Config config) { } @Override - protected void prepareScenario(Scenario scenario) { + public void prepareScenario(Scenario scenario) { // add freight and truck as allowed modes together with car PrepareNetwork.prepareFreightNetwork(scenario.getNetwork()); @@ -197,7 +197,7 @@ protected void prepareScenario(Scenario scenario) { } @Override - protected void prepareControler(Controler controler) { + public void prepareControler(Controler controler) { //analyse PersonMoneyEvents controler.addOverridingModule(new PersonMoneyEventsAnalysisModule()); diff --git a/src/main/java/org/matsim/run/LausitzSingleModeScenario.java b/src/main/java/org/matsim/run/scenarios/LausitzSingleModeScenario.java similarity index 94% rename from src/main/java/org/matsim/run/LausitzSingleModeScenario.java rename to src/main/java/org/matsim/run/scenarios/LausitzSingleModeScenario.java index 8c38ce1..cfd08c5 100644 --- a/src/main/java/org/matsim/run/LausitzSingleModeScenario.java +++ b/src/main/java/org/matsim/run/scenarios/LausitzSingleModeScenario.java @@ -1,4 +1,4 @@ -package org.matsim.run; +package org.matsim.run.scenarios; import com.google.common.collect.Lists; import org.apache.logging.log4j.LogManager; @@ -43,7 +43,7 @@ public LausitzSingleModeScenario() { @Nullable @Override - protected Config prepareConfig(Config config) { + public Config prepareConfig(Config config) { // apply all config changes from base scenario class baseScenario.prepareConfig(config); @@ -61,7 +61,7 @@ protected Config prepareConfig(Config config) { } @Override - protected void prepareScenario(Scenario scenario) { + public void prepareScenario(Scenario scenario) { // apply all scenario changes from base scenario class baseScenario.prepareScenario(scenario); @@ -91,7 +91,7 @@ protected void prepareScenario(Scenario scenario) { } @Override - protected void prepareControler(Controler controler) { + public void prepareControler(Controler controler) { // apply all controller changes from base scenario class baseScenario.prepareControler(controler); } diff --git a/src/main/java/org/matsim/run/LausitzSpeedReductionScenario.java b/src/main/java/org/matsim/run/scenarios/LausitzSpeedReductionScenario.java similarity index 94% rename from src/main/java/org/matsim/run/LausitzSpeedReductionScenario.java rename to src/main/java/org/matsim/run/scenarios/LausitzSpeedReductionScenario.java index 697ea26..36b63fb 100644 --- a/src/main/java/org/matsim/run/LausitzSpeedReductionScenario.java +++ b/src/main/java/org/matsim/run/scenarios/LausitzSpeedReductionScenario.java @@ -1,4 +1,4 @@ -package org.matsim.run; +package org.matsim.run.scenarios; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -47,14 +47,14 @@ public LausitzSpeedReductionScenario() { @Nullable @Override - protected Config prepareConfig(Config config) { + public Config prepareConfig(Config config) { // apply all config changes from base scenario class baseScenario.prepareConfig(config); return config; } @Override - protected void prepareScenario(Scenario scenario) { + public void prepareScenario(Scenario scenario) { // apply all scenario changes from base scenario class baseScenario.prepareScenario(scenario); @@ -81,7 +81,7 @@ protected void prepareScenario(Scenario scenario) { } @Override - protected void prepareControler(Controler controler) { + public void prepareControler(Controler controler) { // apply all controller changes from base scenario class baseScenario.prepareControler(controler); } diff --git a/src/test/java/org/matsim/run/EmissionAndNoiseAnalysisOutputTest.java b/src/test/java/org/matsim/run/EmissionAndNoiseAnalysisOutputTest.java index f4cd898..f060d86 100644 --- a/src/test/java/org/matsim/run/EmissionAndNoiseAnalysisOutputTest.java +++ b/src/test/java/org/matsim/run/EmissionAndNoiseAnalysisOutputTest.java @@ -16,6 +16,7 @@ import org.matsim.core.population.PopulationUtils; import org.matsim.core.utils.io.IOUtils; import org.matsim.dashboards.LausitzSimWrapperRunner; +import org.matsim.run.scenarios.LausitzScenario; import org.matsim.simwrapper.SimWrapperConfigGroup; import org.matsim.testcases.MatsimTestUtils; diff --git a/src/test/java/org/matsim/run/RunIntegrationTest.java b/src/test/java/org/matsim/run/RunIntegrationTest.java index fca0b6e..9c08cbf 100644 --- a/src/test/java/org/matsim/run/RunIntegrationTest.java +++ b/src/test/java/org/matsim/run/RunIntegrationTest.java @@ -25,6 +25,10 @@ import org.matsim.core.router.TripStructureUtils; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.pt.transitSchedule.api.*; +import org.matsim.run.scenarios.LausitzPtScenario; +import org.matsim.run.scenarios.LausitzScenario; +import org.matsim.run.scenarios.LausitzSingleModeScenario; +import org.matsim.run.scenarios.LausitzSpeedReductionScenario; import org.matsim.simwrapper.SimWrapperConfigGroup; import org.matsim.testcases.MatsimTestUtils;