diff --git a/matsim/src/test/java/org/matsim/core/network/algorithms/TransportModeNetworkFilterTest.java b/matsim/src/test/java/org/matsim/core/network/algorithms/TransportModeNetworkFilterTest.java index bd159f2cf7f..381728164b2 100644 --- a/matsim/src/test/java/org/matsim/core/network/algorithms/TransportModeNetworkFilterTest.java +++ b/matsim/src/test/java/org/matsim/core/network/algorithms/TransportModeNetworkFilterTest.java @@ -19,6 +19,7 @@ package org.matsim.core.network.algorithms; +import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -35,6 +36,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.network.DisallowedNextLinks; import org.matsim.core.network.NetworkChangeEvent; import org.matsim.core.network.NetworkChangeEvent.ChangeType; import org.matsim.core.network.NetworkChangeEvent.ChangeValue; @@ -90,6 +92,16 @@ void testFilter_SingleMode() { Assertions.assertNotNull(subNetwork.getNodes().get(f.nodeIds[4]).getInLinks().get(f.linkIds[3])); Assertions.assertEquals(1, subNetwork.getNodes().get(f.nodeIds[7]).getOutLinks().size()); Assertions.assertNotNull(subNetwork.getNodes().get(f.nodeIds[7]).getOutLinks().get(f.linkIds[7])); + Assertions.assertEquals( + new DisallowedNextLinks.Builder() + .withDisallowedLinkSequence(TransportMode.car, Arrays.asList(f.linkIds[14])) + .build(), + NetworkUtils.getDisallowedNextLinks(subNetwork.getLinks().get(f.linkIds[3]))); + Assertions.assertEquals( + new DisallowedNextLinks.Builder() + .withDisallowedLinkSequence(TransportMode.car, Arrays.asList(f.linkIds[7])) + .build(), + NetworkUtils.getDisallowedNextLinks(subNetwork.getLinks().get(f.linkIds[6]))); subNetwork = ScenarioUtils.createScenario(ConfigUtils.createConfig()).getNetwork(); filter.filter(subNetwork, createHashSet(TransportMode.bike)); @@ -115,6 +127,11 @@ void testFilter_SingleMode() { Assertions.assertNotNull(subNetwork.getNodes().get(f.nodeIds[4]).getInLinks().get(f.linkIds[13])); Assertions.assertEquals(1, subNetwork.getNodes().get(f.nodeIds[4]).getOutLinks().size()); Assertions.assertNotNull(subNetwork.getNodes().get(f.nodeIds[4]).getOutLinks().get(f.linkIds[4])); + Assertions.assertEquals( + new DisallowedNextLinks.Builder() + .withDisallowedLinkSequence(TransportMode.bike, Arrays.asList(f.linkIds[7])) + .build(), + NetworkUtils.getDisallowedNextLinks(subNetwork.getLinks().get(f.linkIds[6]))); subNetwork = ScenarioUtils.createScenario(ConfigUtils.createConfig()).getNetwork(); filter.filter(subNetwork, createHashSet(TransportMode.walk)); @@ -137,7 +154,7 @@ void testFilter_SingleMode() { Assertions.assertNotNull(subNetwork.getNodes().get(f.nodeIds[4]).getInLinks().get(f.linkIds[13])); Assertions.assertEquals(1, subNetwork.getNodes().get(f.nodeIds[4]).getOutLinks().size()); Assertions.assertNotNull(subNetwork.getNodes().get(f.nodeIds[4]).getOutLinks().get(f.linkIds[14])); - } + } @Test void testFilter_MultipleModes() { @@ -183,6 +200,17 @@ void testFilter_MultipleModes() { Assertions.assertNotNull(subNetwork.getNodes().get(f.nodeIds[7]).getOutLinks().get(f.linkIds[7])); Assertions.assertEquals(1, subNetwork.getNodes().get(f.nodeIds[10]).getInLinks().size()); Assertions.assertNotNull(subNetwork.getNodes().get(f.nodeIds[10]).getInLinks().get(f.linkIds[9])); + Assertions.assertEquals( + new DisallowedNextLinks.Builder() + .withDisallowedLinkSequence(TransportMode.car, Arrays.asList(f.linkIds[14])) + .build(), + NetworkUtils.getDisallowedNextLinks(subNetwork.getLinks().get(f.linkIds[3]))); + Assertions.assertEquals( + new DisallowedNextLinks.Builder() + .withDisallowedLinkSequence(TransportMode.car, Arrays.asList(f.linkIds[7])) + .withDisallowedLinkSequence(TransportMode.bike, Arrays.asList(f.linkIds[7])) + .build(), + NetworkUtils.getDisallowedNextLinks(subNetwork.getLinks().get(f.linkIds[6]))); subNetwork = ScenarioUtils.createScenario(ConfigUtils.createConfig()).getNetwork(); filter.filter(subNetwork, createHashSet(TransportMode.bike, TransportMode.walk)); @@ -218,6 +246,11 @@ void testFilter_MultipleModes() { Assertions.assertNotNull(subNetwork.getNodes().get(f.nodeIds[4]).getInLinks().get(f.linkIds[13])); Assertions.assertEquals(1, subNetwork.getNodes().get(f.nodeIds[10]).getOutLinks().size()); Assertions.assertNotNull(subNetwork.getNodes().get(f.nodeIds[10]).getOutLinks().get(f.linkIds[16])); + Assertions.assertEquals( + new DisallowedNextLinks.Builder() + .withDisallowedLinkSequence(TransportMode.bike, Arrays.asList(f.linkIds[7])) + .build(), + NetworkUtils.getDisallowedNextLinks(subNetwork.getLinks().get(f.linkIds[6]))); } @Test @@ -361,6 +394,10 @@ void testFilter_timeVariant() { * c cb * * Legend: c = car, w = walk, b = bike + * + * With turn restrictions: + * - for car: 3 -> 14 and 6 -> 7 + * - for bike: 6 -> 7 * * * @@ -419,6 +456,14 @@ private static class Fixture { network.addLink(createLink(network, this.linkIds[14], this.nodeIds[ 4], this.nodeIds[ 7], this.modesCW)); network.addLink(createLink(network, this.linkIds[15], this.nodeIds[ 7], this.nodeIds[10], this.modesW)); network.addLink(createLink(network, this.linkIds[16], this.nodeIds[10], this.nodeIds[13], this.modesCBW)); + + // turn restrictions: create one link with only car turn restriction, one link with car and bike + Link link3 = network.getLinks().get(this.linkIds[3]); + NetworkUtils.addDisallowedNextLinks(link3, TransportMode.car, Arrays.asList(this.linkIds[14])); + + Link link6 = network.getLinks().get(this.linkIds[6]); + NetworkUtils.addDisallowedNextLinks(link6, TransportMode.car, Arrays.asList(this.linkIds[7])); + NetworkUtils.addDisallowedNextLinks(link6, TransportMode.bike, Arrays.asList(this.linkIds[7])); } }