calculation
Class Vertex

java.lang.Object
  extended by calculation.Vertex
All Implemented Interfaces:
java.lang.Comparable<Vertex>

public class Vertex
extends java.lang.Object
implements java.lang.Comparable<Vertex>

This is a Vertex class, to represents the nodes in the graph.

Version:
1
Author:
Potkuri-group

Field Summary
private  Vertex[] adj
          Adjacent vertices.
private  boolean available
          Is this vertex available?
private  int bestDir
          Tells if this vertex is in the best direction for aStar.
private  double distCost
          Cost to goal vertex of aStar as a straight line distance.
static int EAST
          Possible direction of adjacent Vertex.
private  double gCost
          Cost from start vertex of aStar to this vertex.
private  double hCost
          Cost to goal vertex of aStar.
private  double lat
          Latitude coordinate.
private  double lon
          Longitude coordinate.
static int NORTH
          Possible direction of adjacent Vertex.
static int NORTHEAST
          Possible direction of adjacent Vertex.
static int NORTHWEST
          Possible direction of adjacent Vertex.
static int ON_CLOSED_SET
          Value for the field "state".
static int ON_OPEN_SET
          Value for the field "state".
private  Vertex parent
          Parent vertex in a tree aStar is creating.
private  int pathSafety
          Tells if this vertex is in path safety area, value identifies path number.
static int SOUTH
          Possible direction of adjacent Vertex.
static int SOUTHEAST
          Possible direction of adjacent Vertex.
static int SOUTHWEST
          Possible direction of adjacent Vertex.
private  int state
          How A* sees this vertex.
private  boolean storm
          Is this a storm vertex?
private  boolean stormSafety
          Tells if this vertex is in storm safety distance area.
static int UNVISITED
          Value for the field "state".
static int WEST
          Possible direction of adjacent Vertex.
private  int x
          X-coordinate in a graph.
private  int y
          Y-coordinate in a graph.
 
Constructor Summary
Vertex(double lon, double lat, int x, int y, boolean available, Vertex nullVertex)
          Constructor.
 
Method Summary
 double calculateDir(Vertex goal)
          Calculates the angle between this and a certain Vertex.
 double calculateDirCost(Vertex dirStart, double rightDir)
          Compares the given double value with the direction from a given Vertex to this vertex.
 int compareTo(Vertex other)
          Comparable interface needs this to find out which vertex is "better" for aStar method.
 double distanceTo(Vertex other)
          Calculates the straight line distance to other vertex in the graph.
 Vertex getAdjacent(int direction)
          Returns the adjacent Vertex of this Vertex in a certain direction.
 int getAdjacentNumber(Vertex vertex)
          Returns the integer direction of follower vertex given in parameters.
 Vertex[] getAdjacents()
          This method is used as a handle to the list of adjacent vertices.
 int getBestDir()
          Returns the bestDir value of this Vertex.
 double getDistCost()
          Returns the distCost of this Vertex.
 double getGCost()
          Returns the gCost of this Vertex.
 double getHCost()
          Returns the hCost of this vertex.
 double getLat()
          Returns the latitude coordinate of this Vertex.
 double getLon()
          Returns the longitude coordinate of this Vertex.
 Vertex getParent()
          Returns the parent of this Vertex.
 int getPathSafety()
          Returns integer value telling on which path safety area this vertex is in.
 int getState()
          Returns the state of this vertex.
 boolean getStorm()
          Is this Vertex a storm Vertex?
 boolean getStormSafety()
          Returns true if this vertex is in storm safety area.
 int getX()
          Returns the X-coordinate of this Vertex.
 int getY()
          Returns the Y-coordinate of this Vertex.
 double graphDistanceTo(Vertex other)
          Calculates the distance to other vertex in a Graph.
 boolean isAvailable()
          Is this Vertex is available for aStar?
 void reset()
          Resets fields that aStar method uses.
 void setAdjacent(int direction, Vertex other)
          Adds a vertex to the adjacent list.
 void setAvailable(boolean value)
          Sets new boolean value for available field.
 void setBestDir(boolean value)
          Sets a new BestDir value to this Vertex.
 void setDistCost(Vertex goal)
          Sets the distCost of this Vertex.
 void setGCost(double newCost)
          Sets a new gCost to this Vertex.
 void setHCost(Vertex goal)
          Sets a new hCost to this Vertex.
 void setParent(Vertex newParent)
          Sets a new parent to this Vertex.
 void setPathSafety(int isPathSafety)
          Sets this.pathSafety to be as parameter value.
 void setState(int newState)
          Sets new state to this vertex.
 void setStorm(boolean value)
          Marks this Vertex to be a storm Vertex.
 void setStormSafety(boolean isStormSafety)
          Sets parameter value to be value of this.stormSafety.
 java.lang.String toString()
          Returns representation of x- and y-coordinates of this Vertex.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

