Skip to content

Commit

Permalink
testbanCarAndRideFromNetworkArea
Browse files Browse the repository at this point in the history
  • Loading branch information
tschlenther committed Aug 31, 2023
1 parent 82f3c37 commit 4c56c1c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"),
Expand All @@ -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(){
Expand Down

0 comments on commit 4c56c1c

Please sign in to comment.