/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { Defaults.Load(); _streets = OsmStreetSystem.LoadSystem("K:\\OsmData\\schleswig-holstein-latest.sn"); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here _map = new MapControl(spriteBatch, GraphicsDevice, GraphicsDevice.Viewport.Bounds.ToMapRectangle()); _map.Zoom = 15; _map.Position = new MapPointLatLon(53.8265376, 10.4917827); _map.ZoomMode = ZoomingType.Mouse; _routeLayer = _map.AddLayer(); _map.OnRightClick += _map_OnRightClick; }
private void Run() { Defaults.Load(); MeasureTime(() => { Console.WriteLine("Reading network file..."); _streets = OsmStreetSystem.LoadSystem("K:\\OsmData\\schleswig-holstein-latest.sn"); Console.WriteLine("Finished."); }); GC.Collect(); var start = _streets.Waypoints[3444465853]; var end = _streets.Waypoints[620793260]; Console.WriteLine(); Console.WriteLine($"Trying to find path from {start.Id} to {end.Id}"); Console.WriteLine($"Direct distance: {start.DistanceTo(end):##.000} km"); Console.WriteLine(); Console.WriteLine("Using Dijkstra's allgorithm."); var dijkstra = new DijkstraAlgorithm(); var astar = new AStarAlgorithm(); Console.WriteLine(" --------- DIJKSTRA ----------"); for (int i = 0; i < 3; i++) { MeasureTime(() => { Console.WriteLine($"[{i}] Looking for a path in the graph...."); var p = dijkstra.FindPath(start, end); Console.WriteLine($"Finished in {dijkstra.Steps} steps."); Console.WriteLine($"Inspected {dijkstra.InspectedNodes}, visited {dijkstra.VisitedNodes}"); if (p != null) { Console.WriteLine($"Found a path. {p.Waypoints.Count} waypoints. {p.Length:##.000} km."); } else { Console.WriteLine("No path found."); } }); } Console.WriteLine(" --------- A-STAR ----------"); for (int i = 0; i < 3; i++) { MeasureTime(() => { Console.WriteLine($"[{i}] Looking for a path in the graph...."); var p = astar.FindPath(start, end); Console.WriteLine($"Finished in {astar.Steps} steps."); Console.WriteLine($"Inspected {astar.InspectedNodes}, visited {astar.VisitedNodes}"); if (p != null) { Console.WriteLine($"Found a path. {p.Waypoints.Count} waypoints. {p.Length:##.000} km."); } else { Console.WriteLine("No path found."); } }); } Console.ReadLine(); }