Class Algorithm

java.lang.Object
  |
  +--Algorithm
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener
Direct Known Subclasses:
FM, MP, NJ, UPGMA

public abstract class Algorithm
extends java.lang.Object
implements java.awt.event.ActionListener

This class is an abstract class and defines the methods common to all algorithms.


Field Summary
protected  javax.swing.JTextField ansField
          The answer area for the users to type
protected  javax.swing.JFrame ansFrame
          The answer window
protected  javax.swing.JLabel ansLabel
          The field to hold answers
protected  java.lang.String answer
          The answer of the question
protected  int count
          The number of species
protected  boolean display
          The value indicates whether the last step of MP and FM
protected  javax.swing.JTextArea infoArea
          The instruction area to display information
protected  MyJTable inputTable
          The input table in the algorithms
protected  int interNode
          The interior node name
protected  MyJTable interTable
          The intermediate result table in the algorithms
protected  double maxLength
          The maximum branch length in the final trees
protected  java.lang.String maxName
          The longest name of species
protected  int mini
          The row index of the node to be joined
protected  int minj
          The column index of the node to be joined
protected  double minLength
          The minimum branch length in the final trees
protected  java.lang.String[] names
          The names of species
protected  Node[] nodes
          The nodes created in the trees
protected  int numOfNodes
          The number of nodes created so far
protected  int numOfNodesLeft
          The number of nodes left in the each step of the algorithms
protected  javax.swing.JButton okAnsButton
          The OK button used in answer window
protected  javax.swing.JButton okQuesButton
          The OK buttion used in question window
protected  PTCControls phyTreesControls
          The control of PTC package
protected  boolean popUpQues
          The value indicates whether the pop up question is enabled
protected  javax.swing.JFrame quesFrame
          The question window
protected  javax.swing.JLabel quesLabel
          The field to hold pop up questions
protected  java.lang.String question
          The question itself
protected  int random_i
          The random row value used in pop up questions
protected  int random_j
          The random column value used in pop up questions
protected  java.util.Vector roots
          The roots of the trees
protected  int runType
          The algorithm run mode
protected  TreeDisplay treeDisplay
          The object to draw the trees
 
Constructor Summary
Algorithm(PTCControls inPhyTreesControls)
          Initializes the GUI components used in all algorithms and constructs the question and the answer windows.
 
Method Summary
abstract  void calculateNewDistance()
          The abstract method of the algorithm.
 void computeMaxName()
          Computes the longest name of the species.
 void computeMinMaxLength()
          Computes the longest and shortest branch lengths.
 void constructAnsFrame()
          Constructs the answer window.
 javax.swing.JButton constructButton(java.lang.String name)
          Constructs the buttons used in the window.
 void constructQuesFrame()
          Constructs the question window.
 void deleteNodes()
          Kills the nodes joined together in the each step of the algorithms.
 double findMin(double[][] table)
          Finds the smallest value for a matrix.
abstract  boolean findOne()
          The abstract method of the algorithm.
 int getCount()
          Gets the number of species.
 boolean getDisplay()
          The method indicates whether the last step of MP and FM.
 int getInterNode()
          Gets the interior node name.
 double getMaxLength()
          Gets the longest branch length in the trees.
 java.lang.String getMaxName()
          Gets the longest name of the species.
 double getMinLength()
          Gets the shortest branch length in the trees.
 java.lang.String[] getNames()
          Gets the name of the species.
 Node getNode(int index)
          Gets the node at specified index.
 Node[] getNodes()
          Gets the nodes created so far.
 int getNumOfNodes()
          Gets the number of nodes created so far.
 int getNumOfNodesLeft()
          Gets the number of nodes left to join in the trees.
 java.util.Vector getRoots()
          Gets the roots of the trees.
 boolean init()
          Initalizes the components used in the algorithms.
abstract  boolean isEnd()
          The abstract method of the algorithm.
 int randomInt(int seed)
          Generates a random integer value.
 void reset()
          Closes the question and answer windows.
abstract  void run()
          The abstract method of the algorithm.
 void setPopUpQues(boolean inPopUpQues)
          Sets the pop up question flag.
 void setRoots(java.util.Vector inRoots)
          Sets the roots of the trees.
 void setRunType(int inRunType)
          Sets the algorithm run mode.
 double setThreeFractionDigit(double value)
          Formats a double value with threee fraction digits.
abstract  void trace()
          The abstract method of the algorithm.
 void updateTree()
          Updates the tree status in the each step of the algorithm running.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.awt.event.ActionListener
actionPerformed
 

Field Detail

runType

protected int runType
The algorithm run mode


count

protected int count
The number of species


numOfNodes

protected int numOfNodes
The number of nodes created so far


numOfNodesLeft

protected int numOfNodesLeft
The number of nodes left in the each step of the algorithms


mini

protected int mini
The row index of the node to be joined


minj

protected int minj
The column index of the node to be joined


interNode

protected int interNode
The interior node name


names

protected java.lang.String[] names
The names of species


display

protected boolean display
The value indicates whether the last step of MP and FM


maxName

protected java.lang.String maxName
The longest name of species


maxLength

protected double maxLength
The maximum branch length in the final trees


minLength

protected double minLength
The minimum branch length in the final trees


nodes

protected Node[] nodes
The nodes created in the trees


