calculation
Class BuildTree

java.lang.Object
  extended by calculation.BuildTree

public class BuildTree
extends java.lang.Object

Class BuildTree implements the calculation process of the arrival tree for landing air planes. Each time the new tree is calculated, method "calculate" is called with a graph as a parameter.

Version:
1
Author:
Potkuri-group

Field Summary
private  Tree arrivalTree
          Arrival Tree calculated.
private  boolean asked
          An update variable.
private  DataCollection dataCollection
          Data collection.
private  int finalPathCount
          Keeps count on paths, so that paths can not come too close each other.
private  boolean flagArrivalTreeUpdated
          flag is set true when tree updates.
private  Graph graph
          Graph used in calculation.
private  java.util.ArrayList<Vertex> mergePoints
          Merge points of the arrival tree for airplanes.
private  int pathCounter
          Keeps count on which path is a "parent" path to path to be created.
private  int safetyDistance
          Safety distance.
 
Constructor Summary
BuildTree()
          Constructor for testing.
BuildTree(DataCollection dataCollection)
          Constructor.
 
Method Summary
 java.util.ArrayList<Vertex> aStar(Vertex start, Vertex goal)
          Calculates an optimal path between two given vertices of a graph.
 void calculate()
          Method to be called, when wanted to calculate a new arrival tree.
private  java.util.ArrayList<Vertex> calculatePath(Vertex startNode, java.util.ArrayList<Vertex> endNodes)
          Finds out the shortest path from startNode to all Vertexes in endNodes using method aStar.
private  boolean checkTree()
          Method for checking if there is need to re-calculate the arrival-tree.
 java.util.ArrayList<Vertex> getCalculatePath(Vertex startNode, java.util.ArrayList<Vertex> endNodes)
          For testing.
 int getfinalPathCount()
          For testing.
 Graph getGraph()
          Returns this.graph.
 java.util.ArrayList<Vertex> getHalfTable(java.util.ArrayList<Vertex> endNodes, boolean side)
          For testing.
 int getPathCounter()
          For testing.
 void getSetSafetyDistance(Vertex vertex, boolean availability, int distance, boolean set)
          For testing.
 void getSetSlidingSafetyDistance(Vertex startNode, boolean sliding, boolean availability)
          For testing.
 int getTestSide(java.util.ArrayList<Vertex> path, java.util.ArrayList<Vertex> endNodes)
          For testing.
 Tree getTree()
          Returns this.arrivalTree.
 void getTreeRecursion(Vertex startNode, java.util.ArrayList<Vertex> endNodes)
          For testing.
private  java.util.ArrayList<Vertex> halfTable(java.util.ArrayList<Vertex> endNodes, boolean side)
          Takes half of the ArrayList given in parameters and returns it.
 boolean isChanged()
          Method for telling if arrival tree is changed.
 double pathLength(java.util.ArrayList<Vertex> path)
          Returns the length of path.
private  void resetVertices(java.util.PriorityQueue<Vertex> openSet, java.util.ArrayList<Vertex> closedSet)
          Resets vertices which aStar used calling Vertex.reset() method for each Vertex whose fields were changed by aStar.
private  java.util.ArrayList<Vertex> resultPath(Vertex start, Vertex goal, java.util.PriorityQueue<Vertex> openSet, java.util.ArrayList<Vertex> closedSet)
          Creates the resulting path for aStar method.
 void setGraph(Graph graph)
          For testing.
 void setNewTree(Tree tree)
          For testing.
private  void setSafetyDistance(Vertex vertex, boolean availability, int distance, boolean set)
          Makes or removes the safety distance around the node.
 void setSafetyDistanceAirPlanes(Vertex vertex, boolean availability, int distance)
          This method is similar that the method setSafetyDistance.
private  void setSlidingSafetyDistance(Vertex startNode, boolean sliding, boolean availability)
          Sets a safety distance (true or false) to a certain area under the node, determined by value this.safetyDistance.
private  int testSide(java.util.ArrayList<Vertex> path, java.util.ArrayList<Vertex> endNodes)
          Tests if the end of the path went to left or right.
 void treeRecursion(Vertex parStartNode, java.util.ArrayList<Vertex> endNodeTable)
          The method which implements the recursion of the tree in calculation.
 boolean update(Graph graph)
          Method for updating the arrival tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

arrivalTree

private Tree arrivalTree
Arrival Tree calculated.


asked

private boolean asked
An update variable.


dataCollection

private DataCollection dataCollection
Data collection.


finalPathCount

private int finalPathCount
Keeps count on paths, so that paths can not come too close each other.


flagArrivalTreeUpdated

