Module io.jenetics.prog
Package io.jenetics.prog.op
package io.jenetics.prog.op
Operations
When creating a new program tree, it is not necessary to implement own instance of theProgramGene
or ProgramChromosome
class. The
extension point for own programs is the Op
interface.
public interface Op<T> {
String name();
int arity();
T apply(T[] args);
}
final Op<Double> myop = Op.of("myop", 3, v -> v[0]*v[1] + v[2]);
NOTE: The class MathOp
in the
defines a set of mathematical standard operations/functions.
ProgramChromosome
we must
distinguish two different kind of operations:
- Non-terminal operations have an arity greater than zero and form their own sub-tree
- Terminal operations have an arity of zero and form the leaves of a program tree.
Var
,
Const
and
EphemeralConst
.
Var
TheVar
operation defines a variable of a program, which are set
from the program arguments.
final ISeq<Op<Double>> terminals = ISeq.of(
Var.of("x", 0), Var.of("y", 1), Var.of("z", 2)
);
Const
TheConst
operation will always return the same, constant, value
when evaluated.
final Op<Double> one = Const.of(1.0);
final Op<Double> pi = Const.of("π", Math.PI);
EphemeralConst
An ephemeral constant is a special constant, which is only constant within an tree. If a new tree is created, a new constant is created, by the `Supplier
function the ephemeral constant is created
with.
final Op<Double> rand1 = EphemeralConst.of(Math::random);
final Op<Double> rand2 = EphemeralConst.of("R", Math::random);
- Since:
- 3.9
- Version:
- 3.9
-
ClassDescriptionThis class contains basic and secondary boolean operations.Const<T>Represents an operation which always returns the same, constant, value.This class rewrites constant expressions to its single value.Implementation of an ephemeral constant.Contains methods for parsing mathematical expression.This class contains operations for performing basic numeric operations.Op<T>Operation interface.Program<T>This class composes a given operation tree to a new operation, which can serve as a sub program in another operation tree.Val<T>This is the sealed base class for unmodifiable values.Var<T>Represents the program variables.