From ca38361bd2e30a1263190e795abc0f595c57335d Mon Sep 17 00:00:00 2001 From: Paul Heinrich Date: Wed, 8 May 2024 16:02:33 +0200 Subject: [PATCH] add routing test with multiple same options --- .../AbstractLeastCostPathCalculatorTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/matsim/src/test/java/org/matsim/core/router/AbstractLeastCostPathCalculatorTest.java b/matsim/src/test/java/org/matsim/core/router/AbstractLeastCostPathCalculatorTest.java index 0bb049ca193..2c59cad79d6 100644 --- a/matsim/src/test/java/org/matsim/core/router/AbstractLeastCostPathCalculatorTest.java +++ b/matsim/src/test/java/org/matsim/core/router/AbstractLeastCostPathCalculatorTest.java @@ -24,11 +24,13 @@ import javax.xml.parsers.ParserConfigurationException; +import org.apache.logging.log4j.LogManager; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.extension.RegisterExtension; import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.Identifiable; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; @@ -92,4 +94,31 @@ void testCalcLeastCostPath_SameFromTo() throws SAXException, ParserConfiguration assertEquals(network.getNodes().get(Id.create("12", Node.class)), path.nodes.get(0)); } + @Test + void testCalcLeastCostPath_withOptions() throws SAXException, ParserConfigurationException, IOException { + Config config = utils.loadConfig((String)null); + Scenario scenario = ScenarioUtils.createScenario(config); + Network network = scenario.getNetwork(); + new MatsimNetworkReader(scenario.getNetwork()).readFile("test/scenarios/equil/network.xml"); + + //path from 1 to 13 has several options with the same travel time + Node node1 = network.getNodes().get(Id.create("1", Node.class)); + Node node13 = network.getNodes().get(Id.create("13", Node.class)); + + LeastCostPathCalculator routerAlgo = getLeastCostPathCalculator(network); + Path path = routerAlgo.calcLeastCostPath(node1, node13, 8.0*3600, null, null); + + assertEquals(5, path.nodes.size(), "number of nodes wrong."); + assertEquals(4, path.links.size(), "number of links wrong."); + assertEquals(network.getNodes().get(Id.create("1", Node.class)), path.nodes.get(0)); + assertEquals(network.getNodes().get(Id.create("2", Node.class)), path.nodes.get(1)); + assertEquals(network.getNodes().get(Id.create("3", Node.class)), path.nodes.get(2)); + assertEquals(network.getNodes().get(Id.create("12", Node.class)), path.nodes.get(3)); + assertEquals(network.getNodes().get(Id.create("13", Node.class)), path.nodes.get(4)); + assertEquals(network.getLinks().get(Id.create("1", Link.class)), path.links.get(0)); + assertEquals(network.getLinks().get(Id.create("2", Link.class)), path.links.get(1)); + assertEquals(network.getLinks().get(Id.create("11", Link.class)), path.links.get(2)); + assertEquals(network.getLinks().get(Id.create("20", Link.class)), path.links.get(3)); + } + }