Interface | Description |
---|---|
AbstractGenericOperator.OperatorPredicate |
The
AbstractGenericOperator.OperatorPredicate interface. |
GenericOperator<O extends org.opt4j.core.optimizer.Operator<?>> |
The
GenericOperator is an interface for generic operators. |
Class | Description |
---|---|
AbstractGenericOperator<O extends org.opt4j.core.optimizer.Operator<?>,Q extends org.opt4j.core.optimizer.Operator<?>> |
Superclass for
GenericOperator s. |
AbstractGenericOperator.ClassComparator |
Comparator for a specific order: Superclasses always are sorted after
subclasses.
|
AbstractGenericOperator.OperatorClassPredicate |
The
AbstractGenericOperator.OperatorClassPredicate returns true for a given
specific class. |
AbstractGenericOperator.OperatorHolder<P> | |
AbstractGenericOperator.OperatorVoidPredicate |
The
AbstractGenericOperator.OperatorVoidPredicate interface is used as marker for
Operator s for which the predicate is not explicitly defined. |
OperatorModule<P extends org.opt4j.core.optimizer.Operator> |
Module class for an
Operator . |
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
AbstractModule.configure(com.google.inject.Binder)
method by
bind(CustomOperator.class).to(CustomOperatorImplmenentation.class)
or
using the addOperator
methods in the respective
OperatorModule
. Note that this operator will only
handle exactly its target Genotype
classes. To
indicate a specific target, use the Apply
annotation at the respective operator class.
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<BooleanGenotype> { 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); } }