From 4c56c1cfcd746c21f4f4cf16e39b245ef1e73289 Mon Sep 17 00:00:00 2001 From: tschlenther Date: Thu, 31 Aug 2023 14:22:57 +0200 Subject: [PATCH] testbanCarAndRideFromNetworkArea --- .../run/replaceCarByDRT/ReplaceCarByDRT.java | 8 ++++--- .../BerlinNoInnerCarTripsScenarioTest.java | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/matsim/run/replaceCarByDRT/ReplaceCarByDRT.java b/src/main/java/org/matsim/run/replaceCarByDRT/ReplaceCarByDRT.java index cbe13ff..938dcce 100644 --- a/src/main/java/org/matsim/run/replaceCarByDRT/ReplaceCarByDRT.java +++ b/src/main/java/org/matsim/run/replaceCarByDRT/ReplaceCarByDRT.java @@ -528,9 +528,11 @@ private static void deleteCarRoutesThatHaveForbiddenLinks(Population population, .forEach(leg -> { if(leg.getMode().equals(TransportMode.car)){ Route route = leg.getRoute(); - boolean routeTouchesZone = (route instanceof NetworkRoute && ((NetworkRoute) route).getLinkIds().stream().filter(l -> forbiddenLinks.contains(l)).findAny().isPresent() ); - if(routeTouchesZone || forbiddenLinks.contains(route.getStartLinkId()) || forbiddenLinks.contains(route.getEndLinkId()) ){ - leg.setRoute(null); + if (route != null){ + boolean routeTouchesZone = (route instanceof NetworkRoute && ((NetworkRoute) route).getLinkIds().stream().filter(l -> forbiddenLinks.contains(l)).findAny().isPresent() ); + if(routeTouchesZone || forbiddenLinks.contains(route.getStartLinkId()) || forbiddenLinks.contains(route.getEndLinkId()) ){ + leg.setRoute(null); + } } } })); diff --git a/src/test/java/org/matsim/run/replaceCarByDRT/BerlinNoInnerCarTripsScenarioTest.java b/src/test/java/org/matsim/run/replaceCarByDRT/BerlinNoInnerCarTripsScenarioTest.java index e841987..fd449df 100644 --- a/src/test/java/org/matsim/run/replaceCarByDRT/BerlinNoInnerCarTripsScenarioTest.java +++ b/src/test/java/org/matsim/run/replaceCarByDRT/BerlinNoInnerCarTripsScenarioTest.java @@ -12,6 +12,7 @@ import org.matsim.api.core.v01.population.Person; import org.matsim.api.core.v01.population.Plan; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.network.NetworkUtils; import org.matsim.core.population.PopulationUtils; import org.matsim.core.router.TripStructureUtils; import org.matsim.core.scenario.ScenarioUtils; @@ -46,6 +47,8 @@ public static void main() { SCENARIO_CLOSEST_INSIDE = ScenarioUtils.createScenario(ConfigUtils.createConfig()); PopulationUtils.readPopulation(SCENARIO_CLOSEST_INSIDE.getPopulation(), "scenarios/berlin/replaceCarByDRT/noModeChoice/replaceCarByDRT.testPlans.xml.gz"); + NetworkUtils.readNetwork(SCENARIO_CLOSEST_INSIDE.getNetwork(), + "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/berlin/berlin-v5.5-10pct/input/berlin-v5.5-network.xml.gz"); ReplaceCarByDRT.prepareInputPlansForCarProhibitionWithPRLogic(SCENARIO_CLOSEST_INSIDE, Set.of(TransportMode.drt, TransportMode.pt), IOUtils.resolveFileOrResource("scenarios/berlin/replaceCarByDRT/noModeChoice/shp/hundekopf-carBanArea.shp"), @@ -59,6 +62,26 @@ public static void main() { } + @Test + public void testbanCarAndRideFromNetworkArea(){ + ReplaceCarByDRT.banCarAndRideFromNetworkArea(SCENARIO_CLOSEST_INSIDE, + IOUtils.resolveFileOrResource("scenarios/berlin/replaceCarByDRT/noModeChoice/shp/hundekopf-carBanArea.shp"), + Set.of("motorway")); + + //TODO check 1 car route that touched one forbidden link and now the route is null + //TODO check 1 car route that did not touch one forbidden link and still has its route + +// //motorway links inside ban area are still allowed for cars +// Assert.assertTrue(SCENARIO_CLOSEST_INSIDE.getNetwork().getLinks().get(Id.createLinkId("anyMotorwayLink")).getAllowedModes().contains(TransportMode.car)); +// +// //secondary links inside ban area do not allow cars anymore +// Assert.assertFalse(SCENARIO_CLOSEST_INSIDE.getNetwork().getLinks().get(Id.createLinkId("anySmallLink")).getAllowedModes().contains(TransportMode.car)); +// +// //secondary links outside ban area still allow cars +// Assert.assertFalse(SCENARIO_CLOSEST_INSIDE.getNetwork().getLinks().get(Id.createLinkId("anySmallLink")).getAllowedModes().contains(TransportMode.car)); + + } + @Test public void testAgentAttributes(){