public final class ProgramGene<A> extends AbstractTreeGene<Op<A>,ProgramGene<A>> implements Gene<Op<A>,ProgramGene<A>>, Function<A[],A>
Op functions.
Because of the tight coupling with the ProgramChromosome, a
ProgramGene can't be created directly. This reduces the the possible
error space. Since the ProgramGene also is a Tree,
it can be easily used as result.
final ProgramGene<Double> program = engine.stream()
.limit(300)
.collect(EvolutionResult.toBestGenotype())
.getGene();
final double result = program.eval(3.4);| Modifier and Type | Method and Description |
|---|---|
A |
apply(A[] args)
Evaluates this program gene (recursively) with the given variable values.
|
A |
eval(A... args)
Convenient method, which lets you apply the program function without
explicitly create a wrapper array.
|
ISeq<? extends Op<A>> |
getOperations()
Return the allowed operations.
|
ISeq<? extends Op<A>> |
getTerminals()
Return the allowed terminal operations.
|
ProgramGene<A> |
newInstance() |
ProgramGene<A> |
newInstance(Op<A> op)
Create a new program gene with the given operation.
|
ProgramGene<A> |
newInstance(Op<A> op,
int childOffset,
int childCount)
Return a new program gene with the given operation and the local
tree structure.
|
TreeNode<Op<A>> |
toTreeNode()
Creates a new
TreeNode from this program gene. |
bind, checkTreeState, childAt, childCount, childOffset, equals, flattenedNodes, getAllele, getParent, getRoot, hashCode, isRoot, isValid, size, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitisValidbreadthFirstIterator, breadthFirstStream, childAfter, childAtPath, childAtPath, childBefore, childIterator, childPath, childStream, depth, depthFirstIterator, depthFirstStream, equals, firstChild, firstLeaf, getPath, hashCode, identical, indexOf, isAncestor, isChild, isDescendant, isLeaf, isRelated, isSibling, iterator, lastChild, lastLeaf, leafCount, level, nextLeaf, nextNode, nextSibling, path, pathElements, pathFromAncestorIterator, postorderIterator, postorderStream, preorderIterator, preorderStream, previousLeaf, previousNode, previousSibling, sharedAncestor, siblingCount, stream, toParenthesesString, toParenthesesString, toStringforEach, spliteratorpublic A apply(A[] args)
apply in interface Function<A[],A>args - the input variablesNullPointerException - if the given variable array is nulleval(Object[]),
ProgramChromosome.eval(Object[])@SafeVarargs public final A eval(A... args)
args - the function argumentsNullPointerException - if the given variable array is nullapply(Object[]),
ProgramChromosome.eval(Object[])public ISeq<? extends Op<A>> getOperations()
public ISeq<? extends Op<A>> getTerminals()
public TreeNode<Op<A>> toTreeNode()
TreeNode from this program gene.public ProgramGene<A> newInstance()
newInstance in interface Gene<Op<A>,ProgramGene<A>>newInstance in interface Factory<ProgramGene<A>>public ProgramGene<A> newInstance(Op<A> op)
newInstance in interface Gene<Op<A>,ProgramGene<A>>op - the operation of the new program geneNullPointerException - if the given op is nullIllegalArgumentException - if the arity of the given operation is
different from the arity of current operation. This restriction
ensures that only valid program genes are created by this method.public ProgramGene<A> newInstance(Op<A> op, int childOffset, int childCount)
newInstance in interface TreeGene<Op<A>,ProgramGene<A>>op - the new operationchildOffset - the offset of the first node child within the
chromosomechildCount - the number of children of the new tree geneIllegalArgumentException - if the childCount is smaller
than zeroIllegalArgumentException - if the operation arity is different from
the childCount.NullPointerException - if the given op is null© 2007-2019 Franz Wilhelmstötter (2019-11-18 20:30)