- Timestamp:
- 08/13/12 17:31:23 (12 years ago)
- Location:
- branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Graph/Edge.cs
r8461 r8479 44 44 return source.GetHashCode() ^ target.GetHashCode(); 45 45 } 46 47 public int GetMaxSpeed() { 48 int speed = 0; 49 50 //TODO: 51 switch (category) { 52 case 23: 53 case 17: 54 case 18: 55 case 22: 56 case 21: 57 case 24: 58 case 0: 59 speed = 1; 60 break; 61 62 case 20: 63 case 15: 64 case 12: 65 case 11: 66 speed = 15; 67 break; 68 69 case 19: 70 case 16: 71 speed = 30; 72 break; 73 74 case 9: 75 case 10: 76 case 7: 77 case 8: 78 speed = 80; 79 break; 80 81 case 14: 82 case 13: 83 speed = 50; 84 break; 85 86 case 3: 87 case 4: 88 case 5: 89 case 6: 90 speed = 100; 91 break; 92 93 case 1: 94 case 2: 95 speed = 130; 96 break; 97 98 default: 99 speed = 1; 100 break; 101 } 102 return speed; 103 } 46 104 } 47 105 } -
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Graph/Graph.cs
r8461 r8479 2 2 using System; 3 3 using System.Collections.Generic; 4 using HeuristicLab.Problems.RoutePlanning.Osm; 4 5 namespace HeuristicLab.Problems.RoutePlanning.Graph { 5 6 public class Graph : IGraph { … … 74 75 75 76 public List<Edge<Vertex>> GetInEdges(long vertexId) { 76 return incidenceMap[vertexId]; 77 List<Edge<Vertex>> edges; 78 if (incidenceMap.TryGetValue(vertexId, out edges)) { 79 return edges; 80 } else { 81 return new List<Edge<Vertex>>(); 82 } 77 83 } 78 84 … … 82 88 83 89 public List<Edge<Vertex>> GetOutEdges(long vertexId) { 84 return adjacencyMap[vertexId]; 90 List<Edge<Vertex>> edges; 91 if (adjacencyMap.TryGetValue(vertexId, out edges)) { 92 return edges; 93 } else { 94 return new List<Edge<Vertex>>(); 95 } 96 85 97 } 86 98 … … 109 121 foreach (Edge<Vertex> edge in edges) { 110 122 // TODO: check if edge can be traversed (eg. highway tag for car roads, ...) 111 float weight = 1; // TODO: edge.Weight?123 float weight = GetWeight(edge); // TODO: edge.Weight? 112 124 neighbors[edge.Target.Id] = weight; 113 125 } … … 119 131 foreach (Edge<Vertex> edge in edges) { 120 132 // TODO: check if edge can be traversed (eg. highway tag for car roads, ...) 121 float weight = 1; // TODO: edge.Weight?133 float weight = GetWeight(edge); // TODO: edge.Weight? 122 134 neighbors[edge.Source.Id] = weight; 123 135 } 124 136 return neighbors; 125 137 } 138 139 public float GetWeight(Edge<Vertex> edge) { 140 double distance = Utils.Distance(edge.Source.Logitude, edge.Source.Latitude, 141 edge.Target.Logitude, edge.Target.Latitude); 142 //double distance = Utils.LocationDistance(source.Node.Point, target.Node.Point); 143 int speed = edge.GetMaxSpeed(); 144 double weight = (distance / speed) * 3.6; 145 //double weight = (distance / speed); 146 return (float)weight; 147 } 148 149 public float EstimatedCosts(long sourceId, long targetId) { 150 Vertex source = GetVertex(sourceId); 151 Vertex target = GetVertex(targetId); 152 return EstimatedCosts(source, target); 153 } 154 155 public float EstimatedCosts(Vertex source, Vertex target) { 156 double distance = Utils.Distance(source.Logitude, source.Latitude, 157 target.Logitude, target.Latitude); 158 //double distance = Utils.LocationDistance(source.Node.Point, target.Node.Point); 159 int speed = 130; 160 double costs = (distance / speed) * 3.6; 161 //double costs = (distance / speed); 162 return (float)costs; 163 } 126 164 } 127 165 } -
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Graph/IGraph.cs
r8461 r8479 17 17 int GetOutDegree(long id); 18 18 int GetInDegree(long id); 19 20 float EstimatedCosts(long sourceId, long targetId); 19 21 } 20 22 } -
branches/RoutePlanning/HeuristicLab.Problems.RoutePlanning/3.3/Osm/Utils.cs
r8462 r8479 7 7 double dx = p2.X - p1.X; 8 8 double dy = p2.Y - p1.Y; 9 return Math.Sqrt(dx * dx + dy * dy); 10 } 11 12 public static double Distance(double startX, double startY, double endX, double endY) { 13 double dx = endX - startX; 14 double dy = endY - startY; 9 15 return Math.Sqrt(dx * dx + dy * dy); 10 16 }
Note: See TracChangeset
for help on using the changeset viewer.