java.lang.Object
io.jenetics.prog.op.Program<T>
- Type Parameters:
T
- the argument type of the operation
- All Implemented Interfaces:
Op<T>
,Serializable
,Function<T[],
,T> Supplier<Op<T>>
This class composes a given operation tree to a new operation, which can
serve as a sub program in another operation tree.
- Since:
- 3.9
- Version:
- 4.1
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
arity()
Return the arity of the operation function.static void
Validates the given program tree.boolean
static <T> T
Evaluates the given operation tree with the given variables.final T
Convenient method, which lets you apply the program function without explicitly create a wrapper array.int
hashCode()
name()
Return the name of the operation.Create a new, random program tree from the given (non) terminal operations with the desired depth.of
(int depth, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals, RandomGenerator random) Create a new, random program tree from the given (non) terminal operations with the desired depth.static <A> Program
<A> Create a new, random program from the given (non) terminal operations with the desired depth.static <A> Program
<A> of
(String name, int depth, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals, RandomGenerator random) Create a new, random program from the given (non) terminal operations with the desired depth.toString()
Creates a valid program tree from the given flattened sequence of op nodes.tree()
Return the underlying expression tree.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.jenetics.prog.op.Op
get, isTerminal
-
Constructor Details
-
Program
Create a new program with the given name and the given operation tree. The arity of the program is calculated from the given operation tree and set to the maximal arity of the operations of the tree.- Parameters:
name
- the program nametree
- the operation tree- Throws:
NullPointerException
- if one of the given arguments isnull
IllegalArgumentException
- if the given operation tree is invalid, which means there is at least one node where the operation arity and the node child count differ.
-
-
Method Details
-
name
Description copied from interface:Op
Return the name of the operation. -
arity
Description copied from interface:Op
Return the arity of the operation function. If the arity is zero, the operation is terminal operation. -
tree
Return the underlying expression tree.- Returns:
- the underlying expression tree
- Since:
- 4.1
-
apply
-
eval
Convenient method, which lets you apply the program function without explicitly create a wrapper array.- Parameters:
args
- the function arguments- Returns:
- the evaluated value
- Throws:
NullPointerException
- if the given variable array isnull
IllegalArgumentException
- if the length of the argument array is smaller than the program arity- See Also:
-
hashCode
-
equals
-
toString
-
eval
Evaluates the given operation tree with the given variables. This method is equivalent tofinal T result = tree.reduce(variables, Op::apply);
variables
array more conveniently.- Type Parameters:
T
- the argument type- Parameters:
tree
- the operation treevariables
- the input variables- Returns:
- the result of the operation tree evaluation
- Throws:
NullPointerException
- if one of the arguments isnull
IllegalArgumentException
- if the length of the variable array is smaller than the program arity- See Also:
-
check
Validates the given program tree.- Parameters:
program
- the program to validate- Throws:
NullPointerException
- if the givenprogram
isnull
IllegalArgumentException
- if the given operation tree is invalid, which means there is at least one node where the operation arity and the node child count differ.
-
of
public static <A> Program<A> of(String name, int depth, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals) Create a new, random program from the given (non) terminal operations with the desired depth. The created program tree is a full tree.- Type Parameters:
A
- the operational type- Parameters:
name
- the program namedepth
- the desired depth of the program treeoperations
- the list of non-terminal operationsterminals
- the list of terminal operations- Returns:
- a new program
- Throws:
NullPointerException
- if one of the given operations isnull
IllegalArgumentException
- if the given tree depth is smaller than zero- Since:
- 4.1
-
of
public static <A> Program<A> of(String name, int depth, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals, RandomGenerator random) Create a new, random program from the given (non) terminal operations with the desired depth. The created program tree is a full tree.- Type Parameters:
A
- the operational type- Parameters:
name
- the program namedepth
- the desired depth of the program treeoperations
- the list of non-terminal operationsterminals
- the list of terminal operationsrandom
- the random engine used for creating the program- Returns:
- a new program
- Throws:
NullPointerException
- if one of the given operations isnull
IllegalArgumentException
- if the given tree depth is smaller than zero- Since:
- 4.1
-
of
public static <A> TreeNode<Op<A>> of(int depth, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals) Create a new, random program tree from the given (non) terminal operations with the desired depth. The created program tree is a full tree.- Type Parameters:
A
- the operational type- Parameters:
depth
- the desired depth of the program treeoperations
- the list of non-terminal operationsterminals
- the list of terminal operations- Returns:
- a new program tree
- Throws:
NullPointerException
- if one of the given operations isnull
IllegalArgumentException
- if the given tree depth is smaller than zero
-
of
public static <A> TreeNode<Op<A>> of(int depth, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals, RandomGenerator random) Create a new, random program tree from the given (non) terminal operations with the desired depth. The created program tree is a full tree.- Type Parameters:
A
- the operational type- Parameters:
depth
- the desired depth of the program treeoperations
- the list of non-terminal operationsterminals
- the list of terminal operationsrandom
- the random engine used for creating the program- Returns:
- a new program tree
- Throws:
NullPointerException
- if one of the given operations isnull
IllegalArgumentException
- if the given tree depth is smaller than zero- Since:
- 4.1
-
toTree
public static <A> TreeNode<Op<A>> toTree(ISeq<? extends FlatTree<? extends Op<A>, ?>> nodes, ISeq<? extends Op<A>> terminals) Creates a valid program tree from the given flattened sequence of op nodes. The givenoperations
andtermination
nodes are used for repairing the program tree, if necessary.- Type Parameters:
A
- the operation argument type- Parameters:
nodes
- the flattened, possible corrupt, program treeterminals
- the usable non-terminal operation nodes to use for reparation- Returns:
- a new valid program tree build from the flattened program tree
- Throws:
NullPointerException
- if one of the arguments isnull
IllegalArgumentException
- if thenodes
sequence is empty
-