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 the ProgramGene 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]);
In the example above, a new operation with the "myop" and arity 3 is defined. Whenever the operation is evaluated, the function f(x, y, z) = x*y + z is executed.

NOTE: The class MathOp in the defines a set of mathematical standard operations/functions.

When creating a new ProgramChromosome we must distinguish two different kind of operations:
  1. Non-terminal operations have an arity greater than zero and form their own sub-tree
  2. Terminal operations have an arity of zero and form the leaves of a program tree.
There are currently three different types of non-terminal operations implemented, Var, Const and EphemeralConst.

Var

The Var 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)
);
The terminal operation list in the example code above will lead to a program which takes three input parameters, x, y and z, with the argument indices 0, 1 and 2.

Const

The Const 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);
We can create a constant operation in to flavors, with a value only and with a dedicated name. If a constant has a name, the symbolic name is used, instead of the value, when the program tree is printing.

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
  • Class
    Description
    This class contains basic and secondary boolean operations.
    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.
    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.