jenes.stage
Class Parallel<T extends Chromosome>

java.lang.Object
  extended by jenes.stage.AbstractStage<T>
      extended by jenes.stage.Parallel<T>
Type Parameters:
T - The class chromosomes flowing across the stage.

public class Parallel<T extends Chromosome>
extends AbstractStage<T>

A parallel is formed by differents branches; each branch receives a subpopolation according to the population dispenser used (see 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.

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

Field Summary
 
Fields inherited from class jenes.stage.AbstractStage
biggerIsBetter, ga
 
Constructor Summary
Parallel(Dispenser<T> dispenser)
          Constructs a new parallel stage with the specified dispenser.
 
Method Summary
 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 globally)
          Sets if the best individuals have the higher fitness or not.
 void setBranch(int index, AbstractStage<T> stage)
          Sets the specified stage at the specified branch number replacing the stage already present
 
Methods inherited from class jenes.stage.AbstractStage
isBiggerBetter, setBiggerIsBetter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Parallel

public Parallel(Dispenser<T> dispenser)
Constructs a new parallel stage with the specified dispenser.

Parameters:
dispenser - the dispenser to use in the distribute and merge operations
Method Detail

add

public void add(AbstractStage<T> stage)
Adds a new branch to this parallel stage.

Parameters:
stage - the stage to be added as branch

remove

public void remove(AbstractStage<T> stage)
Removes a stage from the parallel andall the stages it contains. The specified stage is a branch stage container, so after it the branch will be empty.

Parameters:
stage - the stage to remove

remove

public void remove(int index)
Removes a specified branch from the parallel

Parameters:
index - the branch index to remove

setBranch

public void setBranch(int index,
                      AbstractStage<T> stage)
Sets the specified stage at the specified branch number replacing the stage already present

Parameters:
index - the branch number where to set the new stage
stage - the stage to add

removeAllBranches

public void removeAllBranches()
Removes all the branch stages from this parallel


init

public void init(GeneticAlgorithm<T> ga)
          throws StageException
Description copied from class: AbstractStage
Initializes this stage according to the genetic algorithm that uses it

Overrides:
init in class AbstractStage<T extends Chromosome>
Parameters:
ga - the Genetic Algorithm in wchic this stage run
Throws:
StageException

dispose

public void dispose()
Description copied from class: AbstractStage
Disposes this stage

Overrides:
dispose in class AbstractStage<T extends Chromosome>

process

public final void process(Population<T> in,
                          Population<T> out)
                   throws StageException
Description copied from class: AbstractStage
Processes the input population and tranforms it into the output population. Note: - Out population is made of recicled individuals. There is a need of new individuals to add only when there is a need to increase the population size. For pre-initalized individual just use setAs method. This is done for an efficient memory management. - A stage can modify the input population. So input passed to process method can be mutated when the process method ends.

Specified by:
process in class AbstractStage<T extends Chromosome>
Parameters:
in - the input population
out - the output population
Throws:
StageException

distribute

protected 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 - he population to distribute
branches - the array of sub populations to fill

mergePopulation

protected 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:
branches - the populations to be merged
out - the final population

setBiggerIsBetter

public void setBiggerIsBetter(boolean flag,
                              boolean globally)
Description copied from class: AbstractStage
Sets if the best individuals have the higher fitness or not. This setting can be or not propagated down to sub-stages.

Overrides:
setBiggerIsBetter in class AbstractStage<T extends Chromosome>
Parameters:
flag - true, if the best individual has the higher fitness
globally - true, to propagate this setting down, otherwise false.