private boolean flagArrivalTreeUpdated
flag is set true when tree updates.


graph

private Graph graph
Graph used in calculation.


mergePoints

private java.util.ArrayList<Vertex> mergePoints
Merge points of the arrival tree for airplanes.


pathCounter

private int pathCounter
Keeps count on which path is a "parent" path to path to be created.


safetyDistance

private int safetyDistance
Safety distance.

Constructor Detail

BuildTree

public BuildTree()
Constructor for testing.


BuildTree

public BuildTree(DataCollection dataCollection)
Constructor.

Parameters:
dataCollection - DataCollection.
Method Detail

aStar

public java.util.ArrayList<Vertex> aStar(Vertex start,
                                         Vertex goal)
Calculates an optimal path between two given vertices of a graph.

Parameters:
start - Start vertex of path
goal - Goal vertex of path
Returns:
Optimal path from start to goal as ArrayList (including start and goal vertices), or null if no path was found

calculate

public void calculate()
Method to be called, when wanted to calculate a new arrival tree. Calls method treeRecursion with parameters got from current this.graph. treeRecursion (and other methods treeRecursion calls) changes this.arrivalTree to be the new wanted tree for air planes.


calculatePath

private java.util.ArrayList<Vertex> calculatePath(Vertex startNode,
                                                  java.util.ArrayList<Vertex> endNodes)
Finds out the shortest path from startNode to all Vertexes in endNodes using method aStar.

Parameters:
startNode - Node from where aStar starts calculating path.
endNodes - Nodes to where aStar calculates paths.
Returns:
shortestPath Shortest found path as ArrayList of vertexes.

checkTree

private boolean checkTree()
Method for checking if there is need to re-calculate the arrival-tree. (Checks if the storm or storm safety distance in current map is over this.arrivalTree.)

Returns:
Boolean value which tells if there is need to recalculate the arrival tree.

getCalculatePath

public java.util.ArrayList<Vertex> getCalculatePath(Vertex startNode,
                                                    java.util.ArrayList<Vertex> endNodes)
For testing. Calls private method calculatePath.

Parameters:
startNode - StartNode for calculatePath.
endNodes - EndNodes for calculatePath.
Returns:
calculatePath(startNode, endNodes)

getfinalPathCount

public int getfinalPathCount()
For testing. Returns this.finalPathCount.

Returns:
this.finalPathCOunt

getGraph

public Graph getGraph()
Returns this.graph.

Returns:
this.graph

getHalfTable

public java.util.ArrayList<Vertex> getHalfTable(java.util.ArrayList<Vertex> endNodes,
                                                boolean side)
For testing. Calls private method halfTable.

Parameters:
endNodes - EndNodes for halfTable.
side - Side for halfTable.
Returns:
halfTable(endNodes, side)

getPathCounter

public int getPathCounter()
For testing. Returns this.pathCounter.

Returns:
this.pathCounter

getSetSafetyDistance

public void getSetSafetyDistance(Vertex vertex,
                                 boolean availability,
                                 int distance,
                                 boolean set)
For testing. Calls private method setSafetyDistance.

Parameters:
vertex - Vertex for setSafetyDistance.
availability - Availability for setSafetyDistance.
distance - Distance for setSafetyDistance.
set - Set for setSafetyDistance.

getSetSlidingSafetyDistance

public void getSetSlidingSafetyDistance(Vertex startNode,
                                        boolean sliding,
                                        boolean availability)
For testing. Calls private method setSlidingSafetyDistance.

Parameters:
startNode - StartNode for setSlidingSafetyDistance.
sliding - Sliding for setSlidingSafetyDistance.
availability - Availability for setSlidingSafetyDistance.

getTestSide

public int getTestSide(java.util.ArrayList<Vertex> path,
                       java.util.ArrayList<Vertex> endNodes)
For testing. Calls private method testSide.

Parameters:
path - Path for testSide.
endNodes - EndNodes for testSide.
Returns:
getTestSide(path, endNodes);

getTree

public Tree getTree()
Returns this.arrivalTree.

Returns:
this.arrivalTree

getTreeRecursion

public void getTreeRecursion(Vertex startNode,
                             java.util.ArrayList<Vertex> endNodes)
For testing. Calls private method treeRecursion.

Parameters:
startNode - StartNode for treeRecursion.
endNodes - EndNodes for treeRecursion.

halfTable

private java.util.ArrayList<Vertex> halfTable(java.util.ArrayList<Vertex> endNodes,
                                              boolean side)
Takes half of the ArrayList given in parameters and returns it. The decision which side will be taken, is ruled by parameter "side".

Parameters:
endNodes - End node table to be cut in half.
side - Side, which will be taken from the endNodes. True if left, False if right.
Returns:
Half of the table endNodes.

