Exemple #1
0
        private IEnumerable <TEdge> RouteInternal(
            P source, P target, Func <TEdge, double> cost, Func <TEdge, double> bound = null, double max = Double.NaN)
        {
            IEnumerable <TEdge> edges = EmptyPath;

            //On same road && forward
            if (source.Edge.Equals(target.Edge) && source.Fraction <= target.Fraction)
            {
                edges = GetPathOnSameRoad(source.Edge);
            }
            else if (source.Edge.Target.Equals(target.Edge.Source)) //is neighborhood
            {
                edges = GetPathOnNeighborhoodRoad(source.Edge, target.Edge);
            }
            else
            {
                var t = _precomputedTable.GetPathByVertex(source.Edge.Target, target.Edge.Source);
                return(CombineHeadTailEdges(source.Edge, target.Edge, t.Path));
            }

            return(edges);
        }
        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);
        }