Class Program

All Implemented Interfaces:
Serializable, Copyable<Variable>, Defined, Named, Variable

public class Program extends AbstractVariable
A decision variable for programs. The program is represented as a strongly-typed expression tree.
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
    • Program

      public Program(String name, Rules rules)
      Constructs a new program variable with the specified syntax rules and name.
      Parameters:
      name - the name of this decision variable
      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
    • getBody

      public Node getBody()
      Returns the body of this program.
      Returns:
      the top-level node
    • setBody

      public void setBody(Node node)
      Sets the body of this program.
      Parameters:
      node - the top-level node
    • copy

      public Program copy()
      Description copied from interface: Copyable
      Creates and returns a copy of this object. 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).
      Returns:
      the copy
    • evaluate

      public Object evaluate(Environment environment)
      Evaluates this program using the given environment.
      Parameters:
      environment - the environment
      Returns:
      the result
    • randomize

      public void randomize()
      Initializes the program tree using ramped half-and-half initialization.
    • getDefinition

      public String getDefinition()
      Description copied from interface: Defined
      Returns the string representation, or definition, of this object.
      Returns:
      the definition
    • 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.)
      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().
      Parameters:
      value - the value as a string
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class AbstractVariable
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class AbstractVariable