jenes.stage
Class Dispenser<T extends Chromosome>

java.lang.Object
  extended by jenes.stage.Dispenser<T>
Type Parameters:
T - The class chromosomes flowing across the stage.
Direct Known Subclasses:
ExclusiveDispenser

public abstract class Dispenser<T extends Chromosome>
extends java.lang.Object

A Dispencer distributes a population between the branches of a parallel stage and merges the output of each branch in the output population of the parallel.

The distribute method adds individual taken from the input population in one (or more) of the input population of the branches (see distribute(Population, Population[])). The number of branches is indicated by the span parameter passed to the constructor.

For example, if span==2 can have

           
        int count=0;    
        for( Individual i : in ) {
                int branch=count%2;
                        branches[branch].add(i);
        }
 
The method mergePopulation(Population[], Population) takes the output populations from the branches array and merges them in the output population according to some policy. A simple implementation is:

        int count = 0;
        for(Population  branch : branches) {
                for(Individual i : branch) {
                        Individual dest = out.getIndividual(count++);
                        // This check is necessary because out could have
                        // lesser elements than those resulting from branches
                        if( dest != null )
                                dest.setAs(i);
                        else{
                                if(count<=out.size())
                                        throw new IllegalStateException("out population can't contains null individual");
                                out.add(i.clone());
                        }
                }
        }
 
        // If out has more elements than the sum of elements
        // resulting from branches, we remove the exceeding elements
        int outSize=out.size();
        for( int i = outSize-1; i >= count; --i )
                out.remove(i);
 

Since:
1.0
Version:
1.2
Author:
Luigi Troiano, Pierpaolo Lombardi, Giuseppe Pascale, Thierry Bodhuin
See Also:
Parallel

Field Summary
protected  int span
          The dispencer amplitude, that is the number of populations where it will add individuals in the distribution method
 
Constructor Summary
Dispenser(int span)
          Constructs a new dispencer with the specfied amplitude
 
Method Summary
abstract  void distribute(Population<T> in, Population<T>[] branches)
          Distributes the specified population between those ones in the specified array.
abstract  void mergePopulation(Population<T>[] branches, Population<T> out)
          Merges the populations within the specified array in the specified one.
 int span()
          Returns the dispenser amplitude.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

span

protected int span
The dispencer amplitude, that is the number of populations where it will add individuals in the distribution method

Constructor Detail

Dispenser

public Dispenser(int span)
Constructs a new dispencer with the specfied amplitude

Parameters:
span - the dispencer amplitude
Method Detail

span

public int span()
Returns the dispenser amplitude.

Returns:
the dispenser amplitude

distribute

public abstract void distribute(Population<T> in,
                                Population<T>[] branches)
Distributes the specified population between those ones in the specified array. If some populations within inStagePop are not empty they will contain the initial individuals too at the end of distribute operation.

Parameters:
in - the population to be distributed
branches - the array of sub populations of the initial one

mergePopulation

public abstract void mergePopulation(Population<T>[] branches,
                                     Population<T> out)
Merges the populations within the specified array in the specified one. If population is not empty it will contain the initial individuals too at the end of merge operation.

Parameters:
out - the final population
branches - the populations to be merged