- Timestamp:
- 09/13/12 10:34:51 (12 years ago)
- Location:
- branches/RoutePlanning/HeuristicLab.Algorithms.GraphRouting/3.3
- Files:
-
- 2 added
- 1 deleted
- 4 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)); -
branches/RoutePlanning/HeuristicLab.Algorithms.GraphRouting/3.3/DijkstraNoDecAlgorithm.cs
r8539 r8640 3 3 using System.Collections.Generic; 4 4 using HeuristicLab.Algorithms.GraphRouting.Interfaces; 5 using HeuristicLab.Problems.RoutePlanning.Interfaces; 5 6 using HeuristicLab.Algorithms.GraphRouting.PriorityQueues; 6 using HeuristicLab.Problems.RoutePlanning.Interfaces;7 7 namespace HeuristicLab.Algorithms.GraphRouting { 8 8 public class DijkstraNoDecAlgorithm : IRouter { … … 19 19 20 20 public long[] Calculate(long sourceNodeId, long targetNodeId) { 21 unvisitedNodes = new BinHeap<float, long>(1000000); // unvisited 21 unvisitedNodes = new NaivePriorityQueue<float, long>(); 22 //unvisitedNodes = new BinaryHeap<float, long>(1000000); // unvisited 22 23 //unvisitedNodes = new BinomialHeap<float, long>(); // unvisited 23 //unvisitedNodes = new BinaryHeap<float, long>(float.MaxValue, float.MinValue, 1000000); // unvisited 24 //unvisitedNodes = new BinaryHeapV2<float, long>(float.MaxValue, float.MinValue, 1000000); // unvisited 25 //unvisitedNodes = new BinaryHeapV3<float, long>(float.MaxValue, float.MinValue, 1000000); // unvisited 26 //unvisitedNodes = new Heap4<float, long>(float.MaxValue, float.MinValue, 1000000); // unvisited 27 //unvisitedNodes = new FibonacciHeap<float, long>(); // unvisited 24 28 distances = new Dictionary<long, float>(); 25 29 predecessors = new Dictionary<long, long>(); … … 41 45 currentWeight = data.Key; 42 46 47 //-------------- 48 //Logger.LogToFile("cn = " + currentNode + " (" + currentWeight + ")"); 49 //-------------- 50 43 51 if (currentNode == targetNodeId) { 44 52 break; … … 49 57 RelaxNeighbors(currentNode, currentWeight); 50 58 } 59 60 //-------------- 61 //Logger.LogToFile(""); 62 //-------------- 51 63 } 52 64 … … 67 79 predecessors[neighbor.Key] = nodeId; 68 80 unvisitedNodes.Insert(totalWeight, neighbor.Key); 81 82 //-------------- 83 //Logger.LogToFile(" neigb:" + neighbor.Key + " (" + totalWeight + ")"); 84 //-------------- 69 85 } 70 86 } -
branches/RoutePlanning/HeuristicLab.Algorithms.GraphRouting/3.3/HeuristicLab.Algorithms.GraphRouting.csproj
r8546 r8640 61 61 <Compile Include="AStarAlgorithmV4.cs" /> 62 62 <Compile Include="AStarAlgorithmV5.cs" /> 63 <Compile Include="DijkstraAlgorithm.cs" /> 63 64 <Compile Include="DijkstraNoDecAlgorithm.cs" /> 64 <Compile Include=" DijkstraAlgorithmV2.cs" />65 <Compile Include="NaiveDijkstraAlgorithm.cs" /> 65 66 <Compile Include="GraphRoutingAlgorithm.cs" /> 66 67 <Compile Include="Interfaces\IHeap.cs" /> -
branches/RoutePlanning/HeuristicLab.Algorithms.GraphRouting/3.3/PriorityQueues/FibonacciHeap.cs
r8572 r8640 47 47 min = n; 48 48 } else { 49 // concateneate the root list (becoming left sibling of root) 49 50 n.Right = min; 50 51 n.Left = min.Left; 51 52 n.Right.Left = n; 52 53 n.Left.Right = n; 54 // update point of minimum if necessary 53 55 if (n.Key.CompareTo(min.Key) < 0) { 54 56 min = n; … … 103 105 104 106 private void Link(HeapNode y, HeapNode z) { 107 // remove y from the root list 105 108 y.Left.Right = y.Right; 106 109 y.Right.Left = y.Left; 107 110 111 // make y a child of x, ... 108 112 y.Parent = z; 109 113 if (z.Child == null) { … … 117 121 y.Right.Left = y; 118 122 } 123 124 // ... incrementing degree[x] 119 125 z.Degree++; 120 126 y.Mark = false; … … 122 128 123 129 private void Consolidate() { 124 //TODO: explain magic number125 HeapNode[] A = new HeapNode[ 45];130 int dn = (int)Math.Floor(Math.Log(size) / Math.Log(2)) + 1; // log2size[Heap] 131 HeapNode[] A = new HeapNode[dn]; // consolidation array 126 132 HeapNode start = min; 127 133 HeapNode w = min; 128 134 135 // for each node w in the root list 129 136 do { 130 137 HeapNode x = w; … … 157 164 min = null; 158 165 159 for (int i = 0; i < 45; i++) { 166 // find the new minimum key 167 for (int i = 0; i < dn; i++) { 160 168 if (A[i] != null) { 161 169 HeapNode n = A[i];
Note: See TracChangeset
for help on using the changeset viewer.