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 Test3Vertices() { // build graph. var graph = new DirectedDynamicGraph(ContractedEdgeDataSerializer.DynamicFixedSize); graph.AddEdge(0, 1, 100, null); graph.AddEdge(1, 0, 100, null); graph.AddEdge(1, 2, 100, null); graph.AddEdge(2, 1, 100, null); graph.Compress(); // contract graph. var hierarchyBuilder = new HierarchyBuilder(graph, new EdgeDifferencePriorityCalculator(graph, new DykstraWitnessCalculator(int.MaxValue)), new DykstraWitnessCalculator(int.MaxValue), (i) => Enumerable.Empty <uint[]>()); 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 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 HierarchyBuilder <Weight>(graph, new EdgeDifferencePriorityCalculator(graph, new DykstraWitnessCalculator(int.MaxValue)), 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 edge10 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 0); Assert.IsNull(edge10); }
/// <summary> /// The main entry point for the application /// </summary> private static void Main(string[] args) { try { Settings settings; if (!TryInitialize(out settings)) { Usage(); return; } using (var builder = new HierarchyBuilder(settings)) { builder.Run(); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } } catch (Exception ex) { Console.WriteLine(ex); Usage(); } }
/// <summary> /// The main entry point for the application /// </summary> private static void Main(string[] args) { try { Settings settings; if (!TryInitialize(out settings)) { Usage(); return; } using (var builder = new HierarchyBuilder(settings)) { builder.Run(); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); } } catch (Exception ex) { Console.WriteLine(ex); Usage(); } }
/// <summary> /// Creates a new contracted graph and adds it to the router db for the given profile. /// </summary> public static void AddContracted <T>(this RouterDb db, Profiles.Profile profile, WeightHandler <T> weightHandler, bool forceEdgeBased = false) where T : struct { // create the raw directed graph. ContractedDb contractedDb = null; lock (db) { if (forceEdgeBased) { // edge-based is needed when complex restrictions found. var contracted = new DirectedDynamicGraph(weightHandler.DynamicSize); var directedGraphBuilder = new Itinero.Algorithms.Contracted.EdgeBased.DirectedGraphBuilder <T>(db.Network.GeometricGraph.Graph, contracted, weightHandler); directedGraphBuilder.Run(); // contract the graph. var priorityCalculator = new Itinero.Algorithms.Contracted.EdgeBased.EdgeDifferencePriorityCalculator <T>(contracted, weightHandler, new Itinero.Algorithms.Contracted.EdgeBased.Witness.DykstraWitnessCalculator <T>(weightHandler, int.MaxValue)); priorityCalculator.DifferenceFactor = 5; priorityCalculator.DepthFactor = 5; priorityCalculator.ContractedFactor = 8; var hierarchyBuilder = new Itinero.Algorithms.Contracted.EdgeBased.HierarchyBuilder <T>(contracted, priorityCalculator, new Itinero.Algorithms.Contracted.EdgeBased.Witness.DykstraWitnessCalculator <T>(weightHandler, int.MaxValue), weightHandler, db.GetGetRestrictions(profile, null)); hierarchyBuilder.Run(); contractedDb = new ContractedDb(contracted); } else { // vertex-based is ok when no complex restrictions found. var contracted = new DirectedMetaGraph(ContractedEdgeDataSerializer.Size, weightHandler.MetaSize); var directedGraphBuilder = new DirectedGraphBuilder <T>(db.Network.GeometricGraph.Graph, contracted, weightHandler); directedGraphBuilder.Run(); // contract the graph. var priorityCalculator = new EdgeDifferencePriorityCalculator(contracted, new DykstraWitnessCalculator(int.MaxValue)); priorityCalculator.DifferenceFactor = 5; priorityCalculator.DepthFactor = 5; priorityCalculator.ContractedFactor = 8; var hierarchyBuilder = new HierarchyBuilder <T>(contracted, priorityCalculator, new DykstraWitnessCalculator(int.MaxValue), weightHandler); hierarchyBuilder.Run(); contractedDb = new ContractedDb(contracted); } } // add the graph. lock (db) { db.AddContracted(profile, contractedDb); } }
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 Test3VerticesComplete() { // 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(0, 2, 100, null, Constants.NO_VERTEX); graph.AddEdge(2, 0, 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 edges02 = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 2); Assert.IsNotNull(edges02); var edge10 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 0); Assert.IsNull(edge10); var edge12 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 2); Assert.IsNull(edge12); var edges20 = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 0); Assert.IsNull(edges20); var edges21 = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 1); Assert.IsNotNull(edges21); }
public void TestRestrictedNetwork2() { // build graph. var graph = new DirectedDynamicGraph(ContractedEdgeDataSerializer.DynamicFixedSize); graph.AddEdge(0, 1, 100, null); graph.AddEdge(1, 0, 100, null); graph.AddEdge(1, 2, 100, null); graph.AddEdge(2, 1, 100, null); graph.AddEdge(1, 3, 100, null); graph.AddEdge(3, 1, 100, null); graph.AddEdge(1, 4, 100, null); graph.AddEdge(4, 1, 100, null); graph.AddEdge(2, 3, 100, null); graph.AddEdge(3, 2, 100, null); 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); priorities.Add(4, 4); var hierarchyBuilder = new HierarchyBuilder(graph, new MockPriorityCalculator(priorities), new DykstraWitnessCalculator(int.MaxValue), (i) => { if (i == 0 || i == 1 || i == 4) { return(new uint[][] { new uint[] { 0, 1, 4 } }); } return(null); }); hierarchyBuilder.Run(); // check all edges. ContractedEdgeData edgeData; var edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x => { if (x.Neighbour == 4) { edgeData = ContractedEdgeDataSerializer.Deserialize(x.Data[0], Constants.NO_VERTEX); return(edgeData.Direction == true); } return(false); }); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX); Assert.AreEqual(500, edgeData.Weight); Assert.AreEqual(true, edgeData.Direction); Assert.AreEqual(1, edge.GetContracted()); edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x => { if (x.Neighbour == 4) { edgeData = ContractedEdgeDataSerializer.Deserialize(x.Data[0], Constants.NO_VERTEX); return(edgeData.Direction == false); } return(false); }); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX); Assert.AreEqual(200, edgeData.Weight); Assert.AreEqual(false, edgeData.Direction); Assert.AreEqual(1, edge.GetContracted()); edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 2); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX); Assert.AreEqual(200, edgeData.Weight); Assert.AreEqual(null, edgeData.Direction); Assert.AreEqual(1, edge.GetContracted()); edge = graph.GetEdgeEnumerator(0).FirstOrDefault(x => x.Neighbour == 3); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX); Assert.AreEqual(200, edgeData.Weight); Assert.AreEqual(null, edgeData.Direction); Assert.AreEqual(1, edge.GetContracted()); edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 0); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX); Assert.AreEqual(100, edgeData.Weight); Assert.AreEqual(null, edgeData.Direction); Assert.AreEqual(null, edge.GetContracted()); edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 2); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX); Assert.AreEqual(100, edgeData.Weight); Assert.AreEqual(null, edgeData.Direction); Assert.AreEqual(null, edge.GetContracted()); edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 3); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX); Assert.AreEqual(100, edgeData.Weight); Assert.AreEqual(null, edgeData.Direction); Assert.AreEqual(null, edge.GetContracted()); edge = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 4); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX); Assert.AreEqual(100, edgeData.Weight); Assert.AreEqual(null, edgeData.Direction); Assert.AreEqual(null, edge.GetContracted()); edge = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 3); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX); Assert.AreEqual(100, edgeData.Weight); Assert.AreEqual(null, edgeData.Direction); Assert.AreEqual(null, edge.GetContracted()); edge = graph.GetEdgeEnumerator(2).FirstOrDefault(x => x.Neighbour == 4); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX); Assert.AreEqual(200, edgeData.Weight); Assert.AreEqual(null, edgeData.Direction); Assert.AreEqual(1, edge.GetContracted()); edge = graph.GetEdgeEnumerator(3).FirstOrDefault(x => x.Neighbour == 4); Assert.IsNotNull(edge); edgeData = ContractedEdgeDataSerializer.Deserialize(edge.Data[0], Constants.NO_VERTEX); Assert.AreEqual(200, edgeData.Weight); Assert.AreEqual(null, edgeData.Direction); Assert.AreEqual(1, edge.GetContracted()); }
public void TestPentagonDirected() { // build graph. var graph = new DirectedDynamicGraph(ContractedEdgeDataSerializer.DynamicFixedSize); graph.AddEdge(0, 1, 100, true); graph.AddEdge(1, 0, 100, false); graph.AddEdge(1, 2, 100, true); graph.AddEdge(2, 1, 100, false); graph.AddEdge(2, 3, 100, true); graph.AddEdge(3, 2, 100, false); graph.AddEdge(3, 4, 100, true); graph.AddEdge(4, 3, 100, false); graph.AddEdge(4, 0, 100, true); graph.AddEdge(0, 4, 100, false); 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), (i) => Enumerable.Empty <uint[]>()); 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 s1 = edges41.GetSequence1(); var s2 = edges41.GetSequence2(); Assert.AreEqual(1, s1.Length); Assert.AreEqual(0, s1[0]); Assert.AreEqual(1, s2.Length); Assert.AreEqual(0, s2[0]); 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); s1 = edges31.GetSequence1(); s2 = edges31.GetSequence2(); Assert.AreEqual(1, s1.Length); Assert.AreEqual(4, s1[0]); Assert.AreEqual(1, s2.Length); Assert.AreEqual(0, s2[0]); var edges13 = graph.GetEdgeEnumerator(1).FirstOrDefault(x => x.Neighbour == 3); Assert.IsNull(edges13); }
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); }