Beispiel #1
0
        public void TestCHContractionTest2()
        {
            //
            // (-1/1)-------->(-3/2)------->(-5/3)
            //

            // build the data.
            DynamicGraphRouterDataSource <CHEdgeData> data = this.BuildData(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OsmSharp.Test.Unittests.Routing.CH.Contraction.contraction_test2.osm"));

            // build the witness calculator.
            INodeWitnessCalculator witness_calculator = new DykstraWitnessCalculator();

            // test the ordering operators.
            SparseOrdering sparse_ordering = new SparseOrdering(
                data);

            Assert.AreEqual(-1, sparse_ordering.Calculate(2));
            EdgeDifference edge_difference_ordering = new EdgeDifference(
                data, witness_calculator);

            Assert.AreEqual(0, edge_difference_ordering.Calculate(2));

            // do the actual contraction.
            CHPreProcessor pre_processor = new CHPreProcessor(
                data, edge_difference_ordering, witness_calculator);

            pre_processor.Contract(2);

            // check the neighbours of each vertex.
            HashSet <uint> neighbours = this.BuildNeighboursSet(data.GetArcs(2));

            Assert.IsTrue(neighbours.Contains(1));
            Assert.IsTrue(neighbours.Contains(3));

            neighbours = this.BuildNeighboursSet(data.GetArcs(1));
            Assert.IsTrue(neighbours.Contains(3));
            Assert.IsFalse(neighbours.Contains(2));

            neighbours = this.BuildNeighboursSet(data.GetArcs(3));
            Assert.IsTrue(neighbours.Contains(1));
            Assert.IsFalse(neighbours.Contains(2));
        }
Beispiel #2
0
        public void TestCHContractionTest1()
        {
            //
            // (-1/1)---------(-3/2)--------(-5/3)
            //

            // build the data.
            var data = this.BuildData(
                Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    "OsmSharp.Test.Unittests.Routing.CH.Contraction.contraction_test1.osm"));

            // build the witness calculator.
            var witnessCalculator = new DykstraWitnessCalculator();

            // test the ordering operators.
            var sparseOrdering = new SparseOrdering(
                data);

            Assert.AreEqual(-1, sparseOrdering.Calculate(2));
            var edgeDifferenceOrdering = new EdgeDifference(
                data, witnessCalculator);

            Assert.AreEqual(2, edgeDifferenceOrdering.Calculate(2));

            // do the actual contraction.
            var preProcessor = new CHPreProcessor(
                data, edgeDifferenceOrdering, witnessCalculator);

            preProcessor.Contract(2);

            // check the neighbours of each vertex.
            var neighbours = data.GetEdges(2);

            Assert.AreEqual(2, neighbours.Length);
            Assert.IsTrue(neighbours.Any((x) =>
            {
                return(x.Key == 1 && x.Value.ToHigher);
            }));
            Assert.IsTrue(neighbours.Any((x) =>
            {
                return(x.Key == 3 && x.Value.ToHigher);
            }));

            neighbours = data.GetEdges(1);
            Assert.AreEqual(2, neighbours.Length);
            Assert.IsTrue(neighbours.Any((x) =>
            {
                return(x.Key == 2 && x.Value.ToLower);
            }));
            Assert.IsTrue(neighbours.Any((x) =>
            {
                return(x.Key == 3 && !x.Value.ToHigher && !x.Value.ToLower);
            }));

            neighbours = data.GetEdges(3);
            Assert.AreEqual(2, neighbours.Length);
            Assert.IsTrue(neighbours.Any((x) =>
            {
                return(x.Key == 2 && x.Value.ToLower);
            }));
            Assert.IsTrue(neighbours.Any((x) =>
            {
                return(x.Key == 1 && !x.Value.ToHigher && !x.Value.ToLower);
            }));
        }