adj

private Vertex[] adj
Adjacent vertices.


available

private boolean available
Is this vertex available? Can be false for example because of a storm or a plane route.


bestDir

private int bestDir
Tells if this vertex is in the best direction for aStar. Should be 1 if it is.


distCost

private double distCost
Cost to goal vertex of aStar as a straight line distance.


EAST

public static final int EAST
Possible direction of adjacent Vertex.

See Also:
Constant Field Values

gCost

private double gCost
Cost from start vertex of aStar to this vertex.


hCost

private double hCost
Cost to goal vertex of aStar.


lat

private final double lat
Latitude coordinate.


lon

private final double lon
Longitude coordinate.


NORTH

public static final int NORTH
Possible direction of adjacent Vertex.

See Also:
Constant Field Values

NORTHEAST

public static final int NORTHEAST
Possible direction of adjacent Vertex.

See Also:
Constant Field Values

NORTHWEST

public static final int NORTHWEST
Possible direction of adjacent Vertex.

See Also:
Constant Field Values

ON_CLOSED_SET

public static final int ON_CLOSED_SET
Value for the field "state".

See Also:
Constant Field Values

ON_OPEN_SET

public static final int ON_OPEN_SET
Value for the field "state".

See Also:
Constant Field Values

parent

private Vertex parent
Parent vertex in a tree aStar is creating.


pathSafety

private int pathSafety
Tells if this vertex is in path safety area, value identifies path number.


SOUTH

public static final int SOUTH
Possible direction of adjacent Vertex.

See Also:
Constant Field Values

SOUTHEAST

public static final int SOUTHEAST
Possible direction of adjacent Vertex.

See Also:
Constant Field Values

SOUTHWEST

public static final int SOUTHWEST
Possible direction of adjacent Vertex.

See Also:
Constant Field Values

state

private int state
How A* sees this vertex. Should be 0 if aStar is not using this vertex, 1 if this is in the open set of aStar, and 2 if this is in the closed set of aStar.


storm

private boolean storm
Is this a storm vertex? We use this when we check do we have to re-calculate arrival tree.


stormSafety

private boolean stormSafety
Tells if this vertex is in storm safety distance area.


UNVISITED

public static final int UNVISITED
Value for the field "state".

See Also:
Constant Field Values

WEST

public static final int WEST
Possible direction of adjacent Vertex.

See Also:
Constant Field Values

x

private final int x
X-coordinate in a graph.


y

private final int y
Y-coordinate in a graph.

Constructor Detail

Vertex

public Vertex(double lon,
              double lat,
              int x,
              int y,
              boolean available,
              Vertex nullVertex)
Constructor.

Parameters:
lon - Longitude coordinate
lat - Latitude coordinate
x - X-coordinate
y - Y-coordinate
available - Is this Vertex available?
nullVertex - default adjacent Vertex
Method Detail

calculateDir

public double calculateDir(Vertex goal)
Calculates the angle between this and a certain Vertex.

Parameters:
goal - given Vertex
Returns:
angle between this and goal vertices as radians

calculateDirCost

public double calculateDirCost(Vertex dirStart,
                               double rightDir)
Compares the given double value with the direction from a given Vertex to this vertex.

Parameters:
dirStart - Vertex from which the direction to this Vertex is measured
rightDir - double value with which the calculated direction is compared
Returns:
the difference between rightDir and the measured direction as a positive double value (< PI)

compareTo

public final int compareTo(Vertex other)
Comparable interface needs this to find out which vertex is "better" for aStar method.

Specified by:
compareTo in interface java.lang.Comparable<Vertex>
Parameters:
other - vertex to compare to.
Returns:
-1 if this is better
0 if vertices are equal
1 if the other is better.
-2 if something went wrong.

distanceTo

public double distanceTo(Vertex other)
Calculates the straight line distance to other vertex in the graph.

Parameters:
other - the other vertex.
Returns:
the distance as double.

getAdjacent

public Vertex getAdjacent(int direction)
Returns the adjacent Vertex of this Vertex in a certain direction.

