Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/22/12 19:14:33 (12 years ago)
Author:
spimming
Message:

#1894:

  • extended datasource interface to get routing graph for a specific vehicle type
  • use ICostCalculator to calculate edge weights
  • moved common enums in own file
  • removed method to estimate cost from graph; use ICostCalculator
Location:
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/RoutingGraph
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/RoutingGraph/EarthDistanceCostCalculator.cs

    r8516 r8520  
    1 using System;
     1using HeuristicLab.Problems.RoutePlanning.Data.Core;
    22using HeuristicLab.Problems.RoutePlanning.Interfaces;
     3using HeuristicLab.Problems.RoutePlanning.Utilities;
    34
    45namespace HeuristicLab.Problems.RoutePlanning.RoutingGraph {
    56  public class EarthDistanceCostCalculator : ICostCalculator {
    6     private const double earthMeanRadius = 6371.0 * 1000.0;
    7 
    87    #region ICostCalculator Members
    98
     
    1211    }
    1312
     13    public float CalculateCosts(Vertex source, Vertex destination, HighwayType category) {
     14      double distanceKms = Utils.LocationDistance(source.Logitude, source.Latitude,
     15                                            destination.Logitude, destination.Latitude);
     16      double weight = distanceKms;
     17      return (float)weight;
     18    }
     19
    1420    public float EstimatedCosts(Vertex source, Vertex destination) {
    15       return (float)EarthDistance(source.Logitude, source.Latitude, destination.Logitude, destination.Latitude);
     21      double distanceKms = Utils.LocationDistance(source.Logitude, source.Latitude,
     22                                            destination.Logitude, destination.Latitude);
     23      double weight = distanceKms;
     24      return (float)weight;
    1625    }
    1726
    1827    #endregion
    19 
    20     private double DegToRad(double alpha) {
    21       return alpha * Math.PI / 180;
    22     }
    23 
    24     private double AngularDistance(double startLon, double startLat, double endLon, double endLat) {
    25       double lat1 = DegToRad(startLat);
    26       double lat2 = DegToRad(endLat);
    27       double long1 = DegToRad(startLon);
    28       double long2 = DegToRad(endLat);
    29 
    30       double x = Math.Sin(lat1) * Math.Sin(lat2) + Math.Cos(lat1) * Math.Cos(lat2) * Math.Cos(long1 - long2);
    31       x = Math.Min(1, Math.Max(0, x));
    32 
    33       return Math.Acos(x);
    34     }
    35 
    36     private double EarthDistance(double startLon, double startLat, double endLon, double endLat) {
    37       return earthMeanRadius * AngularDistance(startLon, startLat, endLon, endLat);
    38     }
    3928  }
    4029}
  • branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/RoutingGraph/Edge.cs

    r8516 r8520  
    1313    }
    1414
    15     private short category;
    16     public short Category {
    17       get { return category; }
    18       set { category = value; }
    19     }
     15    //private short category;
     16    //public short Category {
     17    //  get { return category; }
     18    //  set { category = value; }
     19    //}
    2020
    2121    private float weight;
     
    3030    }
    3131
    32     public Edge(Vertex source, Vertex target, short category) {
     32    public Edge(Vertex source, Vertex target, float weight) {
    3333      this.source = source;
    3434      this.target = target;
    35       this.category = category;
     35      this.weight = weight;
    3636    }
    3737
     
    5151      return source.GetHashCode() ^ target.GetHashCode();
    5252    }
    53 
    54     public int GetMaxSpeed() {
    55       int speed = 0;
    56 
    57       //TODO:
    58       switch (category) {
    59         case 23:
    60         case 17:
    61         case 18:
    62         case 22:
    63         case 21:
    64         case 24:
    65         case 16:
    66         case 20:
    67         case 15:
    68         case 12:
    69         case 0:
    70           speed = 1;
    71           break;
    72 
    73         case 11:
    74         case 14:
    75           speed = 15;
    76           break;
    77 
    78         case 19:
    79           speed = 30;
    80           break;
    81 
    82         case 9:
    83         case 10:
    84         case 7:
    85         case 8:
    86           speed = 80;
    87           break;
    88 
    89         case 13:
    90           speed = 50;
    91           break;
    92 
    93         case 3:
    94         case 4:
    95         case 5:
    96         case 6:
    97           speed = 100;
    98           break;
    99 
    100         case 1:
    101         case 2:
    102           speed = 130;
    103           break;
    104 
    105         default:
    106           speed = 1;
    107           break;
    108       }
    109       return speed;
    110     }
    11153  }
    11254}
  • branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/RoutingGraph/Graph.cs

    r8516 r8520  
    33using System.Collections.Generic;
    44using HeuristicLab.Problems.RoutePlanning.Interfaces;
    5 using HeuristicLab.Problems.RoutePlanning.Utilities;
    65namespace HeuristicLab.Problems.RoutePlanning.RoutingGraph {
    76  public class Graph : IGraph {
     
    126125      foreach (Edge<Vertex> edge in edges) {
    127126        // TODO: check if edge can be traversed (eg. highway tag for car roads, ...)
    128         float weight = GetWeight(edge); // TODO:  edge.Weight?
    129         neighbors[edge.Target.Id] = weight;
     127        //float weight = GetWeight(edge); // TODO:  edge.Weight?
     128        //neighbors[edge.Target.Id] = weight;
     129        neighbors[edge.Target.Id] = edge.Weight;
    130130      }
    131131      return neighbors;
     
    136136      foreach (Edge<Vertex> edge in edges) {
    137137        // TODO: check if edge can be traversed (eg. highway tag for car roads, ...)
    138         float weight = GetWeight(edge); // TODO:  edge.Weight?
    139         neighbors[edge.Source.Id] = weight;
     138        //float weight = GetWeight(edge); // TODO:  edge.Weight?
     139        //neighbors[edge.Source.Id] = weight;
     140        neighbors[edge.Source.Id] = edge.Weight;
    140141      }
    141142      return neighbors;
    142143    }
    143144
    144     public float GetWeight(Edge<Vertex> edge) {
    145       //double distance = Utils.Distance(edge.Source.Logitude, edge.Source.Latitude,
    146       //                                 edge.Target.Logitude, edge.Target.Latitude);
     145    //public float GetWeight(Edge<Vertex> edge) {
     146    //  //double distance = Utils.Distance(edge.Source.Logitude, edge.Source.Latitude,
     147    //  //                                 edge.Target.Logitude, edge.Target.Latitude);
    147148
    148       PointD s = new PointD(edge.Source.Logitude, edge.Source.Latitude);
    149       PointD t = new PointD(edge.Target.Logitude, edge.Target.Latitude);
    150       double distance = Utils.LocationDistance(s, t);
     149    //  PointD s = new PointD(edge.Source.Logitude, edge.Source.Latitude);
     150    //  PointD t = new PointD(edge.Target.Logitude, edge.Target.Latitude);
     151    //  double distance = Utils.LocationDistance(s, t);
    151152
    152       int speed = edge.GetMaxSpeed();
    153       double weight = (distance / speed) * 60;
    154       //double weight = (distance / speed) * 3.6;
    155       //double weight = (distance / speed);
    156       //double weight = distance;
    157       return (float)weight;
    158     }
     153    //  //int speed = edge.GetMaxSpeed();
     154    //  //double weight = (distance / speed) * 60;
     155    //  //double weight = (distance / speed) * 3.6;
     156    //  //double weight = (distance / speed);
     157    //  //double weight = distance;
     158    //  //return (float)weight;
     159    //  return (float)1;
     160    //}
    159161
    160     public float EstimatedCosts(long sourceId, long targetId) {
    161       Vertex source = GetVertex(sourceId);
    162       Vertex target = GetVertex(targetId);
    163       return EstimatedCosts(source, target);
    164     }
     162    //public float EstimatedCosts(long sourceId, long targetId) {
     163    //  Vertex source = GetVertex(sourceId);
     164    //  Vertex target = GetVertex(targetId);
     165    //  return EstimatedCosts(source, target);
     166    //}
    165167
    166     public float EstimatedCosts(Vertex source, Vertex target) {
    167       //double distance = Utils.Distance(source.Logitude, source.Latitude,
    168       //                                 target.Logitude, target.Latitude);
     168    //public float EstimatedCosts(Vertex source, Vertex target) {
     169    //  //double distance = Utils.Distance(source.Logitude, source.Latitude,
     170    //  //                                 target.Logitude, target.Latitude);
    169171
    170       PointD s = new PointD(source.Logitude, source.Latitude);
    171       PointD t = new PointD(target.Logitude, target.Latitude);
    172       double distance = Utils.LocationDistance(s, t);
     172    //  PointD s = new PointD(source.Logitude, source.Latitude);
     173    //  PointD t = new PointD(target.Logitude, target.Latitude);
     174    //  double distance = Utils.LocationDistance(s, t);
    173175
    174       //int speed = 130;
    175       //int speed = 10;
    176       int speed = 130;
    177       double costs = (distance / speed) * 60;
    178       //double costs = (distance / speed) * 3.6;
    179       //double costs = (distance / speed);
    180       //double costs = distance;
    181       return (float)costs;
    182     }
     176    //  //int speed = 130;
     177    //  //int speed = 10;
     178    //  int speed = 130;
     179    //  double costs = (distance / speed) * 60;
     180    //  //double costs = (distance / speed) * 3.6;
     181    //  //double costs = (distance / speed);
     182    //  //double costs = distance;
     183    //  return (float)costs;
     184    //}
    183185  }
    184186}
  • branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/RoutingGraph/TravelTimeCostCalculator.cs

    r8516 r8520  
    11
     2using HeuristicLab.Problems.RoutePlanning.Data.Core;
    23using HeuristicLab.Problems.RoutePlanning.Interfaces;
    34using HeuristicLab.Problems.RoutePlanning.Utilities;
     
    78
    89    public float Costs(Edge<Vertex> edge) {
    9       double distance = Utils.Distance(edge.Source.Logitude, edge.Source.Latitude,
    10                                        edge.Target.Logitude, edge.Target.Latitude);
     10      //double distance = Utils.Distance(edge.Source.Logitude, edge.Source.Latitude,
     11      //                                 edge.Target.Logitude, edge.Target.Latitude);
    1112      //double distance = Utils.LocationDistance(source.Node.Point, target.Node.Point);
    12       int speed = edge.GetMaxSpeed();
    13       double weight = (distance / speed) * 3.6;
     13      //int speed = edge.GetMaxSpeed();
     14      //double weight = (distance / speed) * 3.6;
    1415      //double weight = (distance / speed);
     16      //return (float)1;
     17      return edge.Weight;
     18    }
     19
     20    public float CalculateCosts(Vertex source, Vertex destination, HighwayType category) {
     21      double distanceKms = Utils.Distance(source.Logitude, source.Latitude,
     22                                          destination.Logitude, destination.Latitude);
     23      int speedKmH = GetMaxSpeed(category);
     24      double weight = (distanceKms / speedKmH) * 60;
    1525      return (float)weight;
    1626    }
    1727
    1828    public float EstimatedCosts(Vertex source, Vertex destination) {
    19       double distance = Utils.Distance(source.Logitude, source.Latitude,
    20                                        destination.Logitude, destination.Latitude);
     29      //double distance = Utils.Distance(source.Logitude, source.Latitude,
     30      //                                 destination.Logitude, destination.Latitude);
    2131      //double distance = Utils.LocationDistance(source.Node.Point, target.Node.Point);
    22       int speed = 130;
    23       double costs = (distance / speed) * 3.6;
     32      int speedKmH = 130;
     33      //double costs = (distance / speed) * 3.6;
    2434      //double costs = (distance / speed);
    25       return (float)costs;
     35      //return (float)costs;
     36      double distanceKms = Utils.Distance(source.Logitude, source.Latitude,
     37                                          destination.Logitude, destination.Latitude);
     38      double weight = (distanceKms / speedKmH) * 60;
     39      return (float)weight;
     40    }
     41
     42    private int GetMaxSpeed(short category) {
     43      int speed = 0;
     44
     45      //TODO:
     46      switch (category) {
     47        case 23:
     48        case 17:
     49        case 18:
     50        case 22:
     51        case 21:
     52        case 24:
     53        case 16:
     54        case 20:
     55        case 15:
     56        case 12:
     57        case 0:
     58          speed = 1;
     59          break;
     60
     61        case 11:
     62        case 14:
     63          speed = 15;
     64          break;
     65
     66        case 19:
     67          speed = 30;
     68          break;
     69
     70        case 9:
     71        case 10:
     72        case 7:
     73        case 8:
     74          speed = 80;
     75          break;
     76
     77        case 13:
     78          speed = 50;
     79          break;
     80
     81        case 3:
     82        case 4:
     83        case 5:
     84        case 6:
     85          speed = 100;
     86          break;
     87
     88        case 1:
     89        case 2:
     90          speed = 130;
     91          break;
     92
     93        default:
     94          speed = 1;
     95          break;
     96      }
     97      return speed;
     98    }
     99
     100    public int GetMaxSpeed(HighwayType ht) {
     101      int speed = 0;
     102
     103      //TODO:
     104      switch (ht) {
     105        case HighwayType.bridleway:
     106        case HighwayType.bus_guideway:
     107        case HighwayType.raceway:
     108        case HighwayType.cycleway:
     109        case HighwayType.footway:
     110        case HighwayType.steps:
     111        case HighwayType.null_type:
     112          speed = 1;
     113          break;
     114
     115        case HighwayType.path:
     116        case HighwayType.service:
     117        case HighwayType.pedestrian:
     118        case HighwayType.living_street:
     119          speed = 15;
     120          break;
     121
     122        case HighwayType.road:
     123        case HighwayType.track:
     124          speed = 30;
     125          break;
     126
     127        case HighwayType.tertiary:
     128        case HighwayType.tertiary_link:
     129        case HighwayType.secondary:
     130        case HighwayType.secondary_link:
     131          speed = 80;
     132          break;
     133
     134        case HighwayType.unclassified:
     135        case HighwayType.residential:
     136          speed = 50;
     137          break;
     138
     139        case HighwayType.trunk:
     140        case HighwayType.trunk_link:
     141        case HighwayType.primary:
     142        case HighwayType.primary_link:
     143          speed = 100;
     144          break;
     145        case HighwayType.motorway:
     146        case HighwayType.motorway_link:
     147          speed = 130;
     148          break;
     149
     150        default:
     151          speed = 1;
     152          break;
     153      }
     154      return speed;
    26155    }
    27156
Note: See TracChangeset for help on using the changeset viewer.