public void TestVerifiedContraction1NoWitnesses() { var graph = new DirectedGraph<CHEdgeData>(); var vertex1 = graph.AddVertex(1, 0); var vertex2 = graph.AddVertex(2, 0); var vertex3 = graph.AddVertex(3, 0); graph.AddEdge(vertex1, vertex3, new CHEdgeData(1, true, true, true, 10)); graph.AddEdge(vertex3, vertex1, new CHEdgeData(1, false, true, true, 10)); graph.AddEdge(vertex2, vertex3, new CHEdgeData(1, true, true, true, 10)); graph.AddEdge(vertex3, vertex2, new CHEdgeData(1, false, true, true, 10)); var witnessCalculator = new DykstraWitnessCalculator(); var preProcessor = new CHPreprocessor(graph, new EdgeDifferenceContractedSearchSpace(graph, witnessCalculator), witnessCalculator); preProcessor.Contract(3); // there should be no edge from 1->3 and from 2->3. Assert.IsFalse(graph.ContainsEdges(1, 3)); Assert.IsFalse(graph.ContainsEdges(2, 3)); var router = new CHRouter(); // expected: (1)-10s-(3)-10s-(2) (20s in total). var path = router.Calculate(graph, 1, 2); Assert.IsNotNull(path); Assert.AreEqual(20, path.Weight); var pathArray = path.ToArrayWithWeight(); Assert.AreEqual(3, pathArray.Length); float latitude, longitude; Assert.AreEqual(0, pathArray[0].Item2); Assert.IsTrue(graph.GetVertex((uint)pathArray[0].Item1, out latitude, out longitude)); Assert.AreEqual(1, latitude); Assert.AreEqual(10, pathArray[1].Item2); Assert.IsTrue(graph.GetVertex((uint)pathArray[1].Item1, out latitude, out longitude)); Assert.AreEqual(3, latitude); Assert.AreEqual(20, pathArray[2].Item2); Assert.IsTrue(graph.GetVertex((uint)pathArray[2].Item1, out latitude, out longitude)); Assert.AreEqual(2, latitude); // expected: (2)-10s-(3)-10s-(1) (20s in total). path = router.Calculate(graph, 2, 1); Assert.IsNotNull(path); Assert.AreEqual(20, path.Weight); pathArray = path.ToArrayWithWeight(); Assert.AreEqual(3, pathArray.Length); Assert.AreEqual(0, pathArray[0].Item2); Assert.IsTrue(graph.GetVertex((uint)pathArray[0].Item1, out latitude, out longitude)); Assert.AreEqual(2, latitude); Assert.AreEqual(10, pathArray[1].Item2); Assert.IsTrue(graph.GetVertex((uint)pathArray[1].Item1, out latitude, out longitude)); Assert.AreEqual(3, latitude); Assert.AreEqual(20, pathArray[2].Item2); Assert.IsTrue(graph.GetVertex((uint)pathArray[2].Item1, out latitude, out longitude)); Assert.AreEqual(1, latitude); }
public void TestVerifiedContraction6DuplicateForward() { var graph = new DirectedGraph<CHEdgeData>(); var witnessCalculator = new DykstraWitnessCalculator(); var preProcessor = new CHPreprocessor(graph, new EdgeDifferenceContractedSearchSpace(graph, witnessCalculator), witnessCalculator); var vertex1 = graph.AddVertex(1, 0); var vertex2 = graph.AddVertex(2, 0); var vertex3 = graph.AddVertex(3, 0); var vertex4 = graph.AddVertex(4, 0); graph.AddEdge(vertex1, vertex3, new CHEdgeData(1, true, false, true, 10)); graph.AddEdge(vertex3, vertex1, new CHEdgeData(1, false, true, false, 10)); graph.AddEdge(vertex2, vertex3, new CHEdgeData(1, true, true, false, 10)); graph.AddEdge(vertex3, vertex2, new CHEdgeData(1, false, false, true, 10)); graph.AddEdge(vertex1, vertex4, new CHEdgeData(1, true, true, false, 15)); graph.AddEdge(vertex4, vertex1, new CHEdgeData(1, false, false, true, 15)); graph.AddEdge(vertex2, vertex4, new CHEdgeData(1, true, false, true, 15)); graph.AddEdge(vertex4, vertex2, new CHEdgeData(1, false, true, false, 15)); preProcessor.Contract(3); Assert.IsTrue(graph.ContainsEdge(vertex1, vertex2, new CHEdgeData(3, false, true, 20))); Assert.IsTrue(graph.ContainsEdge(vertex2, vertex1, new CHEdgeData(3, true, false, 20))); preProcessor.Contract(4); Assert.IsTrue(graph.ContainsEdge(vertex1, vertex2, new CHEdgeData(4, true, false, 30))); Assert.IsTrue(graph.ContainsEdge(vertex2, vertex1, new CHEdgeData(4, false, true, 30))); Assert.IsTrue(graph.ContainsEdge(vertex1, vertex2, new CHEdgeData(3, false, true, 20))); Assert.IsTrue(graph.ContainsEdge(vertex2, vertex1, new CHEdgeData(3, true, false, 20))); }
public void TestVerifiedContraction4ReplacePrevious() { var graph = new DirectedGraph<CHEdgeData>(); var vertex1 = graph.AddVertex(1, 0); var vertex2 = graph.AddVertex(2, 0); var vertex3 = graph.AddVertex(3, 0); var vertex4 = graph.AddVertex(4, 0); graph.AddEdge(vertex1, vertex4, new CHEdgeData(1, true, true, true, 15)); graph.AddEdge(vertex4, vertex1, new CHEdgeData(1, false, true, true, 15)); graph.AddEdge(vertex2, vertex4, new CHEdgeData(1, true, true, true, 15)); graph.AddEdge(vertex4, vertex2, new CHEdgeData(1, false, true, true, 15)); var witnessCalculator = new DykstraWitnessCalculator(); var preProcessor = new CHPreprocessor(graph, new EdgeDifferenceContractedSearchSpace(graph, witnessCalculator), witnessCalculator); preProcessor.Contract(4); Assert.IsTrue(graph.ContainsEdge(vertex1, vertex2, new CHEdgeData(4, true, true, 30))); Assert.IsTrue(graph.ContainsEdge(vertex2, vertex1, new CHEdgeData(4, true, true, 30))); // add edges later to prevent witnesses from being found! graph.AddEdge(vertex1, vertex3, new CHEdgeData(1, true, true, true, 10)); graph.AddEdge(vertex3, vertex1, new CHEdgeData(1, false, true, true, 10)); graph.AddEdge(vertex2, vertex3, new CHEdgeData(1, true, true, true, 10)); graph.AddEdge(vertex3, vertex2, new CHEdgeData(1, false, true, true, 10)); preProcessor.Contract(3); Assert.IsTrue(graph.ContainsEdge(vertex1, vertex2, new CHEdgeData(3, true, true, 20))); Assert.IsTrue(graph.ContainsEdge(vertex2, vertex1, new CHEdgeData(3, true, true, 20))); }