Exemplo n.º 1
0
        public void TestQuadrilateralOneWay()
        {
            // build graph.
            var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size,
                                              ContractedEdgeDataSerializer.MetaSize);

            graph.AddEdge(0, 2, 100, true, Constants.NO_VERTEX);
            graph.AddEdge(2, 0, 100, false, Constants.NO_VERTEX);
            graph.AddEdge(0, 3, 10, false, Constants.NO_VERTEX);
            graph.AddEdge(3, 0, 10, true, Constants.NO_VERTEX);
            graph.AddEdge(1, 2, 1000, false, Constants.NO_VERTEX);
            graph.AddEdge(2, 1, 1000, true, Constants.NO_VERTEX);
            graph.AddEdge(1, 3, 10000, true, Constants.NO_VERTEX);
            graph.AddEdge(3, 1, 10000, false, Constants.NO_VERTEX);
            graph.Compress();

            // create a witness calculator and the priority calculator.
            var contractedFlags    = new BitArray32(graph.VertexCount);
            var priorityCalculator = new EdgeDifferencePriorityCalculator(graph,
                                                                          new WitnessCalculatorMock(new uint[][]
            {
                new uint[] { 1, 3, 2, 1 },
                new uint[] { 3, 0, 1, 1 }
            }));

            Assert.AreEqual(0, priorityCalculator.Calculate(contractedFlags, 0));
            Assert.AreEqual(0, priorityCalculator.Calculate(contractedFlags, 1));
            Assert.AreEqual(0, priorityCalculator.Calculate(contractedFlags, 2));
            Assert.AreEqual(0, priorityCalculator.Calculate(contractedFlags, 3));
        }
Exemplo n.º 2
0
        public void TestQuadrilateralOneWay()
        {
            // build graph.
            var graph = new DirectedDynamicGraph(ContractedEdgeDataSerializer.DynamicFixedSize);

            graph.AddEdge(0, 2, 100, true);
            graph.AddEdge(2, 0, 100, false);
            graph.AddEdge(0, 3, 10, false);
            graph.AddEdge(3, 0, 10, true);
            graph.AddEdge(1, 2, 1000, false);
            graph.AddEdge(2, 1, 1000, true);
            graph.AddEdge(1, 3, 10000, true);
            graph.AddEdge(3, 1, 10000, false);
            graph.Compress();

            // create a witness calculator and the priority calculator.
            var contractedFlags    = new BitArray32(graph.VertexCount);
            var priorityCalculator = new EdgeDifferencePriorityCalculator(graph,
                                                                          new Itinero.Algorithms.Contracted.EdgeBased.Witness.DykstraWitnessCalculator(10));

            //var priorityCalculator = new EdgeDifferencePriorityCalculator(graph,
            //    new WitnessCalculatorMock(new uint[][]
            //        {
            //            new uint[] { 1, 3, 2, 1 },
            //            new uint[] { 3, 0, 1, 1 }
            //        }));

            Assert.AreEqual(0, priorityCalculator.Calculate(contractedFlags, (i) => null, 0));
            Assert.AreEqual(0, priorityCalculator.Calculate(contractedFlags, (i) => null, 1));
            Assert.AreEqual(0, priorityCalculator.Calculate(contractedFlags, (i) => null, 2));
            Assert.AreEqual(0, priorityCalculator.Calculate(contractedFlags, (i) => null, 3));
        }
Exemplo n.º 3
0
        public void TestTwoNeighboursOneWay()
        {
            // build graph.
            var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size,
                                              ContractedEdgeDataSerializer.MetaSize);

            graph.AddEdge(0, 1, 100, true, Constants.NO_VERTEX);
            graph.AddEdge(1, 0, 100, false, Constants.NO_VERTEX);
            graph.AddEdge(0, 2, 100, false, Constants.NO_VERTEX);
            graph.AddEdge(2, 0, 100, true, Constants.NO_VERTEX);

            // create a witness calculator and the priority calculator.
            var priorityCalculator = new EdgeDifferencePriorityCalculator(graph,
                                                                          new WitnessCalculatorMock());
            var priority = priorityCalculator.Calculate(new BitArray32(graph.VertexCount), 0);

            Assert.AreEqual(0, priority);

            // build another graph.
            graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size,
                                          ContractedEdgeDataSerializer.MetaSize);
            graph.AddEdge(0, 1, 100, false, Constants.NO_VERTEX);
            graph.AddEdge(1, 0, 100, true, Constants.NO_VERTEX);
            graph.AddEdge(0, 2, 100, true, Constants.NO_VERTEX);
            graph.AddEdge(2, 0, 100, false, Constants.NO_VERTEX);

            // create a witness calculator and the priority calculator.
            priorityCalculator = new EdgeDifferencePriorityCalculator(graph,
                                                                      new WitnessCalculatorMock());
            priority = priorityCalculator.Calculate(new BitArray32(graph.VertexCount), 0);

            Assert.AreEqual(0, priority);
        }
