cz.cuni.astar
Class AStarResult

java.lang.Object
  extended by cz.cuni.astar.AStarResult

public class AStarResult
extends java.lang.Object

This class is returned by AStar.aStar(). It contains results from the search as well as method for finding the path from the startNode to the goalNode. It contains all data structures the AStar is using during the work. Everything is made public here so that AStar (during work) and you (for browsing the results) may use it.


Field Summary
 java.util.Collection closeList
          Nodes which were examined by the algoritm.
 java.util.HashMap estimatedCost
          Used and filled by A* alorithm (AStar.aStar()).
 java.lang.Object goalNode
          Node which was marked as a goalNode by AStarMap.
 long interations
          Contains the number of iterations made by A* search.
 java.util.Collection openList
          List of nodes which is opened -> was touched by the algorithm and are subjects of examination.
private  java.util.ArrayList path
          Used by getPath() to cache the path from startNode to goalNode once it has been found.
 java.util.HashMap pathCost
          Used and filled by A* algorithm (AStar.aStar()).
 java.util.HashMap previousNode
          Used by getPath() and filled by A* algorithm (AStar.aStar()).
 java.lang.Object startNode
          Start node of the A*.
 boolean success
          Wether goalNode was found during the A* run.
 
Constructor Summary
AStarResult()
           
 
Method Summary
 int getCostToNode(java.lang.Object node)
          Returns cost of the path from startNode to node if the node was touched by A* algorithm (if A* was successful, then this always contains the goalNode and every node on the path).
 int getDistanceToGoal()
          If the AStar succeeded then it returns the distance to the goal.
 int getEstimatedCostToNode(java.lang.Object node)
          Returns estimated cost of the path from startNode to goal through node.
 java.util.ArrayList getPath()
          Returns the path from startNode to goalNode.
 java.lang.Object getPreviousNode(java.lang.Object node)
          Used by getPath() method when creating a list of nodes (the path) from startNode to goalNode.
 void putCostToNode(java.lang.Object node, int cost)
          Assing cost of the path from startNode to node.
 void putCostToNode(java.lang.Object node, java.lang.Integer cost)
          Assing cost of the path from startNode to node.
 void putEstimatedCostToNode(java.lang.Object node, int cost)
          Assing estimated cost of the path from startNode to goalNode through node.
 void putEstimatedCostToNode(java.lang.Object node, java.lang.Integer cost)
          Assing estimated cost of the path from startNode to goalNode through node.
 void putPreviousNode(java.lang.Object node, java.lang.Object previous)
          Assing 'previous' as an previous node for 'node' (the path from 'startNode' to 'node' goes across 'previous').
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

previousNode

public java.util.HashMap previousNode
Used by getPath() and filled by A* algorithm (AStar.aStar()). Keys are nodes and values are 'parent-nodes' (from where we've come to the key node on the path from startNode to key-node).


openList

public java.util.Collection openList
List of nodes which is opened -> was touched by the algorithm and are subjects of examination. Initialized by AStar.aStar()


closeList

public java.util.Collection closeList
Nodes which were examined by the algoritm. At the end of work of AStar contains all the nodes which were examined. If AStar successful -> at least contains nodes on the shortest path from startNode to goalNode.


pathCost

public java.util.HashMap pathCost
Used and filled by A* algorithm (AStar.aStar()). Here we store the real cost from the startNode to the 'key'.


estimatedCost

public java.util.HashMap estimatedCost
Used and filled by A* alorithm (AStar.aStar()). Here we store estimated cost of the path from 'key' to the goal.


interations

public long interations
Contains the number of iterations made by A* search. One iteration means evaluating of the one node ("touching" each of the neighbours) Is 0-based ... if startGoal == goalNode or startGoal then this will be 0.


startNode

public java.lang.Object startNode
Start node of the A*.


goalNode

public java.lang.Object goalNode
Node which was marked as a goalNode by AStarMap. (Note that you theoreticaly may have many goal nodes but A* searches only for the first one.) It's filled only if A* found the goalNoda! (success == true)


success

public boolean success
Wether goalNode was found during the A* run. If this is true then goalNode is not null.


path

private java.util.ArrayList path
Used by getPath() to cache the path from startNode to goalNode once it has been found.

Constructor Detail

AStarResult

public AStarResult()
Method Detail

getPreviousNode

public java.lang.Object getPreviousNode(java.lang.Object node)
Used by getPath() method when creating a list of nodes (the path) from startNode to goalNode.

Parameters:
node -
Returns:
previous node of supplied node | null

putPreviousNode

public void putPreviousNode(java.lang.Object node,
                            java.lang.Object previous)
Assing 'previous' as an previous node for 'node' (the path from 'startNode' to 'node' goes across 'previous').

Parameters:
node -
previous -

getCostToNode

public int getCostToNode(java.lang.Object node)
Returns cost of the path from startNode to node if the node was touched by A* algorithm (if A* was successful, then this always contains the goalNode and every node on the path). If node wasn't touched by A* algorithm, then it returns -1.

Parameters:
node -
Returns:
cost of the path from startNode to node

putCostToNode

public void putCostToNode(java.lang.Object node,
                          java.lang.Integer cost)
Assing cost of the path from startNode to node.

Parameters:
node -
cost -

putCostToNode

public void putCostToNode(java.lang.Object node,
                          int cost)
Assing cost of the path from startNode to node.

Parameters:
node -
cost -

getEstimatedCostToNode

public int getEstimatedCostToNode(java.lang.Object node)
Returns estimated cost of the path from startNode to goal through node. If the node was touched by A* algorithm then it has this value stored here (if A* was successful, then this always contains the goalNode and every node on the path). If node wasn't touched by A* algorithm, then it returns -1.

Parameters:
node -
Returns:
cost of the path from startNode to node

putEstimatedCostToNode

public void putEstimatedCostToNode(java.lang.Object node,
                                   java.lang.Integer cost)
Assing estimated cost of the path from startNode to goalNode through node.

Parameters:
node -
cost -

putEstimatedCostToNode

public void putEstimatedCostToNode(java.lang.Object node,
                                   int cost)
Assing estimated cost of the path from startNode to goalNode through node.

Parameters:
node -
cost -

getPath

public java.util.ArrayList getPath()
Returns the path from startNode to goalNode. (Don't change it as it's cached, if you want to alter it - then copy it :-) First item is startNode and the last item is goalNode. If startNode == goalNode then it contains only one item. For each index ... path[index] has neighbour path[index+1]. If the path doesn't exist - returns null.


getDistanceToGoal

public int getDistanceToGoal()
If the AStar succeeded then it returns the distance to the goal. Returns -1 otherwise.

Returns:
distance | -1