Пример #1
0
        public void Test3Vertices()
        {
            // build graph.
            var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size,
                                              ContractedEdgeDataSerializer.MetaSize);

            graph.AddEdge(0, 1, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(1, 0, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(1, 2, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(2, 1, 100, null, Constants.NO_VERTEX);
            graph.Compress();

            // contract graph.
            var hierarchyBuilder = new Itinero.Algorithms.Contracted.Dual.HierarchyBuilder(graph,
                                                                                           new DykstraWitnessCalculator(graph.Graph, int.MaxValue));

            hierarchyBuilder.Run();

            // check edges.
            var edges01 = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 1);

            Assert.IsNotNull(edges01);
            var edge10 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 0);

            Assert.IsNull(edge10);
            var edge12 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 0);

            Assert.IsNull(edge12);
            var edges21 = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 1);

            Assert.IsNotNull(edges21);
        }
Пример #2
0
        public void TestUncontractedWitnessed()
        {
            // build graph.
            var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size,
                                              ContractedEdgeDataSerializer.MetaSize);

            graph.AddEdge(0, 1, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(1, 0, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(1, 2, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(2, 1, 100, null, Constants.NO_VERTEX);
            graph.AddEdge(1, 3, 10, null, Constants.NO_VERTEX);
            graph.AddEdge(3, 1, 10, null, Constants.NO_VERTEX);
            graph.AddEdge(3, 2, 10, null, Constants.NO_VERTEX);
            graph.AddEdge(2, 3, 10, null, Constants.NO_VERTEX);
            graph.Compress();

            // contract graph.
            var hierarchyBuilder = new Itinero.Algorithms.Contracted.Dual.HierarchyBuilder(graph,
                                                                                           new DykstraWitnessCalculator(graph.Graph, int.MaxValue));

            hierarchyBuilder.ContractedFactor = 0;
            hierarchyBuilder.DepthFactor      = 0;
            hierarchyBuilder.Run();

            var edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 1);

            Assert.IsNotNull(edge);
            var edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]);

            Assert.AreEqual(100, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId);

            edge = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 1);
            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]);
            Assert.AreEqual(100, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId);

            edge = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 3);
            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]);
            Assert.AreEqual(10, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId);

            edge = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 1);
            Assert.IsNotNull(edge);
            edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]);
            Assert.AreEqual(10, edgeData.Weight);
            Assert.AreEqual(null, edgeData.Direction);
            Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId);
        }
Пример #3
0
        public void TestPentagonAugmented()
        {
            // build graph.
            var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size,
                                              ContractedEdgeDataSerializer.DynamicAugmentedFixedSize);

            graph.AddEdge(0, 1, 100, null, Constants.NO_VERTEX, 50, 1000);
            graph.AddEdge(1, 0, 100, null, Constants.NO_VERTEX, 50, 1000);
            graph.AddEdge(1, 2, 100, null, Constants.NO_VERTEX, 50, 1000);
            graph.AddEdge(2, 1, 100, null, Constants.NO_VERTEX, 50, 1000);
            graph.AddEdge(2, 3, 100, null, Constants.NO_VERTEX, 50, 1000);
            graph.AddEdge(3, 2, 100, null, Constants.NO_VERTEX, 50, 1000);
            graph.AddEdge(3, 4, 100, null, Constants.NO_VERTEX, 50, 1000);
            graph.AddEdge(4, 3, 100, null, Constants.NO_VERTEX, 50, 1000);
            graph.AddEdge(4, 0, 100, null, Constants.NO_VERTEX, 50, 1000);
            graph.AddEdge(0, 4, 100, null, Constants.NO_VERTEX, 50, 1000);
            graph.Compress();

            // contract graph.
            var weightHandler    = new WeightHandler(null);
            var hierarchyBuilder = new Itinero.Algorithms.Contracted.Dual.HierarchyBuilder <Weight>(graph,
                                                                                                    new DykstraWitnessCalculator <Weight>(graph.Graph, weightHandler, int.MaxValue), weightHandler);

            hierarchyBuilder.ContractedFactor = 0;
            hierarchyBuilder.DepthFactor      = 0;
            hierarchyBuilder.Run();

            // check edges.
            var edges01 = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 1);

            Assert.IsNotNull(edges01);
            var edges10 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 0);

            Assert.IsNull(edges10);

            var edges12 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 2);

            Assert.IsNull(edges12);
            var edges21 = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 1);

            Assert.IsNotNull(edges21);

            var edges23 = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 3);

            Assert.IsNotNull(edges23);
            var edges32 = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 2);

            Assert.IsNull(edges32);

            var edges34 = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 4);

            Assert.IsNull(edges34);
            var edges43 = graph.GetEdgeEnumerator(4).FirstOrDefault(x => x.Neighbour == 3);

            Assert.IsNotNull(edges43);

            var edges40 = graph.GetEdgeEnumerator(4).FirstOrDefault(x => x.Neighbour == 0);

            Assert.IsNull(edges40);
            var edges04 = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 4);

            Assert.IsNotNull(edges04);

            var edges41 = graph.GetEdgeEnumerator(4).FirstOrDefault(x => x.Neighbour == 1);

            Assert.IsNotNull(edges41);
            var edges14 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 4);

            Assert.IsNull(edges14);

            var edges31 = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 1);

            Assert.IsNotNull(edges31);
            var edges13 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 3);

            Assert.IsNull(edges13);
        }