T
- The class chromosomes flowing across the stage.public class Parallel<T extends Chromosome> extends AbstractStage<T>
Dispenser.distribute(Population, Population[])
).
Each branch is a stage and can be added with the add(AbstractStage)
method.
The output population is obtained merging the output of each branch.
The dispenser is responsable of this merging.
Note: generally a dispenser can add the same input individual in different branches. So don't modify the stages input individuals.
Dispenser
,
ExclusiveDispenser
biggerIsBetter, fitness, ga
Constructor and Description |
---|
Parallel(Dispenser<T> dispenser)
Constructs a new parallel stage with the specified dispenser.
|
Modifier and Type | Method and Description |
---|---|
void |
add(AbstractStage<T> stage)
Adds a new branch to this parallel stage.
|
void |
dispose()
Disposes this stage
|
protected void |
distribute(Population<T> in,
Population<T>[] branches)
Distributes the specified population between those ones in the specified array.
|
void |
init(GeneticAlgorithm<T> ga)
Initializes this stage according to the genetic algorithm
that uses it
|
protected void |
mergePopulation(Population<T>[] branches,
Population<T> out)
Merges the populations within the specified array in the specified one.
|
void |
process(Population<T> in,
Population<T> out)
Processes the input population and tranforms it into the output population.
|
void |
remove(AbstractStage<T> stage)
Removes a stage from the parallel andall the stages it contains.
|
void |
remove(int index)
Removes a specified branch from the parallel
|
void |
removeAllBranches()
Removes all the branch stages from this parallel
|
void |
setBiggerIsBetter(boolean flag,
boolean recursively)
Deprecated.
|
void |
setBranch(int index,
AbstractStage<T> stage)
Sets the specified stage at the specified branch number replacing the
stage already present
|
void |
setFitness(Fitness fit,
boolean recursively)
Change the
Fitness to this stage propagating the change recursively
according to the flag given as parameter |
getFitness, isBiggerBetter, isFitnessChanged, setBiggerIsBetter, setFitness
public void add(AbstractStage<T> stage)
stage
- the stage to be added as branchpublic void remove(AbstractStage<T> stage)
stage
- the stage to removepublic void remove(int index)
index
- the branch index to removepublic void setBranch(int index, AbstractStage<T> stage)
index
- the branch number where to set the new stagestage
- the stage to addpublic void removeAllBranches()
public void init(GeneticAlgorithm<T> ga) throws StageException
AbstractStage
init
in class AbstractStage<T extends Chromosome>
ga
- the Genetic Algorithm in wchic this stage runStageException
public void dispose()
AbstractStage
dispose
in class AbstractStage<T extends Chromosome>
public final void process(Population<T> in, Population<T> out) throws StageException
AbstractStage
process
in class AbstractStage<T extends Chromosome>
in
- the input populationout
- the output populationStageException
protected void distribute(Population<T> in, Population<T>[] branches)
in
- he population to distributebranches
- the array of sub populations to fillprotected void mergePopulation(Population<T>[] branches, Population<T> out)
branches
- the populations to be mergedout
- the final population@Deprecated public void setBiggerIsBetter(boolean flag, boolean recursively)
setBiggerIsBetter
in class AbstractStage<T extends Chromosome>
flag
- true, if the best individual has the higher fitnessrecursively
- true, to propagate this setting down, otherwise false.public void setFitness(Fitness fit, boolean recursively)
AbstractStage
Fitness
to this stage propagating the change recursively
according to the flag given as parametersetFitness
in class AbstractStage<T extends Chromosome>