JGAP

org.jgap.impl
Class BestChromosomesSelector

java.lang.Object
  extended by org.jgap.NaturalSelector
      extended by org.jgap.NaturalSelectorExt
          extended by org.jgap.impl.BestChromosomesSelector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Configurable, INaturalSelector, ICloneable

public class BestChromosomesSelector
extends NaturalSelectorExt
implements ICloneable

Implementation of a NaturalSelector that takes the top n chromosomes into the next generation. n can be specified. Which chromosomes are the best is decided by evaluating their fitness value.

Since:
1.1
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jgap.NaturalSelector
NaturalSelector.AgeFitnessValueComparator, NaturalSelector.FitnessAgeValueComparator, NaturalSelector.FitnessValueComparator
 
Field Summary
 
Fields inherited from class org.jgap.NaturalSelector
m_monitor, m_monitorActive
 
Constructor Summary
BestChromosomesSelector()
          Default constructor.
BestChromosomesSelector(Configuration a_config)
          Using original rate of 1.0
BestChromosomesSelector(Configuration a_config, double a_originalRate)
           
 
Method Summary
protected  void add(IChromosome a_chromosomeToAdd)
          Add a Chromosome instance to this selector's working pool of Chromosomes.
 java.lang.Object clone()
           
 void empty()
          Empties out the working pool of Chromosomes.
 boolean equals(java.lang.Object a_o)
           
 double getOriginalRate()
           
 boolean returnsUniqueChromosomes()
           
 void selectChromosomes(int a_howManyToSelect, Population a_to_pop)
          Selects a given number of chromosomes from the pool that will move on to the next generation population.
 void setOriginalRate(double a_originalRate)
          Setting this parameter controls how many chromosomes of the original population will be considered for selection to the next population.
 
Methods inherited from class org.jgap.NaturalSelectorExt
getDoubletteChromosomesAllowed, init, select, selectChromosome, setDoubletteChromosomesAllowed
 
Methods inherited from class org.jgap.NaturalSelector
getConfiguration
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BestChromosomesSelector

public BestChromosomesSelector()
                        throws InvalidConfigurationException
Default constructor. Attention: The configuration used is the one set with the static method Genotype.setConfiguration.

Throws:
InvalidConfigurationException
Since:
1.1

BestChromosomesSelector

public BestChromosomesSelector(Configuration a_config)
                        throws InvalidConfigurationException
Using original rate of 1.0

Parameters:
a_config - the configuration to use
Throws:
InvalidConfigurationException
Since:
3.0

BestChromosomesSelector

public BestChromosomesSelector(Configuration a_config,
                               double a_originalRate)
                        throws InvalidConfigurationException
Throws:
InvalidConfigurationException
Method Detail

add

protected void add(IChromosome a_chromosomeToAdd)
Add a Chromosome instance to this selector's working pool of Chromosomes.

Specified by:
add in class NaturalSelectorExt
Parameters:
a_chromosomeToAdd - the specimen to add to the pool
Since:
1.1

selectChromosomes

public void selectChromosomes(int a_howManyToSelect,
                              Population a_to_pop)
Selects a given number of chromosomes from the pool that will move on to the next generation population. This selection will be guided by the fitness values. The chromosomes with the best fitness value win.

Specified by:
selectChromosomes in class NaturalSelectorExt
Parameters:
a_to_pop - the population the chromosomes will be added to
a_howManyToSelect - the number of chromosomes to select
Since:
1.1

empty

public void empty()
Empties out the working pool of Chromosomes.

Specified by:
empty in interface INaturalSelector
Since:
1.1

returnsUniqueChromosomes

public boolean returnsUniqueChromosomes()
Specified by:
returnsUniqueChromosomes in interface INaturalSelector
Returns:
always true as no Chromosome can be returnd multiple times
Since:
2.0

setOriginalRate

public void setOriginalRate(double a_originalRate)
Setting this parameter controls how many chromosomes of the original population will be considered for selection to the next population. If the value is 1 then the whole original population is considered, if it is 0.5 only half of the chromosomes are considered. If doublettes are allowed, then a number of chromosomes missing (number of to be selected minus number selected) will be added.

Parameters:
a_originalRate - the rate of how many of the original chromosomes will be selected according to BestChromosomeSelector's strategy. The rest (non-original) of the chromosomes is added as duplicates
Since:
2.0

getOriginalRate

public double getOriginalRate()
Returns:
see setOriginalRate
Since:
2.0

equals

public boolean equals(java.lang.Object a_o)
Overrides:
equals in class NaturalSelectorExt
Parameters:
a_o - the object to compare
Returns:
true: compared object is seen as equal to current instance

clone

public java.lang.Object clone()
Specified by:
clone in interface ICloneable
Overrides:
clone in class java.lang.Object
Returns:
clone of the current object instance

JGAP