Skip to content

Commit

Permalink
test turn restrictions in mode filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
tduberne committed May 3, 2024
1 parent b08d6b9 commit 19005ec
Showing 1 changed file with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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() {
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
*
* </pre>
*
Expand Down Expand Up @@ -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]));
}

}
Expand Down

0 comments on commit 19005ec

Please sign in to comment.