/// <summary>
        /// Executes the CH contractions while verifying each step.
        /// </summary>
        /// <param name="stream"></param>
        public void DoTestCHEdgeDifferenceVerifiedContraction(Stream stream)
        {
            _interpreter = new OsmRoutingInterpreter();

            var tagsIndex = new TagsIndex();

            // do the data processing.
            _data = new RouterDataSource <CHEdgeData>(new DirectedGraph <CHEdgeData>(), tagsIndex);
            var targetData = new CHEdgeGraphOsmStreamTarget(
                _data, _interpreter, tagsIndex, Vehicle.Car);
            var dataProcessorSource = new XmlOsmStreamSource(stream);
            var sorter = new OsmStreamFilterSort();

            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            // do the pre-processing part.
            var witnessCalculator = new DykstraWitnessCalculator();
            var preProcessor      = new CHPreprocessor(_data,
                                                       new EdgeDifferenceContractedSearchSpace(_data, witnessCalculator), witnessCalculator);

            preProcessor.OnBeforeContractionEvent +=
                new CHPreprocessor.VertexDelegate(pre_processor_OnBeforeContractionEvent);
            preProcessor.OnAfterContractionEvent +=
                new CHPreprocessor.VertexDelegate(pre_processor_OnAfterContractionEvent);
            preProcessor.Start();
        }
        /// <summary>
        /// Creates a router.
        /// </summary>
        /// <param name="interpreter"></param>
        /// <param name="manifestResourceName"></param>
        /// <returns></returns>
        protected override Router CreateRouter(IOsmRoutingInterpreter interpreter, string manifestResourceName)
        {
            TagsIndex tagsIndex = new TagsIndex();

            // do the data processing.
            var data       = new RouterDataSource <CHEdgeData>(new DirectedGraph <CHEdgeData>(), tagsIndex);
            var targetData = new CHEdgeGraphOsmStreamTarget(
                data, interpreter, tagsIndex, Vehicle.Car);
            var dataProcessorSource = new XmlOsmStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestResourceName));
            var sorter = new OsmStreamFilterSort();

            sorter.RegisterSource(dataProcessorSource);
            targetData.RegisterSource(sorter);
            targetData.Pull();

            // do the pre-processing part.
            var witnessCalculator = new DykstraWitnessCalculator();
            var preProcessor      = new CHPreprocessor(data,
                                                       new EdgeDifferenceContractedSearchSpace(data, witnessCalculator), witnessCalculator);

            preProcessor.Start();

            return(Router.CreateCHFrom(data, new CHRouter(), interpreter));
        }
        public void TestVerifiedContraction3TinyOneWay()
        {
            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);
            var vertex5 = graph.AddVertex(5, 0);

            graph.AddEdge(vertex1, vertex4, new CHEdgeData(1, true, true, true, 10));
            graph.AddEdge(vertex4, vertex1, new CHEdgeData(1, false, true, true, 10));
            graph.AddEdge(vertex1, vertex2, new CHEdgeData(1, true, true, false, 10));  // oneway forward
            graph.AddEdge(vertex2, vertex1, new CHEdgeData(1, false, false, true, 10)); // oneway backward.
            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));
            graph.AddEdge(vertex2, vertex5, new CHEdgeData(1, true, true, true, 10));
            graph.AddEdge(vertex5, vertex2, new CHEdgeData(1, false, true, true, 10));

            Assert.IsFalse(graph.ContainsEdges(vertex1, vertex1));
            Assert.IsTrue(graph.ContainsEdges(vertex2, vertex1));
            Assert.IsTrue(graph.ContainsEdges(vertex3, vertex1));
            Assert.IsTrue(graph.ContainsEdges(vertex4, vertex1));
            Assert.IsFalse(graph.ContainsEdges(vertex5, vertex1));
            Assert.IsTrue(graph.ContainsEdges(vertex1, vertex2));
            Assert.IsFalse(graph.ContainsEdges(vertex2, vertex2));
            Assert.IsTrue(graph.ContainsEdges(vertex3, vertex2));
            Assert.IsFalse(graph.ContainsEdges(vertex4, vertex2));
            Assert.IsTrue(graph.ContainsEdges(vertex5, vertex2));
            Assert.IsTrue(graph.ContainsEdges(vertex1, vertex3));
            Assert.IsTrue(graph.ContainsEdges(vertex2, vertex3));
            Assert.IsFalse(graph.ContainsEdges(vertex3, vertex3));
            Assert.IsFalse(graph.ContainsEdges(vertex4, vertex3));
            Assert.IsFalse(graph.ContainsEdges(vertex5, vertex3));
            Assert.IsTrue(graph.ContainsEdges(vertex1, vertex4));
            Assert.IsFalse(graph.ContainsEdges(vertex2, vertex4));
            Assert.IsFalse(graph.ContainsEdges(vertex3, vertex4));
            Assert.IsFalse(graph.ContainsEdges(vertex4, vertex4));
            Assert.IsFalse(graph.ContainsEdges(vertex5, vertex4));
            Assert.IsFalse(graph.ContainsEdges(vertex1, vertex5));
            Assert.IsTrue(graph.ContainsEdges(vertex2, vertex5));
            Assert.IsFalse(graph.ContainsEdges(vertex3, vertex5));
            Assert.IsFalse(graph.ContainsEdges(vertex4, vertex5));
            Assert.IsFalse(graph.ContainsEdges(vertex5, vertex5));

            var witnessCalculator = new DykstraWitnessCalculator();
            var preProcessor      = new CHPreprocessor(graph,
                                                       new EdgeDifferenceContractedSearchSpace(graph, witnessCalculator), witnessCalculator);

            preProcessor.Start();

            var router = new CHRouter();
            // expected: (4)-10s-(1)-10s-(2)-10s-(3) (30s in total).
            var path = router.Calculate(graph, 4, 5);

            Assert.IsNotNull(path);
            Assert.AreEqual(30, path.Weight);
            var pathArray = path.ToArrayWithWeight();

            Assert.AreEqual(4, 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(4, latitude);
            Assert.AreEqual(10, pathArray[1].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[1].Item1, out latitude, out longitude));
            Assert.AreEqual(1, latitude);
            Assert.AreEqual(20, pathArray[2].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[2].Item1, out latitude, out longitude));
            Assert.AreEqual(2, latitude);
            Assert.AreEqual(30, pathArray[3].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[3].Item1, out latitude, out longitude));
            Assert.AreEqual(5, latitude);

            // expected: (5)-10s-(2)-10s-(3)-10s-(1)-10s-(4) (40s in total).
            path = router.Calculate(graph, 5, 4);
            Assert.IsNotNull(path);
            Assert.AreEqual(40, path.Weight);
            pathArray = path.ToArrayWithWeight();
            Assert.AreEqual(5, pathArray.Length);
            Assert.AreEqual(0, pathArray[0].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[0].Item1, out latitude, out longitude));
            Assert.AreEqual(5, latitude);
            Assert.AreEqual(10, pathArray[1].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[1].Item1, out latitude, out longitude));
            Assert.AreEqual(2, latitude);
            Assert.AreEqual(20, pathArray[2].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[2].Item1, out latitude, out longitude));
            Assert.AreEqual(3, latitude);
            Assert.AreEqual(30, pathArray[3].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[3].Item1, out latitude, out longitude));
            Assert.AreEqual(1, latitude);
            Assert.AreEqual(40, pathArray[4].Item2);
            Assert.IsTrue(graph.GetVertex((uint)pathArray[4].Item1, out latitude, out longitude));
            Assert.AreEqual(4, latitude);
        }