roots

protected java.util.Vector roots
The roots of the trees


infoArea

protected javax.swing.JTextArea infoArea
The instruction area to display information


interTable

protected MyJTable interTable
The intermediate result table in the algorithms


inputTable

protected MyJTable inputTable
The input table in the algorithms


treeDisplay

protected TreeDisplay treeDisplay
The object to draw the trees


phyTreesControls

protected PTCControls phyTreesControls
The control of PTC package


popUpQues

protected boolean popUpQues
The value indicates whether the pop up question is enabled


answer

protected java.lang.String answer
The answer of the question


question

protected java.lang.String question
The question itself


random_i

protected int random_i
The random row value used in pop up questions


random_j

protected int random_j
The random column value used in pop up questions


okQuesButton

protected javax.swing.JButton okQuesButton
The OK buttion used in question window


ansField

protected javax.swing.JTextField ansField
The answer area for the users to type


quesLabel

protected javax.swing.JLabel quesLabel
The field to hold pop up questions


quesFrame

protected javax.swing.JFrame quesFrame
The question window


okAnsButton

protected javax.swing.JButton okAnsButton
The OK button used in answer window


ansLabel

protected javax.swing.JLabel ansLabel
The field to hold answers


ansFrame

protected javax.swing.JFrame ansFrame
The answer window

Constructor Detail

Algorithm

public Algorithm(PTCControls inPhyTreesControls)
Initializes the GUI components used in all algorithms and constructs the question and the answer windows.

Parameters:
inPhyTreesControls - the PTCControls object
Method Detail

run

public abstract void run()
The abstract method of the algorithm.
Each algorithm should implements the method to define its own behavior.


trace

public abstract void trace()
The abstract method of the algorithm.
Each algorithm should implements the method to define its own behavior.


calculateNewDistance

public abstract void calculateNewDistance()
The abstract method of the algorithm.
Each algorithm should implements the method to define the way how new distances are calculated.


isEnd

public abstract boolean isEnd()
The abstract method of the algorithm.
Each algorithm should implements the method to define when the algorithm terminates.


findOne

public abstract boolean findOne()
The abstract method of the algorithm.
Each algorithm should implements the method to define when one final tree is identified, especially in MP and FM.


getCount

public int getCount()
Gets the number of species.

Returns:
the number of species

getNumOfNodesLeft

public int getNumOfNodesLeft()
Gets the number of nodes left to join in the trees.

Returns:
the number of nodes left to join in the trees

getInterNode

public int getInterNode()
Gets the interior node name.

Returns:
the interior node name

getNodes

public Node[] getNodes()
Gets the nodes created so far.

Returns:
the nodes created so far

getNumOfNodes

public int getNumOfNodes()
Gets the number of nodes created so far.

Returns:
the number of nodes created so far

getNames

public java.lang.String[] getNames()
Gets the name of the species.

Returns:
the name of the species

getNode

public Node getNode(int index)
Gets the node at specified index.

Returns:
the node at the index

getRoots

public java.util.Vector getRoots()
Gets the roots of the trees.

Returns:
the roots of the trees

getMaxLength

public double getMaxLength()
Gets the longest branch length in the trees.

Returns:
the longest branch length in the trees

getMinLength

public double getMinLength()
Gets the shortest branch length in the trees.

Returns:
the shortest branch length in the trees

getDisplay

public boolean getDisplay()
The method indicates whether the last step of MP and FM.

Returns:
true - it is the last step of MP and FM
false - it is not the last step of MP and FM

getMaxName

public java.lang.String getMaxName()
Gets the longest name of the species.

Returns:
the longest name of the species

setRoots

public void setRoots(java.util.Vector inRoots)
Sets the roots of the trees.

Parameters:
inRoots - the roots of the trees

setPopUpQues

public void setPopUpQues(boolean inPopUpQues)
Sets the pop up question flag.

Parameters:
inPopUpQues - the flag of pop up questions

setRunType

public void setRunType(int inRunType)
Sets the algorithm run mode.

Parameters:
inRunType - the algorrithm run mode

init

public boolean init()
Initalizes the components used in the algorithms.

Returns:
true - the algorithm is properly initialized
false - input data is not right

reset

public void reset()
Closes the question and answer windows.


setThreeFractionDigit

public double setThreeFractionDigit(double value)
Formats a double value with threee fraction digits.

Parameters:
value - a double value
Returns:
the double value with three fraction digits

computeMaxName

public void computeMaxName()
Computes the longest name of the species.


updateTree

public void updateTree()
Updates the tree status in the each step of the algorithm running.


computeMinMaxLength

public void computeMinMaxLength()
Computes the longest and shortest branch lengths.


findMin

public double findMin(double[][] table)
Finds the smallest value for a matrix.

Parameters:
table - the matrix
Returns:
the smallest value in the matrix

deleteNodes

public void deleteNodes()
Kills the nodes joined together in the each step of the algorithms.


randomInt

public int randomInt(int seed)
Generates a random integer value.

Parameters:
seed - the seed in each generation
Returns:
the random integer

constructQuesFrame

public void constructQuesFrame()
Constructs the question window.


constructAnsFrame

public void constructAnsFrame()
Constructs the answer window.


constructButton

public javax.swing.JButton constructButton(java.lang.String name)
Constructs the buttons used in the window.