diff --git a/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/router/DiversionTest.java b/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/router/DiversionTest.java index ed2c0c27587..16e1f5be09f 100644 --- a/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/router/DiversionTest.java +++ b/contribs/dvrp/src/test/java/org/matsim/contrib/dvrp/router/DiversionTest.java @@ -51,6 +51,7 @@ import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.QSimConfigGroup; import org.matsim.core.config.groups.QSimConfigGroup.StarttimeInterpretation; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; import org.matsim.core.mobsim.framework.MobsimTimer; @@ -124,7 +125,7 @@ void testRepeatedSameDestinationDiversions() { { /* Create some necessary configuration for the test */ - + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.controller().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); config.controller().setLastIteration(0); @@ -454,6 +455,7 @@ void testRepeatedDiversionToDifferentDestinationRightBeforeLastLink() { config.controller().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); config.controller().setLastIteration(0); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.qsim().setStartTime(0.0); config.qsim().setSimStarttimeInterpretation(StarttimeInterpretation.onlyUseStarttime); diff --git a/contribs/emissions/src/test/java/org/matsim/contrib/emissions/TestPositionEmissionModule.java b/contribs/emissions/src/test/java/org/matsim/contrib/emissions/TestPositionEmissionModule.java index f1824def7cd..a3059795499 100644 --- a/contribs/emissions/src/test/java/org/matsim/contrib/emissions/TestPositionEmissionModule.java +++ b/contribs/emissions/src/test/java/org/matsim/contrib/emissions/TestPositionEmissionModule.java @@ -18,11 +18,7 @@ import org.matsim.contrib.emissions.utils.EmissionsConfigGroup; import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.config.ConfigUtils; -import org.matsim.core.config.groups.ControllerConfigGroup; -import org.matsim.core.config.groups.NetworkConfigGroup; -import org.matsim.core.config.groups.ReplanningConfigGroup; -import org.matsim.core.config.groups.ScoringConfigGroup; -import org.matsim.core.config.groups.QSimConfigGroup; +import org.matsim.core.config.groups.*; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy; @@ -91,6 +87,7 @@ void compareToOtherModule_singleVehicleSingleLink() { var config = ConfigUtils.loadConfig(configFile, emissionConfig); config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); config.controller().setOutputDirectory(testUtils.getOutputDirectory()); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); emissionConfig.setAverageColdEmissionFactorsFile("../sample_41_EFA_ColdStart_vehcat_2020average.csv"); emissionConfig.setAverageWarmEmissionFactorsFile( "../sample_41_EFA_HOT_vehcat_2020average.csv" ); diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierModuleTest.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierModuleTest.java index b0d4922fcf9..49dc173dd05 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierModuleTest.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/CarrierModuleTest.java @@ -27,6 +27,7 @@ import org.matsim.api.core.v01.Scenario; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; @@ -53,6 +54,7 @@ public class CarrierModuleTest { @BeforeEach public void setUp(){ Config config = ConfigUtils.createConfig() ; + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); ScoringConfigGroup.ActivityParams workParams = new ScoringConfigGroup.ActivityParams("w"); workParams.setTypicalDuration(60 * 60 * 8); config.scoring().addActivityParams(workParams); diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/controler/EquilWithCarrierWithPersonsIT.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/controler/EquilWithCarrierWithPersonsIT.java index acfb8eab226..75800bfd34d 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/controler/EquilWithCarrierWithPersonsIT.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/controler/EquilWithCarrierWithPersonsIT.java @@ -30,6 +30,7 @@ import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; @@ -57,6 +58,8 @@ static Config commonConfig( MatsimTestUtils testUtils ) { config.controller().setOutputDirectory(testUtils.getOutputDirectory()); config.network().setInputFile( testUtils.getClassInputDirectory() + "network.xml" ); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + return config; } diff --git a/contribs/freight/src/test/java/org/matsim/freight/carriers/controler/EquilWithCarrierWithoutPersonsIT.java b/contribs/freight/src/test/java/org/matsim/freight/carriers/controler/EquilWithCarrierWithoutPersonsIT.java index 83f1dd9e021..70b01111b10 100644 --- a/contribs/freight/src/test/java/org/matsim/freight/carriers/controler/EquilWithCarrierWithoutPersonsIT.java +++ b/contribs/freight/src/test/java/org/matsim/freight/carriers/controler/EquilWithCarrierWithoutPersonsIT.java @@ -30,6 +30,7 @@ import org.matsim.api.core.v01.Scenario; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; import org.matsim.freight.carriers.FreightCarriersConfigGroup; @@ -50,6 +51,7 @@ public class EquilWithCarrierWithoutPersonsIT { public void setUp() { Config config = EquilWithCarrierWithPersonsIT.commonConfig( testUtils ); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); Scenario scenario = EquilWithCarrierWithPersonsIT.commonScenario( config, testUtils ); controler = new Controler(scenario); } diff --git a/contribs/locationchoice/src/test/java/org/matsim/contrib/locationchoice/LocationChoiceIT.java b/contribs/locationchoice/src/test/java/org/matsim/contrib/locationchoice/LocationChoiceIT.java index 4f39e4a0b72..1a045c7c8f6 100644 --- a/contribs/locationchoice/src/test/java/org/matsim/contrib/locationchoice/LocationChoiceIT.java +++ b/contribs/locationchoice/src/test/java/org/matsim/contrib/locationchoice/LocationChoiceIT.java @@ -84,6 +84,7 @@ public class LocationChoiceIT { void testLocationChoice() { final Config config = localCreateConfig( utils.getPackageInputDirectory() + "config2.xml"); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); final MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); diff --git a/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/MultiModalControlerListenerTest.java b/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/MultiModalControlerListenerTest.java index cb24c3d8849..fa7c3b2f767 100644 --- a/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/MultiModalControlerListenerTest.java +++ b/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/MultiModalControlerListenerTest.java @@ -89,7 +89,7 @@ void testSimpleScenario() { static void runSimpleScenario(int numberOfThreads) { Config config = ConfigUtils.createConfig(); - + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.qsim().setEndTime(24 * 3600); config.controller().setLastIteration(0); diff --git a/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/MultiModalTripRouterTest.java b/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/MultiModalTripRouterTest.java index a939cb76327..ea6ba8549c3 100644 --- a/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/MultiModalTripRouterTest.java +++ b/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/MultiModalTripRouterTest.java @@ -39,6 +39,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.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Injector; @@ -73,6 +74,7 @@ void testRouteLeg() { config.routing().addParam("teleportedModeSpeed_ride", "15.0"); config.routing().addParam("teleportedModeSpeed_undefined", "13.88888888888889"); config.routing().addParam("teleportedModeSpeed_walk", "1.34"); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.scoring().addModeParams( new ScoringConfigGroup.ModeParams( TransportMode.ride ) ); final Scenario scenario = ScenarioUtils.createScenario(config); diff --git a/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/RunMultimodalExampleTest.java b/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/RunMultimodalExampleTest.java index 3a3c2101c9a..4cad691e8b5 100644 --- a/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/RunMultimodalExampleTest.java +++ b/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/RunMultimodalExampleTest.java @@ -20,8 +20,9 @@ void main(){ URL url = IOUtils.extendUrl( ExamplesUtils.getTestScenarioURL( "berlin" ), "config_multimodal.xml" );; String [] args = { url.toString(), - "--config:controler.outputDirectory" , utils.getOutputDirectory() - } ; + "--config:controler.outputDirectory" , utils.getOutputDirectory(), + "--config:routing.networkRouteConsistencyCheck", "disable" + } ;; try{ RunMultimodalExample.main( args ); diff --git a/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/pt/MultiModalPTCombinationTest.java b/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/pt/MultiModalPTCombinationTest.java index ca3a78fce35..78231bd1790 100644 --- a/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/pt/MultiModalPTCombinationTest.java +++ b/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/pt/MultiModalPTCombinationTest.java @@ -85,6 +85,7 @@ void testMultiModalPtCombination() { Scenario scenario = f.scenario; Config config = scenario.getConfig(); config.controller().setOutputDirectory(utils.getOutputDirectory()); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); MultiModalConfigGroup mmcg = new MultiModalConfigGroup(); mmcg.setMultiModalSimulationEnabled(true); diff --git a/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/simengine/StuckAgentTest.java b/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/simengine/StuckAgentTest.java index 790922dd590..d0776605026 100644 --- a/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/simengine/StuckAgentTest.java +++ b/contribs/multimodal/src/test/java/org/matsim/contrib/multimodal/simengine/StuckAgentTest.java @@ -46,6 +46,7 @@ import org.matsim.contrib.multimodal.config.MultiModalConfigGroup; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; import org.matsim.core.controler.Controler; import org.matsim.core.events.handler.BasicEventHandler; @@ -69,7 +70,7 @@ public class StuckAgentTest { void testStuckEvents() { Config config = ConfigUtils.createConfig(); config.controller().setOutputDirectory(utils.getOutputDirectory()); - + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.qsim().setEndTime(24*3600); config.controller().setLastIteration(0); diff --git a/contribs/noise/src/test/java/org/matsim/contrib/noise/NoiseConfigGroupIT.java b/contribs/noise/src/test/java/org/matsim/contrib/noise/NoiseConfigGroupIT.java index d5b61b0b590..1b5e2db9ccd 100644 --- a/contribs/noise/src/test/java/org/matsim/contrib/noise/NoiseConfigGroupIT.java +++ b/contribs/noise/src/test/java/org/matsim/contrib/noise/NoiseConfigGroupIT.java @@ -22,17 +22,18 @@ */ package org.matsim.contrib.noise; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.matsim.api.core.v01.Scenario; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy; import org.matsim.core.scenario.ScenarioUtils; -import org.matsim.testcases.MatsimTestUtils; - +import org.matsim.testcases.MatsimTestUtils; + /** * @author ikaddoura * @@ -41,9 +42,9 @@ public class NoiseConfigGroupIT { @RegisterExtension - private MatsimTestUtils testUtils = new MatsimTestUtils(); - - @Test + private MatsimTestUtils testUtils = new MatsimTestUtils(); + + @Test final void test0(){ String configFile = testUtils.getPackageInputDirectory() + "NoiseConfigGroupTest/config0.xml"; @@ -69,14 +70,15 @@ final void test0(){ String tunnelLinkIds = noiseParameters.getTunnelLinkIDsSet().toArray()[0] + "," + noiseParameters.getTunnelLinkIDsSet().toArray()[1]; Assertions.assertEquals("link1,link2", tunnelLinkIds, "wrong config parameter"); - } - - @Test + } + + @Test final void test1(){ String configFile = testUtils.getPackageInputDirectory() + "NoiseConfigGroupTest/config1.xml"; Config config = ConfigUtils.loadConfig(configFile, new NoiseConfigGroup()); config.controller().setOutputDirectory(testUtils.getOutputDirectory()); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); NoiseConfigGroup noiseParameters = (NoiseConfigGroup) config.getModule("noise"); diff --git a/contribs/roadpricing/src/test/java/org/matsim/contrib/roadpricing/CalcPaidTollTest.java b/contribs/roadpricing/src/test/java/org/matsim/contrib/roadpricing/CalcPaidTollTest.java index 85c90cb3e79..9cfbfca06ed 100644 --- a/contribs/roadpricing/src/test/java/org/matsim/contrib/roadpricing/CalcPaidTollTest.java +++ b/contribs/roadpricing/src/test/java/org/matsim/contrib/roadpricing/CalcPaidTollTest.java @@ -34,6 +34,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.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.mobsim.qsim.QSimBuilder; @@ -58,6 +59,7 @@ public class CalcPaidTollTest { @Test void testDistanceToll() { Config config = ConfigUtils.loadConfig(utils.getClassInputDirectory() + "config.xml"); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); final String tollFile = utils.getClassInputDirectory() + "/roadpricing1.xml"; Id id1 = Id.create("1", Person.class); @@ -94,6 +96,7 @@ void testDistanceToll() { @Test void testAreaToll() { Config config = ConfigUtils.loadConfig(utils.getClassInputDirectory() + "config.xml"); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); final String tollFile = utils.getClassInputDirectory() + "/roadpricing2.xml"; Id id1 = Id.create("1", Person.class); @@ -145,6 +148,7 @@ void testAreaToll() { @Test void testCordonToll() { Config config = ConfigUtils.loadConfig(utils.getClassInputDirectory() + "config.xml"); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); final String tollFile = utils.getClassInputDirectory() + "/roadpricing3.xml"; Id id1 = Id.create("1", Person.class); diff --git a/contribs/roadpricing/src/test/java/org/matsim/contrib/roadpricing/PlansCalcRouteWithTollOrNotTest.java b/contribs/roadpricing/src/test/java/org/matsim/contrib/roadpricing/PlansCalcRouteWithTollOrNotTest.java index e75ed598afa..e5651f02648 100644 --- a/contribs/roadpricing/src/test/java/org/matsim/contrib/roadpricing/PlansCalcRouteWithTollOrNotTest.java +++ b/contribs/roadpricing/src/test/java/org/matsim/contrib/roadpricing/PlansCalcRouteWithTollOrNotTest.java @@ -36,6 +36,7 @@ import org.matsim.api.core.v01.population.PlanElement; import org.matsim.api.core.v01.population.Population; import org.matsim.core.config.Config; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.RoutingConfigGroup.AccessEgressType; import org.matsim.core.controler.Injector; import org.matsim.core.controler.NewControlerModule; @@ -74,6 +75,7 @@ public class PlansCalcRouteWithTollOrNotTest { @Test void testBestAlternatives() { Config config = matsimTestUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles); MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); RoadPricingTestUtils.createNetwork2(scenario); @@ -180,6 +182,7 @@ private PlansCalcRouteWithTollOrNot testee(final Scenario scenario, final RoadPr @Test void testTolledActLink() { Config config = matsimTestUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); RoadPricingTestUtils.createNetwork2(scenario); @@ -206,6 +209,7 @@ void testTolledActLink() { @Test void testAllAlternativesTolled() { Config config = matsimTestUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); RoadPricingTestUtils.createNetwork2(scenario); @@ -245,6 +249,7 @@ private static Leg getLeg3(Config config, Population population, Id id1) @Test void testOutsideTollTime() { Config config = matsimTestUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); RoadPricingTestUtils.createNetwork2(scenario); diff --git a/contribs/roadpricing/src/test/java/org/matsim/contrib/roadpricing/TollTravelCostCalculatorTest.java b/contribs/roadpricing/src/test/java/org/matsim/contrib/roadpricing/TollTravelCostCalculatorTest.java index 84052e33d8c..4eecbfef4df 100644 --- a/contribs/roadpricing/src/test/java/org/matsim/contrib/roadpricing/TollTravelCostCalculatorTest.java +++ b/contribs/roadpricing/src/test/java/org/matsim/contrib/roadpricing/TollTravelCostCalculatorTest.java @@ -24,6 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import java.util.List; +import java.util.Map; import jakarta.inject.Provider; import org.junit.jupiter.api.Test; @@ -74,6 +75,7 @@ public class TollTravelCostCalculatorTest { @Test void testDisutilityResults() { Config config = ConfigUtils.createConfig() ; + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); Scenario scenario = ScenarioUtils.createScenario(config) ; RoadPricingTestUtils.createNetwork2((MutableScenario)scenario); @@ -124,11 +126,12 @@ void testDisutilityResults() { @Test void testDistanceTollRouter() { Config config = utils.createConfig(); - MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); RoadPricingTestUtils.createNetwork2(scenario); Network network = scenario.getNetwork(); // a basic toll where only the morning hours are tolled - RoadPricingSchemeImpl toll = RoadPricingUtils.addOrGetMutableRoadPricingScheme(ScenarioUtils.createScenario( ConfigUtils.createConfig() ) ); + RoadPricingSchemeImpl toll = RoadPricingUtils.addOrGetMutableRoadPricingScheme(ScenarioUtils.createScenario( config ) ); toll.setType(RoadPricingScheme.TOLL_TYPE_DISTANCE); toll.addLink(Id.create("5", Link.class)); toll.addLink(Id.create("11", Link.class)); @@ -209,11 +212,12 @@ void testDistanceTollRouter() { @Test void testLinkTollRouter() { Config config = utils.createConfig(); - MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); RoadPricingTestUtils.createNetwork2(scenario); Network network = scenario.getNetwork(); // a basic toll where only the morning hours are tolled - RoadPricingSchemeImpl toll = RoadPricingUtils.addOrGetMutableRoadPricingScheme(ScenarioUtils.createScenario( ConfigUtils.createConfig() ) ); + RoadPricingSchemeImpl toll = RoadPricingUtils.addOrGetMutableRoadPricingScheme(ScenarioUtils.createScenario( config ) ); toll.setType(RoadPricingScheme.TOLL_TYPE_LINK); toll.addLink(Id.create("5", Link.class)); toll.addLink(Id.create("11", Link.class)); @@ -304,11 +308,11 @@ void testLinkTollRouter() { @Test void testCordonTollRouter() { Config config = utils.createConfig(); - MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); RoadPricingTestUtils.createNetwork2(scenario); - Network network = scenario.getNetwork(); // a basic toll where only the morning hours are tolled - RoadPricingSchemeImpl toll = RoadPricingUtils.addOrGetMutableRoadPricingScheme(ScenarioUtils.createScenario( ConfigUtils.createConfig() ) ); + RoadPricingSchemeImpl toll = RoadPricingUtils.addOrGetMutableRoadPricingScheme(ScenarioUtils.createScenario( config ) ); // toll.setType(RoadPricingScheme.TOLL_TYPE_CORDON); toll.setType(RoadPricingScheme.TOLL_TYPE_LINK); toll.addLink(Id.create("5", Link.class)); diff --git a/contribs/signals/src/test/java/org/matsim/contrib/signals/analysis/DelayAnalysisToolTest.java b/contribs/signals/src/test/java/org/matsim/contrib/signals/analysis/DelayAnalysisToolTest.java index 22c34ad8ddc..c7b0852857e 100644 --- a/contribs/signals/src/test/java/org/matsim/contrib/signals/analysis/DelayAnalysisToolTest.java +++ b/contribs/signals/src/test/java/org/matsim/contrib/signals/analysis/DelayAnalysisToolTest.java @@ -25,6 +25,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.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.events.algorithms.EventWriterXML; @@ -140,6 +141,7 @@ private void generateOutput(Scenario scenario, final List eventslist) { private Scenario prepareTest(int numberOfPersons) { Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); Scenario scenario = ScenarioUtils.createScenario(config); createNetwork(scenario); createPopulation(scenario, numberOfPersons); diff --git a/contribs/signals/src/test/java/org/matsim/contrib/signals/builder/Fixture.java b/contribs/signals/src/test/java/org/matsim/contrib/signals/builder/Fixture.java index 63f18a921a9..d51e4727e4b 100644 --- a/contribs/signals/src/test/java/org/matsim/contrib/signals/builder/Fixture.java +++ b/contribs/signals/src/test/java/org/matsim/contrib/signals/builder/Fixture.java @@ -45,6 +45,7 @@ import org.matsim.contrib.signals.model.SignalSystem; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; @@ -87,6 +88,7 @@ private Config createConfigOneSignal(Boolean useIntergreens) { } Config conf = ConfigUtils.createConfig(testUtils.classInputResourcePath()); conf.controller().setOverwriteFileSetting(OverwriteFileSetting.overwriteExistingFiles); + conf.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); ActivityParams params = new ActivityParams("h"); params.setTypicalDuration(24.0 * 3600.0); conf.scoring().addActivityParams(params); diff --git a/contribs/signals/src/test/java/org/matsim/contrib/signals/builder/TravelTimeFourWaysTest.java b/contribs/signals/src/test/java/org/matsim/contrib/signals/builder/TravelTimeFourWaysTest.java index ba97489f89e..ff0080324d1 100644 --- a/contribs/signals/src/test/java/org/matsim/contrib/signals/builder/TravelTimeFourWaysTest.java +++ b/contribs/signals/src/test/java/org/matsim/contrib/signals/builder/TravelTimeFourWaysTest.java @@ -30,6 +30,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.RoutingConfigGroup; import org.matsim.core.controler.*; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; import org.matsim.core.events.EventsUtils; @@ -77,6 +78,8 @@ private Scenario createTestScenario(){ conf.network().setLaneDefinitionsFile("testLaneDefinitions_v2.0.xml"); conf.qsim().setUseLanes(true); conf.qsim().setUsingFastCapacityUpdate(false); + conf.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + SignalSystemsConfigGroup signalsConfig = ConfigUtils.addOrGetModule(conf, SignalSystemsConfigGroup.GROUP_NAME, SignalSystemsConfigGroup.class ); signalsConfig.setUseSignalSystems(true); diff --git a/contribs/signals/src/test/java/org/matsim/contrib/signals/controller/fixedTime/DefaultPlanbasedSignalSystemControllerIT.java b/contribs/signals/src/test/java/org/matsim/contrib/signals/controller/fixedTime/DefaultPlanbasedSignalSystemControllerIT.java index e5f7d325967..91323bda153 100644 --- a/contribs/signals/src/test/java/org/matsim/contrib/signals/controller/fixedTime/DefaultPlanbasedSignalSystemControllerIT.java +++ b/contribs/signals/src/test/java/org/matsim/contrib/signals/controller/fixedTime/DefaultPlanbasedSignalSystemControllerIT.java @@ -61,6 +61,7 @@ import org.matsim.contrib.signals.utils.SignalUtils; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings; import org.matsim.core.controler.AbstractModule; @@ -719,6 +720,7 @@ private void createSignals() { private Config defineConfig() { Config config = ConfigUtils.createConfig(); config.controller().setOutputDirectory(testUtils.getOutputDirectory()); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); // set number of iterations config.controller().setLastIteration(0); diff --git a/contribs/socnetsim/src/test/java/org/matsim/contrib/socnetsim/jointtrips/router/JointTripRouterFactoryTest.java b/contribs/socnetsim/src/test/java/org/matsim/contrib/socnetsim/jointtrips/router/JointTripRouterFactoryTest.java index 993cfdb52bb..71b3dbf77b9 100644 --- a/contribs/socnetsim/src/test/java/org/matsim/contrib/socnetsim/jointtrips/router/JointTripRouterFactoryTest.java +++ b/contribs/socnetsim/src/test/java/org/matsim/contrib/socnetsim/jointtrips/router/JointTripRouterFactoryTest.java @@ -48,6 +48,7 @@ import org.matsim.contrib.socnetsim.jointtrips.population.PassengerRoute; import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Injector; import org.matsim.core.events.EventsUtils; @@ -95,6 +96,8 @@ private static Scenario createScenario() { Scenario sc = ScenarioUtils.createScenario( ConfigUtils.createConfig() ); + sc.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + Network net = (Network) sc.getNetwork(); final Id id5 = node1; Node node1inst = NetworkUtils.createAndAddNode(net, id5, new Coord((double) 0, (double) 1)); diff --git a/contribs/vsp/src/test/java/org/matsim/integration/drtAndPt/PtAlongALine2Test.java b/contribs/vsp/src/test/java/org/matsim/integration/drtAndPt/PtAlongALine2Test.java index d298b4ad003..f90f6112f3a 100644 --- a/contribs/vsp/src/test/java/org/matsim/integration/drtAndPt/PtAlongALine2Test.java +++ b/contribs/vsp/src/test/java/org/matsim/integration/drtAndPt/PtAlongALine2Test.java @@ -111,7 +111,7 @@ void testPtAlongALineWithRaptorAndDrtServiceArea() { // === ROUTER: === config.routing().setAccessEgressType(AccessEgressType.accessEgressModeToLink); - + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.qsim().setVehiclesSource(QSimConfigGroup.VehiclesSource.modeVehicleTypesFromVehiclesData); // (as of today, will also influence router. kai, jun'19) diff --git a/contribs/vsp/src/test/java/playground/vsp/cadyts/marginals/ModalDistanceAndCountsCadytsIT.java b/contribs/vsp/src/test/java/playground/vsp/cadyts/marginals/ModalDistanceAndCountsCadytsIT.java index 0173d5e8552..dbdb804cb9b 100644 --- a/contribs/vsp/src/test/java/playground/vsp/cadyts/marginals/ModalDistanceAndCountsCadytsIT.java +++ b/contribs/vsp/src/test/java/playground/vsp/cadyts/marginals/ModalDistanceAndCountsCadytsIT.java @@ -68,6 +68,7 @@ private Config createConfig() { Config config = ConfigUtils.createConfig(); String[] modes = new String[]{TransportMode.car, TransportMode.bike}; + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.controller().setOutputDirectory(this.utils.getOutputDirectory()); config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); config.controller().setLastIteration(40); diff --git a/contribs/vsp/src/test/java/playground/vsp/cadyts/marginals/ModalDistanceCadytsMultipleDistancesIT.java b/contribs/vsp/src/test/java/playground/vsp/cadyts/marginals/ModalDistanceCadytsMultipleDistancesIT.java index 796380440ad..add356bc92e 100644 --- a/contribs/vsp/src/test/java/playground/vsp/cadyts/marginals/ModalDistanceCadytsMultipleDistancesIT.java +++ b/contribs/vsp/src/test/java/playground/vsp/cadyts/marginals/ModalDistanceCadytsMultipleDistancesIT.java @@ -14,11 +14,8 @@ import org.matsim.contrib.cadyts.general.CadytsScoring; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; -import org.matsim.core.config.groups.ChangeModeConfigGroup; -import org.matsim.core.config.groups.ReplanningConfigGroup; -import org.matsim.core.config.groups.ScoringConfigGroup; +import org.matsim.core.config.groups.*; import org.matsim.core.config.groups.RoutingConfigGroup.AccessEgressType; -import org.matsim.core.config.groups.QSimConfigGroup; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy; @@ -134,6 +131,8 @@ public ScoringFunction createNewScoringFunction(Person person) { private Config createConfig() { Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + String[] modes = new String[]{TransportMode.car, TransportMode.bike}; config.controller().setOutputDirectory(this.utils.getOutputDirectory()); diff --git a/contribs/vsp/src/test/java/playground/vsp/cadyts/marginals/ModalDistanceCadytsSingleDistanceIT.java b/contribs/vsp/src/test/java/playground/vsp/cadyts/marginals/ModalDistanceCadytsSingleDistanceIT.java index 2a7f0fdc897..133a4a48d83 100644 --- a/contribs/vsp/src/test/java/playground/vsp/cadyts/marginals/ModalDistanceCadytsSingleDistanceIT.java +++ b/contribs/vsp/src/test/java/playground/vsp/cadyts/marginals/ModalDistanceCadytsSingleDistanceIT.java @@ -139,7 +139,7 @@ private Config createConfig() { Config config = ConfigUtils.createConfig(); String[] modes = new String[]{TransportMode.car, TransportMode.bike}; - + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.controller().setOutputDirectory(this.utils.getOutputDirectory()); config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists); config.controller().setLastIteration(20); diff --git a/contribs/vsp/src/test/java/playground/vsp/congestion/CombinedFlowAndStorageDelayTest.java b/contribs/vsp/src/test/java/playground/vsp/congestion/CombinedFlowAndStorageDelayTest.java index 755df67d97d..b8b5dfa08b2 100644 --- a/contribs/vsp/src/test/java/playground/vsp/congestion/CombinedFlowAndStorageDelayTest.java +++ b/contribs/vsp/src/test/java/playground/vsp/congestion/CombinedFlowAndStorageDelayTest.java @@ -40,6 +40,7 @@ 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.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.mobsim.qsim.QSimBuilder; @@ -163,6 +164,7 @@ private class createPseudoInputs { public createPseudoInputs(){ config=ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); this.scenario = ScenarioUtils.loadScenario(config); network = (Network) this.scenario.getNetwork(); population = this.scenario.getPopulation(); diff --git a/contribs/vsp/src/test/java/playground/vsp/congestion/CorridorNetworkTest.java b/contribs/vsp/src/test/java/playground/vsp/congestion/CorridorNetworkTest.java index ae8f04f18a4..be42f9e8a5a 100644 --- a/contribs/vsp/src/test/java/playground/vsp/congestion/CorridorNetworkTest.java +++ b/contribs/vsp/src/test/java/playground/vsp/congestion/CorridorNetworkTest.java @@ -42,6 +42,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.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.events.handler.BasicEventHandler; @@ -68,7 +69,7 @@ public class CorridorNetworkTest { void v3Test(){ CorridorNetworkAndPlans inputs = new CorridorNetworkAndPlans(); Scenario sc = inputs.getDesiredScenario(); - + List v3_events = getCongestionEvents("v3", sc); Assertions.assertEquals(6, v3_events.size(), MatsimTestUtils.EPSILON, "wrong number of congestion events"); @@ -83,27 +84,27 @@ void v3Test(){ } else if ( event.getAffectedAgentId().equals(Id.createPersonId(3)) ) { // agent 3 is delayed on link 2 due to agent 2, 1 if(event.getCausingAgentId().equals(Id.createPersonId(2))) { - + Assertions.assertEquals(4, event.getDelay(), MatsimTestUtils.EPSILON, "wrong delay"); - + } else { - + Assertions.assertEquals(2, event.getDelay(), MatsimTestUtils.EPSILON, "wrong delay"); - + } - } else if(event.getAffectedAgentId().equals(Id.createPersonId(4))){ // agent 4 is first delayed due to spill back on link 1 (3 sec) and then on link 2 (6sec) + } else if(event.getAffectedAgentId().equals(Id.createPersonId(4))){ // agent 4 is first delayed due to spill back on link 1 (3 sec) and then on link 2 (6sec) if(event.getCausingAgentId().equals(Id.createPersonId(3))){ - + Assertions.assertEquals(4, event.getDelay(), MatsimTestUtils.EPSILON, "wrong delay"); - + } else if (event.getCausingAgentId().equals(Id.createPersonId(2))){ - + Assertions.assertEquals(4, event.getDelay(), MatsimTestUtils.EPSILON, "wrong delay"); - + } else { - + Assertions.assertEquals("1", event.getCausingAgentId().toString(), "wrong causing agent"); Assertions.assertEquals(1, event.getDelay(), MatsimTestUtils.EPSILON, "wrong delay"); } @@ -130,35 +131,35 @@ void v4Test(){ } else if ( event.getAffectedAgentId().equals(Id.createPersonId(3)) ) { // agent 3 is delayed on link 2 due to agent 2, 1 if(event.getCausingAgentId().equals(Id.createPersonId(2))) { - + Assertions.assertEquals(4, event.getDelay(), MatsimTestUtils.EPSILON, "wrong delay"); - + } else { - + Assertions.assertEquals(2, event.getDelay(), MatsimTestUtils.EPSILON, "wrong delay"); - + } - } else if(event.getAffectedAgentId().equals(Id.createPersonId(4))){ // agent 4 is first delayed due to spill back on link 1 (3 sec) and then on link 2 (6sec) + } else if(event.getAffectedAgentId().equals(Id.createPersonId(4))){ // agent 4 is first delayed due to spill back on link 1 (3 sec) and then on link 2 (6sec) if(event.getCausingAgentId().equals(Id.createPersonId(3)) ){ if ( event.getTime() == 10.0 ) { - + Assertions.assertEquals(3, event.getDelay(), MatsimTestUtils.EPSILON, "wrong delay"); - + } else { - + Assertions.assertEquals(18.0, event.getTime(), MatsimTestUtils.EPSILON, "wrong congestion event time"); Assertions.assertEquals(4, event.getDelay(), MatsimTestUtils.EPSILON, "wrong delay"); - + } - + } else { - + Assertions.assertEquals("2", event.getCausingAgentId().toString(), "wrong causing agent"); Assertions.assertEquals(2, event.getDelay(), MatsimTestUtils.EPSILON, "wrong delay"); - - } + + } } } } @@ -173,7 +174,7 @@ private List getCongestionEvents (String congestionPricingImpl, events.addHandler( new CongestionEventHandler() { @Override - public void reset(int iteration) { + public void reset(int iteration) { } @Override @@ -188,7 +189,7 @@ public void handleEvent(CongestionEvent event) { LogManager.getLogger( CorridorNetworkTest.class ).warn( event ); } }); - + if(congestionPricingImpl.equalsIgnoreCase("v3")) { events.addHandler(new CongestionHandlerImplV3(events, (MutableScenario)sc)); } @@ -204,10 +205,10 @@ public void handleEvent(CongestionEvent event) { private class CorridorNetworkAndPlans { /** - * generates network with 3 links. - *

+ * generates network with 3 links. + *

*

o--0---o---1---o---2---o---3---o - *

+ *

*/ Scenario scenario; Config config; @@ -221,6 +222,7 @@ private class CorridorNetworkAndPlans { CorridorNetworkAndPlans(){ config=ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); this.scenario = ScenarioUtils.loadScenario(config); network = (Network) this.scenario.getNetwork(); population = this.scenario.getPopulation(); diff --git a/contribs/vsp/src/test/java/playground/vsp/congestion/MarginalCongestionHandlerFlowQueueQsimTest.java b/contribs/vsp/src/test/java/playground/vsp/congestion/MarginalCongestionHandlerFlowQueueQsimTest.java index 94c1f09f388..576d33e53ed 100644 --- a/contribs/vsp/src/test/java/playground/vsp/congestion/MarginalCongestionHandlerFlowQueueQsimTest.java +++ b/contribs/vsp/src/test/java/playground/vsp/congestion/MarginalCongestionHandlerFlowQueueQsimTest.java @@ -45,6 +45,7 @@ import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.config.Config; import org.matsim.core.config.groups.QSimConfigGroup; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.mobsim.qsim.QSim; @@ -301,6 +302,7 @@ private Scenario loadScenario1() { // -----link1---- ----link2---- ----link3---- ----link4---- ----link5---- Config config = testUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); QSimConfigGroup qSimConfigGroup = config.qsim(); qSimConfigGroup.setFlowCapFactor(1.0); qSimConfigGroup.setStorageCapFactor(1.0); diff --git a/contribs/vsp/src/test/java/playground/vsp/congestion/MarginalCongestionHandlerFlowSpillbackQueueQsimTest.java b/contribs/vsp/src/test/java/playground/vsp/congestion/MarginalCongestionHandlerFlowSpillbackQueueQsimTest.java index 1d0f93eb272..a3952fcf727 100644 --- a/contribs/vsp/src/test/java/playground/vsp/congestion/MarginalCongestionHandlerFlowSpillbackQueueQsimTest.java +++ b/contribs/vsp/src/test/java/playground/vsp/congestion/MarginalCongestionHandlerFlowSpillbackQueueQsimTest.java @@ -136,6 +136,7 @@ public class MarginalCongestionHandlerFlowSpillbackQueueQsimTest { final void testFlowAndStorageCongestion_3agents(){ Scenario sc = loadScenario1(); + sc.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); setPopulation1(sc); final List congestionEvents = new ArrayList(); @@ -181,6 +182,7 @@ public void handleEvent(CongestionEvent event) { final void testFlowAndStorageCongestion_3agents_V9() { Scenario sc = loadScenario1(); + sc.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); setPopulation1(sc); final List congestionEvents = new ArrayList(); @@ -222,6 +224,7 @@ public void handleEvent(CongestionEvent event) { final void testFlowAndStorageCongestion_3agents_V8() { Scenario sc = loadScenario1(); + sc.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); setPopulation1(sc); final List congestionEvents = new ArrayList(); @@ -264,6 +267,7 @@ public void handleEvent(CongestionEvent event) { final void testFlowAndStorageCongestion_3agents_V10() { Scenario sc = loadScenario1(); + sc.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); setPopulation1(sc); final List congestionEvents = new ArrayList(); @@ -318,6 +322,7 @@ final void testRouting(){ Config config = ConfigUtils.loadConfig( configFile ) ; config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.none); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); final Scenario scenario = ScenarioUtils.loadScenario( config ); Controler controler = new Controler( scenario ); @@ -454,6 +459,7 @@ else if(((event.getServices().getConfig().controller().getLastIteration())-(even final void testInsertingWaitingVehicles_01(){ Scenario sc = loadScenario4(); + sc.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); setPopulation4(sc); final List congestionEvents = new ArrayList(); @@ -513,6 +519,7 @@ public void handleEvent(LinkLeaveEvent event) { final void testInsertingWaitingVehicles_02(){ Scenario sc = loadScenario5(); + sc.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); setPopulation5(sc); final List congestionEvents = new ArrayList(); @@ -574,6 +581,7 @@ public void handleEvent(LinkLeaveEvent event) { final void testInsertingWaitingVehicles_03(){ Scenario sc = loadScenario4(); + sc.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); setPopulation6(sc); final List congestionEvents = new ArrayList(); diff --git a/contribs/vsp/src/test/java/playground/vsp/congestion/MarginalCongestionHandlerV3Test.java b/contribs/vsp/src/test/java/playground/vsp/congestion/MarginalCongestionHandlerV3Test.java index 1f70380e3de..a9ca7a13c8e 100644 --- a/contribs/vsp/src/test/java/playground/vsp/congestion/MarginalCongestionHandlerV3Test.java +++ b/contribs/vsp/src/test/java/playground/vsp/congestion/MarginalCongestionHandlerV3Test.java @@ -70,7 +70,7 @@ final void testCongestionExample(){ Config config = ConfigUtils.loadConfig( configFile ) ; config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.none); - + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); final Controler controler = new Controler(config); controler.addOverridingModule(new AbstractModule() { @Override diff --git a/contribs/vsp/src/test/java/playground/vsp/congestion/MarginalCongestionPricingTest.java b/contribs/vsp/src/test/java/playground/vsp/congestion/MarginalCongestionPricingTest.java index a398d462e77..4ef9873280a 100644 --- a/contribs/vsp/src/test/java/playground/vsp/congestion/MarginalCongestionPricingTest.java +++ b/contribs/vsp/src/test/java/playground/vsp/congestion/MarginalCongestionPricingTest.java @@ -42,6 +42,7 @@ 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.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.mobsim.qsim.QSimBuilder; @@ -81,6 +82,7 @@ final void implV4Test(){ sc.getVehicles().addVehicleType(car); sc.getConfig().qsim().setVehiclesSource(QSimConfigGroup.VehiclesSource.modeVehicleTypesFromVehiclesData); + sc.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); EventsManager events = EventsUtils.createEventsManager(); diff --git a/contribs/vsp/src/test/java/playground/vsp/congestion/TestForEmergenceTime.java b/contribs/vsp/src/test/java/playground/vsp/congestion/TestForEmergenceTime.java index 9cdfa5b37b1..835ef5a9c9a 100644 --- a/contribs/vsp/src/test/java/playground/vsp/congestion/TestForEmergenceTime.java +++ b/contribs/vsp/src/test/java/playground/vsp/congestion/TestForEmergenceTime.java @@ -40,6 +40,7 @@ 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.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.mobsim.qsim.QSimBuilder; @@ -109,6 +110,7 @@ private List getAffectedPersonId2Delays(String congestionPricin sc.getVehicles().addVehicleType(car); sc.getConfig().qsim().setVehiclesSource(QSimConfigGroup.VehiclesSource.modeVehicleTypesFromVehiclesData); + sc.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); EventsManager events = EventsUtils.createEventsManager(); diff --git a/matsim/src/main/java/org/matsim/core/config/groups/RoutingConfigGroup.java b/matsim/src/main/java/org/matsim/core/config/groups/RoutingConfigGroup.java index a693d0c0297..c38fba94eec 100644 --- a/matsim/src/main/java/org/matsim/core/config/groups/RoutingConfigGroup.java +++ b/matsim/src/main/java/org/matsim/core/config/groups/RoutingConfigGroup.java @@ -104,6 +104,13 @@ public enum AccessEgressType { "settings for helper modes such as for " + TransportMode.non_network_walk; private boolean clearingDefaultModeRoutingParams = false ; + private static final String NETWORK_ROUTE_CONSISTENCY_CHECK = "networkRouteConsistencyCheck"; + private NetworkRouteConsistencyCheck networkRouteConsistencyCheck = NetworkRouteConsistencyCheck.abortOnInconsistency; + + public enum NetworkRouteConsistencyCheck { + disable, abortOnInconsistency + } + /** * @deprecated -- use {@link TeleportedModeParams} to be consistent with xml config. kai, jun'23 */ @@ -519,6 +526,8 @@ public void addParam(final String key, final String value) { } else if (ACCESSEGRESSTYPE.equals( key ) ) { this.setAccessEgressType(AccessEgressType.valueOf(value)); + } else if (NETWORK_ROUTE_CONSISTENCY_CHECK.equals(key)){ + this.setNetworkRouteConsistencyCheck(NetworkRouteConsistencyCheck.valueOf(value)); } else { throw new IllegalArgumentException(key); @@ -532,6 +541,7 @@ public final Map getParams() { map.put( CLEAR_MODE_ROUTING_PARAMS, Boolean.toString( this.clearingDefaultModeRoutingParams ) ) ; map.put( RANDOMNESS, Double.toString( this.routingRandomness ) ) ; map.put( ACCESSEGRESSTYPE, getAccessEgressType().toString()) ; + map.put(NETWORK_ROUTE_CONSISTENCY_CHECK, NetworkRouteConsistencyCheck.abortOnInconsistency.toString()); return map; } @@ -547,6 +557,7 @@ public final Map getComments() { + "Technically the width parameter of a log-normal distribution. 3.0 seems to be a good value. " ) ; map.put( CLEAR_MODE_ROUTING_PARAMS, CLEAR_MODE_ROUTING_PARAMS_CMT ) ; map.put(ACCESSEGRESSTYPE, ACCESSEGRESSTYPE_CMT); + map.put(NETWORK_ROUTE_CONSISTENCY_CHECK, "Defines whether the network consistency should be checked."); return map; } @@ -650,6 +661,16 @@ public void setRoutingRandomness(double routingRandomness) { this.routingRandomness = routingRandomness; } + @StringGetter(NETWORK_ROUTE_CONSISTENCY_CHECK) + public NetworkRouteConsistencyCheck getNetworkRouteConsistencyCheck() { + return networkRouteConsistencyCheck; + } + + @StringSetter(NETWORK_ROUTE_CONSISTENCY_CHECK) + public void setNetworkRouteConsistencyCheck(NetworkRouteConsistencyCheck networkRouteConsistencyCheck) { + this.networkRouteConsistencyCheck = networkRouteConsistencyCheck; + } + @Override protected void checkConsistency(Config config) { super.checkConsistency(config); Set modesRoutedAsTeleportation = this.getModeRoutingParams().keySet(); diff --git a/matsim/src/main/java/org/matsim/core/controler/PrepareForSimImpl.java b/matsim/src/main/java/org/matsim/core/controler/PrepareForSimImpl.java index 359a812887a..fc9be952cc3 100644 --- a/matsim/src/main/java/org/matsim/core/controler/PrepareForSimImpl.java +++ b/matsim/src/main/java/org/matsim/core/controler/PrepareForSimImpl.java @@ -34,11 +34,8 @@ import org.matsim.api.core.v01.population.Person; import org.matsim.api.core.v01.population.Plan; import org.matsim.api.core.v01.population.Population; -import org.matsim.core.config.groups.FacilitiesConfigGroup; -import org.matsim.core.config.groups.GlobalConfigGroup; -import org.matsim.core.config.groups.PlansConfigGroup; +import org.matsim.core.config.groups.*; import org.matsim.core.config.groups.PlansConfigGroup.HandlingOfPlansWithoutRoutingMode; -import org.matsim.core.config.groups.QSimConfigGroup; import org.matsim.core.gbl.Gbl; import org.matsim.core.network.NetworkUtils; import org.matsim.core.network.algorithms.TransportModeNetworkFilter; @@ -331,6 +328,11 @@ private void createAndAddVehicleIfNecessary(Id vehicleId, VehicleType v private static boolean insistingOnPlansWithoutRoutingModeLogWarnNotShownYet = true; + /** + * Make sure that each leg has a routing mode. + * Legs with outdated fallback modes will be treated in a special way. + * Legs with no routing mode will have their network mode as routing mode. + */ private void adaptOutdatedPlansForRoutingMode() { for (Person person : population.getPersons().values()) { for (Plan plan : person.getPlans()) { @@ -369,8 +371,7 @@ private void adaptOutdatedPlansForRoutingMode() { // there is only a single leg (e.g. after Trips2Legs and a mode choice replanning // module) - String oldMainMode = replaceOutdatedFallbackModesAndReturnOldMainMode(legs.get(0), - null); + String oldMainMode = replaceOutdatedFallbackModesAndReturnOldMainMode(legs.get(0), null); if (oldMainMode != null) { routingMode = oldMainMode; TripStructureUtils.setRoutingMode(legs.get(0), routingMode); diff --git a/matsim/src/main/java/org/matsim/core/network/NetworkUtils.java b/matsim/src/main/java/org/matsim/core/network/NetworkUtils.java index 9e98fbe2269..9e7da2c044f 100644 --- a/matsim/src/main/java/org/matsim/core/network/NetworkUtils.java +++ b/matsim/src/main/java/org/matsim/core/network/NetworkUtils.java @@ -21,6 +21,7 @@ package org.matsim.core.network; import java.util.*; +import java.util.function.Function; import javax.annotation.Nullable; @@ -38,6 +39,7 @@ import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.NetworkConfigGroup; import org.matsim.core.gbl.Gbl; +import org.matsim.core.network.algorithms.NetworkModeRestriction; import org.matsim.core.network.algorithms.NetworkSimplifier; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.utils.geometry.CoordUtils; @@ -1018,8 +1020,30 @@ public static boolean addDisallowedNextLinks(Link link, String mode, List modes = new HashSet<>(link.getAllowedModes()); + modes.add(mode); + link.setAllowedModes(modes); + } + + public static void removeAllowedMode(Link link, String mode) { + Set modes = new HashSet<>(link.getAllowedModes()); + modes.remove(mode); + link.setAllowedModes(modes); + } + + /** + * Removes the given modes from the links and runs the network cleaner afterwards. Thus, some more links may be restricted to keep the network consistent. + * That means, each link can be reached from each other link. + * @param network the network + * @param modesToRemoveByLinkId map of modes that should be removed from the links + */ + public static void restrictModesAndCleanNetwork(Network network, Function, Set> modesToRemoveByLinkId) { + new NetworkModeRestriction(modesToRemoveByLinkId).run(network); + } } diff --git a/matsim/src/main/java/org/matsim/core/network/algorithms/NetworkCleaner.java b/matsim/src/main/java/org/matsim/core/network/algorithms/NetworkCleaner.java index 89965f05f2e..9df6cd6d896 100644 --- a/matsim/src/main/java/org/matsim/core/network/algorithms/NetworkCleaner.java +++ b/matsim/src/main/java/org/matsim/core/network/algorithms/NetworkCleaner.java @@ -75,7 +75,7 @@ private Map, Node> findCluster(final Node startNode, final Network netw pendingBackward.add(startNode); // step through the network in forward mode - while (pendingForward.size() > 0) { + while (!pendingForward.isEmpty()) { int idx = pendingForward.size() - 1; Node currNode = pendingForward.remove(idx); // get the last element to prevent object shifting in the array for (Link link : currNode.getOutLinks().values()) { @@ -89,7 +89,7 @@ private Map, Node> findCluster(final Node startNode, final Network netw } // now step through the network in backward mode - while (pendingBackward.size() > 0) { + while (!pendingBackward.isEmpty()) { int idx = pendingBackward.size()-1; Node currNode = pendingBackward.remove(idx); // get the last element to prevent object shifting in the array for (Link link : currNode.getInLinks().values()) { @@ -112,7 +112,7 @@ private Map, Node> findCluster(final Node startNode, final Network netw /** * Searches the biggest cluster in the given Network. The Network is not modified. */ - public Map, Node> searchBiggestCluster(Network network) { + private Map, Node> searchBiggestCluster(Network network) { final Map, Node> visitedNodes = new TreeMap<>(); Map, Node> biggestCluster = new TreeMap<>(); @@ -142,11 +142,11 @@ public Map, Node> searchBiggestCluster(Network network) { return biggestCluster; } - /** + /** * Reducing the network so it only contains nodes included in the biggest Cluster. * Loop over all nodes and check if they are in the cluster, if not, remove them from the network */ - public static void reduceToBiggestCluster(Network network, Map, Node> biggestCluster) { + private static void reduceToBiggestCluster(Network network, Map, Node> biggestCluster) { List allNodes2 = new ArrayList<>(network.getNodes().values()); for (Node node : allNodes2) { if (!biggestCluster.containsKey(node.getId())) { @@ -157,7 +157,7 @@ public static void reduceToBiggestCluster(Network network, Map, Node> b network.getLinks().size() + " links."); log.info("done."); } - + @Override public void run(final Network network) { Map, Node> biggestCluster = this.searchBiggestCluster(network); diff --git a/matsim/src/main/java/org/matsim/core/network/algorithms/NetworkModeRestriction.java b/matsim/src/main/java/org/matsim/core/network/algorithms/NetworkModeRestriction.java new file mode 100644 index 00000000000..c2457da636c --- /dev/null +++ b/matsim/src/main/java/org/matsim/core/network/algorithms/NetworkModeRestriction.java @@ -0,0 +1,88 @@ +package org.matsim.core.network.algorithms; + +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.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.api.core.v01.network.Node; +import org.matsim.core.api.internal.NetworkRunnable; +import org.matsim.core.network.NetworkUtils; + +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * This class changes the allowed modes of links in a network and cleans the network afterward. + * I.e. for each mode, it removes by running the {@link NetworkCleaner} that mode for links, that are not reachable from all other links + * or from which all other links are not reachable. + */ +public class NetworkModeRestriction implements NetworkRunnable { + private static final Logger log = LogManager.getLogger(NetworkModeRestriction.class); + + private final Function, Set> modesToRemoveByLinkId; + + public NetworkModeRestriction(Function, Set> modesToRemoveByLinkId) { + this.modesToRemoveByLinkId = modesToRemoveByLinkId; + } + + public NetworkModeRestriction(Map, Set> modesToRemoveByLinkId) { + this.modesToRemoveByLinkId = l -> modesToRemoveByLinkId.getOrDefault(l, Set.of()); + } + + @Override + public void run(Network network) { + Map modeCountBefore = countModes(network); + + applyModeChanges(network); + cleanNetworkPerMode(network); + removeLinksWithNoModes(network); + removeNodesWithNoLinks(network); + + Map modeCountAfter = countModes(network); + logModeCountDifference(modeCountBefore, modeCountAfter); + } + + private void applyModeChanges(Network network) { + for (Map.Entry, ? extends Link> link : network.getLinks().entrySet()) { + this.modesToRemoveByLinkId.apply(link.getKey()).forEach(m -> NetworkUtils.removeAllowedMode(link.getValue(), m)); + } + } + + private void cleanNetworkPerMode(Network network) { + Set modes = network.getLinks().values().stream().flatMap(l -> l.getAllowedModes().stream()).collect(Collectors.toSet()); + for (String mode : modes) { + MultimodalNetworkCleaner multimodalNetworkCleaner = new MultimodalNetworkCleaner(network); + multimodalNetworkCleaner.run(Set.of(mode)); + } + } + + private void removeLinksWithNoModes(Network network) { + network.getLinks().values().stream() + .filter(l -> l.getAllowedModes().isEmpty()) + .map(Link::getId) + .forEach(network::removeLink); + } + + private void removeNodesWithNoLinks(Network network) { + network.getNodes().values().stream() + .filter(n -> n.getInLinks().isEmpty() && n.getOutLinks().isEmpty()) + .map(Node::getId) + .forEach(network::removeNode); + } + + private void logModeCountDifference(Map modeCountBefore, Map modeCountAfter) { + modeCountBefore.forEach((mode, countBefore) -> { + long countAfter = modeCountAfter.getOrDefault(mode, 0L); + log.info("Removed mode {} from {} links.", mode, countBefore - countAfter); + }); + } + + private static Map countModes(Network network) { + return network.getLinks().values().stream() + .flatMap(l -> l.getAllowedModes().stream()) + .collect(Collectors.groupingBy(m -> m, Collectors.counting())); + } +} diff --git a/matsim/src/main/java/org/matsim/core/population/PopulationUtils.java b/matsim/src/main/java/org/matsim/core/population/PopulationUtils.java index 5755982b6ed..5b62242de72 100644 --- a/matsim/src/main/java/org/matsim/core/population/PopulationUtils.java +++ b/matsim/src/main/java/org/matsim/core/population/PopulationUtils.java @@ -57,6 +57,7 @@ import org.matsim.core.config.groups.PlansConfigGroup; import org.matsim.core.gbl.Gbl; import org.matsim.core.gbl.MatsimRandom; +import org.matsim.core.population.algorithms.PersonRouteCheck; import org.matsim.core.population.io.PopulationReader; import org.matsim.core.population.io.PopulationWriter; import org.matsim.core.population.io.StreamingPopulationReader; @@ -1295,4 +1296,16 @@ public static void insertVehicleIdsIntoPersonAttributes(Person person, Map modes = new HashSet(); - modes.add(TransportMode.car); - filter.filter(net, modes); + filter.filter(net, Set.of(TransportMode.car)); } this.xy2links = new XY2Links(net, scenario.getActivityFacilities()); @@ -110,121 +106,32 @@ public void run(final Person person) { log.warn("Person " + person.getId() + " has no plans!"); return; } - + // yyyyyy need to find out somewhere here if the access/egress legs of the incoming plans // are consistent with the config setting. Otherwise need to re-route all of them. kai, jul'18 - // make sure all the plans have valid act-locations and valid routes for (Plan plan : person.getPlans()) { boolean needsXY2Links = false; boolean needsReRoute = false; - - // for backward compatibility: add routingMode to legs if not present - for (Trip trip : TripStructureUtils.getTrips(plan.getPlanElements())) { - List legs = trip.getLegsOnly(); - if (legs.size() >= 1) { - String routingMode = TripStructureUtils.getRoutingMode(legs.get(0)); - - for (Leg leg : legs) { - // check all legs either have the same routing mode or all have routingMode==null - String existingRoutingMode = TripStructureUtils.getRoutingMode(leg); - if (existingRoutingMode == null) { - if (routingMode == null) { - // outdated initial plan without routingMode - } else { - String errorMessage = "Found a mixed trip, some legs with routingMode and others without. " - + "This is inconsistent. Agent id: " + person.getId().toString(); - log.error(errorMessage); - throw new RuntimeException(errorMessage); - } - } else { - if (!routingMode.equals(existingRoutingMode)) { - String errorMessage = "Found a trip whose legs have different routingModes. " - + "This is inconsistent. Agent id: " + person.getId().toString(); - log.error(errorMessage); - throw new RuntimeException(errorMessage); - } - } - } - // add routing mode - if (routingMode == null) { - if (legs.size() == 1) { - // there is only a single leg (e.g. after Trips2Legs and a mode choice replanning module) - routingMode = legs.get(0).getMode(); - if (routingMode.equals(TransportMode.transit_walk)) { - String errorMessage = "Found a trip of only one leg of mode transit_walk. " - + "This should not happen during simulation since transit_walk was replaced by walk and " - + "routingMode. Agent id: " + person.getId().toString(); - log.error(errorMessage); - throw new RuntimeException(errorMessage); - } - TripStructureUtils.setRoutingMode(legs.get(0), routingMode); - } else { - String errorMessage = "Found a trip whose legs have no routingMode. " - + "This is only allowed for (outdated) input plans, not during simulation (after PrepareForSim). Agent id: " - + person.getId().toString(); - log.error(errorMessage); - throw new RuntimeException(errorMessage); - } - } - } - } - - for (PlanElement pe : plan.getPlanElements()) { - if (pe instanceof Activity) { - Activity act = (Activity) pe; - if ( act.getLinkId() == null // neither activity nor facility has a link - && - //this check is necessary here, else, XY2Links will put the link/coord back to activity which is clear violation of facilitiesConfigGroup.removingLinksAndCoordinates =true. Amit July'18 - ( act.getFacilityId() == null - || this.activityFacilities.getFacilities().isEmpty() - || this.activityFacilities.getFacilities().get(act.getFacilityId()) == null - || this.activityFacilities.getFacilities().get(act.getFacilityId()).getLinkId() == null) - ) { - needsXY2Links = true; + // for backward compatibility: add routingMode to legs if not present + checkAndAddRoutingMode(plan); + + // make sure all the plans have valid act-locations and valid routes + planLoop: for (PlanElement pe : plan.getPlanElements()) { + switch (pe) { + case Activity act -> { + boolean needsReComputation = needsReComputation(act); + if (needsReComputation) { + needsXY2Links = true; needsReRoute = true; - break; - } - } else if (pe instanceof Leg) { - Leg leg = (Leg) pe; - - if (TripStructureUtils.getRoutingMode(leg) == null) { - String errorMessage = "Routing mode not set for leg :" + leg.toString() + " of agent id " + person.getId().toString(); - log.error( errorMessage ); - throw new RuntimeException( errorMessage ); - } - - if (leg.getRoute() == null) { - needsReRoute = true; - } else if (Double.isNaN(leg.getRoute().getDistance())){ - Double dist = null; - if (leg.getRoute() instanceof NetworkRoute){ - /* So far, 1.0 is always used as relative position on start and end link. - * This means that the end link is considered in route distance and the start link not. - * tt feb'16 - */ - double relativePositionStartLink = scenario.getConfig().global().getRelativePositionOfEntryExitOnLink() ; - double relativePositionEndLink = scenario.getConfig().global().getRelativePositionOfEntryExitOnLink() ; -// dist = RouteUtils.calcDistance((NetworkRoute) leg.getRoute(), relativePositionStartLink, relativePositionEndLink, this.network); - dist = RouteUtils.calcDistance((NetworkRoute) leg.getRoute(), relativePositionStartLink, relativePositionEndLink, scenario.getNetwork() ); - // using the full network for the distance calculation. kai, jul'18 - } else if (leg.getRoute() instanceof ExperimentalTransitRoute) { - // replace deprecated ExperimentalTransitRoute with DefaultTransitPassengerRoute - ExperimentalTransitRoute oldRoute = (ExperimentalTransitRoute) leg.getRoute(); - DefaultTransitPassengerRoute newRoute = new DefaultTransitPassengerRoute( - oldRoute.getStartLinkId(), - oldRoute.getEndLinkId(), - oldRoute.getAccessStopId(), - oldRoute.getEgressStopId(), - oldRoute.getLineId(), - oldRoute.getRouteId()); - leg.setRoute(newRoute); - } - if (dist != null){ - leg.getRoute().setDistance(dist); + break planLoop; } } + case Leg leg -> { + needsReRoute |= needsReRoute(person, leg); + } + default -> throw new IllegalStateException("Unexpected PlanElement: " + pe); } } if (needsXY2Links) { @@ -237,4 +144,135 @@ public void run(final Person person) { } + private boolean needsReRoute(Person person, Leg leg) { + if (TripStructureUtils.getRoutingMode(leg) == null) { + String errorMessage = "Routing mode not set for leg :" + leg + " of agent id " + person.getId().toString(); + log.error( errorMessage ); + throw new RuntimeException( errorMessage ); + } + + if (leg.getRoute() == null) { + return true; + } + + checkModeConsistent(person, leg); + + if(!Double.isNaN(leg.getRoute().getDistance())){ + return false; + } + + adaptRoute(leg); + + return false; + } + + private void adaptRoute(Leg leg) { + if (leg.getRoute() instanceof NetworkRoute){ + /* So far, 1.0 is always used as relative position on start and end link. + * This means that the end link is considered in route distance and the start link not. + * tt feb'16 + */ + double relativePositionStartLink = scenario.getConfig().global().getRelativePositionOfEntryExitOnLink() ; + double relativePositionEndLink = scenario.getConfig().global().getRelativePositionOfEntryExitOnLink() ; +// dist = RouteUtils.calcDistance((NetworkRoute) leg.getRoute(), relativePositionStartLink, relativePositionEndLink, this.network); + double dist = RouteUtils.calcDistance((NetworkRoute) leg.getRoute(), relativePositionStartLink, relativePositionEndLink, scenario.getNetwork() ); + leg.getRoute().setDistance(dist); + // using the full network for the distance calculation. kai, jul'18 + } else if (leg.getRoute() instanceof ExperimentalTransitRoute) { + // replace deprecated ExperimentalTransitRoute with DefaultTransitPassengerRoute + ExperimentalTransitRoute oldRoute = (ExperimentalTransitRoute) leg.getRoute(); + DefaultTransitPassengerRoute newRoute = new DefaultTransitPassengerRoute( + oldRoute.getStartLinkId(), + oldRoute.getEndLinkId(), + oldRoute.getAccessStopId(), + oldRoute.getEgressStopId(), + oldRoute.getLineId(), + oldRoute.getRouteId()); + leg.setRoute(newRoute); + } + } + + private void checkModeConsistent(Person person, Leg leg) { + if(this.scenario.getConfig().routing().getNetworkRouteConsistencyCheck() == RoutingConfigGroup.NetworkRouteConsistencyCheck.disable) { + return; + } + + if(!(leg.getRoute() instanceof NetworkRoute networkRoute)) { + return; + } + + boolean linkModesConsistent = networkRoute.getLinkIds().stream() + .map(l -> scenario.getNetwork().getLinks().get(l)) + .allMatch(l -> l.getAllowedModes().contains(leg.getMode())); + + if(!linkModesConsistent){ + String errorMessage = "Route inconsistent with link modes for: Person " + person.getId() + "; Leg '" + leg + "'"; + log.error(errorMessage + "\n Consider cleaning inconsistent routes by using PopulationUtils.checkRouteModeAndReset()." + + "\n If this is intended, set the routing config parameter 'networkRouteConsistencyCheck' to 'disable'."); + throw new RuntimeException(errorMessage); + } + } + + private boolean needsReComputation(Activity act) { + return act.getLinkId() == null // neither activity nor facility has a link + && + //this check is necessary here, else, XY2Links will put the link/coord back to activity which is clear violation of facilitiesConfigGroup.removingLinksAndCoordinates =true. Amit July'18 + (act.getFacilityId() == null + || this.activityFacilities.getFacilities().isEmpty() + || this.activityFacilities.getFacilities().get(act.getFacilityId()) == null + || this.activityFacilities.getFacilities().get(act.getFacilityId()).getLinkId() == null); + } + + private void checkAndAddRoutingMode(Plan plan) { + for (Trip trip : TripStructureUtils.getTrips(plan.getPlanElements())) { + List legs = trip.getLegsOnly(); + if (!legs.isEmpty()) { + String routingMode = TripStructureUtils.getRoutingMode(legs.get(0)); + + for (Leg leg : legs) { + // check all legs either have the same routing mode or all have routingMode==null + String existingRoutingMode = TripStructureUtils.getRoutingMode(leg); + if (existingRoutingMode == null) { + if (routingMode == null) { + // outdated initial plan without routingMode + } else { + String errorMessage = "Found a mixed trip, some legs with routingMode and others without. " + + "This is inconsistent. Agent id: " + plan.getPerson().getId().toString(); + log.error(errorMessage); + throw new RuntimeException(errorMessage); + } + } else { + if (!routingMode.equals(existingRoutingMode)) { + String errorMessage = "Found a trip whose legs have different routingModes. " + + "This is inconsistent. Agent id: " + plan.getPerson().getId().toString(); + log.error(errorMessage); + throw new RuntimeException(errorMessage); + } + } + } + + // add routing mode + if (routingMode == null) { + if (legs.size() == 1) { + // there is only a single leg (e.g. after Trips2Legs and a mode choice replanning module) + routingMode = legs.get(0).getMode(); + if (routingMode.equals(TransportMode.transit_walk)) { + String errorMessage = "Found a trip of only one leg of mode transit_walk. " + + "This should not happen during simulation since transit_walk was replaced by walk and " + + "routingMode. Agent id: " + plan.getPerson().getId().toString(); + log.error(errorMessage); + throw new RuntimeException(errorMessage); + } + TripStructureUtils.setRoutingMode(legs.get(0), routingMode); + } else { + String errorMessage = "Found a trip whose legs have no routingMode. " + + "This is only allowed for (outdated) input plans, not during simulation (after PrepareForSim). Agent id: " + + plan.getPerson().getId().toString(); + log.error(errorMessage); + throw new RuntimeException(errorMessage); + } + } + } + } + } } diff --git a/matsim/src/main/java/org/matsim/core/population/algorithms/PersonRouteCheck.java b/matsim/src/main/java/org/matsim/core/population/algorithms/PersonRouteCheck.java new file mode 100644 index 00000000000..aca5f9bb976 --- /dev/null +++ b/matsim/src/main/java/org/matsim/core/population/algorithms/PersonRouteCheck.java @@ -0,0 +1,43 @@ +package org.matsim.core.population.algorithms; + +import org.matsim.api.core.v01.network.Network; +import org.matsim.api.core.v01.population.Leg; +import org.matsim.api.core.v01.population.Person; +import org.matsim.api.core.v01.population.Route; +import org.matsim.core.population.routes.NetworkRoute; + +public class PersonRouteCheck implements PersonAlgorithm{ + private final Network network; + + public PersonRouteCheck(Network network) { + this.network = network; + } + + @Override + public void run(Person person) { + person.getPlans().stream() + .flatMap(p -> p.getPlanElements().stream()) + .filter(pe -> pe instanceof Leg) + .map(pe -> (Leg) pe) + .forEach(this::resetRouteIfInconsistentModes); + } + + private void resetRouteIfInconsistentModes(Leg leg) { + Route route = leg.getRoute(); + if (route == null) { + return; + } + + if (!(route instanceof NetworkRoute netRoute)) { + return; + } + + boolean allLinksHaveLegMode = netRoute.getLinkIds().stream() + .map(id -> network.getLinks().get(id)) + .allMatch(link -> link.getAllowedModes().contains(leg.getMode())); + + if (!allLinksHaveLegMode) { + leg.setRoute(null); + } + } +} diff --git a/matsim/src/main/java/org/matsim/core/population/io/PopulationReaderMatsimV6.java b/matsim/src/main/java/org/matsim/core/population/io/PopulationReaderMatsimV6.java index 725ffb83654..54447776f4d 100644 --- a/matsim/src/main/java/org/matsim/core/population/io/PopulationReaderMatsimV6.java +++ b/matsim/src/main/java/org/matsim/core/population/io/PopulationReaderMatsimV6.java @@ -461,6 +461,7 @@ private void startRoute(final Attributes atts) { if ("pt".equals(legMode)) { routeType = "experimentalPt1"; } else if ("car".equals(legMode)) { + //yyyy couldn't we check against all network modes of config here? paul, jul '24 routeType = "links"; } else { routeType = "generic"; diff --git a/matsim/src/main/java/org/matsim/core/router/DefaultRoutingModules.java b/matsim/src/main/java/org/matsim/core/router/DefaultRoutingModules.java index 8e26e960a76..88e99ba95ce 100644 --- a/matsim/src/main/java/org/matsim/core/router/DefaultRoutingModules.java +++ b/matsim/src/main/java/org/matsim/core/router/DefaultRoutingModules.java @@ -60,6 +60,7 @@ public static RoutingModule createTeleportationRouter( String mode, Scenario sce /** * Creates network router without access/egress. */ + @Deprecated // use AccessEgressNetworkRouter instead public static RoutingModule createPureNetworkRouter( String mode, PopulationFactory popFact, Network net, final LeastCostPathCalculator routeAlgo ) { return new NetworkRoutingModule( mode, diff --git a/matsim/src/main/java/org/matsim/core/router/NetworkRoutingModule.java b/matsim/src/main/java/org/matsim/core/router/NetworkRoutingModule.java index 5380f45d47d..82e9b04928f 100644 --- a/matsim/src/main/java/org/matsim/core/router/NetworkRoutingModule.java +++ b/matsim/src/main/java/org/matsim/core/router/NetworkRoutingModule.java @@ -42,6 +42,7 @@ * * @author thibautd */ +@Deprecated // use NetworkRoutingInclAccessEgressModule instead public final class NetworkRoutingModule implements RoutingModule { // I think it makes sense to NOT add the bushwhacking mode directly into here ... // ... since it makes sense be able to to route from facility.getLinkId() to facility.getLinkId(). kai, dec'15 @@ -81,11 +82,13 @@ public List calcRoute(RoutingRequest request) { Link fromLink = this.network.getLinks().get(fromFacility.getLinkId()); if ( fromLink==null ) { + //if an activity takes place on a link which is not part of the modal network, use coord as fallback Gbl.assertNotNull( fromFacility.getCoord() ) ; fromLink = NetworkUtils.getNearestLink( network, fromFacility.getCoord()) ; } Link toLink = this.network.getLinks().get(toFacility.getLinkId()); if ( toLink==null ) { + //if an activity takes place on a link which is not part of the modal network, use coord as fallback Gbl.assertNotNull( toFacility.getCoord() ) ; toLink = NetworkUtils.getNearestLink(network, toFacility.getCoord()); } diff --git a/matsim/src/main/java/org/matsim/core/router/NetworkRoutingProvider.java b/matsim/src/main/java/org/matsim/core/router/NetworkRoutingProvider.java index 667764861ca..a6c00d06942 100644 --- a/matsim/src/main/java/org/matsim/core/router/NetworkRoutingProvider.java +++ b/matsim/src/main/java/org/matsim/core/router/NetworkRoutingProvider.java @@ -29,10 +29,9 @@ import org.matsim.api.core.v01.TransportMode; import org.matsim.api.core.v01.network.Network; import org.matsim.api.core.v01.population.PopulationFactory; -import org.matsim.core.config.groups.NetworkConfigGroup; +import org.matsim.core.config.groups.ControllerConfigGroup; import org.matsim.core.config.groups.RoutingConfigGroup; -import org.matsim.core.network.NetworkUtils; -import org.matsim.core.network.algorithms.TransportModeNetworkFilter; +import org.matsim.core.network.algorithms.NetworkCleaner; import org.matsim.core.router.costcalculators.TravelDisutilityFactory; import org.matsim.core.router.util.LeastCostPathCalculator; import org.matsim.core.router.util.LeastCostPathCalculatorFactory; @@ -41,9 +40,7 @@ import com.google.inject.name.Named; -import java.util.HashSet; import java.util.Map; -import java.util.Set; public class NetworkRoutingProvider implements Provider{ private static final Logger log = LogManager.getLogger( NetworkRoutingProvider.class ) ; @@ -55,8 +52,6 @@ public class NetworkRoutingProvider implements Provider{ @Inject SingleModeNetworksCache singleModeNetworksCache; @Inject RoutingConfigGroup routingConfigGroup; - @Inject Network network; - @Inject NetworkConfigGroup networkConfigGroup; @Inject PopulationFactory populationFactory; @Inject LeastCostPathCalculatorFactory leastCostPathCalculatorFactory; @Inject Scenario scenario ; @@ -101,6 +96,8 @@ public RoutingModule get() { // the network refers to the (transport)mode: Network filteredNetwork = singleModeNetworksCache.getOrCreateSingleModeNetwork(mode); + checkNetwork(filteredNetwork); + // the travel time & disutility refer to the routing mode: TravelDisutilityFactory travelDisutilityFactory = this.travelDisutilityFactories.get(routingMode); if (travelDisutilityFactory == null) { @@ -135,7 +132,26 @@ public RoutingModule get() { } } else { + log.warn("[mode: {}; routingMode: {}] Using deprecated routing module without access/egress. Consider using AccessEgressNetworkRouter instead.", mode, routingMode); return DefaultRoutingModules.createPureNetworkRouter(mode, populationFactory, filteredNetwork, routeAlgo); } } + + private void checkNetwork(Network filteredNetwork) { + if(routingConfigGroup.getNetworkRouteConsistencyCheck() == RoutingConfigGroup.NetworkRouteConsistencyCheck.disable) { + return; + } + + int nLinks = filteredNetwork.getLinks().size(); + int nNodes = filteredNetwork.getNodes().size(); + new NetworkCleaner().run(filteredNetwork); + boolean changed = nLinks != filteredNetwork.getLinks().size() || nNodes != filteredNetwork.getNodes().size(); + + if(changed) { + String errorMessage = "Network for mode '" + mode + "' has unreachable links and nodes. This may be caused by mode restrictions on certain links. Aborting."; + log.error(errorMessage + "\n If you restricted modes on some links, consider doing that with NetworkUtils.restrictModesAndCleanNetwork(). This makes sure, that the network is consistent for each mode." + + "\n If this network topology is intended, set the routing config parameter 'networkRouteConsistencyCheck' to 'disable'."); + throw new RuntimeException(errorMessage); + } + } } diff --git a/matsim/src/main/java/org/matsim/core/router/PlanRouter.java b/matsim/src/main/java/org/matsim/core/router/PlanRouter.java index 2e96a046a94..f52b9a85169 100644 --- a/matsim/src/main/java/org/matsim/core/router/PlanRouter.java +++ b/matsim/src/main/java/org/matsim/core/router/PlanRouter.java @@ -71,17 +71,6 @@ public PlanRouter( final TripRouter routingHandler, final TimeInterpretation tim this( routingHandler , null, timeInterpretation ); } -// /** -// * Gives access to the {@link TripRouter} used -// * to compute routes. -// * -// * @return the internal TripRouter instance. -// */ -// @Deprecated // get TripRouter out of injection instead. kai, feb'16 -// public TripRouter getTripRouter() { -// return tripRouter; -// } - @Override public void run(final Plan plan) { final List trips = TripStructureUtils.getTrips( plan ); diff --git a/matsim/src/main/java/org/matsim/core/router/TripRouter.java b/matsim/src/main/java/org/matsim/core/router/TripRouter.java index ac39295ebe8..84769313c86 100644 --- a/matsim/src/main/java/org/matsim/core/router/TripRouter.java +++ b/matsim/src/main/java/org/matsim/core/router/TripRouter.java @@ -169,26 +169,25 @@ public synchronized List calcRoute( RoutingModule module = routingModules.get( mainMode ); - if (module != null) { - RoutingRequest request = DefaultRoutingRequest.of( - fromFacility, - toFacility, - departureTime, - person, - routingAttributes); - - List trip = module.calcRoute(request); - - if ( trip == null ) { - trip = fallbackRoutingModule.calcRoute(request) ; - } - for (Leg leg: TripStructureUtils.getLegs(trip)) { - TripStructureUtils.setRoutingMode(leg, mainMode); - } - return trip; + if (module == null) { + throw new UnknownModeException( "unregistered main mode |"+mainMode+"|: does not pertain to "+routingModules.keySet() ); } + RoutingRequest request = DefaultRoutingRequest.of( + fromFacility, + toFacility, + departureTime, + person, + routingAttributes); + + List trip = module.calcRoute(request); - throw new UnknownModeException( "unregistered main mode |"+mainMode+"|: does not pertain to "+routingModules.keySet() ); + if ( trip == null ) { + trip = fallbackRoutingModule.calcRoute(request) ; + } + for (Leg leg: TripStructureUtils.getLegs(trip)) { + TripStructureUtils.setRoutingMode(leg, mainMode); + } + return trip; } public static class UnknownModeException extends RuntimeException { diff --git a/matsim/src/test/java/ch/sbb/matsim/routing/pt/raptor/Fixture.java b/matsim/src/test/java/ch/sbb/matsim/routing/pt/raptor/Fixture.java index 97bdc02747a..f842302b4d6 100644 --- a/matsim/src/test/java/ch/sbb/matsim/routing/pt/raptor/Fixture.java +++ b/matsim/src/test/java/ch/sbb/matsim/routing/pt/raptor/Fixture.java @@ -30,6 +30,7 @@ import org.matsim.api.core.v01.network.Node; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.population.routes.NetworkRoute; import org.matsim.core.population.routes.RouteUtils; import org.matsim.core.scenario.MutableScenario; @@ -100,6 +101,7 @@ public Fixture() { this.config = ConfigUtils.createConfig(); this.config.transit().setUseTransit(true); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); ScenarioBuilder scBuilder = new ScenarioBuilder(config) ; this.scenario = (MutableScenario) scBuilder.build() ; diff --git a/matsim/src/test/java/ch/sbb/matsim/routing/pt/raptor/IntermodalFixture.java b/matsim/src/test/java/ch/sbb/matsim/routing/pt/raptor/IntermodalFixture.java index 495868e6991..a29767b6a48 100644 --- a/matsim/src/test/java/ch/sbb/matsim/routing/pt/raptor/IntermodalFixture.java +++ b/matsim/src/test/java/ch/sbb/matsim/routing/pt/raptor/IntermodalFixture.java @@ -30,6 +30,7 @@ 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.RoutingConfigGroup; import org.matsim.core.population.routes.NetworkRoute; import org.matsim.core.population.routes.RouteUtils; import org.matsim.core.scenario.ScenarioUtils; @@ -96,6 +97,7 @@ class IntermodalFixture { IntermodalFixture() { this.srrConfig = new SwissRailRaptorConfigGroup(); this.config = ConfigUtils.createConfig(this.srrConfig); + this.config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); this.scenario = ScenarioUtils.createScenario(this.config); TransitSchedule schedule = this.scenario.getTransitSchedule(); diff --git a/matsim/src/test/java/org/matsim/analysis/LinkStatsControlerListenerTest.java b/matsim/src/test/java/org/matsim/analysis/LinkStatsControlerListenerTest.java index 8ec2fb9f37d..0a47e4b929f 100644 --- a/matsim/src/test/java/org/matsim/analysis/LinkStatsControlerListenerTest.java +++ b/matsim/src/test/java/org/matsim/analysis/LinkStatsControlerListenerTest.java @@ -33,6 +33,7 @@ import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.LinkStatsConfigGroup; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.*; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Injector; @@ -352,6 +353,7 @@ void testReset_CorrectlyExecuted() throws IOException { config.controller().setFirstIteration(0); config.controller().setLastIteration(7); config.controller().setWritePlansInterval(0); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); LinkStatsConfigGroup lsConfig = config.linkStats(); lsConfig.setWriteLinkStatsInterval(3); diff --git a/matsim/src/test/java/org/matsim/core/controler/ControlerIT.java b/matsim/src/test/java/org/matsim/core/controler/ControlerIT.java index 2a735f508af..703ea500d06 100644 --- a/matsim/src/test/java/org/matsim/core/controler/ControlerIT.java +++ b/matsim/src/test/java/org/matsim/core/controler/ControlerIT.java @@ -1018,6 +1018,7 @@ private static class Fixture { Link link3 = null; protected Fixture(final Config config) { + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); this.scenario = ScenarioUtils.createScenario(config); this.network = this.scenario.getNetwork(); diff --git a/matsim/src/test/java/org/matsim/core/controler/PrepareForSimImplTest.java b/matsim/src/test/java/org/matsim/core/controler/PrepareForSimImplTest.java index af9ec71a41b..5f0e60dd990 100644 --- a/matsim/src/test/java/org/matsim/core/controler/PrepareForSimImplTest.java +++ b/matsim/src/test/java/org/matsim/core/controler/PrepareForSimImplTest.java @@ -829,7 +829,7 @@ public List calcRoute(RoutingRequest request) { } } - private Link createAndAddNetwork(Scenario sc) { + private void createAndAddNetwork(Scenario sc) { Network net = sc.getNetwork(); Link link1; { @@ -851,6 +851,5 @@ private Link createAndAddNetwork(Scenario sc) { net.addLink(link1); net.addLink(l2); } - return link1; } } diff --git a/matsim/src/test/java/org/matsim/core/controler/TransitControlerIntegrationTest.java b/matsim/src/test/java/org/matsim/core/controler/TransitControlerIntegrationTest.java index 10d912cfe9d..20699888afa 100644 --- a/matsim/src/test/java/org/matsim/core/controler/TransitControlerIntegrationTest.java +++ b/matsim/src/test/java/org/matsim/core/controler/TransitControlerIntegrationTest.java @@ -41,6 +41,7 @@ import org.matsim.api.core.v01.population.Population; import org.matsim.api.core.v01.population.PopulationFactory; import org.matsim.core.config.Config; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings; import org.matsim.core.population.routes.NetworkRoute; @@ -68,6 +69,7 @@ public class TransitControlerIntegrationTest { @Test void testTransitRouteCopy() { Config config = utils.loadConfig((String)null); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.transit().setUseTransit(true); MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/hermes/HermesTest.java b/matsim/src/test/java/org/matsim/core/mobsim/hermes/HermesTest.java index 09cb1763746..426a984aa8a 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/hermes/HermesTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/hermes/HermesTest.java @@ -59,6 +59,7 @@ import org.matsim.core.api.experimental.events.TeleportationArrivalEvent; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.events.handler.BasicEventHandler; @@ -808,6 +809,7 @@ private LogCounter runConsistentRoutesTestSim(final String startLinkId, final St void testStartAndEndTime() { final Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); // --- @@ -864,6 +866,7 @@ void testStartAndEndTime() { void testCleanupSim_EarlyEnd() { MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); Config config = scenario.getConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); double simEndTime = 8.0*3600; @@ -990,6 +993,7 @@ public static final class Fixture { public Fixture() { this.scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); this.config = scenario.getConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); /* build network */ diff --git a/matsim/src/test/java/org/matsim/core/mobsim/hermes/StorageCapacityTest.java b/matsim/src/test/java/org/matsim/core/mobsim/hermes/StorageCapacityTest.java index fd7958999fb..290d4632d45 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/hermes/StorageCapacityTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/hermes/StorageCapacityTest.java @@ -44,6 +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.RoutingConfigGroup; import org.matsim.core.events.EventsUtils; import org.matsim.core.network.NetworkUtils; import org.matsim.core.population.PersonUtils; @@ -68,6 +69,7 @@ public class StorageCapacityTest { void testStorageCapacity() { ScenarioImporter.flush(); Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.hermes().setStuckTime(Integer.MAX_VALUE); Scenario scenario = ScenarioUtils.createScenario(config); var links = generateNetwork(scenario.getNetwork()); @@ -120,6 +122,7 @@ void testStorageCapacityDownscaling() { config.hermes().setStuckTime(Integer.MAX_VALUE); config.hermes().setFlowCapacityFactor(0.1); config.hermes().setStorageCapacityFactor(0.1); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); Scenario scenario = ScenarioUtils.createScenario(config); var links = generateNetwork(scenario.getNetwork()); @@ -169,6 +172,7 @@ void testStorageCapacityDownscaling() { void testStorageCapacityWithDifferentPCUs() { ScenarioImporter.flush(); Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.hermes().setStuckTime(Integer.MAX_VALUE); Scenario scenario = ScenarioUtils.createScenario(config); var links = generateNetwork(scenario.getNetwork()); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/FlowStorageSpillbackTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/FlowStorageSpillbackTest.java index dbf47866033..311831b6bad 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/FlowStorageSpillbackTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/FlowStorageSpillbackTest.java @@ -38,6 +38,7 @@ import org.matsim.api.core.v01.population.*; import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.config.Config; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.population.PopulationUtils; @@ -230,6 +231,7 @@ private Scenario loadScenario() { // (0)-----link1-----(1)-----link2-----(2)-----link3-----(3)-----link4-----(4) Config config = testUtils.loadConfig((String) null); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); Scenario scenario = (ScenarioUtils.createScenario(config)); Network network = (Network) scenario.getNetwork(); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/NetsimRoutingConsistencyTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/NetsimRoutingConsistencyTest.java index 6899e6c95f1..e8693333c25 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/NetsimRoutingConsistencyTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/NetsimRoutingConsistencyTest.java @@ -46,6 +46,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.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; @@ -213,7 +214,7 @@ void testRoutingVsSimulation() { @Test void testRoutingVsSimulationFullStack() { Config config = ConfigUtils.createConfig(); - + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.controller().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); config.controller().setLastIteration(0); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/NodeTransitionTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/NodeTransitionTest.java index b37c5f2a32d..40403107cb9 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/NodeTransitionTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/NodeTransitionTest.java @@ -43,6 +43,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.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup; import org.matsim.core.config.groups.QSimConfigGroup.NodeTransition; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; @@ -292,6 +293,7 @@ void testBlockedNodeSituationWithEmptyBufferAfterBufferRandomDistribution(boolea Scenario scenario = Fixture.createBlockedNodeScenario(); scenario.getConfig().qsim().setNodeTransitionLogic(NodeTransition.emptyBufferAfterBufferRandomDistribution_nodeBlockedWhenSingleOutlinkFull); scenario.getConfig().qsim().setUsingFastCapacityUpdate(useFastCapUpdate); + scenario.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); EventsManager events = EventsUtils.createEventsManager(); List> linksOfInterest = new LinkedList<>(); @@ -374,6 +376,7 @@ void testBlockedNodeSituationWithMoveVehByVehRandomDistribution(boolean useFastC Scenario scenario = Fixture.createBlockedNodeScenario(); scenario.getConfig().qsim().setNodeTransitionLogic(NodeTransition.moveVehByVehRandomDistribution_nodeBlockedWhenSingleOutlinkFull); scenario.getConfig().qsim().setUsingFastCapacityUpdate(useFastCapUpdate); + scenario.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); EventsManager events = EventsUtils.createEventsManager(); List> linksOfInterest = new LinkedList<>(); @@ -457,6 +460,7 @@ void testBlockedNodeSituationWithMoveVehByVehDeterministicPriorities(boolean use Scenario scenario = Fixture.createBlockedNodeScenario(); scenario.getConfig().qsim().setNodeTransitionLogic(NodeTransition.moveVehByVehDeterministicPriorities_nodeBlockedWhenSingleOutlinkFull); scenario.getConfig().qsim().setUsingFastCapacityUpdate(useFastCapUpdate); + scenario.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); EventsManager events = EventsUtils.createEventsManager(); List> linksOfInterest = new LinkedList<>(); @@ -548,6 +552,7 @@ void testNodeTransitionWithTimeStepSizeSmallerOne(boolean useFastCapUpdate) { scenario.getConfig().qsim().setNodeTransitionLogic(NodeTransition.emptyBufferAfterBufferRandomDistribution_dontBlockNode); scenario.getConfig().qsim().setTimeStepSize(0.5); scenario.getConfig().qsim().setUsingFastCapacityUpdate(useFastCapUpdate); + scenario.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); EventsManager events = EventsUtils.createEventsManager(); List> linksOfInterest = new LinkedList<>(); @@ -633,9 +638,11 @@ static Scenario createMergeScenario() { config.controller().setLastIteration(0); config.qsim().setStuckTime(24*3600); config.qsim().setRemoveStuckVehicles(false); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); ScoringConfigGroup.ActivityParams dummyAct = new ScoringConfigGroup.ActivityParams("dummy"); dummyAct.setTypicalDuration(12 * 3600); config.scoring().addActivityParams(dummyAct); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); Scenario scenario = ScenarioUtils.createScenario(config); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/QSimTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/QSimTest.java index e33947ee22f..96c12d442be 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/QSimTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/QSimTest.java @@ -66,6 +66,7 @@ import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.QSimConfigGroup; import org.matsim.core.config.groups.QSimConfigGroup.TrafficDynamics; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.events.ParallelEventsManager; @@ -1393,6 +1394,7 @@ private LogCounter runConsistentRoutesTestSim(final String startLinkId, final St void testStartAndEndTime(boolean isUsingFastCapacityUpdate, int numberOfThreads) { final Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.qsim().setUsingFastCapacityUpdate(isUsingFastCapacityUpdate); // --- @@ -1461,6 +1463,7 @@ void testCleanupSim_EarlyEnd(boolean isUsingFastCapacityUpdate, int numberOfThre MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); Config config = scenario.getConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.qsim().setUsingFastCapacityUpdate(isUsingFastCapacityUpdate); config.qsim().setNumberOfThreads(numberOfThreads); @@ -1806,6 +1809,8 @@ public Fixture(boolean isUsingFastCapacityUpdate, int numberOfThreads) { this.config.qsim().setUsingFastCapacityUpdate(isUsingFastCapacityUpdate); this.config.qsim().setNumberOfThreads(numberOfThreads); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + /* build network */ this.network = this.scenario.getNetwork(); this.network.setCapacityPeriod(Time.parseTime("1:00:00")); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/TeleportationEngineWDistanceCheckTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/TeleportationEngineWDistanceCheckTest.java index 8f0286cf9cd..5fa782435f3 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/TeleportationEngineWDistanceCheckTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/TeleportationEngineWDistanceCheckTest.java @@ -39,6 +39,7 @@ import org.matsim.api.core.v01.population.PopulationFactory; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings; import org.matsim.core.controler.AbstractModule; @@ -64,6 +65,7 @@ final void test() { config.controller().setOutputDirectory( utils.getOutputDirectory() ); config.controller().setOverwriteFileSetting( OverwriteFileSetting.deleteDirectoryIfExists ); config.controller().setLastIteration(0); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); ActivityParams params = new ActivityParams("dummy" ) ; config.scoring().addActivityParams(params); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/VehicleSourceTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/VehicleSourceTest.java index 9460bd95d03..367eb5d10db 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/VehicleSourceTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/VehicleSourceTest.java @@ -36,6 +36,7 @@ import org.matsim.api.core.v01.population.*; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; import org.matsim.core.config.groups.QSimConfigGroup; import org.matsim.core.config.groups.QSimConfigGroup.VehiclesSource; @@ -94,6 +95,7 @@ void main(VehiclesSource vehiclesSource, boolean usingPersonIdForMissingVehicleI createPlans(vehiclesSource, providingVehiclesInPerson); Config config = scenario.getConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.qsim().setFlowCapFactor(1.0); config.qsim().setStorageCapFactor(1.0); config.qsim().setMainModes(Arrays.asList(transportModes)); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/pt/QSimIntegrationTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/pt/QSimIntegrationTest.java index 25234b89cd0..078d2355b42 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/pt/QSimIntegrationTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/pt/QSimIntegrationTest.java @@ -44,6 +44,7 @@ import org.matsim.core.api.experimental.events.VehicleDepartsAtFacilityEvent; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.mobsim.qsim.QSimBuilder; @@ -425,7 +426,8 @@ private static class Fixture { public Fixture() throws SAXException, ParserConfigurationException, IOException { // setup: config final Config config = ConfigUtils.createConfig(); - config.transit().setUseTransit(true); + config.transit().setUseTransit(true); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.qsim().setEndTime(8.0*3600); this.scenario = (MutableScenario) ScenarioUtils.createScenario(config); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/pt/TransitAgentTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/pt/TransitAgentTest.java index 59c7341e27e..7b73108a13f 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/pt/TransitAgentTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/pt/TransitAgentTest.java @@ -39,7 +39,9 @@ import org.matsim.api.core.v01.population.Plan; import org.matsim.api.core.v01.population.PopulationFactory; 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.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.mobsim.qsim.QSim; @@ -65,7 +67,9 @@ public class TransitAgentTest { @Test void testAcceptLineRoute() { - MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); + Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); Network network = (Network) scenario.getNetwork(); Node node1 = NetworkUtils.createAndAddNode(network, Id.create("1", Node.class), new Coord((double) 0, (double) 0)); @@ -117,7 +121,9 @@ void testAcceptLineRoute() { @Test void testArriveAtStop() { - MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); + Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); Network network = (Network) scenario.getNetwork(); Node node1 = NetworkUtils.createAndAddNode(network, Id.create("1", Node.class), new Coord((double) 0, (double) 0)); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/pt/TransitQueueSimulationTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/pt/TransitQueueSimulationTest.java index 914190b0228..c635f01df74 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/pt/TransitQueueSimulationTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/pt/TransitQueueSimulationTest.java @@ -63,6 +63,7 @@ import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.ExternalMobimConfigGroup; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.events.handler.BasicEventHandler; @@ -108,6 +109,7 @@ public class TransitQueueSimulationTest { void testCreateAgents() { // setup: config final Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.transit().setUseTransit(true); config.qsim().setEndTime(8.0*3600); @@ -310,6 +312,7 @@ void testAddAgentToStopWrongLink() { assertThrows(TransitAgentTriesToTeleportException.class, () -> { // setup: config final Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.transit().setUseTransit(true); MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); @@ -381,6 +384,7 @@ void testAddAgentToStopWrongLink() { void testHandleStop() { // setup: config final Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.transit().setUseTransit(true); config.qsim().setEndTime(8.0*3600); @@ -631,6 +635,7 @@ protected SpyHandleStopData(final TransitStopFacility stopFacility, final double @Test void testStartAndEndTime() { final Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.transit().setUseTransit(true); MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); @@ -728,6 +733,7 @@ public void reset(final int iteration) { @Test void testEvents() { final Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.transit().setUseTransit(true); MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/DeparturesOnSameLinkSameTimeTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/DeparturesOnSameLinkSameTimeTest.java index bc69576a7f2..f603260e3ce 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/DeparturesOnSameLinkSameTimeTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/DeparturesOnSameLinkSameTimeTest.java @@ -34,6 +34,7 @@ import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.QSimConfigGroup.VehiclesSource; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.mobsim.qsim.QSimBuilder; @@ -147,6 +148,7 @@ public PseudoInputs(String travelMode) { config=ConfigUtils.createConfig(); this.scenario = ScenarioUtils.loadScenario(config); config.qsim().setMainModes(Arrays.asList(travelMode)); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); //following is necessary for mixed traffic, providing a route was obstructing // the requirement of these which might be all right in some cases. Amit Jan'18 diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/FlowCapacityVariationTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/FlowCapacityVariationTest.java index d94ce42724a..2507353faa1 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/FlowCapacityVariationTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/FlowCapacityVariationTest.java @@ -37,6 +37,7 @@ import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.QSimConfigGroup.VehiclesSource; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.mobsim.qsim.QSimBuilder; @@ -130,7 +131,7 @@ public PseudoInputs(String travelMode){ config = scenario.getConfig(); config.qsim().setMainModes(Arrays.asList(travelMode)); config.qsim().setUsingFastCapacityUpdate(true); - + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); population = scenario.getPopulation(); } diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/FlowEfficiencyCalculatorTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/FlowEfficiencyCalculatorTest.java index 2d373a8e2b1..89594e75077 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/FlowEfficiencyCalculatorTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/FlowEfficiencyCalculatorTest.java @@ -37,6 +37,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.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; @@ -132,6 +133,7 @@ private Scenario createScenario() { Config config = ConfigUtils.createConfig(); config.controller().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); config.controller().setLastIteration(0); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); ActivityParams genericParams = new ActivityParams("generic"); genericParams.setTypicalDuration(1.0); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/JavaRoundingErrorInQsimTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/JavaRoundingErrorInQsimTest.java index ca771b4156c..bf41bf3241c 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/JavaRoundingErrorInQsimTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/JavaRoundingErrorInQsimTest.java @@ -39,6 +39,7 @@ import org.matsim.api.core.v01.population.*; import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.mobsim.qsim.QSimBuilder; @@ -142,6 +143,7 @@ private static final class PseudoInputs{ public PseudoInputs(){ scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); scenario.getConfig().qsim().setUsingFastCapacityUpdate(true); + scenario.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); population = scenario.getPopulation(); } diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/LinkSpeedCalculatorIntegrationTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/LinkSpeedCalculatorIntegrationTest.java index 2a6554df93d..c84fa35e061 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/LinkSpeedCalculatorIntegrationTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/LinkSpeedCalculatorIntegrationTest.java @@ -39,6 +39,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.RoutingConfigGroup; import org.matsim.core.controler.Injector; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; import org.matsim.core.controler.PrepareForSimUtils; @@ -222,7 +223,9 @@ static class Fixture { Scenario scenario; public Fixture() { - this.scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); + Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + this.scenario = ScenarioUtils.createScenario(config); Id[] nodeIds = new Id[5]; for (int i = 0; i < nodeIds.length; i++) { diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/PassingTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/PassingTest.java index a145ecf6c39..2db8d64118c 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/PassingTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/PassingTest.java @@ -38,6 +38,7 @@ 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.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.controler.events.IterationEndsEvent; import org.matsim.core.controler.events.StartupEvent; @@ -182,6 +183,7 @@ public SimpleNetwork(){ config.qsim().setStorageCapFactor(1.0); config.qsim().setMainModes(Arrays.asList("car","bike")); config.qsim().setLinkDynamics(QSimConfigGroup.LinkDynamics.PassingQ); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); network = (Network) scenario.getNetwork(); this.network.setCapacityPeriod(Time.parseTime("1:00:00")); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/QLinkLanesTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/QLinkLanesTest.java index 53794c1f44a..ba289374fe9 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/QLinkLanesTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/QLinkLanesTest.java @@ -33,6 +33,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.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.mobsim.qsim.QSim; @@ -137,6 +138,7 @@ private static void createThreeLanes(Scenario scenario) { @Test void testCapacityWoLanes() { Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); initNetwork(scenario.getNetwork()); @@ -155,6 +157,7 @@ void testCapacityWoLanes() { @Test void testCapacityWithOneLaneOneLane() { Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); initNetwork(scenario.getNetwork()); createOneLane(scenario, 1); @@ -191,6 +194,7 @@ void testCapacityWithOneLaneOneLane() { @Test void testCapacityWithOneLaneTwoLanes() { Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); initNetwork(scenario.getNetwork()); createOneLane(scenario, 2); @@ -228,6 +232,7 @@ void testCapacityWithOneLaneTwoLanes() { @Test void testCapacityWithLanes() { Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); initNetwork(scenario.getNetwork()); createThreeLanes(scenario); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/QLinkTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/QLinkTest.java index 394ef272b28..93e9ed84e07 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/QLinkTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/QLinkTest.java @@ -46,6 +46,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.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.gbl.MatsimRandom; @@ -313,6 +314,7 @@ void testGetVehicle_Departing(boolean isUsingFastCapacityUpdate) { @ValueSource(booleans = {true, false}) void testBuffer(boolean isUsingFastCapacityUpdate) { Config conf = utils.loadConfig((String)null); + conf.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); conf.qsim().setUsingFastCapacityUpdate(isUsingFastCapacityUpdate); @@ -543,6 +545,7 @@ void testStuckEvents(boolean isUsingFastCapacityUpdate) { Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); scenario.getConfig().qsim().setStuckTime(100); scenario.getConfig().qsim().setRemoveStuckVehicles(true); + scenario.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); MatsimRandom.reset(4711); // yyyyyy !!!!!! Network network = (Network) scenario.getNetwork(); network.setCapacityPeriod(3600.0); @@ -622,6 +625,7 @@ private static final class Fixture { this.scenario.getConfig().qsim().setStuckTime(100); this.scenario.getConfig().qsim().setRemoveStuckVehicles(true); this.scenario.getConfig().qsim().setUsingFastCapacityUpdate(usingFastCapacityUpdate); + this.scenario.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); Network network = (Network) this.scenario.getNetwork(); network.setCapacityPeriod(3600.0); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/SeepageTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/SeepageTest.java index c562b59987b..081028398b1 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/SeepageTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/SeepageTest.java @@ -40,6 +40,7 @@ import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.QSimConfigGroup.LinkDynamics; import org.matsim.core.config.groups.QSimConfigGroup.VehiclesSource; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.mobsim.qsim.QSimBuilder; @@ -170,6 +171,7 @@ public SimpleNetwork(){ config.qsim().setStorageCapFactor(1.0); config.qsim().setMainModes(Arrays.asList(TransportMode.car,TransportMode.walk)); config.qsim().setLinkDynamics(LinkDynamics.SeepageQ); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.qsim().setSeepModes(Arrays.asList(TransportMode.walk) ); config.qsim().setSeepModeStorageFree(false); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/SimulatedLaneFlowCapacityTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/SimulatedLaneFlowCapacityTest.java index 018ef7c995f..36d56ad9d2c 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/SimulatedLaneFlowCapacityTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/SimulatedLaneFlowCapacityTest.java @@ -48,6 +48,7 @@ import org.matsim.core.api.experimental.events.handler.LaneLeaveEventHandler; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; @@ -210,6 +211,7 @@ private static void initPopulation(Population population) { @Test void testCapacityWoLanes() { Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); ActivityParams dummyAct = new ActivityParams("dummy"); dummyAct.setTypicalDuration(12 * 3600); config.scoring().addActivityParams(dummyAct); @@ -238,6 +240,7 @@ void testCapacityWoLanes() { @Test void testCapacityWithOneLaneOneLane() { Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); ActivityParams dummyAct = new ActivityParams("dummy"); dummyAct.setTypicalDuration(12 * 3600); config.scoring().addActivityParams(dummyAct); @@ -270,6 +273,7 @@ void testCapacityWithOneLaneOneLane() { @Test void testCapacityWithOneLaneTwoLanes() { Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); ActivityParams dummyAct = new ActivityParams("dummy"); dummyAct.setTypicalDuration(12 * 3600); config.scoring().addActivityParams(dummyAct); @@ -303,6 +307,7 @@ void testCapacityWithOneLaneTwoLanes() { @Test void testCapacityWithThreeLanes() { Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); ActivityParams dummyAct = new ActivityParams("dummy"); dummyAct.setTypicalDuration(12 * 3600); config.scoring().addActivityParams(dummyAct); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/VehVsLinkSpeedTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/VehVsLinkSpeedTest.java index 820914fc323..51d9f80872f 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/VehVsLinkSpeedTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/VehVsLinkSpeedTest.java @@ -39,6 +39,7 @@ 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.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.mobsim.qsim.QSimBuilder; @@ -128,6 +129,7 @@ public SimpleNetwork(){ config.qsim().setMainModes(Arrays.asList("car")); config.qsim().setLinkDynamics(QSimConfigGroup.LinkDynamics.PassingQ); config.qsim().setVehiclesSource(QSimConfigGroup.VehiclesSource.modeVehicleTypesFromVehiclesData); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); network = (Network) scenario.getNetwork(); this.network.setCapacityPeriod(Time.parseTime("1:00:00")); diff --git a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/VehicleHandlerTest.java b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/VehicleHandlerTest.java index 292ae461e58..bfaac4a4eaa 100644 --- a/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/VehicleHandlerTest.java +++ b/matsim/src/test/java/org/matsim/core/mobsim/qsim/qnetsimengine/VehicleHandlerTest.java @@ -43,6 +43,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.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; @@ -184,6 +185,7 @@ public void handleEvent(PersonArrivalEvent event) { private Scenario createScenario() { Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.controller().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); config.controller().setLastIteration(0); config.controller().setOutputDirectory(utils.getOutputDirectory()); diff --git a/matsim/src/test/java/org/matsim/core/network/algorithms/NetworkCleanerTest.java b/matsim/src/test/java/org/matsim/core/network/algorithms/NetworkCleanerTest.java index db870267bcc..b60c8052c73 100644 --- a/matsim/src/test/java/org/matsim/core/network/algorithms/NetworkCleanerTest.java +++ b/matsim/src/test/java/org/matsim/core/network/algorithms/NetworkCleanerTest.java @@ -22,13 +22,18 @@ import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; import org.matsim.api.core.v01.Coord; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; import org.matsim.api.core.v01.network.Node; import org.matsim.core.network.NetworkUtils; +import org.matsim.core.utils.io.IOUtils; +import org.matsim.examples.ExamplesUtils; /** * A very simple test for the NetworkCleaner, it doesn't test by far all possible cases. @@ -189,4 +194,23 @@ void testDoubleSource() { assertEquals(4, network.getLinks().size(), "# links"); } + /** + * This test essentially does the same by modifying the equil scenario. + * Visualization: + * /... ...\ + * ------o------------o------------o----------- + * l1 (n2) l6 (n7) l15 (n12) l20 + */ + @ParameterizedTest + @CsvSource({"6,15", "15,6"}) + void testNetworkCleaner(String removedBefore, String expectedRemovedAfter){ + Network net = NetworkUtils.readNetwork(IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("equil"), "network.xml").toString()); + net.removeLink(Id.createLinkId(removedBefore)); + int size = net.getLinks().size(); + + NetworkUtils.runNetworkCleaner(net); + Assertions.assertFalse(net.getLinks().containsKey(Id.createLinkId(expectedRemovedAfter))); + assertEquals(net.getLinks().size(), size - 1); + } + } diff --git a/matsim/src/test/java/org/matsim/core/network/algorithms/NetworkModeRestrictionTest.java b/matsim/src/test/java/org/matsim/core/network/algorithms/NetworkModeRestrictionTest.java new file mode 100644 index 00000000000..92f3bef546f --- /dev/null +++ b/matsim/src/test/java/org/matsim/core/network/algorithms/NetworkModeRestrictionTest.java @@ -0,0 +1,144 @@ +package org.matsim.core.network.algorithms; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.network.Network; +import org.matsim.core.network.NetworkUtils; +import org.matsim.core.utils.io.IOUtils; +import org.matsim.examples.ExamplesUtils; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +// @formatter:off +/** + * In this test, we restrict the allowed modes of a link. The base case is the equil scenario. + *

+ * /... ...\ + * ------o------------o------------o----------- + * l1 (n2) l6 (n7) l15 (n12) l20 + */ +// @formatter:on +class NetworkModeRestrictionTest { + + /** + * Test that all links and nodes are removed if the network is not connected any more for every mode. + */ + @Test + void testRemoveWholeNetwork() { + Network network = getNetwork(); + + Map, Set> changes = new HashMap<>(); + changes.put(Id.createLinkId(1), Set.of("car","bike")); + + new NetworkModeRestriction(changes).run(network); + + assertTrue(network.getLinks().isEmpty()); + assertTrue(network.getNodes().isEmpty()); + } + + /** + * Test that mode is removed from each node if there is not connected any more for this mode. + */ + @ParameterizedTest + @ValueSource(strings = {"car", "bike"}) + void testRemoveWholeMode(String modeToRemove) { + Network network = getNetwork(); + + int linksBefore = network.getLinks().size(); + int nodesBefore = network.getNodes().size(); + + Map, Set> changes = new HashMap<>(); + changes.put(Id.createLinkId(1), Set.of(modeToRemove)); + + new NetworkModeRestriction(changes).run(network); + + assertEquals(linksBefore, network.getLinks().size()); + assertEquals(nodesBefore, network.getNodes().size()); + + Assertions.assertTrue(network.getLinks().values().stream() + .allMatch(l -> l.getAllowedModes().size() == 1 && l.getAllowedModes().contains(getOtherMode(modeToRemove)))); + } + + /** + * Test that removing a mode from link 6 or 15 also removes it from the other link. + */ + @ParameterizedTest + @CsvSource({"6,car", "6,bike", "15,car", "15,bike"}) + void testRemoveModePartially(int link, String modeToRemove) { + Network network = getNetwork(); + + int linksBefore = network.getLinks().size(); + int nodesBefore = network.getNodes().size(); + + //prepare removal + Map, Set> changes = new HashMap<>(); + changes.put(Id.createLinkId(link), Set.of(modeToRemove)); + + //remove + new NetworkModeRestriction(changes).run(network); + + //links and nodes should all still be there + assertEquals(linksBefore, network.getLinks().size()); + assertEquals(nodesBefore, network.getNodes().size()); + + Set link6Modes = network.getLinks().get(Id.createLinkId(6)).getAllowedModes(); + Set link15Modes = network.getLinks().get(Id.createLinkId(15)).getAllowedModes(); + + //link 6 and 15 should have the mode removed + Assertions.assertEquals(1, link6Modes.size()); + Assertions.assertEquals(1, link15Modes.size()); + Assertions.assertTrue(link6Modes.contains(getOtherMode(modeToRemove))); + Assertions.assertTrue(link15Modes.contains(getOtherMode(modeToRemove))); + } + + /** + * Test that removing each mode from link 6 or 15 also removes both links at all. + */ + @ParameterizedTest + @ValueSource(ints = {6, 15}) + void testRemovePartialNetwork(int link) { + Network network = getNetwork(); + + int linksBefore = network.getLinks().size(); + int nodesBefore = network.getNodes().size(); + + //prepare removal + Map, Set> changes = new HashMap<>(); + changes.put(Id.createLinkId(link), Set.of("car", "bike")); + + //remove + new NetworkModeRestriction(changes).run(network); + + //both links and the node in between should be removed + assertEquals(linksBefore - 2, network.getLinks().size()); + assertEquals(nodesBefore - 1, network.getNodes().size()); + + //check node + Assertions.assertNull(network.getNodes().get(Id.createNodeId(7))); + + //check links + Assertions.assertNull(network.getLinks().get(Id.createLinkId(6))); + Assertions.assertNull(network.getLinks().get(Id.createLinkId(15))); + } + + + private static Network getNetwork() { + Network network = NetworkUtils.readNetwork(IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("equil"), "network.xml").toString()); + network.getLinks().values().forEach(l -> l.setAllowedModes(Set.of("car", "bike"))); + return network; + } + + private String getOtherMode(String mode) { + return mode.equals("car") ? "bike" : "car"; + } +} diff --git a/matsim/src/test/java/org/matsim/core/network/io/NetworkReprojectionIOTest.java b/matsim/src/test/java/org/matsim/core/network/io/NetworkReprojectionIOTest.java index 8398f1a7db1..3e0170943e9 100644 --- a/matsim/src/test/java/org/matsim/core/network/io/NetworkReprojectionIOTest.java +++ b/matsim/src/test/java/org/matsim/core/network/io/NetworkReprojectionIOTest.java @@ -32,6 +32,7 @@ import org.matsim.api.core.v01.network.Node; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.Controler; import org.matsim.core.network.NetworkUtils; import org.matsim.core.scenario.ProjectionUtils; @@ -119,6 +120,7 @@ void testWithControlerAndAttributes() { new NetworkWriter( initialNetwork ).write( networkFile ); final Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.network().setInputFile( networkFile ); // web mercator. This would be a pretty silly choice for simulation, @@ -171,6 +173,7 @@ void testWithControlerAndConfigParameters() { new NetworkWriter( initialNetwork ).write( networkFile ); final Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.network().setInputFile( networkFile ); config.network().setInputCRS( INITIAL_CRS ); diff --git a/matsim/src/test/java/org/matsim/population/algorithms/PersonPrepareForSimTest.java b/matsim/src/test/java/org/matsim/core/population/algorithms/PersonPrepareForSimTest.java similarity index 86% rename from matsim/src/test/java/org/matsim/population/algorithms/PersonPrepareForSimTest.java rename to matsim/src/test/java/org/matsim/core/population/algorithms/PersonPrepareForSimTest.java index baec9afc911..4a5cf91dd6a 100644 --- a/matsim/src/test/java/org/matsim/population/algorithms/PersonPrepareForSimTest.java +++ b/matsim/src/test/java/org/matsim/core/population/algorithms/PersonPrepareForSimTest.java @@ -17,9 +17,10 @@ * * * *********************************************************************** */ -package org.matsim.population.algorithms; +package org.matsim.core.population.algorithms; import java.util.HashSet; +import java.util.List; import java.util.Set; import org.junit.jupiter.api.Assertions; @@ -38,11 +39,13 @@ import org.matsim.api.core.v01.population.Plan; import org.matsim.api.core.v01.population.Population; import org.matsim.api.core.v01.population.PopulationFactory; +import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimImpl; import org.matsim.core.population.PopulationUtils; -import org.matsim.core.population.algorithms.PersonPrepareForSim; -import org.matsim.core.population.algorithms.PlanAlgorithm; +import org.matsim.core.population.routes.NetworkRoute; +import org.matsim.core.population.routes.RouteUtils; import org.matsim.core.router.TripStructureUtils; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.pt.routes.DefaultTransitPassengerRoute; @@ -144,9 +147,7 @@ void testSingleLegTripRoutingMode() { new PersonPrepareForSim(new DummyRouter(), sc).run(person); - Assertions.assertEquals(TransportMode.pt, - TripStructureUtils.getRoutingMode(leg), - "wrong routing mode!"); + Assertions.assertEquals(TransportMode.pt, TripStructureUtils.getRoutingMode(leg),"wrong routing mode!"); } // test routing mode set @@ -167,9 +168,7 @@ void testSingleLegTripRoutingMode() { new PersonPrepareForSim(new DummyRouter(), sc).run(person); - Assertions.assertEquals(TransportMode.pt, - TripStructureUtils.getRoutingMode(leg), - "wrong routing mode!"); + Assertions.assertEquals(TransportMode.pt, TripStructureUtils.getRoutingMode(leg),"wrong routing mode!"); } } @@ -203,10 +202,7 @@ void testSingleFallbackModeLegTrip() { person.addPlan(plan); pop.addPerson(person); - try { - new PersonPrepareForSim(new DummyRouter(), sc).run(person); - Assertions.fail("expected Exception, got none."); - } catch (RuntimeException expected) {} + Assertions.assertThrows(RuntimeException.class, () -> new PersonPrepareForSim(new DummyRouter(), sc).run(person)); } // test outdated fallback mode single leg trip (arbitrary drt mode) @@ -228,9 +224,7 @@ void testSingleFallbackModeLegTrip() { new PersonPrepareForSim(new DummyRouter(), sc).run(person); Assertions.assertEquals("drt67_fallback", leg.getMode(), "wrong leg mode replacement"); - Assertions.assertEquals("drt67_fallback", - TripStructureUtils.getRoutingMode(leg), - "wrong routing mode set"); + Assertions.assertEquals("drt67_fallback", TripStructureUtils.getRoutingMode(leg),"wrong routing mode set"); } } @@ -368,6 +362,9 @@ void testRoutingModeConsistency() { Population pop = sc.getPopulation(); // test trip with inconsistent routing modes causes exception + // modes: walk - drt - walk + // routing modes: pt - drt - drt + // expected behaviour: throws RuntimeException, because routing modes are inconsistent { PopulationFactory pf = pop.getFactory(); Person person = pf.createPerson(Id.create("3", Person.class)); @@ -392,13 +389,13 @@ void testRoutingModeConsistency() { person.addPlan(plan); pop.addPerson(person); - try { - new PersonPrepareForSim(new DummyRouter(), sc).run(person); - Assertions.fail("expected Exception, got none."); - } catch (RuntimeException expected) {} + Assertions.assertThrows(RuntimeException.class, () -> new PersonPrepareForSim(new DummyRouter(), sc).run(person)); } // test trip with legs with and others without routing modes causes exception + // modes: walk - drt - walk + // routing modes: null - drt - drt + // expected behaviour: throws RuntimeException, because routing modes are inconsistent { PopulationFactory pf = pop.getFactory(); Person person = pf.createPerson(Id.create("4", Person.class)); @@ -423,10 +420,7 @@ void testRoutingModeConsistency() { person.addPlan(plan); pop.addPerson(person); - try { - new PersonPrepareForSim(new DummyRouter(), sc).run(person); - Assertions.fail("expected Exception, got none."); - } catch (RuntimeException expected) {} + Assertions.assertThrows(RuntimeException.class, () -> new PersonPrepareForSim(new DummyRouter(), sc).run(person)); } } @@ -478,13 +472,76 @@ void testReplaceExperimentalTransitRoute() { Assertions.assertEquals(route, ((DefaultTransitPassengerRoute) leg.getRoute()).getRouteId()); } + @Test + void testLegRouteModeConsistency_throws() { + // set config, such that exception is thrown due to inconsistency + Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.abortOnInconsistency); + Scenario scenario = ScenarioUtils.createScenario(config); + Person person = createInconsistentPersonForModeConsistencyCheck(scenario); + + // check exception + Assertions.assertThrows(RuntimeException.class, () -> new PersonPrepareForSim(new DummyRouter(), scenario).run(person)); + } + + @Test + void testLegRouteModeConsistency_ignored() { + // set config, such that inconsistency is ignored + Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + Scenario scenario = ScenarioUtils.createScenario(config); + Person person = createInconsistentPersonForModeConsistencyCheck(scenario); + + DummyRouter router = new DummyRouter(); + new PersonPrepareForSim(router, scenario).run(person); + // check no router call + Assertions.assertEquals(0, router.getCounter()); + } + + /** + * Creates a person with one leg, that has mode pt, but route goes over link with only mode car. + */ + private Person createInconsistentPersonForModeConsistencyCheck(Scenario scenario) { + createAndAddNetwork(scenario); + + Population pop = scenario.getPopulation(); + PopulationFactory pf = pop.getFactory(); + Person person = pf.createPerson(Id.create("1", Person.class)); + Plan plan = pf.createPlan(); + + Id l1Id = Id.createLinkId("1"); + Activity act1 = pf.createActivityFromLinkId("home", l1Id); + // Leg mode is pt, but route goes over links with car mode + Leg leg = pf.createLeg(TransportMode.pt); + NetworkRoute route = RouteUtils.createLinkNetworkRouteImpl(l1Id, List.of(l1Id), l1Id); + leg.setRoute(route); + Activity act2 = pf.createActivityFromLinkId("home", l1Id); + plan.addActivity(act1); + plan.addLeg(leg); + plan.addActivity(act2); + person.addPlan(plan); + return person; + } + private static class DummyRouter implements PlanAlgorithm { + private int counter = 0; @Override public void run(final Plan plan) { + counter++; + } + + public int getCounter() { + return counter; } } - private Link createAndAddNetwork(Scenario sc) { + /** + * Creates Network: + * (n1)---l1---(n2)---l2---(n3) + * l1 modes: car + * l2 modes: pt + */ + private void createAndAddNetwork(Scenario sc) { Network net = sc.getNetwork(); Link link1; { @@ -506,6 +563,5 @@ private Link createAndAddNetwork(Scenario sc) { net.addLink(link1); net.addLink(l2); } - return link1; } } diff --git a/matsim/src/test/java/org/matsim/core/router/FallbackRoutingModuleTest.java b/matsim/src/test/java/org/matsim/core/router/FallbackRoutingModuleTest.java index b2654bc7734..ecfb14eefe0 100644 --- a/matsim/src/test/java/org/matsim/core/router/FallbackRoutingModuleTest.java +++ b/matsim/src/test/java/org/matsim/core/router/FallbackRoutingModuleTest.java @@ -20,6 +20,7 @@ import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.ReplanningConfigGroup; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; import org.matsim.core.replanning.strategies.DefaultPlanStrategiesModule; @@ -33,6 +34,7 @@ public class FallbackRoutingModuleTest{ void calcRoute(){ Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.controller().setOutputDirectory( utils.getOutputDirectory() ); config.controller().setLastIteration( 1 ); diff --git a/matsim/src/test/java/org/matsim/core/router/NetworkRoutingInclAccessEgressModuleTest.java b/matsim/src/test/java/org/matsim/core/router/NetworkRoutingInclAccessEgressModuleTest.java index 392a301d1c4..6781d0872d2 100644 --- a/matsim/src/test/java/org/matsim/core/router/NetworkRoutingInclAccessEgressModuleTest.java +++ b/matsim/src/test/java/org/matsim/core/router/NetworkRoutingInclAccessEgressModuleTest.java @@ -181,6 +181,7 @@ private static List> getNetworkRoute(List elements) { void calcRoute_modeVehiclesFromVehiclesData_differentTypesTakeDifferentRoutes() { Config config = createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); // set test specific things Collection modes = Arrays.asList(SLOW_MODE, FAST_MODE); @@ -234,6 +235,7 @@ void calcRoute_modeVehiclesFromVehiclesData_differentTypesTakeDifferentRoutes() void calcRoute_defaultVehicle_defaultVehicleIsAssigned() { Config config = createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.qsim().setVehiclesSource(QSimConfigGroup.VehiclesSource.defaultVehicle); Scenario scenario = createScenario(config); @@ -266,7 +268,8 @@ void useAccessEgressTimeFromLinkAttributes() { Config config = createConfig(); config.qsim().setVehiclesSource(QSimConfigGroup.VehiclesSource.defaultVehicle); config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.walkConstantTimeToLink); - Scenario scenario = createScenario(config); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + Scenario scenario = createScenario(config); NetworkUtils.setLinkAccessTime(scenario.getNetwork().getLinks().get(Id.createLinkId(START_LINK)),TransportMode.car,75); NetworkUtils.setLinkEgressTime(scenario.getNetwork().getLinks().get(Id.createLinkId(END_LINK)),TransportMode.car,180); // add persons @@ -285,6 +288,7 @@ void useAccessEgressTimeFromLinkAttributes() { void useAccessEgressTimeFromConstantAndWalkTime() { Config config = createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.qsim().setVehiclesSource(QSimConfigGroup.VehiclesSource.defaultVehicle); config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.accessEgressModeToLinkPlusTimeConstant); Scenario scenario = createScenario(config); @@ -308,6 +312,7 @@ void useAccessEgressTimeFromConstantAndWalkTime() { void routingModeInEvents() { Config config = createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.qsim().setVehiclesSource(QSimConfigGroup.VehiclesSource.defaultVehicle); config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.accessEgressModeToLinkPlusTimeConstant); Scenario scenario = createScenario(config); @@ -352,6 +357,7 @@ void failifNoAccessTimeSet() { Config config = createConfig(); config.qsim().setVehiclesSource(QSimConfigGroup.VehiclesSource.defaultVehicle); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.walkConstantTimeToLink); Scenario scenario = createScenario(config); NetworkUtils.setLinkAccessTime(scenario.getNetwork().getLinks().get(Id.createLinkId(START_LINK)), TransportMode.car, 75); @@ -385,6 +391,7 @@ void calcAccessTimeFromDistanceToLink() { Config config = createConfig(); config.qsim().setVehiclesSource(QSimConfigGroup.VehiclesSource.defaultVehicle); config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.accessEgressModeToLink); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); Scenario scenario = createScenario(config); NetworkUtils.setLinkAccessTime(scenario.getNetwork().getLinks().get(Id.createLinkId(START_LINK)),TransportMode.car,75); NetworkUtils.setLinkAccessTime(scenario.getNetwork().getLinks().get(Id.createLinkId(END_LINK)),TransportMode.car,180); @@ -410,6 +417,7 @@ void noBushwackingLegs() { Config config = createConfig(); config.qsim().setVehiclesSource(QSimConfigGroup.VehiclesSource.defaultVehicle); config.routing().setAccessEgressType(AccessEgressType.none); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); Scenario scenario = createScenario(config); NetworkUtils.setLinkAccessTime(scenario.getNetwork().getLinks().get(Id.createLinkId(START_LINK)),TransportMode.car,75); NetworkUtils.setLinkAccessTime(scenario.getNetwork().getLinks().get(Id.createLinkId(END_LINK)),TransportMode.car,180); diff --git a/matsim/src/test/java/org/matsim/core/router/PseudoTransitRoutingModuleTest.java b/matsim/src/test/java/org/matsim/core/router/PseudoTransitRoutingModuleTest.java index 74f366f4864..60a48326aeb 100644 --- a/matsim/src/test/java/org/matsim/core/router/PseudoTransitRoutingModuleTest.java +++ b/matsim/src/test/java/org/matsim/core/router/PseudoTransitRoutingModuleTest.java @@ -37,6 +37,7 @@ import org.matsim.api.core.v01.population.Person; import org.matsim.api.core.v01.population.PlanElement; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.RoutingConfigGroup.TeleportedModeParams; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.ControlerDefaultsModule; @@ -135,6 +136,7 @@ private static class Fixture { public Fixture() { s.getConfig().controller().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); + s.getConfig().routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); TeleportedModeParams walk = new TeleportedModeParams(TransportMode.walk); walk.setBeelineDistanceFactor(1.3); walk.setTeleportedModeSpeed(3.0 / 3.6); diff --git a/matsim/src/test/java/org/matsim/core/router/TripRouterFactoryImplTest.java b/matsim/src/test/java/org/matsim/core/router/TripRouterFactoryImplTest.java index d2a23b546a1..bd671737a31 100644 --- a/matsim/src/test/java/org/matsim/core/router/TripRouterFactoryImplTest.java +++ b/matsim/src/test/java/org/matsim/core/router/TripRouterFactoryImplTest.java @@ -66,6 +66,7 @@ public class TripRouterFactoryImplTest { void testRestrictedNetworkNoPt() throws Exception { Config config = ConfigUtils.createConfig(); config.transit().setUseTransit( false ); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); testRestrictedNetwork( config ); } @@ -153,6 +154,7 @@ public void install() { @Test void testMonomodalNetwork() throws Exception { final Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); final Scenario scenario = ScenarioUtils.createScenario( config ); Network net = scenario.getNetwork(); diff --git a/matsim/src/test/java/org/matsim/core/utils/timing/TimeInterpretationTest.java b/matsim/src/test/java/org/matsim/core/utils/timing/TimeInterpretationTest.java index d771d585de9..497f1233891 100644 --- a/matsim/src/test/java/org/matsim/core/utils/timing/TimeInterpretationTest.java +++ b/matsim/src/test/java/org/matsim/core/utils/timing/TimeInterpretationTest.java @@ -39,6 +39,7 @@ import org.matsim.api.core.v01.population.PopulationFactory; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; import org.matsim.core.config.groups.PlansConfigGroup.TripDurationHandling; import org.matsim.core.controler.Controler; @@ -55,6 +56,7 @@ public class TimeInterpretationTest { @Test void testIgnoreDelays() { Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.plans().setTripDurationHandling(TripDurationHandling.ignoreDelays); Controler controller = prepareController(config); @@ -76,6 +78,7 @@ void testIgnoreDelays() { @Test void testShiftActivityEndTime() { Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.plans().setTripDurationHandling(TripDurationHandling.shiftActivityEndTimes); Controler controller = prepareController(config); diff --git a/matsim/src/test/java/org/matsim/examples/ModeRestrictionTest.java b/matsim/src/test/java/org/matsim/examples/ModeRestrictionTest.java new file mode 100644 index 00000000000..dee40f8f38d --- /dev/null +++ b/matsim/src/test/java/org/matsim/examples/ModeRestrictionTest.java @@ -0,0 +1,392 @@ +package org.matsim.examples; + +import com.google.common.collect.Lists; +import com.google.inject.ProvisionException; +import com.google.inject.spi.Message; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; +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.events.LinkEnterEvent; +import org.matsim.api.core.v01.events.LinkLeaveEvent; +import org.matsim.api.core.v01.events.PersonEntersVehicleEvent; +import org.matsim.api.core.v01.events.PersonLeavesVehicleEvent; +import org.matsim.api.core.v01.events.handler.LinkEnterEventHandler; +import org.matsim.api.core.v01.events.handler.LinkLeaveEventHandler; +import org.matsim.api.core.v01.events.handler.PersonEntersVehicleEventHandler; +import org.matsim.api.core.v01.events.handler.PersonLeavesVehicleEventHandler; +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.population.Activity; +import org.matsim.api.core.v01.population.Leg; +import org.matsim.api.core.v01.population.Person; +import org.matsim.core.config.Config; +import org.matsim.core.config.groups.RoutingConfigGroup; +import org.matsim.core.config.groups.ScoringConfigGroup; +import org.matsim.core.controler.AbstractModule; +import org.matsim.core.controler.Controler; +import org.matsim.core.events.EventsUtils; +import org.matsim.core.network.NetworkUtils; +import org.matsim.core.population.PopulationUtils; +import org.matsim.core.router.util.TravelTime; +import org.matsim.core.scenario.ScenarioUtils; +import org.matsim.testcases.MatsimTestUtils; +import org.matsim.utils.eventsfilecomparison.ComparisonResult; +import org.matsim.vehicles.Vehicle; + +import java.util.*; +import java.util.stream.Stream; + +// @formatter:off +/** + * In this test, we restrict the allowed modes of a link. The base case is the equil scenario. + *

+ * /... ...\ + * ------o------------o------------o----------- + * l1 (n2) l6 (n7) l15 (n12) l20 + */ +// @formatter:on +public class ModeRestrictionTest { + @RegisterExtension + private MatsimTestUtils utils = new MatsimTestUtils(); + + static Stream intersectLinkAndMode() { + List links = List.of("6", "15", "20"); + List restrictedModes = List.of("car", "bike"); + + return links.stream() + .flatMap(link -> restrictedModes.stream().map(restrictedMode -> Arguments.of(link, restrictedMode))); + } + + /** + * Setting: The agents (both car & bike) have a route from the plan. Link before and at the activity is restricted respectively. Consistency check is turned off. + * Expected behaviour: Since it is not checked, if the route contains link, which are not allowed to use anymore, it can still use the restricted link. + */ + @ParameterizedTest + @MethodSource("intersectLinkAndMode") + void testNoRouteChange_noConsistencyCheck_ok(String link, String restrictedMode) { + final Config config = prepareConfig("plans_act_link20.xml", RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + + Id linkId = Id.createLinkId(link); + Scenario scenario = ScenarioUtils.loadScenario(config); + Link networkLink = scenario.getNetwork().getLinks().get(linkId); + removeModeFromLink(networkLink, restrictedMode); + + FirstLegVisitedLinksCheck firstLegRouteCheck = new FirstLegVisitedLinksCheck( + Map.of(Id.createPersonId("car"), List.of(linkId), Id.createPersonId("bike"), List.of(linkId))); + runController(scenario, firstLegRouteCheck); + firstLegRouteCheck.assertActualContainsExpected(); + assertEventFilesSame(); + } + + /** + * Setting: The agents (both car & bike) have a route from the plan. Link before and at the activity is restricted respectively. Consistency check is turned on. + * Expected behaviour: An exception is thrown because the route is inconsistent and this is checked. + */ + @ParameterizedTest + @MethodSource("intersectLinkAndMode") + void testNoRouteChange_withConsistencyCheck_throws(String link, String restrictedMode) { + final Config config = prepareConfig("plans_act_link20.xml", RoutingConfigGroup.NetworkRouteConsistencyCheck.abortOnInconsistency); + + Id linkId = Id.createLinkId(link); + Scenario scenario = ScenarioUtils.loadScenario(config); + Link networkLink = scenario.getNetwork().getLinks().get(linkId); + removeModeFromLink(networkLink, restrictedMode); + + FirstLegVisitedLinksCheck firstLegRouteCheck = new FirstLegVisitedLinksCheck(); + RuntimeException exception = Assertions.assertThrows(RuntimeException.class, () -> runController(scenario, firstLegRouteCheck)); + Assertions.assertInstanceOf(ProvisionException.class, exception); + Assertions.assertTrue(((ProvisionException) exception).getErrorMessages().stream() + .map(Message::getMessage) + .anyMatch(m -> m.equals("java.lang.RuntimeException: Network for mode '" + restrictedMode + "' has unreachable links and nodes. This may be caused by mode restrictions on certain links. Aborting."))); + } + + /** + * Setting: The agents (both car & bike) have no route. The mode of the link in front of the activity is restricted. Consistency check is turned off. + * Expected behaviour: By default, the network is not cleaned. The router throws an exception since there is no route from home to the activity. + */ + @ParameterizedTest + @ValueSource(strings = {"car", "bike"}) + void testRerouteBeforeSim_toActNotPossible_throws(String restrictedMode) { + final Config config = prepareConfig("plans_act_link15.xml", RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + + Id link = Id.createLinkId("6"); + + Scenario scenario = restrictLinkAndResetRoutes(config, link, restrictedMode); + + FirstLegVisitedLinksCheck firstLegRouteCheck = new FirstLegVisitedLinksCheck(); + RuntimeException exception = Assertions.assertThrows(RuntimeException.class, () -> runController(scenario, firstLegRouteCheck)); + + //we can't check the root exception because the check is done in another thread. So we check for the more general exception. + Assertions.assertTrue( + exception.getMessage().contains("Exception while processing persons. Cannot guarantee that all persons have been fully processed.")); + } + + /** + * Setting: The agents (both car & bike) have no route. The mode of the link behind the activity is restricted. Consistency check is turned off. + * Expected behaviour: By default, the network is not cleaned. The router throws an exception since there is no route from the activity to home. + */ + @ParameterizedTest + @ValueSource(strings = {"car", "bike"}) + void testRerouteBeforeSim_fromActNotPossible_throws(String restrictedMode) { + final Config config = prepareConfig("plans_act_link6.xml", RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + + Id link = Id.createLinkId("15"); + + Scenario scenario = restrictLinkAndResetRoutes(config, link, restrictedMode); + + FirstLegVisitedLinksCheck firstLegRouteCheck = new FirstLegVisitedLinksCheck(); + RuntimeException exception = Assertions.assertThrows(RuntimeException.class, () -> runController(scenario, firstLegRouteCheck)); + + //we can't check the root exception because the check is done in another thread. So we check for the more general exception. + Assertions.assertTrue( + exception.getMessage().contains("Exception while processing persons. Cannot guarantee that all persons have been fully processed.")); + } + + /** + * Setting: Network and routes are cleaned before simulation. Link before the activity is restricted. Consistency check is turned off. + * Expected behaviour: The agent using the restricted are mode is rerouted. The new link of the activity for this agent is the one which is closest to the activity. + */ + @ParameterizedTest + @ValueSource(strings = {"car", "bike"}) + void testCleanNetworkAndRerouteBeforeSim_toActNotPossible_withConsistencyCheck_ok(String restrictedMode){ + final Config config = prepareConfig("plans_act_link15.xml", RoutingConfigGroup.NetworkRouteConsistencyCheck.abortOnInconsistency); + + Id link = Id.createLinkId("6"); + + Scenario scenario = ScenarioUtils.loadScenario(config); + NetworkUtils.restrictModesAndCleanNetwork(scenario.getNetwork(), l -> Map.of(link, Set.of(restrictedMode)).getOrDefault(l, Set.of())); + PopulationUtils.checkRouteModeAndReset(scenario.getPopulation(), scenario.getNetwork()); + + // New route. Note that the end link is 20, but the activity's link in the input was 15. + // But since we restricted the mode for link 6 AND 15, 20 is used as fallback. + List> newRoute = List.of(Id.createLinkId("1"), Id.createLinkId("2"), Id.createLinkId("11"), Id.createLinkId("20")); + List> oldRoute = List.of(Id.createLinkId("1"), Id.createLinkId("6"), Id.createLinkId("15")); + + String other = restrictedMode.equals("car") ? "bike" : "car"; + + FirstLegVisitedLinksCheck firstLegRouteCheck = new FirstLegVisitedLinksCheck(Map.of(Id.createPersonId(restrictedMode), newRoute, Id.createPersonId(other), oldRoute)); + runController(scenario, firstLegRouteCheck); + firstLegRouteCheck.assertActualEqualsExpected(); + assertEventFilesSame(); + } + + /** + * Setting: Network and routes are cleaned before simulation. Link from the activity is restricted. Consistency check is turned off. + * Expected behaviour: The agent using the restricted are mode is rerouted. The new link of the activity for this agent is the one which is closest to the activity. + */ + @ParameterizedTest + @ValueSource(strings = {"car", "bike"}) + void testCleanNetworkAndRerouteBeforeSim_fromActNotPossible_withConsistencyCheck_ok(String restrictedMode){ + final Config config = prepareConfig("plans_act_link6.xml", RoutingConfigGroup.NetworkRouteConsistencyCheck.abortOnInconsistency); + + Id link = Id.createLinkId("15"); + + Scenario scenario = ScenarioUtils.loadScenario(config); + NetworkUtils.restrictModesAndCleanNetwork(scenario.getNetwork(), l -> Map.of(link, Set.of(restrictedMode)).getOrDefault(l, Set.of())); + PopulationUtils.checkRouteModeAndReset(scenario.getPopulation(), scenario.getNetwork()); + + // New route. Note that the end link is 20, but the activity's link in the input was 6. + // But since we restricted the mode for link 6 AND 15, 20 is used as fallback. + List> newRoute = List.of(Id.createLinkId("1"), Id.createLinkId("2"), Id.createLinkId("11"), Id.createLinkId("20")); + List> oldRoute = List.of(Id.createLinkId("1"), Id.createLinkId("6")); + + String other = restrictedMode.equals("car") ? "bike" : "car"; + + FirstLegVisitedLinksCheck firstLegRouteCheck = new FirstLegVisitedLinksCheck(Map.of(Id.createPersonId(restrictedMode), newRoute, Id.createPersonId(other), oldRoute)); + runController(scenario, firstLegRouteCheck); + firstLegRouteCheck.assertActualEqualsExpected(); + assertEventFilesSame(); + } + + /** + * Setting: The agents (both car & bike) have no route. The mode of the activity's link is restricted. Activity has x-y-coordinate. Consistency check is turned off. + * Expected behaviour: The agents (both car & bike) are rerouted to the nearest link to the activity's coordinate. + */ + @ParameterizedTest + @ValueSource(strings = {"car", "bike"}) + void testRerouteBeforeSim_actOnRestrictedLinkWithCoords_ok(String restrictedMode) { + final Config config = prepareConfig("plans_act_link15.xml", RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + + Scenario scenario = restrictLinkAndResetRoutes(config, Id.createLinkId("15"), restrictedMode); + + // New route. Note that the end link is 20, but the activity's link in the input was 15. + // But since we restricted the mode for link 15, 20 is used as fallback. + List> newRoute = List.of(Id.createLinkId("1"), Id.createLinkId("2"), Id.createLinkId("11"), Id.createLinkId("20")); + List> oldRoute = List.of(Id.createLinkId("1"), Id.createLinkId("6"), Id.createLinkId("15")); + + String other = restrictedMode.equals("car") ? "bike" : "car"; + + FirstLegVisitedLinksCheck firstLegRouteCheck = new FirstLegVisitedLinksCheck(Map.of(Id.createPersonId(restrictedMode), newRoute, Id.createPersonId(other), oldRoute)); + runController(scenario, firstLegRouteCheck); + firstLegRouteCheck.assertActualEqualsExpected(); + assertEventFilesSame(); + } + + /** + * Setting: The agents (both car & bike) have no route. The mode of the activity's link is restricted. Activity has no x-y-coordinate. Consistency check is turned off. + * Expected behaviour: The router throws an exception since there is no fallback x-y-coordinate. + */ + @ParameterizedTest + @ValueSource(strings = {"car", "bike"}) + void testRerouteBeforeSim_actOnRestrictedLinkWithoutCoord_throws(String restrictedMode){ + final Config config = prepareConfig("plans_act_link15.xml", RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + + Id person = Id.createPersonId(restrictedMode); + Scenario scenario = restrictLinkAndResetRoutes(config, Id.createLinkId("15"), restrictedMode); + Activity act = (Activity) scenario.getPopulation().getPersons().get(person).getPlans().getFirst().getPlanElements().get(2); + act.setCoord(null); + + RuntimeException exception = Assertions.assertThrows(RuntimeException.class, () -> runController(scenario, new FirstLegVisitedLinksCheck())); + + //we can't check the root exception because the check is done in another thread. So we check for the more general exception. + Assertions.assertTrue( + exception.getMessage().contains("Exception while processing persons. Cannot guarantee that all persons have been fully processed.")); + } + + private Config prepareConfig(String plansFile, RoutingConfigGroup.NetworkRouteConsistencyCheck consistencyCheck) { + final Config config = utils.loadConfig(utils.getClassInputDirectory() + "config.xml", MatsimTestUtils.TestMethodType.Parameterized); + config.routing().setNetworkRouteConsistencyCheck(consistencyCheck); + config.plans().setInputFile(plansFile); + + ScoringConfigGroup.ModeParams params = new ScoringConfigGroup.ModeParams("bike") ; + config.scoring().addModeParams(params); + + config.qsim().setMainModes( new HashSet<>( Arrays.asList( TransportMode.car, TransportMode.bike ) ) ) ; + config.routing().setNetworkModes( Arrays.asList( TransportMode.car, TransportMode.bike ) ); + config.routing().removeTeleportedModeParams("bike"); + config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.accessEgressModeToLink); + + config.controller().setLastIteration(0); + return config; + } + + private static Scenario restrictLinkAndResetRoutes(Config config, Id link, String restrictedMode) { + Scenario scenario = ScenarioUtils.loadScenario(config); + removeModeFromLink(scenario.getNetwork().getLinks().get(link), restrictedMode); + for (Person person : scenario.getPopulation().getPersons().values()) { + Leg leg = (Leg) person.getSelectedPlan().getPlanElements().get(1); + leg.setRoute(null); + } + return scenario; + } + + private static void runController(Scenario scenario, FirstLegVisitedLinksCheck firstLegRouteCheck) { + Controler controler = new Controler(scenario); + controler.addOverridingModule(new AbstractModule() { + @Override + public void install() { + this.addEventHandlerBinding().toInstance(firstLegRouteCheck); + this.addTravelTimeBinding(TransportMode.bike).to(BikeTravelTime.class); + } + }); + controler.run(); + } + + private static void removeModeFromLink(Link networkLink, String restrictedMode) { + Set allowedModes = new HashSet<>(networkLink.getAllowedModes()); + allowedModes.remove(restrictedMode); + networkLink.setAllowedModes(allowedModes); + } + + /** + * Event handler that checks the visited Links of a person on the first leg. + */ + private static class FirstLegVisitedLinksCheck implements LinkEnterEventHandler, LinkLeaveEventHandler, PersonEntersVehicleEventHandler, + PersonLeavesVehicleEventHandler { + private final Map, List>> expected = new HashMap<>(); + private final Map, List>> actual = new HashMap<>(); + private final Map, Id> currentPersonByVehicle = new HashMap<>(); + private final Map, Boolean> onFirstLeg = new HashMap<>(); + + public FirstLegVisitedLinksCheck() { + } + + public FirstLegVisitedLinksCheck(Map, List>> expected) { + this.expected.putAll(expected); + } + + public FirstLegVisitedLinksCheck(Id personId, List> expected) { + this.expected.put(personId, expected); + } + + public FirstLegVisitedLinksCheck(Id personId, Id expected) { + this.expected.put(personId, Collections.singletonList(expected)); + } + + @Override + public void handleEvent(LinkLeaveEvent event) { + addLinkIdToActual(this.currentPersonByVehicle.get(event.getVehicleId()), event.getLinkId()); + } + + @Override + public void handleEvent(LinkEnterEvent event) { + addLinkIdToActual(this.currentPersonByVehicle.get(event.getVehicleId()), event.getLinkId()); + } + + @Override + public void handleEvent(PersonLeavesVehicleEvent event) { + this.currentPersonByVehicle.remove(event.getVehicleId()); + this.onFirstLeg.put(event.getPersonId(), false); + } + + @Override + public void handleEvent(PersonEntersVehicleEvent event) { + this.currentPersonByVehicle.put(event.getVehicleId(), event.getPersonId()); + this.onFirstLeg.putIfAbsent(event.getPersonId(), true); + } + + private void addLinkIdToActual(Id personId, Id linkId) { + if (!this.onFirstLeg.get(personId)) { + return; + } + actual.putIfAbsent(personId, Lists.newArrayList(linkId)); + List> linkIds = actual.get(personId); + if (linkIds.getLast() == null || linkIds.getLast() == linkId) { + return; + } + linkIds.add(linkId); + } + + public void assertActualEqualsExpected() { + Assertions.assertEquals(expected, actual); + } + + public void assertActualContainsExpected() { + for (Map.Entry, List>> entry : expected.entrySet()) { + Id personId = entry.getKey(); + List> expected = entry.getValue(); + List> actual = this.actual.get(personId); + Assertions.assertNotNull(actual); + Assertions.assertTrue(actual.containsAll(expected)); + } + } + } + + + private static class BikeTravelTime implements TravelTime { + @Override public double getLinkTravelTime( Link link, double time, Person person, Vehicle vehicle ){ + return 1. ; + } + } + + /** + * Note that this method alone would be sufficient to check the simulation behaviour. But since I have already written the eventHandler, I will use it as well. + * If at some point it is too nervig, to maintain both test methodologies here, the eventHandler can be removed. + * But, I think it makes clearer what is the relevant thing to check. paul aug '24 + */ + private void assertEventFilesSame() { + String fileName = "output_events.xml.gz"; + + String inputFile = utils.getInputDirectory() + utils.getParameterizedTestInputString() + "/" + fileName; + String outputFile = utils.getOutputDirectory() + "/" + fileName; + + ComparisonResult comparisonResult = EventsUtils.compareEventsFiles(inputFile, outputFile); + if (comparisonResult != ComparisonResult.FILES_ARE_EQUAL) + Assertions.fail("Event files are not equal: " + comparisonResult); + } +} diff --git a/matsim/src/test/java/org/matsim/integration/SimulateAndScoreTest.java b/matsim/src/test/java/org/matsim/integration/SimulateAndScoreTest.java index 9bd875631c0..6c57b14d3ca 100644 --- a/matsim/src/test/java/org/matsim/integration/SimulateAndScoreTest.java +++ b/matsim/src/test/java/org/matsim/integration/SimulateAndScoreTest.java @@ -43,6 +43,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.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Injector; @@ -89,6 +90,7 @@ public class SimulateAndScoreTest { @Test void testRealPtScore() { final Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.transit().setUseTransit(true); ScoringConfigGroup.ActivityParams h = new ScoringConfigGroup.ActivityParams("h"); @@ -240,7 +242,9 @@ public void install() { @Test void testTeleportationScore() { - Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); + Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); + Scenario scenario = ScenarioUtils.createScenario(config); Network network = scenario.getNetwork(); Node node1 = network.getFactory().createNode(Id.create("1", Node.class), new Coord(0, 0)); Node node2 = network.getFactory().createNode(Id.create("2", Node.class), new Coord(100, 0)); diff --git a/matsim/src/test/java/org/matsim/integration/invertednetworks/InvertedNetworkRoutingTestFixture.java b/matsim/src/test/java/org/matsim/integration/invertednetworks/InvertedNetworkRoutingTestFixture.java index e63fb5115fa..4a0a6ef92bd 100644 --- a/matsim/src/test/java/org/matsim/integration/invertednetworks/InvertedNetworkRoutingTestFixture.java +++ b/matsim/src/test/java/org/matsim/integration/invertednetworks/InvertedNetworkRoutingTestFixture.java @@ -38,6 +38,7 @@ 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.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings; import org.matsim.core.replanning.strategies.DefaultPlanStrategiesModule; @@ -78,6 +79,7 @@ public class InvertedNetworkRoutingTestFixture { public InvertedNetworkRoutingTestFixture(boolean doCreateModes, boolean doCreateLanes, boolean doCreateSignals) { Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.controller().setLastIteration(0); config.controller().setLinkToLinkRoutingEnabled(true); config.travelTimeCalculator().setCalculateLinkToLinkTravelTimes(true); diff --git a/matsim/src/test/java/org/matsim/integration/population/NonAlternatingPlanElementsIT.java b/matsim/src/test/java/org/matsim/integration/population/NonAlternatingPlanElementsIT.java index 033857c8a4c..d4caf530dc0 100644 --- a/matsim/src/test/java/org/matsim/integration/population/NonAlternatingPlanElementsIT.java +++ b/matsim/src/test/java/org/matsim/integration/population/NonAlternatingPlanElementsIT.java @@ -37,6 +37,7 @@ import org.matsim.core.config.Config; import org.matsim.core.config.groups.FacilitiesConfigGroup; import org.matsim.core.config.groups.PlansConfigGroup.HandlingOfPlansWithoutRoutingMode; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.Controler; import org.matsim.core.network.io.MatsimNetworkReader; import org.matsim.core.population.routes.NetworkRoute; @@ -97,6 +98,7 @@ void test_Controler_QSim_Routechoice_acts() { @Test void test_Controler_QSim_Routechoice_legs() { Config config = this.utils.loadConfig("test/scenarios/equil/config.xml"); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.controller().setMobsim("qsim"); config.controller().setLastIteration(10); config.plans().setHandlingOfPlansWithoutRoutingMode(HandlingOfPlansWithoutRoutingMode.useMainModeIdentifier); diff --git a/matsim/src/test/java/org/matsim/integration/replanning/ChangeTripModeIntegrationTest.java b/matsim/src/test/java/org/matsim/integration/replanning/ChangeTripModeIntegrationTest.java index e3d4651b7e0..950434f316d 100644 --- a/matsim/src/test/java/org/matsim/integration/replanning/ChangeTripModeIntegrationTest.java +++ b/matsim/src/test/java/org/matsim/integration/replanning/ChangeTripModeIntegrationTest.java @@ -38,6 +38,7 @@ import org.matsim.api.core.v01.population.Population; import org.matsim.core.config.Config; import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Injector; import org.matsim.core.controler.NewControlerModule; @@ -78,6 +79,7 @@ public class ChangeTripModeIntegrationTest { void testStrategyManagerConfigLoaderIntegration() { // setup config final Config config = utils.loadConfig((String)null); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); final MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); final StrategySettings strategySettings = new StrategySettings(Id.create("1", StrategySettings.class)); strategySettings.setStrategyName("ChangeTripMode"); diff --git a/matsim/src/test/java/org/matsim/integration/timevariantnetworks/QSimIntegrationTest.java b/matsim/src/test/java/org/matsim/integration/timevariantnetworks/QSimIntegrationTest.java index 609737eb135..7c0b8b6eac7 100644 --- a/matsim/src/test/java/org/matsim/integration/timevariantnetworks/QSimIntegrationTest.java +++ b/matsim/src/test/java/org/matsim/integration/timevariantnetworks/QSimIntegrationTest.java @@ -50,6 +50,7 @@ import org.matsim.api.core.v01.population.Population; import org.matsim.core.api.experimental.events.EventsManager; import org.matsim.core.config.Config; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.controler.PrepareForSimUtils; import org.matsim.core.events.EventsUtils; import org.matsim.core.mobsim.qsim.QSimBuilder; @@ -82,6 +83,7 @@ public class QSimIntegrationTest { @Test void testFreespeed() { Config config = utils.loadConfig((String)null); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.network().setTimeVariantNetwork(true); Scenario scenario = ScenarioUtils.createScenario(config); @@ -132,6 +134,7 @@ void testCapacity() { final double capacityFactor = 0.5; Config config = utils.loadConfig((String)null); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.network().setTimeVariantNetwork(true); MutableScenario scenario = (MutableScenario) ScenarioUtils.createScenario(config); @@ -203,6 +206,7 @@ void testZeroCapacity() { final double capacityFactor = 0.0; Config config = utils.loadConfig((String)null); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.network().setTimeVariantNetwork(true); config.qsim().setStartTime(0.0); final double simEndTime = 7200.0; diff --git a/matsim/src/test/java/org/matsim/testcases/MatsimTestUtils.java b/matsim/src/test/java/org/matsim/testcases/MatsimTestUtils.java index 112bcaaddaf..287858329cb 100644 --- a/matsim/src/test/java/org/matsim/testcases/MatsimTestUtils.java +++ b/matsim/src/test/java/org/matsim/testcases/MatsimTestUtils.java @@ -51,6 +51,10 @@ public final class MatsimTestUtils implements BeforeEachCallback, AfterEachCallback { private static final Logger log = LogManager.getLogger(MatsimTestUtils.class); + public enum TestMethodType { + Normal, Parameterized + } + /** * A constant for the exactness when comparing doubles. */ @@ -79,6 +83,7 @@ public final class MatsimTestUtils implements BeforeEachCallback, AfterEachCallb private Class testClass = null; private String testMethodName = null; + private String testDisplayName = null; public MatsimTestUtils() { MatsimRandom.reset(); @@ -88,6 +93,7 @@ public MatsimTestUtils() { public void beforeEach(ExtensionContext extensionContext) { this.testClass = extensionContext.getTestClass().orElseThrow(); this.testMethodName = extensionContext.getRequiredTestMethod().getName(); + this.testDisplayName = extensionContext.getDisplayName(); } @Override @@ -163,37 +169,62 @@ public Config createConfig(URL context) { return config; } - /** - * Loads a configuration from file (or the default config if configfile is null). + * Loads a configuration from file (or the default config if configfile is null) + * and sets the output directory to {classPath}/{methodName}/. For parameterized tests, the output directory is {classPath}/{methodName}/{parameters}/. * * @param configfile The path/filename of a configuration file, or null to load the default configuration. * @return The loaded configuration. */ - public Config loadConfig(final String configfile, final ConfigGroup... customGroups) { + public Config loadConfig(final String configfile, TestMethodType testMethodType, final ConfigGroup... customGroups) { Config config; if (configfile != null) { config = ConfigUtils.loadConfig(configfile, customGroups); } else { config = ConfigUtils.createConfig( customGroups ); } - this.outputDirectory = getOutputDirectory(); - config.controller().setOutputDirectory(this.outputDirectory); - return config; + return setOutputDirectory(config, testMethodType); } - public Config loadConfig(final URL configfile, final ConfigGroup... customGroups) { + public Config loadConfig(final String configfile, final ConfigGroup... customGroups) { + return loadConfig(configfile, TestMethodType.Normal, customGroups); + } + + public Config loadConfig(final URL configfile, TestMethodType testMethodType, final ConfigGroup... customGroups) { Config config; if (configfile != null) { config = ConfigUtils.loadConfig(configfile, customGroups); } else { config = ConfigUtils.createConfig( customGroups ); } - this.outputDirectory = getOutputDirectory(); + return setOutputDirectory(config, testMethodType); + } + + public Config loadConfig(final URL configfile, final ConfigGroup... customGroups) { + return loadConfig(configfile, TestMethodType.Normal, customGroups); + } + + /** + * Sets the output directory to {classPath}/{methodName}/{subDir}. For normal tests, there is no {subDir}. + * For parameterized tests, {subDir} is a slightly adapted test input parameter string (aka display name of JUnit 5). + * E.g.: "[1] car, 6" will be transformed to "car_6". + */ + private Config setOutputDirectory(Config config, TestMethodType testMethodType) { + String subDirectory = switch (testMethodType) { + case Normal -> ""; + case Parameterized -> getParameterizedTestInputString(); + }; + this.outputDirectory = getOutputDirectory(subDirectory); config.controller().setOutputDirectory(this.outputDirectory); return config; } + public String getParameterizedTestInputString() { + String parameters = this.testDisplayName.replaceFirst("^.*?\\]", "").trim(); + parameters = parameters.replaceAll(" ", "").replaceAll("[^a-zA-Z0-9]", "_"); + return parameters; + } + public Config createConfig(final ConfigGroup... customGroups) { Config config = ConfigUtils.createConfig( customGroups ); this.outputDirectory = getOutputDirectory(); diff --git a/matsim/src/test/java/org/matsim/withinday/controller/ExperiencedPlansWriterTest.java b/matsim/src/test/java/org/matsim/withinday/controller/ExperiencedPlansWriterTest.java index bad57d42cc7..e6cc6ff0c15 100644 --- a/matsim/src/test/java/org/matsim/withinday/controller/ExperiencedPlansWriterTest.java +++ b/matsim/src/test/java/org/matsim/withinday/controller/ExperiencedPlansWriterTest.java @@ -38,6 +38,7 @@ import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.ControllerConfigGroup; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; @@ -82,6 +83,7 @@ void testWriteFile() { Config config = ConfigUtils.createConfig(); config.controller().setOutputDirectory(this.utils.getOutputDirectory()); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.qsim().setEndTime(24 * 3600); diff --git a/matsim/src/test/java/org/matsim/withinday/trafficmonitoring/WithinDayTravelTimeWithNetworkChangeEventsTest.java b/matsim/src/test/java/org/matsim/withinday/trafficmonitoring/WithinDayTravelTimeWithNetworkChangeEventsTest.java index 2b63bbb9f0d..1de5fb1096d 100644 --- a/matsim/src/test/java/org/matsim/withinday/trafficmonitoring/WithinDayTravelTimeWithNetworkChangeEventsTest.java +++ b/matsim/src/test/java/org/matsim/withinday/trafficmonitoring/WithinDayTravelTimeWithNetworkChangeEventsTest.java @@ -43,6 +43,7 @@ import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.groups.ControllerConfigGroup; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; @@ -77,6 +78,7 @@ final void testTTviaMobSimAfterSimStepListener() { String outputDirectory = testUtils.getOutputDirectory() + "output_TTviaMobsimAfterSimStepListener/"; final Config config = ConfigUtils.createConfig(); + config.routing().setNetworkRouteConsistencyCheck(RoutingConfigGroup.NetworkRouteConsistencyCheck.disable); config.controller().setFirstIteration(0); config.controller().setLastIteration(0); diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/config.xml b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/config.xml new file mode 100755 index 00000000000..b61e26d25d8 --- /dev/null +++ b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/config.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/network.xml b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/network.xml new file mode 100644 index 00000000000..e62e521bf50 --- /dev/null +++ b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/network.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/plans_act_link15.xml b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/plans_act_link15.xml new file mode 100644 index 00000000000..72ac9cf223b --- /dev/null +++ b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/plans_act_link15.xml @@ -0,0 +1,37 @@ + + + + + + + + + 1 6 15 + + + + 15 20 21 22 23 1 + + + + + + + + + + bike + + 1 6 15 + + + + + bike + + 15 20 21 22 23 1 + + + + + diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/plans_act_link20.xml b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/plans_act_link20.xml new file mode 100644 index 00000000000..6209ab27a8f --- /dev/null +++ b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/plans_act_link20.xml @@ -0,0 +1,37 @@ + + + + + + + + + 1 6 15 20 + + + + 20 21 22 23 1 + + + + + + + + + + bike + + 1 6 15 20 + + + + + bike + + 20 21 22 23 1 + + + + + diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/plans_act_link6.xml b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/plans_act_link6.xml new file mode 100644 index 00000000000..d8bdcd6ec12 --- /dev/null +++ b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/plans_act_link6.xml @@ -0,0 +1,37 @@ + + + + + + + + + 1 6 + + + + 6 15 20 21 22 23 1 + + + + + + + + + + bike + + 1 6 + + + + + bike + + 6 15 20 21 22 23 1 + + + + + diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testCleanNetworkAndRerouteBeforeSim_fromActNotPossible_withConsistencyCheck_ok/bike/output_events.xml.gz b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testCleanNetworkAndRerouteBeforeSim_fromActNotPossible_withConsistencyCheck_ok/bike/output_events.xml.gz new file mode 100644 index 00000000000..b310d236f60 Binary files /dev/null and b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testCleanNetworkAndRerouteBeforeSim_fromActNotPossible_withConsistencyCheck_ok/bike/output_events.xml.gz differ diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testCleanNetworkAndRerouteBeforeSim_fromActNotPossible_withConsistencyCheck_ok/car/output_events.xml.gz b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testCleanNetworkAndRerouteBeforeSim_fromActNotPossible_withConsistencyCheck_ok/car/output_events.xml.gz new file mode 100644 index 00000000000..1bd8331382e Binary files /dev/null and b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testCleanNetworkAndRerouteBeforeSim_fromActNotPossible_withConsistencyCheck_ok/car/output_events.xml.gz differ diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testCleanNetworkAndRerouteBeforeSim_toActNotPossible_withConsistencyCheck_ok/bike/output_events.xml.gz b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testCleanNetworkAndRerouteBeforeSim_toActNotPossible_withConsistencyCheck_ok/bike/output_events.xml.gz new file mode 100644 index 00000000000..42ba2aa5fe1 Binary files /dev/null and b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testCleanNetworkAndRerouteBeforeSim_toActNotPossible_withConsistencyCheck_ok/bike/output_events.xml.gz differ diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testCleanNetworkAndRerouteBeforeSim_toActNotPossible_withConsistencyCheck_ok/car/output_events.xml.gz b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testCleanNetworkAndRerouteBeforeSim_toActNotPossible_withConsistencyCheck_ok/car/output_events.xml.gz new file mode 100644 index 00000000000..02749b188d5 Binary files /dev/null and b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testCleanNetworkAndRerouteBeforeSim_toActNotPossible_withConsistencyCheck_ok/car/output_events.xml.gz differ diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/15_bike/output_events.xml.gz b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/15_bike/output_events.xml.gz new file mode 100644 index 00000000000..c6c664e79df Binary files /dev/null and b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/15_bike/output_events.xml.gz differ diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/15_car/output_events.xml.gz b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/15_car/output_events.xml.gz new file mode 100644 index 00000000000..c6c664e79df Binary files /dev/null and b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/15_car/output_events.xml.gz differ diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/20_bike/output_events.xml.gz b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/20_bike/output_events.xml.gz new file mode 100644 index 00000000000..c6c664e79df Binary files /dev/null and b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/20_bike/output_events.xml.gz differ diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/20_car/output_events.xml.gz b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/20_car/output_events.xml.gz new file mode 100644 index 00000000000..c6c664e79df Binary files /dev/null and b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/20_car/output_events.xml.gz differ diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/6_bike/output_events.xml.gz b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/6_bike/output_events.xml.gz new file mode 100644 index 00000000000..c6c664e79df Binary files /dev/null and b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/6_bike/output_events.xml.gz differ diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/6_car/output_events.xml.gz b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/6_car/output_events.xml.gz new file mode 100644 index 00000000000..c6c664e79df Binary files /dev/null and b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testNoRouteChange_noConsistencyCheck_ok/6_car/output_events.xml.gz differ diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testRerouteBeforeSim_actOnRestrictedLinkWithCoords_ok/bike/output_events.xml.gz b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testRerouteBeforeSim_actOnRestrictedLinkWithCoords_ok/bike/output_events.xml.gz new file mode 100644 index 00000000000..6db5a801ac3 Binary files /dev/null and b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testRerouteBeforeSim_actOnRestrictedLinkWithCoords_ok/bike/output_events.xml.gz differ diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testRerouteBeforeSim_actOnRestrictedLinkWithCoords_ok/car/output_events.xml.gz b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testRerouteBeforeSim_actOnRestrictedLinkWithCoords_ok/car/output_events.xml.gz new file mode 100644 index 00000000000..b86ec8cdd7e Binary files /dev/null and b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/testRerouteBeforeSim_actOnRestrictedLinkWithCoords_ok/car/output_events.xml.gz differ diff --git a/matsim/test/input/org/matsim/examples/ModeRestrictionTest/vehicles.xml b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/vehicles.xml new file mode 100644 index 00000000000..f38bea12f30 --- /dev/null +++ b/matsim/test/input/org/matsim/examples/ModeRestrictionTest/vehicles.xml @@ -0,0 +1,35 @@ + + + + + + + bike + + + + + + + + + + + + + + + + + + + + + + + + + + + +