Esempio n. 1
0
 public PrecomputedDijkstraRouter(IGraph <TEdge> graph, Func <TEdge, double> cost, Func <TEdge, double> boundingCost, double max)
 {
     _graph            = graph;
     _cost             = cost;
     _boundingCost     = boundingCost;
     _maxRadius        = max;
     _precomputedTable = this.CreateTable();
 }
        public void TestGetPathByVertex(string sourceVertex, string targetVertex)
        {
            var maxRadius = 500D;

            var naiveDijkstra = new BoundedDijkstraShortestPathAlgorithm <string, Edge <string> >(
                MyGraph.GraphInstance, e => MyGraph.EdgeCosts[e], e => MyGraph.EdgeCosts[e], maxRadius);

            naiveDijkstra.Compute(sourceVertex);

            var generator = new PrecomputedDijkstraTableGenerator <string, Edge <string> >();
            var rows      = generator.ComputeRows(MyGraph.GraphInstance, e => MyGraph.EdgeCosts[e], e => MyGraph.EdgeCosts[e], maxRadius);

            var table          = new PrecomputedDijkstraTable <string, Edge <string> >(rows);
            var t              = table.GetPathByVertex(sourceVertex, targetVertex);
            var actualDistance = t.Path.Sum(e => MyGraph.EdgeCosts[e]);

            Assert.True(naiveDijkstra.TryGetPath(targetVertex, out var expectedPath));
            Assert.NotNull(t.Path);
            Assert.NotEmpty(t.Path);
            var expectedDistance = expectedPath.Sum(e => MyGraph.EdgeCosts[e]);

            Assert.Equal(expectedPath, t.Path);
            Assert.Equal(expectedDistance, actualDistance, 8);
        }