예제 #1
0
        public void TestFindingDirectionsAStarSearchLimaLandmarksHeuristic()
        {
            var filename = @"../../../../datasets/Lima/Lima.osm.pbf";

            var(graph, nodes) = OpenStreetMapDataHelper.ExtractMapGraph(filename);
            var    nodeLocator = OpenStreetMapDataHelper.MakeNodeLocator(nodes);
            double latFrom     = -12.073457334109781;
            double lonFrom     = -77.16832519640246;
            double latTo       = -12.045889755060621;
            double lonTo       = -77.04266126523356;
            var    problem     = OpenStreetMapDataHelper.BuildMapProblem(graph, nodeLocator, latFrom, lonFrom, latTo, lonTo);
            var    goal        = problem.GetGoalState();
            // TODO: find a good way to choose landmarks
            var landmarks = new List <FindingDirectionsState>();

            landmarks.Add(nodeLocator.FindNearestNeighbor(new FindingDirectionsState(0, null, -11.9997645637738, -77.08525616778775)));
            landmarks.Add(nodeLocator.FindNearestNeighbor(new FindingDirectionsState(0, null, -12.0730474312380, -77.16825444354458)));
            //landmarks.Add(nodeLocator.FindNearestNeighbor(new FindingDirectionsState(0, null, -12.1900507635347, -76.97454096014161)));
            landmarks.Add(nodeLocator.FindNearestNeighbor(new FindingDirectionsState(0, null, -12.0160677109035, -76.87767227591303)));
            output.WriteLine("Landmarks selected: " + landmarks.Count);
            foreach (var landmark in landmarks)
            {
                output.WriteLine("    " + landmark.ToString());
            }
            var heuristic = HeuristicsHelper.MakeLandmarksHeuristic(goal, graph, landmarks);
            var solver    = new AStarSearchSolver <FindingDirectionsState>(heuristic);

            // real solution Final State (293 moves, 8.98118622895219 cost)
            // test solution Final State (361 moves, 10.7577504383769 cost)
            TestSolver(solver, problem, 8.98118622895219);
        }
예제 #2
0
        public ActionResult <object> GetDirections(double latFrom, double lonFrom, double latTo, double lonTo)
        {
            var timer   = Stopwatch.StartNew();
            var problem = OpenStreetMapDataHelper.BuildMapProblem(mapGraph, locations, latFrom, lonFrom, latTo, lonTo);
            var goal    = problem.GetGoalState();
            Func <FindingDirectionsState, double> heuristic = from => double_heuristic(from, goal);
            var solver          = new AStarSearchSolver <FindingDirectionsState>(heuristic);
            var locationFinding = timer.Elapsed.TotalMilliseconds;

            timer = Stopwatch.StartNew();
            var           solution = solver.Solve(problem).Cast <FindingDirectionsState>().ToArray();
            List <LatLng> steps    = null;

            if (MapController.segmentsGraph == null)
            {
                steps = new List <LatLng>();
                for (int i = 1; i < solution.Length; i++)
                {
                    var parts = MapController.segmentsGraph.GetEdgeWeight(solution[i - 1], solution[i]);
                    steps.AddRange(parts.Select(m => new LatLng {
                        lat = m.Latitude, lng = m.Longitude
                    }));
                }
            }
            else
            {
                steps = solution
                        .Select(m => new LatLng {
                    lat = m.Latitude, lng = m.Longitude
                })
                        .ToList();
            }
            var itemsTime = timer.Elapsed.TotalMilliseconds;

            return(new {
                points = steps,
                problemDefineTime = locationFinding,
                directionsFindTime = itemsTime,
                statesEvaluated = solver.StatesEvaluated,
            });
        }
예제 #3
0
        public void TestFindingDirectionsAStarSearchLimaStraightLineDistanceHeuristic()
        {
            var filename = @"../../../../datasets/Lima/Lima.osm.pbf";

            // var problem = OpenStreetMapDataHelper.ExtractMapProblem(
            //         filename,
            //         -12.073457334109781, -77.16832519640246,
            //         -12.045889755060621,-77.04266126523356
            //         // -12.041839850701912,-77.06330992167841,
            //         // -12.060138589193466,-77.01043821757685
            //     );
            var(graph, nodes) = OpenStreetMapDataHelper.ExtractMapGraph(filename);
            var    nodeLocator = OpenStreetMapDataHelper.MakeNodeLocator(nodes);
            double latFrom     = -12.073457334109781;
            double lonFrom     = -77.16832519640246;
            double latTo       = -12.045889755060621;
            double lonTo       = -77.04266126523356;
            var    problem     = OpenStreetMapDataHelper.BuildMapProblem(graph, nodeLocator, latFrom, lonFrom, latTo, lonTo);
            var    goal        = problem.GetGoalState();
            var    heuristic   = HeuristicsHelper.MakeStraightLineDistanceHeuristic(goal);
            var    solver      = new AStarSearchSolver <FindingDirectionsState>(heuristic);

            TestSolver(solver, problem, 8.98118622895219);
        }