isChanged

public boolean isChanged()
Method for telling if arrival tree is changed.

Returns:
boolean

pathLength

public double pathLength(java.util.ArrayList<Vertex> path)
Returns the length of path.

Parameters:
path - path in a graph
Returns:
the length of the path

resetVertices

private void resetVertices(java.util.PriorityQueue<Vertex> openSet,
                           java.util.ArrayList<Vertex> closedSet)
Resets vertices which aStar used calling Vertex.reset() method for each Vertex whose fields were changed by aStar.

Parameters:
openSet - Open set of aStar
closedSet - Closed set of aStar

resultPath

private java.util.ArrayList<Vertex> resultPath(Vertex start,
                                               Vertex goal,
                                               java.util.PriorityQueue<Vertex> openSet,
                                               java.util.ArrayList<Vertex> closedSet)
Creates the resulting path for aStar method. Calls resetVertices method to reset vertices which aStar used.

Parameters:
start - Start vertex of path
goal - Goal vertex of path
openSet - Open set used by aStar method
closedSet - Closed set used by aStar method
Returns:
Path from start to goal (including start and goal vertices).

setGraph

public void setGraph(Graph graph)
For testing. Sets this.graph.

Parameters:
graph - Graph.

setNewTree

public void setNewTree(Tree tree)
For testing. Sets this.tree.

Parameters:
tree - Tree.

setSafetyDistance

private void setSafetyDistance(Vertex vertex,
                               boolean availability,
                               int distance,
                               boolean set)
Makes or removes the safety distance around the node. Safety distance is the area around the node on where nodes availability values are false so that method aStar can not find paths on where those vertexes are. Safety distance area around the node is always shaped as a square, parameter "distance" determines the distance from the center of the square (vertex) to its end.

Parameters:
vertex - Safety distance is set around this node.
availability - Tells should the safety distance be removed or set.
distance - Tells the distance on how far the safety distance should be set from the node.
set - When the safety distance is set for the first time, set is true, so the pathSafetyDistance values are set to be as this.finalPathCount. Otherwise false.

setSafetyDistanceAirPlanes

public void setSafetyDistanceAirPlanes(Vertex vertex,
                                       boolean availability,
                                       int distance)
This method is similar that the method setSafetyDistance. Only difference is that airplanes uses this method to remove the safety distance of the arrival tree when calculating new temporary paths.

Parameters:
vertex - Safety distance is set around this node.
availability - Tells should the safety distance be removed or set.
distance - Tells the distance on how far the safety distance should be set from the node.

setSlidingSafetyDistance

private void setSlidingSafetyDistance(Vertex startNode,
                                      boolean sliding,
                                      boolean availability)
Sets a safety distance (true or false) to a certain area under the node, determined by value this.safetyDistance. If parameter "sliding" is true, safety distance is set "slidingly", so that under the node safety distance of first nodes are 1, then 2, then 3, etc. as long as safety distance of nodes is finally this.safetyDistance. Area on which safety distance will be one, is length of this.safetyDistance, the area on which safety distance is two will be 2*this.safetyDistance, etc (multiplier grows each time by one). This is done for that there will not be too sharp angles in the arrival tree. If parameter "sliding" is false, all the same areas (as if sliding was true) nodes are set to have a safety distance of this.safetyDistance.

Parameters:
startNode - A node on where setting the sliding safety distance is started.
sliding - Tells should the safety distance be set "slidingly" or just "straight".
availability - Availability to be set for each nodes on certain area.

testSide

private int testSide(java.util.ArrayList<Vertex> path,
                     java.util.ArrayList<Vertex> endNodes)
Tests if the end of the path went to left or right. If it went left, method will return true. Otherwise it will return false. If the path went just in the middle (pairless amount of end nodes), the method will say it went right.

Parameters:
path - The shortest found path in graph.
endNodes - End node table.
Returns:
3 if endNodes were null or sized zero or one, 0 if it went left, 1 if it went right, 2 if there was no success (end node of the path was not in endNodes).

treeRecursion

public void treeRecursion(Vertex parStartNode,
                          java.util.ArrayList<Vertex> endNodeTable)
The method which implements the recursion of the tree in calculation.

Parameters:
parStartNode - A node, from where aStar calculates paths to all endNodeTable nodes and chooses the shortest one. When called first time startNode will be the airport node.
endNodeTable - A table of Vertexes. A path will be calculated with aStar to all Vertexes in this table.

update

public boolean update(Graph graph)
Method for updating the arrival tree.

Parameters:
graph - Graph to be set as this.graph.
Returns:
boolean Success.