Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/RoutingGraph/TravelTimeCostCalculator.cs @ 14604

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

#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
File size: 4.3 KB
Line 
1
2using HeuristicLab.Problems.RoutePlanning.Data.Core;
3using HeuristicLab.Problems.RoutePlanning.Interfaces;
4using HeuristicLab.Problems.RoutePlanning.Utilities;
5namespace HeuristicLab.Problems.RoutePlanning.RoutingGraph {
6  public class TravelTimeCostCalculator : ICostCalculator {
7    #region CostCalculator Members
8
9    public float Costs(Edge<Vertex> edge) {
10      //double distance = Utils.Distance(edge.Source.Logitude, edge.Source.Latitude,
11      //                                 edge.Target.Logitude, edge.Target.Latitude);
12      //double distance = Utils.LocationDistance(source.Node.Point, target.Node.Point);
13      //int speed = edge.GetMaxSpeed();
14      //double weight = (distance / speed) * 3.6;
15      //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;
25      return (float)weight;
26    }
27
28    public float EstimatedCosts(Vertex source, Vertex destination) {
29      //double distance = Utils.Distance(source.Logitude, source.Latitude,
30      //                                 destination.Logitude, destination.Latitude);
31      //double distance = Utils.LocationDistance(source.Node.Point, target.Node.Point);
32      int speedKmH = 130;
33      //double costs = (distance / speed) * 3.6;
34      //double costs = (distance / speed);
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;
155    }
156
157    #endregion
158  }
159}
Note: See TracBrowser for help on using the repository browser.