Package org.moeaframework.core.variable
Class Program
java.lang.Object
org.moeaframework.core.variable.AbstractVariable
org.moeaframework.core.variable.Program
A decision variable for programs. The program is represented as a strongly-typed expression tree.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.moeaframework.core.Defined
Defined.ConstructorComparator
-
Field Summary
Fields inherited from class org.moeaframework.core.variable.AbstractVariable
name
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncopy()
Creates and returns a copy of this object.void
Parses and loads the value of this variable from a string.encode()
Encodes the value of this variable as a string.boolean
evaluate
(Environment environment) Evaluates this program using the given environment.getBody()
Returns the body of this program.Returns the string representation, or definition, of this object.getRules()
Returns the rules defining the program syntax.int
hashCode()
void
Initializes the program tree using ramped half-and-half initialization.void
Sets the body of this program.Methods inherited from class org.moeaframework.core.variable.AbstractVariable
getName
-
Constructor Details
-
Program
Constructs a new program variable with the specified syntax rules.- Parameters:
rules
- the rules defining the program syntax
-
Program
Constructs a new program variable with the specified syntax rules and name.- Parameters:
name
- the name of this decision variablerules
- the rules defining the program syntax
-
-
Method Details
-
getRules
Returns the rules defining the program syntax.- Returns:
- the rules defining the program syntax
-
getBody
Returns the body of this program.- Returns:
- the top-level node
-
setBody
Sets the body of this program.- Parameters:
node
- the top-level node
-
copy
Description copied from interface:Copyable
Creates and returns a copy of this object. It is required thatx.copy()
is completely independent fromx
. This means any method invoked onx.copy()
in no way alters the state ofx
and vice versa. It is typically the case thatx.copy().getClass() == x.getClass()
andx.copy().equals(x)
.- Returns:
- the copy
-
evaluate
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
Description copied from interface:Defined
Returns the string representation, or definition, of this object.- Returns:
- the definition
-
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:- Only contain ASCII characters
- Contain no whitespace (no spaces, tabs, newlines, etc.)
- Returns:
- the encoded value as a string
-
decode
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 byVariable.encode()
.- Parameters:
value
- the value as a string
-
hashCode
public int hashCode()- Overrides:
hashCode
in classAbstractVariable
-
equals
- Overrides:
equals
in classAbstractVariable
-