Class FM

java.lang.Object
  |
  +--Algorithm
        |
        +--FM
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener

public class FM
extends Algorithm

This class implements the Fitch Margoliash algorithm described in the package.


Field Summary
 
Fields inherited from class Algorithm
ansField, ansFrame, ansLabel, answer, count, display, infoArea, inputTable, interNode, interTable, maxLength, maxName, mini, minj, minLength, names, nodes, numOfNodes, numOfNodesLeft, okAnsButton, okQuesButton, phyTreesControls, popUpQues, quesFrame, quesLabel, question, random_i, random_j, roots, runType, treeDisplay
 
Constructor Summary
FM(PTCControls inPhyTreesControls)
          Initializes specific GUI components used in the FM algorithm.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Defines how to handle the actions of the OK buttons for the question and the answer windows in the FM algorithm.
 java.lang.String buildAnswer1()
          Generates the answers for the type 1 questions in the FM algorithm.
 java.lang.String buildAnswer2()
          Generates the answers for the type 2 questions in the FM algorithm.
 double calculateDistanceToOthers(int itself, int notInclude)
          Calculates the distance to the other nodes.
 void calculateNewDistance()
          Implements the method in the Algorithm calss and defines how to calculate new distance matrix in the FM algorithm.
 void calculateOutputDistance()
          Calculates the computed distance matrix.
 void closeBestTrees(java.util.Vector bestTreesFM)
          Closes all best tree windows in the FM algorithm.
 void computeAllNonLeafDistance(Node leftRoot, Node rightRoot, double interDist)
          Computes the distances among the nodes in two trees.
 int computeNumOfTrees(int n)
          Computes the number of different trees for the given number of species.
 double computeSumOfSquares()
          Computes the Sum Of Squares.
 BestTreeFM constructBestTreeFrame(int x, int y)
          Constructs the best tree window used in the FM algorithm.
 void constructComputeDistanceFrame()
          Constructs the computed distance table window.
 double findAndCalculate()
          Defines how to find the nodes to join and calculates branch lengths in the FM algorithm.
 void findMiniMinj()
          Finds the next two nodes to be joined in the FM algorithm.
 boolean findOne()
          Implements the method in the Algorithm class and indicates if one tree is found in the FM algorithm.
 void generateRandom_ij()
          Generates random numbers for pop up questions in the FM algorithm.
 void getAllLeaves(Node node, java.util.Vector leaves)
          Gets the leaves of a node.
 double[][] getDistance()
          Returns the distance matrix in the FM algorithm.
 java.lang.String getFlagString()
          Returns the string corresponding to the negative branch length flag.
 boolean getNegativeFlag()
          Returns the negative branch length flag in the FM algorithm.
 double getSumOfSquares()
          Returns the Sum Of Squares in the FM algorithm.
 boolean init()
          Overrides the method in the Algorithm class and initializes specific data components used in the FM algorithm.
 boolean isEnd()
          Implements the method in the Algorithm class and indicates if the algorithm terminates in the FM algorithm.
 void join(double height)
          Defines how to join the two nodes when there are more than two nodes left in the FM algorithm.
 void joinLastTwoNodes()
          Defines how to join the last two nodes in the FM algorithm.
 void popUpQuestion1()
          Generates type 1 pop up questions in the FM algorithm.
 void popUpQuestion2()
          Generates type 2 pop up questions in the FM algorithm.
 void processLastTwoNodes()
          Defines how to join last two nodes in the FM algorithm.
 void processMoreThanTwoNodes()
          Defines how to join more than two nodes in the FM algorithm.
 void processOneTree()
          Defines how to find one tree in the FM algorithm.
 void reset()
          Overrides the method in the Algorithm class and resets all components in the FM algorithm.
 void run()
          Implements the method in the Algorithm classs and defines how to run the FM algorithm.
 void setPathLength(Node node, double interDist)
          Sets the branch length form the node to its child.
 void trace()
          Implements the method in the Algorithm class and defines how to trace the FM algorithm.
 void updateBestTree()
          Defines how to update the best tree window.
 double updateBestTree(double bestValue, java.util.Vector bestTreesFM, BestTreeFM bestTreeFM, java.lang.String flagString)
          Define how to update one best tree window.
 void updateMiniMinj()
          Updates the index of the nodes to be joined in the FM algorithm.
 void updateUI()
          Defines how to update the tree and the intermediate distance table when there are more than two nodes left in the FM algorithm.
 void updateUILastTwoNodes()
          Defines how to update the tree and the intermediate distance table when there are only two nodes left in the FM algorithm.
 void updateXY()
          Updates the position of the next best tree window.
 
Methods inherited from class Algorithm
computeMaxName, computeMinMaxLength, constructAnsFrame, constructButton, constructQuesFrame, deleteNodes, findMin, getCount, getDisplay, getInterNode, getMaxLength, getMaxName, getMinLength, getNames, getNode, getNodes, getNumOfNodes, getNumOfNodesLeft, getRoots, randomInt, setPopUpQues, setRoots, setRunType, setThreeFractionDigit, updateTree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FM

public FM(PTCControls inPhyTreesControls)
Initializes specific GUI components used in the FM algorithm.

Parameters:
inPhyTreesControls - the PTCControls object
Method Detail

getDistance

public double[][] getDistance()
Returns the distance matrix in the FM algorithm.

Returns:
the distance matrix in the FM algorithm

getSumOfSquares

public double getSumOfSquares()
Returns the Sum Of Squares in the FM algorithm.

Returns:
the Sum Of Squares in the FM algorithm

getNegativeFlag

public boolean getNegativeFlag()
Returns the negative branch length flag in the FM algorithm.

Returns:
true - Negative branch lengths are allowed
false - Negative branch lengths are not allowed

