public class ProgramChromosome<A> extends AbstractTreeChromosome<Op<A>,ProgramGene<A>>
final int depth = 6;
final ISeq<Op<Double>> operations = ISeq.of(...);
final ISeq<Op<Double>> terminals = ISeq.of(...);
final ProgramChromosome<Double> ch = ProgramChromosome.of(
depth,
// If the program has more that 200 nodes, it is marked as "invalid".
ch -> ch.length() <= 200,
operations,
terminals
);
_genes, _valid
Modifier | Constructor and Description |
---|---|
protected |
ProgramChromosome(ISeq<ProgramGene<A>> program,
Predicate<? super ProgramChromosome<A>> validator,
ISeq<? extends Op<A>> operations,
ISeq<? extends Op<A>> terminals)
Create a new program chromosome from the given program genes.
|
Modifier and Type | Method and Description |
---|---|
A |
apply(A[] args)
Evaluates the root node of this chromosome.
|
A |
eval(A... args)
Evaluates the root node of this chromosome.
|
ISeq<? extends Op<A>> |
getOperations()
Return the allowed operations.
|
ISeq<? extends Op<A>> |
getTerminals()
Return the allowed terminal operations.
|
boolean |
isValid() |
ProgramChromosome<A> |
newInstance() |
ProgramChromosome<A> |
newInstance(ISeq<ProgramGene<A>> genes) |
static <A> ProgramChromosome<A> |
of(int depth,
ISeq<? extends Op<A>> operations,
ISeq<? extends Op<A>> terminals)
Create a new program chromosome with the defined depth.
|
static <A> ProgramChromosome<A> |
of(int depth,
Predicate<? super ProgramChromosome<A>> validator,
ISeq<? extends Op<A>> operations,
ISeq<? extends Op<A>> terminals)
Create a new program chromosome with the defined depth.
|
static <A> ProgramChromosome<A> |
of(ISeq<ProgramGene<A>> genes,
ISeq<? extends Op<A>> operations,
ISeq<? extends Op<A>> terminals) |
static <A> ProgramChromosome<A> |
of(ISeq<ProgramGene<A>> genes,
Predicate<? super ProgramChromosome<A>> validator,
ISeq<? extends Op<A>> operations,
ISeq<? extends Op<A>> terminals)
Create a new program chromosome from the given (flattened) program tree.
|
static <A> ProgramChromosome<A> |
of(Tree<? extends Op<A>,?> program,
ISeq<? extends Op<A>> operations,
ISeq<? extends Op<A>> terminals)
Create a new chromosome from the given operation tree (program).
|
static <A> ProgramChromosome<A> |
of(Tree<? extends Op<A>,?> program,
Predicate<? super ProgramChromosome<A>> validator,
ISeq<? extends Op<A>> operations,
ISeq<? extends Op<A>> terminals)
Create a new chromosome from the given operation tree (program).
|
equals, getGene, hashCode, iterator, length, toSeq, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getRoot
forEach, iterator, spliterator
protected ProgramChromosome(ISeq<ProgramGene<A>> program, Predicate<? super ProgramChromosome<A>> validator, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals)
program
is valid. Since the
program validation is quite expensive, the validity check is skipped in
this constructor.program
- the program. During the program evolution, newly created
program trees has the same depth than this tree.validator
- the chromosome validator. A typical validator would
check the size of the tree and if the tree is too large, mark it
at invalid. The validator may be null
.operations
- the allowed non-terminal operationsterminals
- the allowed terminal operationsNullPointerException
- if one of the given arguments is null
IllegalArgumentException
- if either the operations
or
terminals
sequence is emptypublic ISeq<? extends Op<A>> getOperations()
public ISeq<? extends Op<A>> getTerminals()
public boolean isValid()
isValid
in interface Verifiable
isValid
in class AbstractChromosome<ProgramGene<A>>
public A apply(A[] args)
args
- the input variablesNullPointerException
- if the given variable array is null
ProgramGene.apply(Object[])
,
eval(Object[])
@SafeVarargs public final A eval(A... args)
args
- the function argumentsNullPointerException
- if the given variable array is null
ProgramGene.eval(Object[])
,
apply(Object[])
public ProgramChromosome<A> newInstance(ISeq<ProgramGene<A>> genes)
public ProgramChromosome<A> newInstance()
public static <A> ProgramChromosome<A> of(Tree<? extends Op<A>,?> program, Predicate<? super ProgramChromosome<A>> validator, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals)
A
- the operation typeprogram
- the operation treevalidator
- the chromosome validator. A typical validator would
check the size of the tree and if the tree is too large, mark it
at invalid. The validator may be null
.operations
- the allowed non-terminal operationsterminals
- the allowed terminal operationsNullPointerException
- if one of the given arguments is null
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.public static <A> ProgramChromosome<A> of(Tree<? extends Op<A>,?> program, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals)
A
- the operation typeprogram
- the operation treeoperations
- the allowed non-terminal operationsterminals
- the allowed terminal operationsNullPointerException
- if one of the given arguments is null
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.public static <A> ProgramChromosome<A> of(int depth, Predicate<? super ProgramChromosome<A>> validator, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals)
A
- the operation typedepth
- the depth of the created program treevalidator
- the chromosome validator. A typical validator would
check the size of the tree and if the tree is too large, mark it
at invalid. The validator may be null
.operations
- the allowed non-terminal operationsterminals
- the allowed terminal operationsNullPointerException
- if one of the parameters is null
IllegalArgumentException
- if the depth
is smaller than zeropublic static <A> ProgramChromosome<A> of(int depth, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals)
A
- the operation typedepth
- the depth of the created (full) program treeoperations
- the allowed non-terminal operationsterminals
- the allowed terminal operationsNullPointerException
- if one of the parameters is null
IllegalArgumentException
- if the depth
is smaller than zeropublic static <A> ProgramChromosome<A> of(ISeq<ProgramGene<A>> genes, Predicate<? super ProgramChromosome<A>> validator, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals)
final ProgramChromosome<Double> ch = ProgramChromosome.of(
genes,
// If the program has more that 200 nodes, it is marked as "invalid".
ch -> ch.length() <= 200,
operations,
terminals
);
A
- the operation typegenes
- the program genesvalidator
- the chromosome validator to useoperations
- the allowed non-terminal operationsterminals
- the allowed terminal operationsNullPointerException
- if one of the parameters is null
public static <A> ProgramChromosome<A> of(ISeq<ProgramGene<A>> genes, ISeq<? extends Op<A>> operations, ISeq<? extends Op<A>> terminals)
© 2007-2018 Franz Wilhelmstötter (2018-10-28 17:23)