es.udc.gii.common.eaf.algorithm.parallel.migration.acceptance
Class BinaryAcceptancePolicy

java.lang.Object
  extended by es.udc.gii.common.eaf.algorithm.parallel.migration.acceptance.BinaryAcceptancePolicy
All Implemented Interfaces:
MigAcceptancePolicy, Configurable
Direct Known Subclasses:
IntersectionAcceptancePolicy, UnionAcceptancePolicy

public abstract class BinaryAcceptancePolicy
extends java.lang.Object
implements MigAcceptancePolicy

With this class complex acceptance policies can be created as binary trees. The left and right components must not be null. A runtime exception will be thrown if setting either of them to null or when calling the accept(es.udc.gii.common.eaf.algorithm.parallel.topology.migration.MigrationObject, es.udc.gii.common.eaf.algorithm.EvolutionaryAlgorithm, java.util.List) method with some of them set to null.

Since:
1.0
Author:
Grupo Integrado de IngenierĂ­a (www.gii.udc.es)

Field Summary
private  MigAcceptancePolicy leftComponent
          Left component of this node.
private  MigAcceptancePolicy rightComponent
          Right component of this node.
 
Constructor Summary
BinaryAcceptancePolicy()
          Creates a new instance of BinaryAcceptancePolicy
BinaryAcceptancePolicy(MigAcceptancePolicy leftComponent, MigAcceptancePolicy rightComponent)
          Creates a new instance of BinaryAcceptancePolicy
 
Method Summary
 java.util.List<Individual> accept(MigrationObject migrant, EvolutionaryAlgorithm algorithm, java.util.List<Individual> currentPopulation)
          Accepts the individuals that come in a MigrationObject based on some criterion.
protected abstract  java.util.List<Individual> binaryOperation(java.util.List<Individual> acceptedFromLeft, java.util.List<Individual> acceptedFromRight)
          The concrete binary operation that is performed with the results of the left and right components.
 void configure(org.apache.commons.configuration.Configuration conf)
          Configures this object.
 MigAcceptancePolicy getLeftComponent()
           
 MigAcceptancePolicy getRightComponent()
           
 void setLeftComponent(MigAcceptancePolicy leftComponent)
          Set the left component of this node.
 void setRightComponent(MigAcceptancePolicy rightComponent)
          Set the right component of this node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

leftComponent

private MigAcceptancePolicy leftComponent
Left component of this node.


rightComponent

private MigAcceptancePolicy rightComponent
Right component of this node.

Constructor Detail

BinaryAcceptancePolicy

public BinaryAcceptancePolicy()
Creates a new instance of BinaryAcceptancePolicy


BinaryAcceptancePolicy

public BinaryAcceptancePolicy(MigAcceptancePolicy leftComponent,
                              MigAcceptancePolicy rightComponent)
Creates a new instance of BinaryAcceptancePolicy

Method Detail

accept

public java.util.List<Individual> accept(MigrationObject migrant,
                                         EvolutionaryAlgorithm algorithm,
                                         java.util.List<Individual> currentPopulation)
Accepts the individuals that come in a MigrationObject based on some criterion.

This method calls first the same method of its left component, then the same method of its right component and finally it relies on the protected binaryOperation(java.util.List, java.util.List) method for merging the two results accordingly.

Specified by:
accept in interface MigAcceptancePolicy
Returns:
A list of the accepted individuals. If no individual is accepted, then an empty list is returned.

binaryOperation

protected abstract java.util.List<Individual> binaryOperation(java.util.List<Individual> acceptedFromLeft,
                                                              java.util.List<Individual> acceptedFromRight)
The concrete binary operation that is performed with the results of the left and right components.


configure

public void configure(org.apache.commons.configuration.Configuration conf)
Configures this object.

Configuration example:

 <AcceptancePolicy>
     <Class>subclass of BinaryAcceptancePolicy</Class>

     <AcceptancePolicy>
         <Class>...GenerationBasedAcceptance</Class>
         <AcceptIndividualsFrom>ANY_GENERATION</AcceptIndividualsFrom>
     </AcceptancePolicy>

     <AcceptancePolicy>
         <Class>subclass of BinaryAcceptancePolicy</Class>

         <AcceptancePolicy>
             <Class>...GenerationBasedAcceptance</Class>
         <AcceptIndividualsFrom>SOME_GENERATION</AcceptIndividualsFrom>
         </AcceptancePolicy>

         <AcceptancePolicy>
             <Class>some MigAcceptancePolicy</Class>
             ...
         </AcceptancePolicy>
     </AcceptancePolicy>
 </AcceptancePolicy>
 

This constructs the following tree:

               (B1)
              /    \
            (G1)  (B2)
                 /    \
               (G2)   (M)
 

B1 is the constructed BinaryAcceptancePolicy. Its left component is a GenerationBasedAcceptance (G1) with parameter ANY_GENERATION. Its right component is also a BinaryAcceptancePolicy with another GenerationBasedAcceptance (G2) with parameter SOME_GENERATION as left component and some other implementation of MigAcceptancePolicy as right component.

Specified by:
configure in interface Configurable
Parameters:
conf - a Configuration object.
See Also:
Configuration

getLeftComponent

public MigAcceptancePolicy getLeftComponent()

setLeftComponent

public void setLeftComponent(MigAcceptancePolicy leftComponent)
Set the left component of this node. If null is passed, a runtime exception is thrown.


getRightComponent

public MigAcceptancePolicy getRightComponent()

setRightComponent

public void setRightComponent(MigAcceptancePolicy rightComponent)
Set the right component of this node. If null is passed, a runtime exception is thrown.