- All Implemented Interfaces:
TreeGene<Op<A>,
,ProgramGene<A>> FlatTree<Op<A>,
,ProgramGene<A>> Tree<Op<A>,
,ProgramGene<A>> Gene<Op<A>,
,ProgramGene<A>> Factory<ProgramGene<A>>
,Self<ProgramGene<A>>
,Verifiable
,Serializable
,Iterable<ProgramGene<A>>
,Function<A[],
A>
public final class ProgramGene<A>
extends AbstractTreeGene<Op<A>,ProgramGene<A>>
implements Gene<Op<A>,ProgramGene<A>>, Function<A[],A>
This gene represents a program, build upon an AST of
Op
functions.
Because of the tight coupling with the ProgramChromosome
, a
ProgramGene
can't be created directly. This reduces the possible
error space. Since the ProgramGene
also is a Tree
,
it can be easily used as a result.
final ProgramGene<Double> program = engine.stream()
.limit(300)
.collect(EvolutionResult.toBestGenotype())
.getGene();
final double result = program.eval(3.4);
- Since:
- 3.9
- Version:
- 5.2
- See Also:
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionEvaluates this program gene (recursively) with the given variable values.final A
Convenient method, which lets you apply the program function without explicitly create a wrapper array.newInstance
(Op<A> op) Create a new program gene with the given operation.newInstance
(Op<A> op, int childOffset, int childCount) Return a new program gene with the given operation and the local tree structure.Return the allowed operations.Return the allowed terminal operations.Creates a newTreeNode
from this program gene.Methods inherited from class io.jenetics.ext.AbstractTreeGene
allele, bind, checkTreeState, childAt, childCount, childOffset, equals, flattenedNodes, hashCode, isRoot, isValid, parent, root, size, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface io.jenetics.ext.util.Tree
breadthFirstIterator, breadthFirstStream, childAfter, childAtPath, childAtPath, childBefore, childIterator, childPath, childStream, depth, depthFirstIterator, depthFirstStream, firstChild, firstLeaf, identical, indexOf, isAncestor, isChild, isDescendant, isEmpty, isLeaf, isRelated, isSibling, iterator, lastChild, lastLeaf, leafCount, leaves, level, nextLeaf, nextNode, nextSibling, path, pathElements, pathFromAncestorIterator, postorderIterator, postorderStream, preorderIterator, preorderStream, previousLeaf, previousNode, previousSibling, reduce, sharedAncestor, siblingCount, stream, toParenthesesString, toParenthesesString
Methods inherited from interface io.jenetics.ext.TreeGene
newInstance, value
Methods inherited from interface io.jenetics.util.Verifiable
isValid
-
Method Details
-
apply
Evaluates this program gene (recursively) with the given variable values.- Specified by:
apply
in interfaceFunction<A[],
A> - Parameters:
args
- the input variables- Returns:
- the evaluated value
- Throws:
NullPointerException
- if the given variable array isnull
- See Also:
-
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
- See Also:
-
operations
Return the allowed operations.- Returns:
- the allowed operations
-
terminals
Return the allowed terminal operations.- Returns:
- the allowed terminal operations
-
toTreeNode
Creates a newTreeNode
from this program gene.- Returns:
- a new tree node value build from this program gene
- Since:
- 5.0
-
newInstance
- Specified by:
newInstance
in interfaceFactory<A>
- Specified by:
newInstance
in interfaceGene<Op<A>,
ProgramGene<A>>
-
newInstance
Create a new program gene with the given operation.- Specified by:
newInstance
in interfaceGene<Op<A>,
ProgramGene<A>> - Parameters:
op
- the operation of the new program gene- Returns:
- a new program gene with the given operation
- Throws:
NullPointerException
- if the givenop
isnull
IllegalArgumentException
- if the arity of the given operation is different from the arity of the current operation. This restriction ensures that only valid program genes are created by this method.
-
newInstance
Return a new program gene with the given operation and the local tree structure.- Specified by:
newInstance
in interfaceTreeGene<Op<A>,
ProgramGene<A>> - Parameters:
op
- the new operationchildOffset
- the offset of the first node child within the chromosomechildCount
- the number of children of the new tree gene- Returns:
- a new tree gene with the given parameters
- Throws:
IllegalArgumentException
- if thechildCount
is smaller than zeroIllegalArgumentException
- if the operation arity is different from thechildCount
.NullPointerException
- if the givenop
isnull
-