- Timestamp:
- 08/22/12 19:14:33 (12 years ago)
- 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;1 using HeuristicLab.Problems.RoutePlanning.Data.Core; 2 2 using HeuristicLab.Problems.RoutePlanning.Interfaces; 3 using HeuristicLab.Problems.RoutePlanning.Utilities; 3 4 4 5 namespace HeuristicLab.Problems.RoutePlanning.RoutingGraph { 5 6 public class EarthDistanceCostCalculator : ICostCalculator { 6 private const double earthMeanRadius = 6371.0 * 1000.0;7 8 7 #region ICostCalculator Members 9 8 … … 12 11 } 13 12 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 14 20 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; 16 25 } 17 26 18 27 #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 }39 28 } 40 29 } -
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/RoutingGraph/Edge.cs
r8516 r8520 13 13 } 14 14 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 //} 20 20 21 21 private float weight; … … 30 30 } 31 31 32 public Edge(Vertex source, Vertex target, short category) {32 public Edge(Vertex source, Vertex target, float weight) { 33 33 this.source = source; 34 34 this.target = target; 35 this. category = category;35 this.weight = weight; 36 36 } 37 37 … … 51 51 return source.GetHashCode() ^ target.GetHashCode(); 52 52 } 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 }111 53 } 112 54 } -
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/RoutingGraph/Graph.cs
r8516 r8520 3 3 using System.Collections.Generic; 4 4 using HeuristicLab.Problems.RoutePlanning.Interfaces; 5 using HeuristicLab.Problems.RoutePlanning.Utilities;6 5 namespace HeuristicLab.Problems.RoutePlanning.RoutingGraph { 7 6 public class Graph : IGraph { … … 126 125 foreach (Edge<Vertex> edge in edges) { 127 126 // 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; 130 130 } 131 131 return neighbors; … … 136 136 foreach (Edge<Vertex> edge in edges) { 137 137 // 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; 140 141 } 141 142 return neighbors; 142 143 } 143 144 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); 147 148 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); 151 152 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 //} 159 161 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 //} 165 167 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); 169 171 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); 173 175 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 //} 183 185 } 184 186 } -
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/RoutingGraph/TravelTimeCostCalculator.cs
r8516 r8520 1 1 2 using HeuristicLab.Problems.RoutePlanning.Data.Core; 2 3 using HeuristicLab.Problems.RoutePlanning.Interfaces; 3 4 using HeuristicLab.Problems.RoutePlanning.Utilities; … … 7 8 8 9 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); 11 12 //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; 14 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; 15 25 return (float)weight; 16 26 } 17 27 18 28 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); 21 31 //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; 24 34 //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; 26 155 } 27 156
Note: See TracChangeset
for help on using the changeset viewer.