Package org.opt4j.operator
Provides the classes for general (generic) operators.
The Genotype
objects are changed within the
optimization process in order to find better solutions. The variation is
performed by the Operator
classes. The
framework already contains several operators:
Algebra
- Vector-based operator with terms (restricted toDoubleGenotype
)Copy
- Copy operatorCrossover
- Crossover operator that always creates two offspring from two parentsDiversity
- Diversity operator that determines the differences between two genotypesMutate
- Mutate operator that changes one genotypeNeighbor
- Neighbor operator that changes one genotype
Operator
is parameterized with the corresponding target Genotype
. Adding custom operators, e.g., a new Crossover
operator
for the DoubleGenotype
, is quite simple. The new operator has to be
extended from Crossover
with the
parameter DoubleGenotype
or alternatively directly from the
CrossoverDouble
. The corresponding
crossover method has to be implemented. Finally, the operator has to be added
with the
OperatorModule.addOperator(Class)
method. Therefore, you can extend a custom module from
CrossoverModule
.
The appropriate operator is determined at runtime by the framework by
checking the parameter of the operator. Alternatively, the
Apply
annotation can be used to specify a
different target Genotype
class.
Creating completely new operators is done by extending the Operator
interface to the new operator with the specific method. The new operator
implementation can be bound directly within a module in the org.opt4j.operator.OperatorModule#configure(com.google.inject.Binder)
method by
bind(CustomOperator.class).to(CustomOperatorImplmenentation.class)
. Note
that this operator will only handle exactly its target Genotype
classes.
A new generic operator should be instantiated from the
AbstractGenericOperator
. See the existing generic
operators.
Integration of a Custom Operator
To add new operators, two tasks have to be performed:- The implementation of the custom operator
- The binding of the operator
Crossover
operator for the
BooleanGenotype
shall be implemented that performs a bitwise or for
one offspring and a bitwise and for the other offspring.
public class MyOperator implements Crossover<Boolean> {
public Pair<BooleanGenotype> crossover(BooleanGenotype parent1, BooleanGenotype parent2) {
BooleanGenotype g1 = parent1.newInstance();
BooleanGenotype g2 = parent1.newInstance();
for (int i = 0; i < parent1.size(); i++) {
g1.add(i, parent1.get(i) || parent2.get(i));
g2.add(i, parent1.get(i) && parent2.get(i));
}
return new Pair<BooleanGenotype>(g1, g2);
}
}
To tell the framework to use this operator, implement a
CrossoverModule
and add your custom operator.
public class MyOperatorModule extends CrossoverModule {
protected void config() {
addOperator(MyOperator.class);
}
}
-
ClassDescriptionSuperclass for
GenericOperator
s.Comparator for a specific order: Superclasses always are sorted after subclasses.TheAbstractGenericOperator.OperatorClassPredicate
returnstrue
for a given specific class.TheAbstractGenericOperator.OperatorPredicate
interface.TheAbstractGenericOperator.OperatorVoidPredicate
interface is used as marker forOperator
s for which the predicate is not explicitly defined.GenericOperator<O extends Operator<?>>TheGenericOperator
is an interface for generic operators.OperatorModule<P extends Operator>Module class for anOperator
.TheParameters
is a class for the identification of types/classes of a generic parameter.