| Interface | Description |
|---|---|
| AbstractGenericOperator.OperatorPredicate |
The
AbstractGenericOperator.OperatorPredicate interface. |
| GenericOperator<O extends Operator<?>> |
The
GenericOperator is an interface for generic operators. |
| Class | Description |
|---|---|
| AbstractGenericOperator<O extends Operator<?>,Q extends Operator<?>> |
Superclass for
GenericOperators. |
| AbstractGenericOperator.OperatorClassPredicate |
The
AbstractGenericOperator.OperatorClassPredicate returns true for a given
specific class. |
| AbstractGenericOperator.OperatorVoidPredicate |
The
AbstractGenericOperator.OperatorVoidPredicate interface is used as marker for
Operators for which the predicate is not explicitly defined. |
| OperatorModule<P extends Operator> |
Module class for an
Operator. |
| Parameters |
The
Parameters is a class for the identification of types/classes of
a generic parameter. |
| Annotation Type | Description |
|---|---|
| Apply |
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 to DoubleGenotype)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 genotypeOperator 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.
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);
}
}