com.epochx.representation.action
Class IfFoodAheadFunction

java.lang.Object
  extended by com.epochx.representation.Node<TYPE>
      extended by com.epochx.representation.FunctionNode<Action>
          extended by com.epochx.representation.action.IfFoodAheadFunction
All Implemented Interfaces:
java.lang.Cloneable

public class IfFoodAheadFunction
extends FunctionNode<Action>

A FunctionNode which represents the conditional if-then-else statement typically used in the artificial ant domain. This version of the if statement has the condition predefined as a check for whether the next move in the landscape contains a food item.


Constructor Summary
IfFoodAheadFunction(Ant ant, AntLandscape landscape)
          Construct an IfFoodAheadFunction with no children.
IfFoodAheadFunction(Ant ant, AntLandscape landscape, Node<Action> child1, Node<Action> child2)
          Construct an IfFoodAheadFunction with two children.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Compare an object for equality.
 Action evaluate()
          Evaluating an IfFoodAheadFunction involves identifying the next location the ant would move to on the landscape were it to be moved.
 java.lang.String getFunctionName()
          Get the unique name that identifies this function.
 
Methods inherited from class com.epochx.representation.FunctionNode
toString
 
Methods inherited from class com.epochx.representation.Node
clone, getArity, getChild, getChildren, getDepth, getFunctionNodes, getLength, getNodesAtDepth, getNoDistinctFunctions, getNoDistinctTerminals, getNoFunctions, getNoTerminals, getNthNode, getTerminalNodes, hashCode, setChild, setChildren, setNthNode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IfFoodAheadFunction

public IfFoodAheadFunction(Ant ant,
                           AntLandscape landscape)
Construct an IfFoodAheadFunction with no children.

Parameters:
ant - the ant which this function will be controlling.
landscape - the landscape upon which the ant is roaming which will be used to check for food locations.

IfFoodAheadFunction

public IfFoodAheadFunction(Ant ant,
                           AntLandscape landscape,
                           Node<Action> child1,
                           Node<Action> child2)
Construct an IfFoodAheadFunction with two children. When evaluated, if given ant's next location on the provided landscape is a food location then the first child node will be evaluated and executed, otherwise the second child node is evaluated and executed.

Parameters:
ant - the ant which this function will be controlling.
landscape - the landscape upon which the ant is roaming which will be used to check for food locations.
child1 - The first child node.
child2 - The second child node.
Method Detail

evaluate

public Action evaluate()
Evaluating an IfFoodAheadFunction involves identifying the next location the ant would move to on the landscape were it to be moved. If this position contains a food item then the first child is evaluated and executed, else the second child is evaluated and executed.

One of the children will thus have been evaluated (triggering execution of actions at the TerminalNodes) and then this method which must return an Action, returns Action.DO_NOTHING which any functions higher up in the program tree will execute, but with no effect.

Specified by:
evaluate in class Node<Action>
Returns:
The result of evaluating the candidate program.

getFunctionName

public java.lang.String getFunctionName()
Get the unique name that identifies this function.

Specified by:
getFunctionName in class FunctionNode<Action>
Returns:
the unique name for the IfFoodAheadFunction which is IF-FOOD-AHEAD.

equals

public boolean equals(java.lang.Object obj)
Description copied from class: Node
Compare an object for equality. If the given object is a Node then it may be equal if each Node in the tree is equal. Equality of individual Nodes is dependant on the specific node type but typically will be whether they are the same type and have the same children for function nodes and whether they have the same value or are the same variable for terminal nodes.

Overrides:
equals in class FunctionNode<Action>
Parameters:
obj - an object to be compared for equivalence.
Returns:
true if this node tree is the same as the obj argument; false otherwise.