public void testMultipleEnds() { Fixture f = new Fixture(); TestTimeCost tc = new TestTimeCost(); tc.setData(Id.create(1, Link.class), 2.0, 2.0);
public void testMultipleStartsAndEnds() { Fixture f = new Fixture(); TestTimeCost tc = new TestTimeCost(); tc.setData(Id.create(1, Link.class), 2.0, 2.0);
public void testMultipleStarts() { Fixture f = new Fixture(); TestTimeCost tc = new TestTimeCost(); tc.setData(Id.create(1, Link.class), 2.0, 2.0);
/** * Tests that a path is found if some links are in the set of start * as well as in the set of end nodes, but the path only containing * of this node is the not the cheapest. */ public void testSameNodeInFromToSetNotCheapest() { Fixture f = new Fixture(); TestTimeCost tc = new TestTimeCost(); tc.setData(Id.create(1, Link.class), 2.0, 2.0); tc.setData(Id.create(2, Link.class), 1.0, 1.0); tc.setData(Id.create(3, Link.class), 3.0, 3.0); tc.setData(Id.create(4, Link.class), 2.0, 2.0); tc.setData(Id.create(5, Link.class), 1.0, 1.0); tc.setData(Id.create(6, Link.class), 3.0, 3.0); tc.setData(Id.create(7, Link.class), 4.0, 4.0); MultiNodeDijkstra dijkstra = new MultiNodeDijkstra(f.network, tc, tc); Map<Node, InitialNode> fromNodes = new HashMap<Node, InitialNode>(); fromNodes.put(f.network.getNodes().get(Id.create(2, Node.class)), new InitialNode(2.0, 2.0)); fromNodes.put(f.network.getNodes().get(Id.create(4, Node.class)), new InitialNode(10.0, 10.0)); Map<Node, InitialNode> toNodes = new HashMap<Node, InitialNode>(); toNodes.put(f.network.getNodes().get(Id.create(4, Node.class)), new InitialNode(8.0, 8.0)); toNodes.put(f.network.getNodes().get(Id.create(6, Node.class)), new InitialNode(3.0, 3.0)); Path p = dijkstra.calcLeastCostPath(fromNodes, toNodes, null); assertNotNull("no path found!", p); assertEquals(3, p.links.size()); assertEquals("2", p.links.get(0).getId().toString()); assertEquals("7", p.links.get(1).getId().toString()); assertEquals("6", p.links.get(2).getId().toString()); }
/** * Tests that a route is found even if not all given end nodes are reachable */ public void testSomeEndNodesNotReachable() { Fixture f = new Fixture(); TestTimeCost tc = new TestTimeCost(); tc.setData(Id.create(1, Link.class), 2.0, 2.0); tc.setData(Id.create(2, Link.class), 1.0, 1.0); tc.setData(Id.create(3, Link.class), 3.0, 3.0); tc.setData(Id.create(4, Link.class), 2.0, 2.0); tc.setData(Id.create(5, Link.class), 1.0, 1.0); tc.setData(Id.create(6, Link.class), 3.0, 3.0); tc.setData(Id.create(7, Link.class), 4.0, 4.0); MultiNodeDijkstra dijkstra = new MultiNodeDijkstra(f.network, tc, tc); Map<Node, InitialNode> fromNodes = new HashMap<Node, InitialNode>(); fromNodes.put(f.network.getNodes().get(Id.create(2, Node.class)), new InitialNode(2.0, 2.0)); fromNodes.put(f.network.getNodes().get(Id.create(1, Node.class)), new InitialNode(3.0, 3.0)); Map<Node, InitialNode> toNodes = new HashMap<Node, InitialNode>(); toNodes.put(f.network.getNodes().get(Id.create(5, Node.class)), new InitialNode(1.0, 1.0)); toNodes.put(f.network.getNodes().get(Id.create(3, Node.class)), new InitialNode(3.0, 3.0)); // cannot be reached! Path p = dijkstra.calcLeastCostPath(fromNodes, toNodes, null); assertNotNull("no path found!", p); assertEquals(3, p.links.size()); assertEquals("2", p.links.get(0).getId().toString()); assertEquals("7", p.links.get(1).getId().toString()); assertEquals("5", p.links.get(2).getId().toString()); }
/** * Both nodes 1 and 4 are part of the start set. Even if the path from 1 to the * target leads over node 4, it may be faster, due to the intial cost values. * Test that the route does not cut at node 4 as the first node backwards from * the start set. */ public void testStartViaFaster() { Fixture f = new Fixture(); TestTimeCost tc = new TestTimeCost(); tc.setData(Id.create(1, Link.class), 2.0, 2.0); tc.setData(Id.create(2, Link.class), 1.0, 1.0); tc.setData(Id.create(3, Link.class), 3.0, 3.0); tc.setData(Id.create(4, Link.class), 2.0, 2.0); tc.setData(Id.create(5, Link.class), 1.0, 1.0); tc.setData(Id.create(6, Link.class), 3.0, 3.0); tc.setData(Id.create(7, Link.class), 4.0, 4.0); MultiNodeDijkstra dijkstra = new MultiNodeDijkstra(f.network, tc, tc); Map<Node, InitialNode> fromNodes = new HashMap<Node, InitialNode>(); fromNodes.put(f.network.getNodes().get(Id.create(1, Node.class)), new InitialNode(1.0, 1.0)); fromNodes.put(f.network.getNodes().get(Id.create(4, Node.class)), new InitialNode(4.0, 4.0)); Map<Node, InitialNode> toNodes = new HashMap<Node, InitialNode>(); toNodes.put(f.network.getNodes().get(Id.create(5, Node.class)), new InitialNode(0.0, 0.0)); Path p = dijkstra.calcLeastCostPath(fromNodes, toNodes, null); assertNotNull("no path found!", p); assertEquals(3, p.links.size()); assertEquals("1", p.links.get(0).getId().toString()); assertEquals("7", p.links.get(1).getId().toString()); assertEquals("5", p.links.get(2).getId().toString()); }
public void testEndViaFaster() { Fixture f = new Fixture(); TestTimeCost tc = new TestTimeCost(); tc.setData(Id.create(1, Link.class), 2.0, 2.0); tc.setData(Id.create(2, Link.class), 1.0, 1.0); tc.setData(Id.create(3, Link.class), 3.0, 3.0); tc.setData(Id.create(4, Link.class), 2.0, 2.0); tc.setData(Id.create(5, Link.class), 1.0, 1.0); tc.setData(Id.create(6, Link.class), 3.0, 3.0); tc.setData(Id.create(7, Link.class), 4.0, 4.0); MultiNodeDijkstra dijkstra = new MultiNodeDijkstra(f.network, tc, tc); Map<Node, InitialNode> fromNodes = new HashMap<Node, InitialNode>(); fromNodes.put(f.network.getNodes().get(Id.create(2, Node.class)), new InitialNode(1.0, 1.0)); Map<Node, InitialNode> toNodes = new HashMap<Node, InitialNode>(); toNodes.put(f.network.getNodes().get(Id.create(8, Node.class)), new InitialNode(3.0, 3.0)); toNodes.put(f.network.getNodes().get(Id.create(5, Node.class)), new InitialNode(1.0, 1.0)); Path p = dijkstra.calcLeastCostPath(fromNodes, toNodes, null); assertNotNull("no path found!", p); assertEquals(3, p.links.size()); assertEquals("2", p.links.get(0).getId().toString()); assertEquals("7", p.links.get(1).getId().toString()); assertEquals("5", p.links.get(2).getId().toString()); }
/** * Tests that a path is found if some links are in the set of start * as well as in the set of end nodes and the path only containing * of this node is the cheapest. */ public void testSameNodeInFromToSetCheapest() { Fixture f = new Fixture(); TestTimeCost tc = new TestTimeCost(); tc.setData(Id.create(1, Link.class), 2.0, 2.0); tc.setData(Id.create(2, Link.class), 1.0, 1.0); tc.setData(Id.create(3, Link.class), 3.0, 3.0); tc.setData(Id.create(4, Link.class), 2.0, 2.0); tc.setData(Id.create(5, Link.class), 1.0, 1.0); tc.setData(Id.create(6, Link.class), 3.0, 3.0); tc.setData(Id.create(7, Link.class), 4.0, 4.0); MultiNodeDijkstra dijkstra = new MultiNodeDijkstra(f.network, tc, tc); Map<Node, InitialNode> fromNodes = new HashMap<Node, InitialNode>(); fromNodes.put(f.network.getNodes().get(Id.create(2, Node.class)), new InitialNode(2.0, 2.0)); fromNodes.put(f.network.getNodes().get(Id.create(4, Node.class)), new InitialNode(1.0, 1.0)); Map<Node, InitialNode> toNodes = new HashMap<Node, InitialNode>(); toNodes.put(f.network.getNodes().get(Id.create(4, Node.class)), new InitialNode(1.0, 1.0)); toNodes.put(f.network.getNodes().get(Id.create(6, Node.class)), new InitialNode(3.0, 3.0)); Path p = dijkstra.calcLeastCostPath(fromNodes, toNodes, null); assertNotNull("no path found!", p); assertEquals(0, p.links.size()); assertEquals(1, p.nodes.size()); assertEquals("4", p.nodes.get(0).getId().toString()); }
/** * Tests that a route is found even if not all given start nodes lead to an end node */ public void testSomeStartNodesNotUseable() { Fixture f = new Fixture(); TestTimeCost tc = new TestTimeCost(); tc.setData(Id.create(1, Link.class), 2.0, 2.0); tc.setData(Id.create(2, Link.class), 1.0, 1.0); tc.setData(Id.create(3, Link.class), 3.0, 3.0); tc.setData(Id.create(4, Link.class), 2.0, 2.0); tc.setData(Id.create(5, Link.class), 1.0, 1.0); tc.setData(Id.create(6, Link.class), 3.0, 3.0); tc.setData(Id.create(7, Link.class), 4.0, 4.0); MultiNodeDijkstra dijkstra = new MultiNodeDijkstra(f.network, tc, tc); Map<Node, InitialNode> fromNodes = new HashMap<Node, InitialNode>(); fromNodes.put(f.network.getNodes().get(Id.create(2, Node.class)), new InitialNode(2.0, 2.0)); fromNodes.put(f.network.getNodes().get(Id.create(4, Node.class)), new InitialNode(3.0, 3.0)); // cannot lead to 5 or 6 Map<Node, InitialNode> toNodes = new HashMap<Node, InitialNode>(); toNodes.put(f.network.getNodes().get(Id.create(5, Node.class)), new InitialNode(1.0, 1.0)); toNodes.put(f.network.getNodes().get(Id.create(6, Node.class)), new InitialNode(3.0, 3.0)); Path p = dijkstra.calcLeastCostPath(fromNodes, toNodes, null); assertNotNull("no path found!", p); assertEquals(3, p.links.size()); assertEquals("2", p.links.get(0).getId().toString()); assertEquals("7", p.links.get(1).getId().toString()); assertEquals("5", p.links.get(2).getId().toString()); }
public void testOnlyFromToSameNode() { Fixture f = new Fixture(); TestTimeCost tc = new TestTimeCost(); tc.setData(Id.create(1, Link.class), 2.0, 2.0); tc.setData(Id.create(2, Link.class), 1.0, 1.0); tc.setData(Id.create(3, Link.class), 3.0, 3.0); tc.setData(Id.create(4, Link.class), 2.0, 2.0); tc.setData(Id.create(5, Link.class), 1.0, 1.0); tc.setData(Id.create(6, Link.class), 3.0, 3.0); tc.setData(Id.create(7, Link.class), 4.0, 4.0); MultiNodeDijkstra dijkstra = new MultiNodeDijkstra(f.network, tc, tc); Map<Node, InitialNode> fromNodes = new HashMap<Node, InitialNode>(); fromNodes.put(f.network.getNodes().get(Id.create(2, Node.class)), new InitialNode(1.0, 1.0)); Map<Node, InitialNode> toNodes = new HashMap<Node, InitialNode>(); toNodes.put(f.network.getNodes().get(Id.create(2, Node.class)), new InitialNode(3.0, 3.0)); Path p = dijkstra.calcLeastCostPath(fromNodes, toNodes, null); assertNotNull("no path found!", p); assertEquals(0, p.links.size()); assertEquals(1, p.nodes.size()); assertEquals("2", p.nodes.get(0).getId().toString()); }
public void testImpossibleRoute() { Fixture f = new Fixture(); TestTimeCost tc = new TestTimeCost(); tc.setData(Id.create(1, Link.class), 2.0, 2.0); tc.setData(Id.create(2, Link.class), 1.0, 1.0); tc.setData(Id.create(3, Link.class), 3.0, 3.0); tc.setData(Id.create(4, Link.class), 2.0, 2.0); tc.setData(Id.create(5, Link.class), 1.0, 1.0); tc.setData(Id.create(6, Link.class), 3.0, 3.0); tc.setData(Id.create(7, Link.class), 4.0, 4.0); MultiNodeDijkstra dijkstra = new MultiNodeDijkstra(f.network, tc, tc); Map<Node, InitialNode> fromNodes = new HashMap<Node, InitialNode>(); fromNodes.put(f.network.getNodes().get(Id.create(1, Node.class)), new InitialNode(1.0, 1.0)); Map<Node, InitialNode> toNodes = new HashMap<Node, InitialNode>(); toNodes.put(f.network.getNodes().get(Id.create(2, Node.class)), new InitialNode(3.0, 3.0)); Path p = dijkstra.calcLeastCostPath(fromNodes, toNodes, null); assertNull("wow, impossible path found!", p); }