Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/13/12 10:34:51 (12 years ago)
Author:
spimming
Message:

#1894:

  • Included costCalculator in a star search
  • restructured and renamed Dijkstra algorithm
  • Added code comments to FibonacciHeap
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/RoutePlanning/HeuristicLab.Algorithms.GraphRouting/3.3/AStarAlgorithmV3.cs

    r8516 r8640  
    44using HeuristicLab.Algorithms.GraphRouting.Interfaces;
    55using HeuristicLab.Problems.RoutePlanning.Interfaces;
     6using HeuristicLab.Problems.RoutePlanning.RoutingGraph;
    67namespace HeuristicLab.Algorithms.GraphRouting {
    78  public class AStarAlgorithmV3 : IRouter {
    89    private IGraph graph;
     10    private ICostCalculator costCalculator;
    911
    1012    private Dictionary<long, float> distances;
     
    1517    private Dictionary<long, NodeData> openListLookup;
    1618
    17     public AStarAlgorithmV3(IGraph graph) {
     19    public AStarAlgorithmV3(IGraph graph)
     20      : this(graph, new TravelTimeCostCalculator()) {
     21    }
     22
     23    public AStarAlgorithmV3(IGraph graph, ICostCalculator costCalc) {
    1824      this.graph = graph;
     25      this.costCalculator = costCalc;
    1926    }
    2027
     
    3643      distances.Add(currentNode, 0);
    3744
     45      int i = 0;
    3846      while (openList.Count > 0) {
     47
    3948        NodeData data = openList.Min;
     49        //Console.Write(i + ": (" + openList.Count + "/");
    4050        openList.Remove(data);
     51        //Console.Write(openList.Count + ") - (" + openListLookup.Count + "/");
    4152        openListLookup.Remove(data.Node);
     53        //Console.WriteLine(openListLookup.Count + ")");
    4254        currentNode = data.Node;
    4355        if (currentNode == targetNodeId) {
    4456          return ReconstructPath(currentNode).ToArray();
    4557        }
     58
     59        //if (openList.Count != openListLookup.Count) {
     60        //  Console.WriteLine();
     61        //} else {
     62        //  Console.Write(".");
     63        //}
    4664
    4765        Dictionary<long, float> currentNeighbors = graph.GetNeighborsWithWeight(currentNode);
     
    5876          predecessors[neighbor.Key] = currentNode;
    5977
    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);
    6181
    6282          if (openListLookup.ContainsKey(neighbor.Key)) {
     
    6686
    6787          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))
    6989          openListLookup.Add(newNode.Node, newNode);
    7090        }
    7191        closedList.Add(currentNode);
    7292        closedListLookup.Add(currentNode);
     93        i++;
    7394      }
    7495      throw new Exception(string.Format("No route found from {0} to {1}", sourceNodeId, targetNodeId));
Note: See TracChangeset for help on using the changeset viewer.