Beispiel #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);
        }
Beispiel #2
0
        public static void InitializeMapData(string city_name)
        {
            Log.WriteLine("Loading map data: " + city_name);
            var filename = Path.Combine($@"../datasets/{city_name}/{city_name}.osm.pbf");

            //var (graph, nodes) = OpenStreetMapDataHelper.ExtractMapGraph(filename);
            var(graph, segments, nodes) = OpenStreetMapDataHelper.ExtractIntersectionMapGraph(filename);
            MapController.mapGraph      = graph;
            MapController.segmentsGraph = segments;
            MapController.locations     = OpenStreetMapDataHelper.MakeNodeLocator(nodes);
            Log.WriteLine("Calculating heuristic");
            //MapController.double_heuristic = (from, goal) => DistanceHelper.Haversine(from.Latitude, from.Longitude, goal.Latitude, goal.Longitude);
            var random = new Random();

            // TODO: find a better way to choose landmarks
            MapController.landmarks        = nodes.OrderBy(m => random.Next()).Take(4).ToArray();
            MapController.double_heuristic = HeuristicsHelper.MakeLandmarksHeuristicDouble(mapGraph, MapController.landmarks);
            MapController.nodeCount        = nodes.Count;
            Log.WriteLine("Calculating bounding box");
            foreach (var node in nodes)
            {
                if (bbNorthWest == null)
                {
                    bbNorthWest = new LatLng {
                        lat = node.Latitude, lng = node.Longitude
                    }
                }
                ;
                bbNorthWest.lat = Math.Min(bbNorthWest.lat, node.Latitude);
                bbNorthWest.lng = Math.Min(bbNorthWest.lng, node.Longitude);
                if (bbSouthEast == null)
                {
                    bbSouthEast = new LatLng {
                        lat = node.Latitude, lng = node.Longitude
                    }
                }
                ;
                bbSouthEast.lat = Math.Max(bbSouthEast.lat, node.Latitude);
                bbSouthEast.lng = Math.Max(bbSouthEast.lng, node.Longitude);
            }
            Log.WriteLine("Map data loaded: " + city_name);
            Log.WriteLine("    Total map nodes: " + nodes.Count);
        }
Beispiel #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);
        }