Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Graph/EarthDistanceCostCalculator.cs @ 8488

Last change on this file since 8488 was 8488, checked in by spimming, 12 years ago

#1894:

  • introduced weight property in Edge
  • new data source implementation for DIMACS graphs
  • lightweight data source implementation for osm graphs
  • cost calculator interface and implementations added
File size: 1.2 KB
Line 
1using System;
2
3namespace HeuristicLab.Problems.RoutePlanning.Graph {
4  public class EarthDistanceCostCalculator : ICostCalculator {
5    private const double earthMeanRadius = 6371.0 * 1000.0;
6
7    #region ICostCalculator Members
8
9    public float Costs(Edge<Vertex> edge) {
10      return edge.Weight;
11    }
12
13    public float EstimatedCosts(Vertex source, Vertex destination) {
14      return (float)EarthDistance(source.Logitude, source.Latitude, destination.Logitude, destination.Latitude);
15    }
16
17    #endregion
18
19    private double DegToRad(double alpha) {
20      return alpha * Math.PI / 180;
21    }
22
23    private double AngularDistance(double startLon, double startLat, double endLon, double endLat) {
24      double lat1 = DegToRad(startLat);
25      double lat2 = DegToRad(endLat);
26      double long1 = DegToRad(startLon);
27      double long2 = DegToRad(endLat);
28
29      double x = Math.Sin(lat1) * Math.Sin(lat2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Cos(long1 - long2);
30      x = Math.Min(1, Math.Max(0, x));
31
32      return Math.Acos(x);
33    }
34
35    private double EarthDistance(double startLon, double startLat, double endLon, double endLat) {
36      return earthMeanRadius * AngularDistance(startLon, startLat, endLon, endLat);
37    }
38  }
39}
Note: See TracBrowser for help on using the repository browser.