public class ResolverAStarThread extends android.os.AsyncTask<Integer,HeuristicPathTree.Node,HeuristicPathTree>
Modifier and Type | Field and Description |
---|---|
private int |
actualStep |
private static String |
DOWN |
private static int |
EUCLIDIANA |
private ArrayList<HeuristicPathTree.Node> |
expandedNodes |
private ArrayList<String> |
expansionOrder |
private iAStar |
iMethods |
private boolean |
isPathFounded |
private int |
lastX |
private int |
lastY |
private static String |
LEFT |
private static int |
MANHATTAN |
private int |
measureMode |
private HeuristicPathTree.Node[][] |
nodes |
private static String |
RIGHT |
private HeuristicPathTree |
tree |
private static String |
UP |
private long |
updateTime |
private HashSet<HeuristicPathTree.Node> |
visitedNodes |
Constructor and Description |
---|
ResolverAStarThread(HeuristicPathTree.Node[][] nodes,
ArrayList<String> expansionOrder,
long updateTime,
iAStar iMethods,
int measureMode)
First Best algorithm constructor.
|
Modifier and Type | Method and Description |
---|---|
protected HeuristicPathTree |
doInBackground(Integer... values)
In the background execution of the thread, we execute the actual algorithm.
|
private HeuristicPathTree.Node |
expandInDirection(String direction,
int y,
int x,
HashSet<HeuristicPathTree.Node> visitedNodes)
Method to expand a node in all directions, following the expansion order set by the user,
making sure the expansion is possible, rather for map access, or limitations by the user.
|
private void |
getNodesNextStep(HeuristicPathTree.Node node,
ArrayList<HeuristicPathTree.Node> expandedNodes,
HashSet<HeuristicPathTree.Node> visitedNodes)
Get the children of a node, if they are reachable (the is map available), and if the node
is accessible by the options written by the user.
|
protected void |
onPostExecute(HeuristicPathTree heuristicPathTree)
Once the algorithm has finished, we actually need to end the thread and draw the path over the UI.
|
protected void |
onProgressUpdate(HeuristicPathTree.Node... values)
Every time the thread makes a step, we change the character's position.
|
private void |
setFitness(HeuristicPathTree.Node response,
HeuristicPathTree.Node Father)
With the fitness, we either use the Euclidean or Manhattan measurement, and set the remaining
measures to the node.
|
private static final int MANHATTAN
private static final int EUCLIDIANA
private static final String DOWN
private static final String UP
private static final String LEFT
private static final String RIGHT
private ArrayList<HeuristicPathTree.Node> expandedNodes
private HashSet<HeuristicPathTree.Node> visitedNodes
private HeuristicPathTree.Node[][] nodes
private boolean isPathFounded
private iAStar iMethods
private long updateTime
private HeuristicPathTree tree
private int measureMode
private int lastY
private int lastX
private int actualStep
public ResolverAStarThread(HeuristicPathTree.Node[][] nodes, ArrayList<String> expansionOrder, long updateTime, iAStar iMethods, int measureMode)
nodes
- Heuristic nodes.expansionOrder
- List for expanded nodes.updateTime
- Value for the thread refresh.iMethods
- Method (related to the algorithm).measureMode
- Measure mode, since First Best uses Manhattan or Euclidean to weight the nodes.protected HeuristicPathTree doInBackground(Integer... values)
doInBackground
in class android.os.AsyncTask<Integer,HeuristicPathTree.Node,HeuristicPathTree>
values
- Values related to the coordinates for initial and final positions.protected void onProgressUpdate(HeuristicPathTree.Node... values)
onProgressUpdate
in class android.os.AsyncTask<Integer,HeuristicPathTree.Node,HeuristicPathTree>
values
- Values of the positions.protected void onPostExecute(HeuristicPathTree heuristicPathTree)
onPostExecute
in class android.os.AsyncTask<Integer,HeuristicPathTree.Node,HeuristicPathTree>
heuristicPathTree
- The tree whose path needs to be drawn.private void getNodesNextStep(HeuristicPathTree.Node node, ArrayList<HeuristicPathTree.Node> expandedNodes, HashSet<HeuristicPathTree.Node> visitedNodes)
node
- Node to be expanded.expandedNodes
- List of expanded nodes so we dont repeat.visitedNodes
- List of visited nodes so we dont repeat.private void setFitness(HeuristicPathTree.Node response, HeuristicPathTree.Node Father)
response
- the node to process.private HeuristicPathTree.Node expandInDirection(String direction, int y, int x, HashSet<HeuristicPathTree.Node> visitedNodes)
direction
- Direction to check to be expanded.y
- Y actual coordinate.x
- X actual coordinate.visitedNodes
- List of visited nodes so we dont expand incorrectly.