Class Program

java.lang.Object
org.moeaframework.util.tree.Node
org.moeaframework.core.variable.Program
All Implemented Interfaces:
Serializable, Variable

public class Program extends Node implements Variable
A decision variable for programs. The program is represented as a strongly-typed expression tree.

Note: Although Program extends Node, the Program object must never be altered by the optimization algorithm. Only its arguments can undergo variation.

See Also:
  • Constructor Details

    • Program

      public Program(Rules rules)
      Constructs a new program variable with the specified syntax rules.
      Parameters:
      rules - the rules defining the program syntax
  • Method Details

    • getRules

      public Rules getRules()
      Returns the rules defining the program syntax.
      Returns:
      the rules defining the program syntax
    • copy

      public Program copy()
      Description copied from interface: Variable
      Returns an independent copy of this decision variable. It is required that x.copy() is completely independent from x. This means any method invoked on x.copy() in no way alters the state of x and vice versa. It is typically the case that x.copy().getClass() == x.getClass() and x.copy().equals(x).
      Specified by:
      copy in interface Variable
      Returns:
      an independent copy of this decision variable
    • copyNode

      public Program copyNode()
      Description copied from class: Node
      Returns a copy of this node, but without any children or parents assigned.
      Specified by:
      copyNode in class Node
      Returns:
      a copy of this node, but without any children or parents assigned
    • evaluate

      public Object evaluate(Environment environment)
      Description copied from class: Node
      Evaluates this node in the context of the specified environment.
      Specified by:
      evaluate in class Node
      Parameters:
      environment - the execution environment
      Returns:
      the result of evaluating this node
    • randomize

      public void randomize()
      Initializes the program tree using ramped half-and-half initialization.
      Specified by:
      randomize in interface Variable
    • encode

      public String encode()
      Description copied from interface: Variable
      Encodes the value of this variable as a string. This should reflect the internal representation of the value and not necessarily the actual value. For example, a binary-encoded integer should display the bits and not the integer value. Implementations should make an effort to display the value in a meaningful format, but that is not required. Instead, use Variable.toString() if a human-readable format is required. This method along with Variable.decode(String) are used primarily for storing values in text files. To make parsing easier, the resulting string must: 1. Only contain ASCII characters 2. Contain no whitespace (no spaces, tabs, newlines, etc.)
      Specified by:
      encode in interface Variable
      Returns:
      the encoded value as a string
    • decode

      public void decode(String value)
      Description copied from interface: Variable
      Parses and loads the value of this variable from a string. This must be able to process any string produced by Variable.encode().
      Specified by:
      decode in interface Variable
      Parameters:
      value - the value as a string