getFlagString

public java.lang.String getFlagString()
Returns the string corresponding to the negative branch length flag.

Returns:
the string corresponding to the negative branch length flag

init

public boolean init()
Overrides the method in the Algorithm class and initializes specific data components used in the FM algorithm.

Overrides:
init in class Algorithm
Returns:
true - the algorithm is properly initialized
false - input data is not right

trace

public void trace()
Implements the method in the Algorithm class and defines how to trace the FM algorithm.

Specified by:
trace in class Algorithm

run

public void run()
Implements the method in the Algorithm classs and defines how to run the FM algorithm.

Specified by:
run in class Algorithm

processOneTree

public void processOneTree()
Defines how to find one tree in the FM algorithm.


processMoreThanTwoNodes

public void processMoreThanTwoNodes()
Defines how to join more than two nodes in the FM algorithm.


processLastTwoNodes

public void processLastTwoNodes()
Defines how to join last two nodes in the FM algorithm.


findAndCalculate

public double findAndCalculate()
Defines how to find the nodes to join and calculates branch lengths in the FM algorithm.

Returns:
the height of the tree

join

public void join(double height)
Defines how to join the two nodes when there are more than two nodes left in the FM algorithm.


updateUI

public void updateUI()
Defines how to update the tree and the intermediate distance table when there are more than two nodes left in the FM algorithm.


joinLastTwoNodes

public void joinLastTwoNodes()
Defines how to join the last two nodes in the FM algorithm.


updateUILastTwoNodes

public void updateUILastTwoNodes()
Defines how to update the tree and the intermediate distance table when there are only two nodes left in the FM algorithm.


updateBestTree

public void updateBestTree()
Defines how to update the best tree window.


updateBestTree

public double updateBestTree(double bestValue,
                             java.util.Vector bestTreesFM,
                             BestTreeFM bestTreeFM,
                             java.lang.String flagString)
Define how to update one best tree window.

Parameters:
bestValue - the best Sum Of Squares
bestTreesFM - the vector to hold all best trees in the FM algorithm
bestTreeFM - the current best tree
flagString - the flag string displayed
Returns:
the best Sum Of Squares

updateMiniMinj

public void updateMiniMinj()
Updates the index of the nodes to be joined in the FM algorithm.


findMiniMinj

public void findMiniMinj()
Finds the next two nodes to be joined in the FM algorithm.


calculateDistanceToOthers

public double calculateDistanceToOthers(int itself,
                                        int notInclude)
Calculates the distance to the other nodes.

Parameters:
itself - the index of the node itself
notInclude - the index of the node joined with the node itself
Returns:
the distance to the other nodes

calculateOutputDistance

public void calculateOutputDistance()
Calculates the computed distance matrix.


calculateNewDistance

public void calculateNewDistance()
Implements the method in the Algorithm calss and defines how to calculate new distance matrix in the FM algorithm.

Specified by:
calculateNewDistance in class Algorithm

constructBestTreeFrame

public BestTreeFM constructBestTreeFrame(int x,
                                         int y)
Constructs the best tree window used in the FM algorithm.

Parameters:
x - the x axis position in the screen
y - the y axis position in the screen

updateXY

public void updateXY()
Updates the position of the next best tree window.


setPathLength

public void setPathLength(Node node,
                          double interDist)
Sets the branch length form the node to its child.

Parameters:
node - the node to be set
interDist - the branch length

computeAllNonLeafDistance

public void computeAllNonLeafDistance(Node leftRoot,
                                      Node rightRoot,
                                      double interDist)
Computes the distances among the nodes in two trees.

Parameters:
interDist - the branch length between left node and right node

getAllLeaves

public void getAllLeaves(Node node,
                         java.util.Vector leaves)
Gets the leaves of a node.

Parameters:
node - the node
leaves - the leaves of the node

computeSumOfSquares

public double computeSumOfSquares()
Computes the Sum Of Squares.

Returns:
the Sum Of Squares

constructComputeDistanceFrame

public void constructComputeDistanceFrame()
Constructs the computed distance table window.


computeNumOfTrees

public int computeNumOfTrees(int n)
Computes the number of different trees for the given number of species.

Parameters:
n - the number of species
Returns:
the number of trees

findOne

public boolean findOne()
Implements the method in the Algorithm class and indicates if one tree is found in the FM algorithm.

Specified by:
findOne in class Algorithm
Returns:
true - one tree is found
false - one tree is not found

isEnd

public boolean isEnd()
Implements the method in the Algorithm class and indicates if the algorithm terminates in the FM algorithm.

Specified by:
isEnd in class Algorithm
Returns:
true - the algorithm terminates
false - the algorithm does not terminate

reset

public void reset()
Overrides the method in the Algorithm class and resets all components in the FM algorithm.

Overrides:
reset in class Algorithm

closeBestTrees

public void closeBestTrees(java.util.Vector bestTreesFM)
Closes all best tree windows in the FM algorithm.


generateRandom_ij

public void generateRandom_ij()
Generates random numbers for pop up questions in the FM algorithm.


popUpQuestion1

public void popUpQuestion1()
Generates type 1 pop up questions in the FM algorithm.


buildAnswer1

public java.lang.String buildAnswer1()
Generates the answers for the type 1 questions in the FM algorithm.

Returns:
the answer

popUpQuestion2

public void popUpQuestion2()
Generates type 2 pop up questions in the FM algorithm.


buildAnswer2

public java.lang.String buildAnswer2()
Generates the answers for the type 2 questions in the FM algorithm.

Returns:
the answer

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Defines how to handle the actions of the OK buttons for the question and the answer windows in the FM algorithm.

Parameters:
e - the ActionEvent object which is responsible for the action