Changeset 8640 for branches/RoutePlanning/HeuristicLab.Algorithms.GraphRouting/3.3/AStarAlgorithmV3.cs
- Timestamp:
- 09/13/12 10:34:51 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/RoutePlanning/HeuristicLab.Algorithms.GraphRouting/3.3/AStarAlgorithmV3.cs
r8516 r8640 4 4 using HeuristicLab.Algorithms.GraphRouting.Interfaces; 5 5 using HeuristicLab.Problems.RoutePlanning.Interfaces; 6 using HeuristicLab.Problems.RoutePlanning.RoutingGraph; 6 7 namespace HeuristicLab.Algorithms.GraphRouting { 7 8 public class AStarAlgorithmV3 : IRouter { 8 9 private IGraph graph; 10 private ICostCalculator costCalculator; 9 11 10 12 private Dictionary<long, float> distances; … … 15 17 private Dictionary<long, NodeData> openListLookup; 16 18 17 public AStarAlgorithmV3(IGraph graph) { 19 public AStarAlgorithmV3(IGraph graph) 20 : this(graph, new TravelTimeCostCalculator()) { 21 } 22 23 public AStarAlgorithmV3(IGraph graph, ICostCalculator costCalc) { 18 24 this.graph = graph; 25 this.costCalculator = costCalc; 19 26 } 20 27 … … 36 43 distances.Add(currentNode, 0); 37 44 45 int i = 0; 38 46 while (openList.Count > 0) { 47 39 48 NodeData data = openList.Min; 49 //Console.Write(i + ": (" + openList.Count + "/"); 40 50 openList.Remove(data); 51 //Console.Write(openList.Count + ") - (" + openListLookup.Count + "/"); 41 52 openListLookup.Remove(data.Node); 53 //Console.WriteLine(openListLookup.Count + ")"); 42 54 currentNode = data.Node; 43 55 if (currentNode == targetNodeId) { 44 56 return ReconstructPath(currentNode).ToArray(); 45 57 } 58 59 //if (openList.Count != openListLookup.Count) { 60 // Console.WriteLine(); 61 //} else { 62 // Console.Write("."); 63 //} 46 64 47 65 Dictionary<long, float> currentNeighbors = graph.GetNeighborsWithWeight(currentNode); … … 58 76 predecessors[neighbor.Key] = currentNode; 59 77 60 float f = costsFromStart + graph.EstimatedCosts(neighbor.Key, targetNodeId); 78 Vertex vertNeigh = graph.GetVertex(neighbor.Key); 79 Vertex vertTarget = graph.GetVertex(targetNodeId); 80 float f = costsFromStart + costCalculator.EstimatedCosts(vertNeigh, vertTarget); 61 81 62 82 if (openListLookup.ContainsKey(neighbor.Key)) { … … 66 86 67 87 NodeData newNode = new NodeData(neighbor.Key, f); 68 openList.Add(newNode); 88 openList.Add(newNode); // wenn f bereits vorhanden -> kein add: openList.Contains(new NodeData(123, 0.2973786f)) 69 89 openListLookup.Add(newNode.Node, newNode); 70 90 } 71 91 closedList.Add(currentNode); 72 92 closedListLookup.Add(currentNode); 93 i++; 73 94 } 74 95 throw new Exception(string.Format("No route found from {0} to {1}", sourceNodeId, targetNodeId));
Note: See TracChangeset
for help on using the changeset viewer.