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 HierarchyBuilder(graph, new EdgeDifferencePriorityCalculator(graph, new DykstraWitnessCalculator(int.MaxValue)), new DykstraWitnessCalculator(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); }
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)); }
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 priorities = new Dictionary <uint, float>(); priorities.Add(1, 0); priorities.Add(0, 1); priorities.Add(2, 2); priorities.Add(3, 3); var hierarchyBuilder = new HierarchyBuilder(graph, new MockPriorityCalculator(priorities), new DykstraWitnessCalculator(int.MaxValue)); hierarchyBuilder.Run(); // edges 1->2 and 2->1 should have been removed. var edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 3); Assert.IsNotNull(edge); var edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]); Assert.AreEqual(110, edgeData.Weight); Assert.AreEqual(null, edgeData.Direction); Assert.AreEqual(1, edgeData.ContractedId); edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 0); 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(1).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(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); }
public void TestOneEdge() { // build graph. var graph = new Itinero.Graphs.Graph(EdgeDataSerializer.Size); graph.AddVertex(0); graph.AddVertex(1); graph.AddEdge(0, 1, EdgeDataSerializer.Serialize(new EdgeData() { Distance = 100, Profile = 1 })); // build speed profile function. var speed = 100f / 3.6f; Func <ushort, Factor> getFactor = (x) => { return(new Factor() { Direction = 0, Value = 1.0f / speed }); }; // convert graph. var directedGraph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, ContractedEdgeDataSerializer.MetaSize); var algorithm = new DirectedGraphBuilder(graph, directedGraph, getFactor); algorithm.Run(); // check result. Assert.IsTrue(algorithm.HasRun); Assert.IsTrue(algorithm.HasSucceeded); directedGraph.Compress(); Assert.AreEqual(2, directedGraph.VertexCount); Assert.AreEqual(2, directedGraph.EdgeCount); // verify all edges. var edges = directedGraph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count); var data = ContractedEdgeDataSerializer.Serialize(100 * getFactor(1).Value, null); Assert.AreEqual(data, edges.First().Data[0]); Assert.AreEqual(Constants.NO_VERTEX, edges.First().MetaData[0]); Assert.AreEqual(1, edges.First().Neighbour); edges = directedGraph.GetEdgeEnumerator(1); Assert.AreEqual(1, edges.Count); data = ContractedEdgeDataSerializer.Serialize(100 * getFactor(1).Value, null); Assert.AreEqual(data, edges.First().Data[0]); Assert.AreEqual(Constants.NO_VERTEX, edges.First().MetaData[0]); Assert.AreEqual(0, edges.First().Neighbour); }
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); }
public void TestDoubleContraction() { // build graph. var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, ContractedEdgeDataSerializer.MetaSize); graph.AddEdge(0, 2, 100, null, Constants.NO_VERTEX); graph.AddEdge(2, 0, 100, null, Constants.NO_VERTEX); graph.AddEdge(0, 3, 100, null, Constants.NO_VERTEX); graph.AddEdge(3, 0, 100, null, Constants.NO_VERTEX); graph.AddEdge(1, 2, 200, null, Constants.NO_VERTEX); graph.AddEdge(2, 1, 200, null, Constants.NO_VERTEX); graph.AddEdge(1, 3, 200, null, Constants.NO_VERTEX); graph.AddEdge(3, 1, 200, null, Constants.NO_VERTEX); graph.Compress(); // contract graph. var priorityCalculator = new EdgeDifferencePriorityCalculator(graph, new DykstraWitnessCalculator(int.MaxValue)); priorityCalculator.DepthFactor = 0; priorityCalculator.ContractedFactor = 0; var hierarchyBuilder = new HierarchyBuilder(graph, priorityCalculator, new DykstraWitnessCalculator(int.MaxValue)); hierarchyBuilder.Run(); // check edges. var edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 2); Assert.IsNull(edge); edge = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 0); Assert.IsNotNull(edge); edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 3); Assert.IsNull(edge); edge = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 0); Assert.IsNotNull(edge); edge = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 1); Assert.IsNull(edge); edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 2); Assert.IsNotNull(edge); edge = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 1); Assert.IsNull(edge); edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 3); Assert.IsNotNull(edge); }
public void TestSerialize() { var graph = new DirectedMetaGraph(1, 1, 10); // add and compress. graph.AddEdge(0, 1, 1, 100); graph.Compress(); var expectedSize = 1 + 1 + 8 + 8 + 4 + 4 + // the header: two longs representing vertex and edge count and one int for edge size and one for vertex size. graph.VertexCount * 2 * 4 + // the bytes for the vertex-index: 2 uint's. graph.EdgeCount * 2 * 4 + // the bytes for the edges: one edge 1 uint. 4 + 4 + // the header for the meta-data: 2 uint for sizes. graph.EdgeCount * 4; // the bytes for the edges: one edge 1 uint. using (var stream = new System.IO.MemoryStream()) { Assert.AreEqual(expectedSize, graph.Serialize(stream)); Assert.AreEqual(expectedSize, stream.Position); } // verify all edges. var edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(1, edges.First().Data[0]); Assert.AreEqual(1, edges.First().Neighbour); graph = new DirectedMetaGraph(1, 1, 10); // add and compress. graph.AddEdge(0, 1, 10, 100); graph.AddEdge(1, 2, 20, 200); graph.AddEdge(2, 3, 30, 300); graph.AddEdge(3, 4, 40, 400); graph.RemoveEdge(1, 2); graph.Compress(); expectedSize = 1 + 1 + 8 + 8 + 4 + 4 + // the header: two longs representing vertex and edge count and one int for edge size and one for vertex size. graph.VertexCount * 2 * 4 + // the bytes for the vertex-index: 2 uint's. graph.EdgeCount * 2 * 4 + // the bytes for the edges: one edge 1 uint. 4 + 4 + // the header for the meta-data: 2 uint for sizes. graph.EdgeCount * 4; // the bytes for the edges: one edge 1 uint. using (var stream = new System.IO.MemoryStream()) { Assert.AreEqual(expectedSize, graph.Serialize(stream)); Assert.AreEqual(expectedSize, stream.Position); } }
public void Test2VerticesAgumented() { // build graph. var graph = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, ContractedEdgeDataSerializer.MetaAugmentedSize); graph.AddEdge(0, 1, 100, null, Constants.NO_VERTEX, 50, 1000); graph.AddEdge(1, 0, 100, null, Constants.NO_VERTEX, 50, 1000); 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); }
public void TestCompress() { var graph = new DirectedMetaGraph(1, 1, 10); // add and compress. graph.AddEdge(0, 1, 1, 100); graph.Compress(); // verify all edges. var edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(1, edges.First().Data[0]); Assert.AreEqual(1, edges.First().Neighbour); graph = new DirectedMetaGraph(1, 1, 10); // add and compress. graph.AddEdge(0, 1, 10, 100); graph.AddEdge(1, 2, 20, 200); graph.AddEdge(2, 3, 30, 300); graph.AddEdge(3, 4, 40, 400); graph.RemoveEdge(1, 2); // verify all edges. edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(10, edges.First().Data[0]); Assert.AreEqual(100, edges.First().MetaData[0]); Assert.AreEqual(1, edges.First().Neighbour); edges = graph.GetEdgeEnumerator(1); Assert.AreEqual(0, edges.Count()); edges = graph.GetEdgeEnumerator(2); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(30, edges.First().Data[0]); Assert.AreEqual(300, edges.First().MetaData[0]); Assert.AreEqual(3, edges.First().Neighbour); edges = graph.GetEdgeEnumerator(3); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(40, edges.First().Data[0]); Assert.AreEqual(400, edges.First().MetaData[0]); Assert.AreEqual(4, edges.First().Neighbour); // compress. graph.Compress(); // verify all edges. edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(10, edges.First().Data[0]); Assert.AreEqual(100, edges.First().MetaData[0]); Assert.AreEqual(1, edges.First().Neighbour); edges = graph.GetEdgeEnumerator(1); Assert.AreEqual(0, edges.Count()); edges = graph.GetEdgeEnumerator(2); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(30, edges.First().Data[0]); Assert.AreEqual(300, edges.First().MetaData[0]); Assert.AreEqual(3, edges.First().Neighbour); edges = graph.GetEdgeEnumerator(3); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(40, edges.First().Data[0]); Assert.AreEqual(400, edges.First().MetaData[0]); Assert.AreEqual(4, edges.First().Neighbour); }
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 priorityCalculator = new EdgeDifferencePriorityCalculator(graph, new DykstraWitnessCalculator(int.MaxValue)); priorityCalculator.ContractedFactor = 0; priorityCalculator.DepthFactor = 0; var hierarchyBuilder = new HierarchyBuilder <Weight>(graph, priorityCalculator, new DykstraWitnessCalculator(int.MaxValue), new WeightHandler(null)); 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); }
public void TestDoubleContractionOneway() { // 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(); // contract graph. var priorityCalculator = new EdgeDifferencePriorityCalculator(graph, new DykstraWitnessCalculator(int.MaxValue)); priorityCalculator.ContractedFactor = 0; priorityCalculator.DepthFactor = 0; var hierarchyBuilder = new HierarchyBuilder(graph, priorityCalculator, new DykstraWitnessCalculator(int.MaxValue)); hierarchyBuilder.Run(); // check edges. var edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 2); Assert.IsNotNull(edge); var edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]); Assert.AreEqual(100, edgeData.Weight); Assert.AreEqual(true, edgeData.Direction); Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId); edge = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 0); Assert.IsNull(edge); edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 3); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]); Assert.AreEqual(10, edgeData.Weight); Assert.AreEqual(false, edgeData.Direction); Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId); edge = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 0); Assert.IsNull(edge); edge = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 3); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]); Assert.AreEqual(110, edgeData.Weight); Assert.AreEqual(false, edgeData.Direction); Assert.AreEqual(0, edgeData.ContractedId); edge = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 2); Assert.IsNull(edge); edge = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 1); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]); Assert.AreEqual(1000, edgeData.Weight); Assert.AreEqual(true, edgeData.Direction); Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId); edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 2); Assert.IsNull(edge); edge = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 1 && ContractedEdgeDataSerializer.Deserialize(x.Data[0], x.MetaData[0]).Direction == true); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]); Assert.AreEqual(1110, edgeData.Weight); Assert.AreEqual(2, edgeData.ContractedId); edge = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 1 && ContractedEdgeDataSerializer.Deserialize(x.Data[0], x.MetaData[0]).Direction == false); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], edge.MetaData[0]); Assert.AreEqual(10000, edgeData.Weight); Assert.AreEqual(Constants.NO_VERTEX, edgeData.ContractedId); edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 3); Assert.IsNull(edge); }
public void TestPentagonDirected() { // 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(1, 2, 100, true, Constants.NO_VERTEX); graph.AddEdge(2, 1, 100, false, Constants.NO_VERTEX); graph.AddEdge(2, 3, 100, true, Constants.NO_VERTEX); graph.AddEdge(3, 2, 100, false, Constants.NO_VERTEX); graph.AddEdge(3, 4, 100, true, Constants.NO_VERTEX); graph.AddEdge(4, 3, 100, false, Constants.NO_VERTEX); graph.AddEdge(4, 0, 100, true, Constants.NO_VERTEX); graph.AddEdge(0, 4, 100, false, 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(); // 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); }