cz.cuni.amis.pathfinding.alg.astar
Class AStarResult<NODE>

Package class diagram package AStarResult
java.lang.Object
  extended by cz.cuni.amis.pathfinding.alg.astar.AStarResult<NODE>
All Implemented Interfaces:
IAStarResult<NODE>

public class AStarResult<NODE>
extends Object
implements IAStarResult<NODE>

Represents result of the computation of AStar#AStar.findPath(cz.cuni.amis.pathfinding.map.IPFGoal, long).

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
 Set<NODE> closeList
          Nodes which were examined by the algorithm.
 HashMap<NODE,Integer> estimatedCost
          Used and filled by A* algorithm (AStar.aStar()).
 NODE goalNode
          Node which was marked as a goalNode by AStarMap.
 long interations
          Contains the number of iterations made by A* search.
 cz.cuni.amis.utils.heap.Heap<NODE> openList
          List of nodes which is opened -> was touched by the algorithm and are subjects of examination.
 HashMap<NODE,Integer> pathCost
          Used and filled by A* algorithm (AStar.aStar()).
 HashMap<NODE,NODE> previousNode
          Used by getPath() and filled by A* algorithm (AStar.aStar()).
 NODE startNode
          Start node of the A*.
 boolean success
          Whether goalNode was found during the A* run.
 
Constructor Summary
AStarResult()
           
 
Method Summary
 int getCostToNode(NODE 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 at least).
 int getDistanceToGoal()
          If the AStar succeeded then it returns the distance to the goal from the start node.
 int getEstimatedCostToNode(NODE node)
          Returns estimated cost of the path from startNode to goal through node.
 List<NODE> getPath()
          Returns the path from startNode to goalNode.
 NODE getPreviousNode(NODE node)
          Previous node in the path to the goal node.
 boolean isSuccess()
          Whether this result represents the success, i.e., path from start to goal node has been found.
 void putCostToNode(NODE node, Integer cost)
          Assing cost of the path from startNode to node.
 void putEstimatedCostToNode(NODE node, Integer cost)
          Assing estimated cost of the path from startNode to goalNode through node.
 void putPreviousNode(NODE node, NODE 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 HashMap<NODE,NODE> 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 cz.cuni.amis.utils.heap.Heap<NODE> openList
List of nodes which is opened -> was touched by the algorithm and are subjects of examination. Initialized by AStar.aStar()


closeList

public Set<NODE> closeList
Nodes which were examined by the algorithm. 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 HashMap<NODE,Integer> pathCost
Used and filled by A* algorithm (AStar.aStar()). Here we store the real cost from the startNode to the 'key'.


estimatedCost

public HashMap<NODE,Integer> estimatedCost
Used and filled by A* algorithm (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 NODE startNode
Start node of the A*.


goalNode

public NODE 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
Whether goalNode was found during the A* run. If this is true then goalNode is not null.

Constructor Detail

AStarResult

public AStarResult()
Method Detail

getPreviousNode

public NODE getPreviousNode(NODE node)
Description copied from interface: IAStarResult
Previous node in the path to the goal node.

Specified by:
getPreviousNode in interface IAStarResult<NODE>
Returns:
previous node of supplied node | null

putPreviousNode

public void putPreviousNode(NODE node,
                            NODE 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(NODE node)
Description copied from interface: IAStarResult
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 at least).

If node wasn't touched by A* algorithm, then it returns -1.

Specified by:
getCostToNode in interface IAStarResult<NODE>
Returns:
cost of the path from startNode to node

putCostToNode

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

Parameters:
node -
cost -

getEstimatedCostToNode

public int getEstimatedCostToNode(NODE node)
Description copied from interface: IAStarResult
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 at least).

If node wasn't touched by A* algorithm, then it returns -1.

Specified by:
getEstimatedCostToNode in interface IAStarResult<NODE>
Returns:
cost of the path from startNode to node

putEstimatedCostToNode

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

Parameters:
node -
cost -

getPath

public List<NODE> getPath()
Description copied from interface: IAStarResult
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 neighbor path[index+1].

If the path doesn't exist - returns null.

Specified by:
getPath in interface IAStarResult<NODE>
Returns:
path

getDistanceToGoal

public int getDistanceToGoal()
Description copied from interface: IAStarResult
If the AStar succeeded then it returns the distance to the goal from the start node.

Returns -1 otherwise.

Specified by:
getDistanceToGoal in interface IAStarResult<NODE>
Returns:
distance | -1

isSuccess

public boolean isSuccess()
Description copied from interface: IAStarResult
Whether this result represents the success, i.e., path from start to goal node has been found.

Specified by:
isSuccess in interface IAStarResult<NODE>
Returns:


Copyright © 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.