exe
Class VisNode

java.lang.Object
  extended by exe.VisNode
All Implemented Interfaces:
java.lang.Comparable
Direct Known Subclasses:
TreeNode

public class VisNode
extends java.lang.Object
implements java.lang.Comparable

This class maintains the information for a single node in the VisualGraph data structure. A VisNode object contains label, color, and position information, as well as other data members that might be useful to a node in a graph.

In order to use any of these graph classes in a script-producing program, the script-producing program must import the package exe.

Author:
Jeff Lucas (original author), Richard Teviotdale (GAIGS adaptations and additions), Andrew Jungwirth (more GAIGS adaptations and Javadoc comments)

Field Summary
protected  boolean activated
          Maintains the status of this VisNode in a VisualGraph.
protected  char cindex
          Stores this VisNode's unique identifier and label.
protected  boolean closed
          Tracks if this VisNode is on the closed list in a graph-searching algorithm.
protected  int cost
          Contains the length of the current shortest path to this VisNode.
protected  int heuristic
          Stores the heuristic value for this VisNode.
protected  java.lang.String hexColor
          Holds the hexadecimal color String for this VisNode of the form #123456.
protected  char pred
          Stores the name of the VisNode that is the predecessor of this VisNode on the current shortest path to this VisNode.
protected  double x
          Contains the Cartesian x-coordinate of the center of this VisNode in [0,1] space.
protected  double y
          Contains the Cartesian y-coordinate of the center of this VisNode in [0,1] space.
 
Constructor Summary
VisNode()
          Constructs a new VisNode with default information.
VisNode(char label, java.lang.String color, double x, double y)
          Constructs a new VisNode by specifying its unique name/label, hexadecimal color String, and Cartesian coordinates.
VisNode(VisNode copy)
          Constructs a new VisNode that is a copy of copy.
 
Method Summary
 void activate()
          Sets this VisNode to active, meaning that it will be displayed when the VisualGraph to which it belongs is displayed.
 void clearNode()
          Resets this VisNode's data members to their default values.
 int compareTo(java.lang.Object compare)
          Compares two VisNode objects.
 int compareToNoCost(java.lang.Object compare)
          Compares two VisNode objects.
 void deactivate()
          Sets this VisNode to inactive, meaning that it will not be displayed when the VisualGraph to which it belongs is displayed.
 char getChar()
          Returns the name/label for this VisNode.
 int getCost()
          Returns the current shortest cost to this VisNode.
 int getHeuristic()
          Returns the heuristic value for this VisNode.
 java.lang.String getHexColor()
          Gives the hexadecimal String that defines the color for this VisNode.
 char getPred()
          Returns the name of the predecessor on the shortest path to this VisNode.
 double getX()
          Returns the Cartesian x-coordinate in [0,1] space for the center of this VisNode.
 double getY()
          Returns the Cartesian y-coordinate in [0,1] space for the center of this VisNode.
 boolean isActivated()
          Gives the current activation status of this VisNode in a VisualGraph.
 boolean isClosed()
          Gives the closed status of this VisNode.
 void setChar(char my_c)
          Assigns the name/label for this VisNode.
 void setClosed(boolean newClosed)
          Sets closed status of this VisNode in a graph-searching algorithm.
 void setCost(int newCost)
          Sets the length of the current shortest path to this VisNode.
 void setHeuristic(int newHeuristic)
          Assigns the heuristic value for this VisNode.
 void setHexColor(java.lang.String c)
          Sets the color that is displayed within this VisNode.
 void setLimitedX(double my_x)
          Changes the Cartesian x-coordinate in [0,1] space for the center of this VisNode, ensuring that the new x-coordinate is in the range [0,1].
 void setLimitedY(double my_y)
          Changes the Cartesian y-coordinate in [0,1] space for the center of this VisNode, ensuring that the new y-coordinate is in the range [0,1].
 void setPred(char pred)
          Assigns the name of the predecessor VisNode to this VisNode on the current lowest-cost path.
 void setX(double my_x)
          Changes the Cartesian x-coordinate in [0,1] space for the center of this VisNode.
 void setY(double my_y)
          Changes the Cartesian y-coordinate in [0,1] space for the center of this VisNode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cindex