Parameters:
direction - tells which direction to return.
0 North
1 Northeast
2 East
3 Southeast
4 South
5 Southwest
6 West
7 Northwest
Returns:
the adjacent Vertex at a certain direction

getAdjacentNumber

public int getAdjacentNumber(Vertex vertex)
Returns the integer direction of follower vertex given in parameters. If parameter "vertex" is not a follower, returns number 10.

Parameters:
vertex - possible follower
Returns:
adjacentnumber

getAdjacents

public Vertex[] getAdjacents()
This method is used as a handle to the list of adjacent vertices.

Returns:
adjacent vertices

getBestDir

public int getBestDir()
Returns the bestDir value of this Vertex.

Returns:
1 if this Vertex is in the best direction, 0 if not

getDistCost

public double getDistCost()
Returns the distCost of this Vertex.

Returns:
distCost

getGCost

public double getGCost()
Returns the gCost of this Vertex.

Returns:
gCost

getHCost

public double getHCost()
Returns the hCost of this vertex.

Returns:
hCost of this vertex

getLat

public double getLat()
Returns the latitude coordinate of this Vertex.

Returns:
the latitude coordinate

getLon

public double getLon()
Returns the longitude coordinate of this Vertex.

Returns:
the longitude coordinate.

getParent

public Vertex getParent()
Returns the parent of this Vertex.

Returns:
the parent vertex of this vertex.

getPathSafety

public int getPathSafety()
Returns integer value telling on which path safety area this vertex is in.

Returns:
this.pathSafety

getState

public int getState()
Returns the state of this vertex.

Returns:
state of this vertex

getStorm

public boolean getStorm()
Is this Vertex a storm Vertex?

Returns:
true if this Vertex is a storm Vertex, false if not

getStormSafety

public boolean getStormSafety()
Returns true if this vertex is in storm safety area.

Returns:
this.stormSafety

getX

public int getX()
Returns the X-coordinate of this Vertex.

Returns:
X-coordinate.

getY

public int getY()
Returns the Y-coordinate of this Vertex.

Returns:
Y-coordinate.

graphDistanceTo

public double graphDistanceTo(Vertex other)
Calculates the distance to other vertex in a Graph.

Parameters:
other - the other vertex
Returns:
distance between this and other

isAvailable

public boolean isAvailable()
Is this Vertex is available for aStar?

Returns:
true if this Vertex is available for aStar, false if not.

reset

public void reset()
Resets fields that aStar method uses.


setAdjacent

public void setAdjacent(int direction,
                        Vertex other)
Adds a vertex to the adjacent list.

Parameters:
direction - direction where this new adjacent vertex is. 0 if it is in north, 1 if in northeast, ... and 7 if in northwest.
other - the vertex to be added.
Throws:
java.lang.IllegalArgumentException - if direction is not between 0 and 7.

setAvailable

public void setAvailable(boolean value)
Sets new boolean value for available field.

Parameters:
value - true if this vertex should be available, false if not

setBestDir

public void setBestDir(boolean value)
Sets a new BestDir value to this Vertex.

Parameters:
value - true if this vertex is in the best direction for aStar, false if not

setDistCost

public void setDistCost(Vertex goal)
Sets the distCost of this Vertex.

Parameters:
goal - goal vertex of aStar

setGCost

public void setGCost(double newCost)
Sets a new gCost to this Vertex.

Parameters:
newCost - new gCost

setHCost

public void setHCost(Vertex goal)
Sets a new hCost to this Vertex.

Parameters:
goal - the goal vertex of aStar

setParent

public void setParent(Vertex newParent)
Sets a new parent to this Vertex.

Parameters:
newParent - new parent

setPathSafety

public void setPathSafety(int isPathSafety)
Sets this.pathSafety to be as parameter value.

Parameters:
isPathSafety - new pathSafety value

setState

public void setState(int newState)
Sets new state to this vertex.

Parameters:
newState - new state
Throws:
java.lang.IllegalArgumentException - if new state is not between 0 and 2

setStorm

public void setStorm(boolean value)
Marks this Vertex to be a storm Vertex.

Parameters:
value - true marks this to be a storm Vertex, false marks this not to be a storm Vertex.

setStormSafety

public void setStormSafety(boolean isStormSafety)
Sets parameter value to be value of this.stormSafety.

Parameters:
isStormSafety - new stormSafety value

toString

public java.lang.String toString()
Returns representation of x- and y-coordinates of this Vertex.

Overrides:
toString in class java.lang.Object
Returns:
representation of x- and y-coordinates of this Vertex