Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/09/12 16:20:19 (12 years ago)
Author:
spimming
Message:

#1894:

  • calculate distance in kilometers for two locations
  • generate IGraph from a datasource
  • adapted test program
Location:
branches/RoutePlanning
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning.Test/Program.cs

    r8438 r8462  
    2121      string file5 = @"..\..\OsmTestFiles\test_mid.osm";
    2222      string file6 = @"C:\dev\osmfiles\oberosterreich.highway.osm";
     23      string file7 = @"C:\dev\osmfiles\austria.highway.osm";
    2324
    24       IDataSource ds = TestLoad(file6);
     25      IDataSource ds = TestLoad(file5);
    2526      OsmGraph graph = new OsmGraph(ds);
    26       TestRouter(new DijkstraAlgorithm(graph), 529102170, 31372732, false); // inz - hgb
    27       TestRouter(new AStarAlgorithm(graph), 529102170, 31372732, false); // inz - hgb
    28       TestRouter(new AStarAlgorithmV2(graph), 529102170, 31372732, false); // inz - hgb
    29       TestRouter(new BidrectionalDijkstraAlgorithm(graph), 529102170, 31372732, false); // inz - hgb
     27      IGraph graphNew = TestGetRoutingGraph(ds);
     28      TestRouter(new DijkstraAlgorithm(graph), 529102170, 1001363194, true);
     29      TestRouter(new DijkstraAlgorithmV2(graphNew), 529102170, 1001363194, true);
     30      //TestRouter(new DijkstraAlgorithm(graph), 529102170, 31372732, false); // inz - hgb
     31      //TestRouter(new DijkstraAlgorithmV2(graphNew), 529102170, 31372732, false); // inz - hgb
     32      //TestRouter(new AStarAlgorithm(graph), 529102170, 31372732, false); // inz - hgb
     33      //TestRouter(new AStarAlgorithmV2(graph), 529102170, 31372732, false); // inz - hgb
     34      //TestRouter(new BidrectionalDijkstraAlgorithm(graph), 529102170, 31372732, false); // inz - hgb
     35
     36      //TestRouter(new AStarAlgorithmV2(graph), 346151602, 33196510, false); // bregenz (bahnhofstr) - wien (stepansplatz)
    3037
    3138      //TestLoadAndRouter(file6, typeof(DijkstraAlgorithm), 529102170, 31372732, false, false); // inz - hgb
     
    3340      //TestLoadAndRouter(file6, typeof(AStarAlgorithmV2), 529102170, 31372732, false, true); // inz - hgb
    3441
     42      //TestLoadAndRouter(file6, typeof(DijkstraAlgorithm), 529102170, 1001363194, true, false);
    3543      //TestLoadAndRouter(file6, typeof(DijkstraAlgorithm), 529102170, 1001363194, true, false);
    3644      //TestLoadAndRouter(file6, typeof(AStarAlgorithm), 529102170, 1001363194, true, false);
     
    4149      //TestLoadAndRouter(file5, typeof(BidrectionalDijkstraAlgorithm), 529102170, 1001363194, true, true);
    4250      //TestLoadAndRouter(file6, typeof(BidrectionalDijkstraAlgorithm), 529102170, 31372732, false, true); // inz - hgb
     51
     52
     53
     54
    4355
    4456      System.Console.Read();
     
    167179      }
    168180    }
     181
     182    private static IGraph TestGetRoutingGraph(IDataSource ds) {
     183      Console.WriteLine("Test GetRoutingGraph BEGIN ------------------------");
     184      Console.WriteLine();
     185      Console.Write("Construct graph ... ");
     186      var sw = Stopwatch.StartNew();
     187      IGraph graph = ds.GetRoutingGraph();
     188      sw.Stop();
     189      Console.WriteLine("done.");
     190      Console.WriteLine("Time: {0}", sw.Elapsed);
     191      Console.WriteLine();
     192      Console.WriteLine("===================================================");
     193      Console.WriteLine();
     194      return graph;
     195    }
    169196  }
    170197}
  • branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Graph/OsmGraph.cs

    r8434 r8462  
    7171    public float GetWeight(Way edge, OsmVertex<Node> source, OsmVertex<Node> target) {
    7272      double distance = Utils.Distance(source.Node.Point, target.Node.Point);
     73      //double distance = Utils.LocationDistance(source.Node.Point, target.Node.Point);
    7374      int speed = edge.GetMaxSpeed();
    7475      double weight = (distance / speed) * 3.6;
     76      //double weight = (distance / speed);
    7577      return (float)weight;
    7678    }
     
    8486    public float EstimatedCosts(OsmVertex<Node> source, OsmVertex<Node> target) {
    8587      double distance = Utils.Distance(source.Node.Point, target.Node.Point);
     88      //double distance = Utils.LocationDistance(source.Node.Point, target.Node.Point);
    8689      int speed = 130;
    8790      double costs = (distance / speed) * 3.6;
     91      //double costs = (distance / speed);
    8892      return (float)costs;
    8993    }
  • branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Osm.Data/XmlDataSource.cs

    r8316 r8462  
    11
     2using System;
    23using System.Collections.Generic;
    34using System.IO;
    45using System.Xml;
     6using HeuristicLab.Problems.RoutePlanning.Graph;
    57namespace HeuristicLab.Problems.RoutePlanning.Osm.Data {
    68  public class XmlDataSource : IDataSource {
     
    8284    }
    8385
    84     #endregion
     86    public IGraph GetRoutingGraph() {
     87      IGraph graph = new Graph.Graph();
     88      foreach (Way way in ways.Values) {
     89        List<Node> nodes = way.Nodes;
     90        for (int i = 0; i < way.Nodes.Count - 1; i++) {
     91          Vertex v1 = new Vertex(nodes[i].Id, nodes[i].Longitude, nodes[i].Latitude);
     92          graph.AddVertex(v1);
     93          Vertex v2 = new Vertex(nodes[i + 1].Id, nodes[i + 1].Longitude, nodes[i + 1].Latitude);
     94          if (v1.Id == 370626403) {
     95            Console.WriteLine();
     96          }
     97          graph.AddVertex(v2);
     98          if (way.OneWay) {
     99            Edge<Vertex> edge = new Edge<Vertex>(v1, v2);
     100            edge.Category = (short)way.HighwayTag;
     101            graph.AddEdge(edge);
     102          } else {
     103            Edge<Vertex> edgeForward = new Edge<Vertex>(v1, v2);
     104            edgeForward.Category = (short)way.HighwayTag;
     105            graph.AddEdge(edgeForward);
     106
     107            Edge<Vertex> edgeBackward = new Edge<Vertex>(v2, v1);
     108            edgeForward.Category = (short)way.HighwayTag;
     109            graph.AddEdge(edgeBackward);
     110          }
     111
     112        }
     113      }
     114      return graph;
     115    }
     116
     117    #endregion
     118
     119    #region Private Methods
    85120
    86121    private void ReadData() {
     
    214249      }
    215250    }
     251
     252    #endregion
    216253  }
    217254}
  • branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Osm/IDataSource.cs

    r8300 r8462  
    11
    22using System.Collections.Generic;
     3using HeuristicLab.Problems.RoutePlanning.Graph;
    34namespace HeuristicLab.Problems.RoutePlanning.Osm {
    45  public interface IDataSource {
     
    89    List<Way> GetWays(Node node);
    910    Relation GetRelation(long relationId);
     11    IGraph GetRoutingGraph();
    1012  }
    1113}
  • branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Osm/Utils.cs

    r8308 r8462  
    88      double dy = p2.Y - p1.Y;
    99      return Math.Sqrt(dx * dx + dy * dy);
     10    }
     11
     12    public static double LocationDistance(PointD p1, PointD p2) {
     13      // The Haversine formula
     14      /* dlon = lon2 - lon1
     15            dlat = lat2 - lat1
     16            a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
     17            c = 2 * atan2(sqrt(a), sqrt(1-a))
     18            d = R * c
     19       */
     20
     21      double lat1Rad = p1.Y * (Math.PI / 180.0);
     22      double long1Rad = p1.X * (Math.PI / 180.0);
     23      double lat2Rad = p2.Y * (Math.PI / 180.0);
     24      double long2Rad = p2.X * (Math.PI / 180.0);
     25
     26      double longitude = long2Rad - long1Rad;
     27      double latitude = lat2Rad - lat1Rad;
     28
     29      double a = Math.Pow(Math.Sin(latitude / 2.0), 2.0) +
     30                   Math.Cos(lat1Rad) * Math.Cos(lat2Rad) *
     31                   Math.Pow(Math.Sin(longitude / 2.0), 2.0);
     32
     33      double c = 2.0 * Math.Asin(Math.Sqrt(a));
     34
     35      const double earthRadiusKms = 6376.5;
     36      double distance = earthRadiusKms * c;
     37
     38      return distance;
    1039    }
    1140
Note: See TracChangeset for help on using the changeset viewer.