protected char cindex
Stores this VisNode's unique identifier and label.


hexColor

protected java.lang.String hexColor
Holds the hexadecimal color String for this VisNode of the form #123456.


cost

protected int cost
Contains the length of the current shortest path to this VisNode. This is used in graph-searching algorithms.


heuristic

protected int heuristic
Stores the heuristic value for this VisNode. This is used in informed graph searches.


closed

protected boolean closed
Tracks if this VisNode is on the closed list in a graph-searching algorithm.


pred

protected char pred
Stores the name of the VisNode that is the predecessor of this VisNode on the current shortest path to this VisNode. This is used in graph-searching algorithms.


x

protected double x
Contains the Cartesian x-coordinate of the center of this VisNode in [0,1] space.


y

protected double y
Contains the Cartesian y-coordinate of the center of this VisNode in [0,1] space.


activated

protected boolean activated
Maintains the status of this VisNode in a VisualGraph. A value of true means this node is part of the graph and should be displayed, and false indicates it is not active and should not be displayed.

Constructor Detail

VisNode

public VisNode()
Constructs a new VisNode with default information.


VisNode

public VisNode(char label,
               java.lang.String color,
               double x,
               double y)
Constructs a new VisNode by specifying its unique name/label, hexadecimal color String, and Cartesian coordinates.

All other data members are assigned default values and must be set with the corresponding method calls. This newly constructed VisNode is inactive until the activate method is called.

Parameters:
label - Indicates the unique name/label for this VisNode.
color - Gives the hexadecimal String of the form #123456 that defines the color for this VisNode.
x - Specifies the Cartesian x-coordinate in [0,1] space for the center of this VisNode.
y - Specifies the Cartesian y-coordinate in [0,1] space for the center of this VisNode.

VisNode

public VisNode(VisNode copy)
Constructs a new VisNode that is a copy of copy.

Parameters:
copy - Gives a VisNode containing information with which this VisNode should be initialized.
Method Detail

clearNode

public void clearNode()
Resets this VisNode's data members to their default values.


getChar

public char getChar()
Returns the name/label for this VisNode.

Returns:
Gives the value stored in cindex, the unique label for this VisNode.

getHexColor

public java.lang.String getHexColor()
Gives the hexadecimal String that defines the color for this VisNode.

Returns:
Yields a String of the form #123456.

getCost

public int getCost()
Returns the current shortest cost to this VisNode.

Returns:
Gives the value stored in cost.

getHeuristic

public int getHeuristic()
Returns the heuristic value for this VisNode.

Returns:
Yields the value stored in heuristic.

isClosed

public boolean isClosed()
Gives the closed status of this VisNode.

Returns:
Yields true if this VisNode is on the closed list in a graph search or false if it is not on the closed list.

getPred

public char getPred()
Returns the name of the predecessor on the shortest path to this VisNode.

Returns:
Gives the value stored in pred.

getX

public double getX()
Returns the Cartesian x-coordinate in [0,1] space for the center of this VisNode.

Returns:
Gives the value stored in x.

getY

public double getY()
Returns the Cartesian y-coordinate in [0,1] space for the center of this VisNode.

Returns:
Gives the value stored in y.

isActivated

public boolean isActivated()
Gives the current activation status of this VisNode in a VisualGraph.

Returns:
Yields a value of true if this VisNode is a part of the VisualGraph and should be displayed or false if it should not be displayed.

setChar

public void setChar(char my_c)
Assigns the name/label for this VisNode.

Parameters:
my_c - Specifies the name/label that is to appear within this VisNode when it is displayed. This value is assigned to cindex.

setHexColor

public void setHexColor(java.lang.String c)
Sets the color that is displayed within this VisNode.

Parameters:
c - Indicates the color that appears within this VisNode when it is displayed. The value must be a six-digit hexadecimal color String of the form #123456.