Exemplo n.º 4
0
        public void TestTwoNeighboursOneWayOpposite()
        {
            // build graph.
            var graph = new DirectedDynamicGraph(ContractedEdgeDataSerializer.DynamicFixedSize);

            graph.AddEdge(0, 1, 100, true);
            graph.AddEdge(1, 0, 100, false);
            graph.AddEdge(0, 2, 100, true);
            graph.AddEdge(2, 0, 100, false);

            // create a witness calculator and the priority calculator.
            var priorityCalculator = new EdgeDifferencePriorityCalculator(graph,
                                                                          new WitnessCalculatorMock((source, target) =>
            {
                if (source == 0 && target == 1)
                {
                    return(new Tuple <EdgePath <float>, EdgePath <float> >(
                               new EdgePath <float>(0, 100, new EdgePath <float>(1)),
                               new EdgePath <float>()));
                }
                if (source == 0 && target == 2)
                {
                    return(new Tuple <EdgePath <float>, EdgePath <float> >(
                               new EdgePath <float>(0, 100, new EdgePath <float>(2)),
                               new EdgePath <float>()));
                }
                if (source == 1 && target == 0)
                {
                    return(new Tuple <EdgePath <float>, EdgePath <float> >(
                               new EdgePath <float>(),
                               new EdgePath <float>(0, 100, new EdgePath <float>(1))));
                }
                if (source == 2 && target == 0)
                {
                    return(new Tuple <EdgePath <float>, EdgePath <float> >(
                               new EdgePath <float>(),
                               new EdgePath <float>(0, 100, new EdgePath <float>(2))));
                }
                if (source == 1 && target == 2)
                {
                    return(new Tuple <EdgePath <float>, EdgePath <float> >(
                               new EdgePath <float>(),
                               new EdgePath <float>()));
                }
                if (source == 2 && target == 1)
                {
                    return(new Tuple <EdgePath <float>, EdgePath <float> >(
                               new EdgePath <float>(),
                               new EdgePath <float>()));
                }
                return(null);
            }));
            var priority = priorityCalculator.Calculate(new BitArray32(graph.VertexCount), (i) => null, 0);

            Assert.AreEqual(-2, priority);
        }
Exemplo n.º 5
0
        public void TestNoNeighbours()
        {
            // build graph.
            var graph = new DirectedDynamicGraph(ContractedEdgeDataSerializer.DynamicFixedSize);

            graph.AddEdge(1, 0, 100, null);

            // create a witness calculator and the priority calculator.
            var priorityCalculator = new EdgeDifferencePriorityCalculator(graph,
                                                                          new WitnessCalculatorMock());
            var priority = priorityCalculator.Calculate(new BitArray32(graph.VertexCount), (i) => null, 0);

            Assert.AreEqual(0, priority);
        }
Exemplo n.º 6
0
        public void TestOneNeighboursContracted()
        {
            // build graph.
            var graph = new DirectedDynamicGraph(ContractedEdgeDataSerializer.DynamicFixedSize);

            graph.AddEdge(0, 1, 100, true);
            graph.AddEdge(1, 0, 100, false);

            // create a witness calculator and the priority calculator.
            var contractedFlags = new BitArray32(graph.VertexCount);

            contractedFlags[1] = true;
            var priorityCalculator = new EdgeDifferencePriorityCalculator(graph,
                                                                          new WitnessCalculatorMock());
            var priority = priorityCalculator.Calculate(contractedFlags, (i) => null, 0);

            Assert.AreEqual(-2, priority);
        }
Exemplo n.º 7
0
        public void TestOneNeighboursNotifyContracted()
        {
            // build graph.
            var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size,
                                              ContractedEdgeDataSerializer.MetaSize);

            graph.AddEdge(0, 1, 100, true, Constants.NO_VERTEX);
            graph.AddEdge(1, 0, 100, false, Constants.NO_VERTEX);

            // create a witness calculator and the priority calculator.
            var contractedFlags = new BitArray32(graph.VertexCount);

            contractedFlags[1] = true;
            var priorityCalculator = new EdgeDifferencePriorityCalculator(graph,
                                                                          new WitnessCalculatorMock());

            priorityCalculator.NotifyContracted(1);
            var priority = priorityCalculator.Calculate(contractedFlags, 0);

            Assert.AreEqual(1, priority);
        }
Exemplo n.º 8
0
        public void TestThreeNeighbours()
        {
            // build graph.
            var graph = new DirectedDynamicGraph(ContractedEdgeDataSerializer.DynamicFixedSize);

            graph.AddEdge(0, 1, 100, null);
            graph.AddEdge(1, 0, 100, null);
            graph.AddEdge(0, 2, 100, null);
            graph.AddEdge(2, 0, 100, null);
            graph.AddEdge(0, 3, 100, null);
            graph.AddEdge(3, 0, 100, null);

            // create a witness calculator and the priority calculator.
            var priorityCalculator = new EdgeDifferencePriorityCalculator(graph,
                                                                          new WitnessCalculatorMock((source, target) =>
            {
                return(new Tuple <EdgePath <float>, EdgePath <float> >(
                           new EdgePath <float>(0),
                           new EdgePath <float>(0)));
            }));
            var priority = priorityCalculator.Calculate(new BitArray32(graph.VertexCount), (i) => null, 0);

            Assert.AreEqual(3, priority);
        }