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)); }
public void TestCHEdgeDifferenceContractions() { IOsmRoutingInterpreter interpreter = new OsmSharp.Routing.Osm.Interpreter.OsmRoutingInterpreter(); CHPreProcessor processor = this.BuildCHPreProcessor(interpreter); //processor.InitializeQueue(); INodeWeightCalculator edgeDifference = processor.NodeWeightCalculator; Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4. Assert.AreEqual(6, edgeDifference.Calculate(2)); Assert.AreEqual(0, edgeDifference.Calculate(3)); Assert.AreEqual(0, edgeDifference.Calculate(4)); Assert.AreEqual(0, edgeDifference.Calculate(5)); Assert.AreEqual(0, edgeDifference.Calculate(6)); Assert.AreEqual(3, edgeDifference.Calculate(7)); Assert.AreEqual(3, edgeDifference.Calculate(8)); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(3, edgeDifference.Calculate(10)); Assert.AreEqual(3, edgeDifference.Calculate(11)); Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(3, edgeDifference.Calculate(16)); Assert.AreEqual(0, edgeDifference.Calculate(17)); Assert.AreEqual(0, edgeDifference.Calculate(18)); Assert.AreEqual(0, edgeDifference.Calculate(19)); Assert.AreEqual(-1, edgeDifference.Calculate(20)); Assert.AreEqual(0, edgeDifference.Calculate(21)); Assert.AreEqual(0, edgeDifference.Calculate(22)); Assert.AreEqual(-1, edgeDifference.Calculate(23)); // contract 20. processor.Contract(20); Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4. Assert.AreEqual(6, edgeDifference.Calculate(2)); Assert.AreEqual(0, edgeDifference.Calculate(3)); Assert.AreEqual(0, edgeDifference.Calculate(4)); Assert.AreEqual(0, edgeDifference.Calculate(5)); Assert.AreEqual(0, edgeDifference.Calculate(6)); Assert.AreEqual(3, edgeDifference.Calculate(7)); Assert.AreEqual(3, edgeDifference.Calculate(8)); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(3, edgeDifference.Calculate(10)); Assert.AreEqual(3, edgeDifference.Calculate(11)); Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(3, edgeDifference.Calculate(16)); Assert.AreEqual(0, edgeDifference.Calculate(17)); Assert.AreEqual(0, edgeDifference.Calculate(18)); Assert.AreEqual(0, edgeDifference.Calculate(19)); Assert.AreEqual(-1, edgeDifference.Calculate(21)); Assert.AreEqual(0, edgeDifference.Calculate(22)); Assert.AreEqual(-1, edgeDifference.Calculate(23)); // contract 21. processor.Contract(21); Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4. Assert.AreEqual(6, edgeDifference.Calculate(2)); Assert.AreEqual(0, edgeDifference.Calculate(3)); Assert.AreEqual(0, edgeDifference.Calculate(4)); Assert.AreEqual(0, edgeDifference.Calculate(5)); Assert.AreEqual(0, edgeDifference.Calculate(6)); Assert.AreEqual(3, edgeDifference.Calculate(7)); Assert.AreEqual(3, edgeDifference.Calculate(8)); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(3, edgeDifference.Calculate(10)); Assert.AreEqual(3, edgeDifference.Calculate(11)); Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(0, edgeDifference.Calculate(16)); Assert.AreEqual(0, edgeDifference.Calculate(17)); Assert.AreEqual(0, edgeDifference.Calculate(18)); Assert.AreEqual(0, edgeDifference.Calculate(19)); Assert.AreEqual(0, edgeDifference.Calculate(22)); Assert.AreEqual(-1, edgeDifference.Calculate(23)); // contract 23. processor.Contract(23); Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4. Assert.AreEqual(6, edgeDifference.Calculate(2)); Assert.AreEqual(0, edgeDifference.Calculate(3)); Assert.AreEqual(0, edgeDifference.Calculate(4)); Assert.AreEqual(0, edgeDifference.Calculate(5)); Assert.AreEqual(0, edgeDifference.Calculate(6)); Assert.AreEqual(3, edgeDifference.Calculate(7)); Assert.AreEqual(3, edgeDifference.Calculate(8)); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(3, edgeDifference.Calculate(10)); Assert.AreEqual(3, edgeDifference.Calculate(11)); Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(0, edgeDifference.Calculate(16)); Assert.AreEqual(0, edgeDifference.Calculate(17)); Assert.AreEqual(0, edgeDifference.Calculate(18)); Assert.AreEqual(0, edgeDifference.Calculate(19)); Assert.AreEqual(-1, edgeDifference.Calculate(22)); // contract 22. processor.Contract(22); Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4. Assert.AreEqual(6, edgeDifference.Calculate(2)); Assert.AreEqual(0, edgeDifference.Calculate(3)); Assert.AreEqual(0, edgeDifference.Calculate(4)); Assert.AreEqual(0, edgeDifference.Calculate(5)); Assert.AreEqual(0, edgeDifference.Calculate(6)); Assert.AreEqual(3, edgeDifference.Calculate(7)); Assert.AreEqual(3, edgeDifference.Calculate(8)); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(3, edgeDifference.Calculate(10)); Assert.AreEqual(3, edgeDifference.Calculate(11)); Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(-1, edgeDifference.Calculate(16)); Assert.AreEqual(0, edgeDifference.Calculate(17)); Assert.AreEqual(0, edgeDifference.Calculate(18)); Assert.AreEqual(0, edgeDifference.Calculate(19)); // contract 16. processor.Contract(16); Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4. Assert.AreEqual(6, edgeDifference.Calculate(2)); Assert.AreEqual(0, edgeDifference.Calculate(3)); Assert.AreEqual(0, edgeDifference.Calculate(4)); Assert.AreEqual(0, edgeDifference.Calculate(5)); Assert.AreEqual(0, edgeDifference.Calculate(6)); Assert.AreEqual(3, edgeDifference.Calculate(7)); Assert.AreEqual(3, edgeDifference.Calculate(8)); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(3, edgeDifference.Calculate(10)); Assert.AreEqual(3, edgeDifference.Calculate(11)); Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(-1, edgeDifference.Calculate(17)); Assert.AreEqual(0, edgeDifference.Calculate(18)); Assert.AreEqual(0, edgeDifference.Calculate(19)); // contract 17. processor.Contract(17); Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4. Assert.AreEqual(6, edgeDifference.Calculate(2)); Assert.AreEqual(0, edgeDifference.Calculate(3)); Assert.AreEqual(0, edgeDifference.Calculate(4)); Assert.AreEqual(0, edgeDifference.Calculate(5)); Assert.AreEqual(0, edgeDifference.Calculate(6)); Assert.AreEqual(0, edgeDifference.Calculate(7)); Assert.AreEqual(3, edgeDifference.Calculate(8)); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(3, edgeDifference.Calculate(10)); Assert.AreEqual(3, edgeDifference.Calculate(11)); Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(0, edgeDifference.Calculate(18)); Assert.AreEqual(0, edgeDifference.Calculate(19)); processor.Contract(3); Assert.AreEqual(1, edgeDifference.Calculate(1)); // witness paths from 2<->4. Assert.AreEqual(6, edgeDifference.Calculate(2)); Assert.AreEqual(-2, edgeDifference.Calculate(4)); Assert.AreEqual(0, edgeDifference.Calculate(5)); Assert.AreEqual(0, edgeDifference.Calculate(6)); Assert.AreEqual(0, edgeDifference.Calculate(7)); Assert.AreEqual(3, edgeDifference.Calculate(8)); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(3, edgeDifference.Calculate(10)); Assert.AreEqual(3, edgeDifference.Calculate(11)); Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(0, edgeDifference.Calculate(18)); Assert.AreEqual(0, edgeDifference.Calculate(19)); processor.Contract(4); Assert.AreEqual(0, edgeDifference.Calculate(1)); // witness paths from 2<->4. Assert.AreEqual(3, edgeDifference.Calculate(2)); Assert.AreEqual(0, edgeDifference.Calculate(5)); Assert.AreEqual(0, edgeDifference.Calculate(6)); Assert.AreEqual(0, edgeDifference.Calculate(7)); Assert.AreEqual(3, edgeDifference.Calculate(8)); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(3, edgeDifference.Calculate(10)); Assert.AreEqual(3, edgeDifference.Calculate(11)); Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(0, edgeDifference.Calculate(18)); Assert.AreEqual(0, edgeDifference.Calculate(19)); processor.Contract(1); Assert.AreEqual(1, edgeDifference.Calculate(2)); // witness paths from 11<->5. Assert.AreEqual(-2, edgeDifference.Calculate(5)); // witness paths from 11<->6. Assert.AreEqual(0, edgeDifference.Calculate(6)); Assert.AreEqual(0, edgeDifference.Calculate(7)); Assert.AreEqual(3, edgeDifference.Calculate(8)); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(3, edgeDifference.Calculate(10)); Assert.AreEqual(3, edgeDifference.Calculate(11)); Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(0, edgeDifference.Calculate(18)); Assert.AreEqual(0, edgeDifference.Calculate(19)); processor.Contract(5); Assert.AreEqual(1, edgeDifference.Calculate(2)); // witness paths from 11<->5. Assert.AreEqual(-2, edgeDifference.Calculate(6)); Assert.AreEqual(0, edgeDifference.Calculate(7)); Assert.AreEqual(3, edgeDifference.Calculate(8)); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(3, edgeDifference.Calculate(10)); Assert.AreEqual(3, edgeDifference.Calculate(11)); Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(0, edgeDifference.Calculate(18)); Assert.AreEqual(0, edgeDifference.Calculate(19)); processor.Contract(6); Assert.AreEqual(0, edgeDifference.Calculate(2)); // witness paths from 11<->5. Assert.AreEqual(-1, edgeDifference.Calculate(7)); Assert.AreEqual(3, edgeDifference.Calculate(8)); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(3, edgeDifference.Calculate(10)); Assert.AreEqual(3, edgeDifference.Calculate(11)); Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(0, edgeDifference.Calculate(18)); Assert.AreEqual(0, edgeDifference.Calculate(19)); processor.Contract(7); Assert.AreEqual(0, edgeDifference.Calculate(2)); // witness paths from 11<->5. Assert.AreEqual(3, edgeDifference.Calculate(8)); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(3, edgeDifference.Calculate(10)); Assert.AreEqual(0, edgeDifference.Calculate(11)); Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(0, edgeDifference.Calculate(18)); Assert.AreEqual(0, edgeDifference.Calculate(19)); processor.Contract(2); Assert.AreEqual(3, edgeDifference.Calculate(8)); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(3, edgeDifference.Calculate(10)); Assert.AreEqual(-2, edgeDifference.Calculate(11)); // witness paths from 18<->10. Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(0, edgeDifference.Calculate(18)); Assert.AreEqual(0, edgeDifference.Calculate(19)); processor.Contract(11); Assert.AreEqual(3, edgeDifference.Calculate(8)); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(1, edgeDifference.Calculate(10)); Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(-2, edgeDifference.Calculate(18)); // witness paths from 10<->8. Assert.AreEqual(0, edgeDifference.Calculate(19)); processor.Contract(18); Assert.AreEqual(0, edgeDifference.Calculate(8)); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(0, edgeDifference.Calculate(10)); Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(0, edgeDifference.Calculate(19)); processor.Contract(8); Assert.AreEqual(0, edgeDifference.Calculate(9)); Assert.AreEqual(0, edgeDifference.Calculate(10)); Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(0, edgeDifference.Calculate(19)); processor.Contract(9); Assert.AreEqual(-2, edgeDifference.Calculate(10)); // witness paths from 19<->12. Assert.AreEqual(0, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(-2, edgeDifference.Calculate(19)); // witness paths from 15<->10. processor.Contract(10); Assert.AreEqual(-2, edgeDifference.Calculate(12)); Assert.AreEqual(0, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(-2, edgeDifference.Calculate(19)); // witness paths from 15<->10. processor.Contract(12); Assert.AreEqual(-1, edgeDifference.Calculate(13)); Assert.AreEqual(0, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(-1, edgeDifference.Calculate(19)); // witness paths from 15<->10. processor.Contract(13); Assert.AreEqual(-1, edgeDifference.Calculate(14)); Assert.AreEqual(0, edgeDifference.Calculate(15)); Assert.AreEqual(-1, edgeDifference.Calculate(19)); // witness paths from 15<->10. processor.Contract(14); Assert.AreEqual(-1, edgeDifference.Calculate(15)); Assert.AreEqual(-1, edgeDifference.Calculate(19)); // witness paths from 15<->10. processor.Contract(15); Assert.AreEqual(0, edgeDifference.Calculate(19)); processor.Contract(19); }
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); })); }