setCost

public void setCost(int newCost)
Sets the length of the current shortest path to this VisNode.

Parameters:
newCost - Specifies the current lowest cost to reach this VisNode in a VisualGraph.

setHeuristic

public void setHeuristic(int newHeuristic)
Assigns the heuristic value for this VisNode.

Parameters:
newHeuristic - Indicates the heuristic value for this VisNode in an informed graph search.

setClosed

public void setClosed(boolean newClosed)
Sets closed status of this VisNode in a graph-searching algorithm.

Parameters:
newClosed - Gives a value that indicates if this VisNode is on the closed list; true means it appears on the closed list while false indicates that it does not.

setPred

public void setPred(char pred)
Assigns the name of the predecessor VisNode to this VisNode on the current lowest-cost path.

Parameters:
pred - Indicates the name/label of the VisNode that is the predecessor to this VisNode along its current shortest path. This value is useful for retracing the path to this VisNode in a graph-searching algorithm.

setX

public void setX(double my_x)
Changes the Cartesian x-coordinate in [0,1] space for the center of this VisNode.

Parameters:
my_x - Specifies the new x-coordinate for this VisNode.

setY

public void setY(double my_y)
Changes the Cartesian y-coordinate in [0,1] space for the center of this VisNode.

Parameters:
my_y - Specifies the new y-coordinate for this VisNode.

setLimitedX

public void setLimitedX(double my_x)
Changes the Cartesian x-coordinate in [0,1] space for the center of this VisNode, ensuring that the new x-coordinate is in the range [0,1].

Parameters:
my_x - Specifies the new x-coordinate for this VisNode. If the value is less than 0, the x-coordinate is set as 0, and, if the value is greater than 1, the x-coordinate is set as 1.

setLimitedY

public void setLimitedY(double my_y)
Changes the Cartesian y-coordinate in [0,1] space for the center of this VisNode, ensuring that the new y-coordinate is in the range [0,1].

Parameters:
my_y - Specifies the new y-coordinate for this VisNode. If the value is less than 0, the y-coordinate is set as 0, and, if the value is greater than 1, the y-coordinate is set as 1.

activate

public void activate()
Sets this VisNode to active, meaning that it will be displayed when the VisualGraph to which it belongs is displayed.


deactivate

public void deactivate()
Sets this VisNode to inactive, meaning that it will not be displayed when the VisualGraph to which it belongs is displayed.


compareTo

public int compareTo(java.lang.Object compare)
Compares two VisNode objects. The two objects are compared using the sums of their cost and heuristic values. If one of them has a lower sum of these two values, it is considered less than the other. When these sums are equal, if one of the objects has a heuristic value of 0 (and the other has a value not equal to 0), it is considered less than the other. If the least of the two VisNodes still has not been found at this point, they are compared using the alphabetical order of their cindex values (their names/labels). If, at this point, their cindex values are identical, both objects are considered equal by this method.

This method is ideal as a comparison function for use when inserting VisNode objects into an open priority queue in graph-searching algorithms. Note that this comparison method still works for algorithms that do not use a heuristic because, in these cases, the value of each object's heuristic data member will be the default of 0 and will not affect the comparison.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
compare - Indicates the VisNode to which this VisNode is to be compared.
Returns:
Gives a value of -1 if the calling object is less than compare, 0 if the two objects are equal, and 1 if the calling object is greater than compare.

compareToNoCost

public int compareToNoCost(java.lang.Object compare)
Compares two VisNode objects. The two objects are compared using only their heuristic values. The node with the lower heuristic value is considered less than the other. When the nodes have the same heuristic values, they are compared using the alphabetical order of their cindex values (their names/labels). If, at this point, their cindex values are identical, both objects are considered equal by this method.

Parameters:
compare - Indicates the VisNode to which this VisNode is to be compared.
Returns:
Gives a value of -1 if the calling object is less than compare, 0 if the two objects are equal, and 1 if the calling object is greater than compare.