T
- The class chromosomes flowing across the stage.public abstract class Dispenser<T extends Chromosome>
extends java.lang.Object
distribute(Population, Population[])
). The number of branches is indicated by the
span parameter passed to the constructor.The methodint count=0; for( Individuali : in ) { int branch=count%2; branches[branch].add(i); }
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(Populationbranch : 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);
Parallel
Modifier and Type | Field and Description |
---|---|
protected int |
span
The dispencer amplitude, that is the number of populations where it will add individuals
in the distribution method
|
Constructor and Description |
---|
Dispenser(int span)
Constructs a new dispencer with the specfied amplitude
|
Modifier and Type | Method and Description |
---|---|
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.
|
protected int span
public Dispenser(int span)
span
- the dispencer amplitudepublic int span()
public abstract void distribute(Population<T> in, Population<T>[] branches)
in
- the population to be distributedbranches
- the array of sub populations of the initial onepublic abstract void mergePopulation(Population<T>[] branches, Population<T> out)
out
- the final populationbranches
- the populations to be merged