Package org.opt4j.operators
Class AbstractGenericOperator<O extends org.opt4j.core.optimizer.Operator<?>,Q extends org.opt4j.core.optimizer.Operator<?>>
- java.lang.Object
-
- org.opt4j.operators.AbstractGenericOperator<O,Q>
-
- Type Parameters:
O
- The specifiedOperator
.Q
- The specifiedOperator
with a wildcard (?).
- All Implemented Interfaces:
GenericOperator<O>
- Direct Known Subclasses:
AlgebraGenericImplementation
,CopyGenericImplementation
,CrossoverGenericImplementation
,DiversityGenericImplementation
,MutateGenericImplementation
,NeighborGenericImplementation
public abstract class AbstractGenericOperator<O extends org.opt4j.core.optimizer.Operator<?>,Q extends org.opt4j.core.optimizer.Operator<?>> extends java.lang.Object implements GenericOperator<O>
Superclass forGenericOperator
s.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractGenericOperator.ClassComparator
Comparator for a specific order: Superclasses always are sorted after subclasses.static class
AbstractGenericOperator.OperatorClassPredicate
TheAbstractGenericOperator.OperatorClassPredicate
returnstrue
for a given specific class.protected static class
AbstractGenericOperator.OperatorHolder<P>
static interface
AbstractGenericOperator.OperatorPredicate
TheAbstractGenericOperator.OperatorPredicate
interface.static class
AbstractGenericOperator.OperatorVoidPredicate
TheAbstractGenericOperator.OperatorVoidPredicate
interface is used as marker forOperator
s for which the predicate is not explicitly defined.
-
Field Summary
Fields Modifier and Type Field Description protected com.google.common.collect.Multimap<java.lang.Class<? extends org.opt4j.core.Genotype>,O>
classOperators
protected java.util.List<java.lang.Class<? extends Q>>
cldef
protected com.google.common.collect.Multimap<AbstractGenericOperator.OperatorPredicate,O>
genericOperators
protected java.util.Map<java.util.AbstractMap.SimpleEntry<java.lang.Class<? extends org.opt4j.core.Genotype>,java.lang.Class<? extends org.opt4j.core.optimizer.Operator<?>>>,IOperatorSelector>
operatorSelectors
-
Constructor Summary
Constructors Constructor Description AbstractGenericOperator(java.lang.Class<? extends Q>... clazzes)
Constructs anAbstractGenericOperator
class with the given clazzes of default operators.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addOperator(AbstractGenericOperator.OperatorPredicate predicate, O operator)
Adds an operator.void
addOperatorSelector(java.util.AbstractMap.SimpleEntry<java.lang.Class<? extends org.opt4j.core.Genotype>,java.lang.Class<? extends org.opt4j.core.optimizer.Operator<?>>> selectorKey, IOperatorSelector selector)
Adds anIOperatorSelector
that decides whichOperator
is executed in case multipleOperator
s are registered for aGenotype
.O
getOperator(org.opt4j.core.Genotype genotype)
Returns theOperator
for a specificGenotype
.java.util.Collection<O>
getOperators()
Returns all classOperators.protected static <O> java.lang.Class<? extends org.opt4j.core.Genotype>
getTarget(O operator)
Returns the targetGenotype
for an operator based on theApply
annotation.protected void
inject(AbstractGenericOperator.OperatorHolder<Q> holder)
Inject and organize the operators.
-
-
-
Field Detail
-
operatorSelectors
protected java.util.Map<java.util.AbstractMap.SimpleEntry<java.lang.Class<? extends org.opt4j.core.Genotype>,java.lang.Class<? extends org.opt4j.core.optimizer.Operator<?>>>,IOperatorSelector> operatorSelectors
-
classOperators
protected com.google.common.collect.Multimap<java.lang.Class<? extends org.opt4j.core.Genotype>,O extends org.opt4j.core.optimizer.Operator<?>> classOperators
-
genericOperators
protected com.google.common.collect.Multimap<AbstractGenericOperator.OperatorPredicate,O extends org.opt4j.core.optimizer.Operator<?>> genericOperators
-
cldef
protected java.util.List<java.lang.Class<? extends Q extends org.opt4j.core.optimizer.Operator<?>>> cldef
-
-
Constructor Detail
-
AbstractGenericOperator
public AbstractGenericOperator(java.lang.Class<? extends Q>... clazzes)
Constructs anAbstractGenericOperator
class with the given clazzes of default operators.- Parameters:
clazzes
- the default operators
-
-
Method Detail
-
inject
@Inject protected void inject(AbstractGenericOperator.OperatorHolder<Q> holder)
Inject and organize the operators.- Parameters:
holder
- the operator holder
-
addOperator
public void addOperator(AbstractGenericOperator.OperatorPredicate predicate, O operator)
Description copied from interface:GenericOperator
Adds an operator.- Specified by:
addOperator
in interfaceGenericOperator<O extends org.opt4j.core.optimizer.Operator<?>>
- Parameters:
predicate
- the operator predicateoperator
- TheOperator
-
addOperatorSelector
public void addOperatorSelector(java.util.AbstractMap.SimpleEntry<java.lang.Class<? extends org.opt4j.core.Genotype>,java.lang.Class<? extends org.opt4j.core.optimizer.Operator<?>>> selectorKey, IOperatorSelector selector)
Description copied from interface:GenericOperator
Adds anIOperatorSelector
that decides whichOperator
is executed in case multipleOperator
s are registered for aGenotype
.- Specified by:
addOperatorSelector
in interfaceGenericOperator<O extends org.opt4j.core.optimizer.Operator<?>>
selector
- TheIOperatorSelector
to add.
-
getOperator
public O getOperator(org.opt4j.core.Genotype genotype)
Description copied from interface:GenericOperator
Returns theOperator
for a specificGenotype
.- Specified by:
getOperator
in interfaceGenericOperator<O extends org.opt4j.core.optimizer.Operator<?>>
- Parameters:
genotype
- the genotype- Returns:
- the operator for this genotype
-
getOperators
public java.util.Collection<O> getOperators()
Description copied from interface:GenericOperator
Returns all classOperators.- Specified by:
getOperators
in interfaceGenericOperator<O extends org.opt4j.core.optimizer.Operator<?>>
- Returns:
- all classOperators
-
getTarget
protected static <O> java.lang.Class<? extends org.opt4j.core.Genotype> getTarget(O operator)
Returns the targetGenotype
for an operator based on theApply
annotation.- Type Parameters:
O
- the type of operator- Parameters:
operator
- the operator- Returns:
- the target genotype
-
-