com.rubecula.darwin.domain.world
Class Population_Managed

java.lang.Object
  extended by net.sf.tostring0.AToString
      extended by com.rubecula.darwin.foundation.Evolvable_
          extended by com.rubecula.darwin.domain.world.Population_
              extended by com.rubecula.darwin.domain.world.Population_Managed
All Implemented Interfaces:
Censusible, Population, PopulationExposed, Managed, Countable, Evolvable, Generational, Terminal, Theological, Visualizable, net.sf.tostring0.Identifiable, net.sf.tostring0.IToString
Direct Known Subclasses:
Population_TS

public abstract class Population_Managed
extends Population_
implements Managed

This abstract class is designed to be a base class for populations whose evolution is "managed". That's to say that we, the programmer, like to play God. For an example of a managed evolution in the real world, see the Lenski experiment. Such managed populations tend to have the following properties:

An example of such a population would be the population for the traveling salesman problem. The details of how this works are a little different from the Lenski experiment. In the latter experiment there are 12 colonies, but after their initial founding from a single colony, they are kept strictly apart (for 22 years so far). In the traveling salesman problem, after each new client is added and convergence reached, only the "best" colony is retained, and then a number of new colonies are created from the best (founder) colony.

Author:
Robin Hillyard

Nested Class Summary
protected  class Population_Managed.ProcessBestInEnvironment
          Type which provides a callback method which is called whenever a new best organism in the environment is found.
 
Field Summary
protected  int convergentGenerations
           
 
Fields inherited from class com.rubecula.darwin.domain.world.Population_
_colonies, _index, LOG, S_COLON
 
Fields inherited from interface net.sf.tostring0.IToString
ANGBR_OPEN, ANGBRA_CLSE, BRA_CLSE, BRA_OPEN, BRCE_OPEN, BRCS_CLSE, COLON, LIST_SEPARATOR, MAX_ELEMENTS_DEFAULT, S_MT, S_PERCENT, SEPARATOR, SPACE
 
Constructor Summary
protected Population_Managed(java.lang.String identifier, java.lang.String updateSourceProperty)
           
 
Method Summary
protected  boolean findAndProcessBestFit()
          Generally speaking, we invoke processBestFit(ProcessBest) with an appropriate processor.
protected  Best_Organism getBestInEnvironment()
           
protected  int getConvergentGenerations()
           
protected  int getMaxColonies()
           
protected abstract  boolean isEnvironmentStable(Environment env)
           
protected abstract  void logBestFitness(Organism organism, Phenotype phenotype)
           
protected abstract  void logBestOrganism(Colony colony)
           
protected abstract  int makeDaughterColonies(Colony founderColony, Environment founderEnvironment)
           
protected  int makeDaughterColonies(Colony founderColony, int size, java.lang.Object addition)
           
protected abstract  Colony makeDaughterColony(Colony founderColony, java.lang.Object addition, int pos)
          clone the founderColony to create a new colony with the newClient appropriately positioned in the new colony's environment.
 void midGenerationProcessing()
          XXX check that we really still want this stuff with pardons.
protected  void normalizeGenomes()
          This method processes each of the Organisms in the population by normalizing its genome in reference to the "best" genome.
 void postGenerationCleanup()
          First, we invoke the super-method, i.e.
 void preGenerationPreparation()
          First, we invoke the super-method, i.e.
protected  boolean processBestFit(ProcessBest<Organism> bestOfGenerationProcessor)
          TODO this needs to be rewritten.
protected abstract  boolean processExtendedPhenotypes(java.util.Collection<ExPhen> exphens, java.lang.Object criterion)
          Typical behavior for this method is to loop through the extended phenotypes provided and for each invoke ExPhen.applyToEnvironment(Object), passing in the criterion.
 void seedMembers()
          First we get the seed population property from the Taxon system to which we belong by invoking Taxon.getSeedPopulation() and recording the result as number.
protected abstract  Organism seedOrganism(Colony colony, int i)
           
 void setConvergentGenerations(int convergentGenerations)
           
 void setMaxColonies(int maxColonies)
           
protected abstract  java.lang.String showEnvironment1(Environment environment)
           
protected abstract  java.lang.String showEnvironment2(Environment environment)
           
protected  void thinColonies(int thinFactor)
          Reduce the population of each colony of this population by the thinFactor.
 boolean updateEnvironmentAndColonies(Colony founderColony, java.lang.Object source)
          This is a critical part of the evolutionary process for a Population_Managed and is called by the Population_Managed.ProcessBestInEnvironment.onUpdate(Organism), which in turn is invoked when there is a new best organism by Best_Organism#update(Organism, boolean).
 void wrapUp(java.lang.String cause)
          Do some logging regarding this population.
 
Methods inherited from class com.rubecula.darwin.domain.world.Population_
addColony, censusMe, cullMembers, determineResult, equals, getCensusibleChildren, getColonies, getColony, getCount, getGeneration, getIndividuals, getRealm, getSequence, getSink, getTaxon, getTotal, hashCode, isFinished, nextGeneration, setIndex, setTaxon, toString
 
Methods inherited from class com.rubecula.darwin.foundation.Evolvable_
getIdentifier, getMaxGenerations, getResult, setMaxGenerations, setResult
 
Methods inherited from class net.sf.tostring0.AToString
toString, toStringBrief, toStringId
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.tostring0.IToString
toStringBrief, toStringId
 
Methods inherited from interface net.sf.tostring0.Identifiable
getIdentifier
 

Field Detail

convergentGenerations

protected transient int convergentGenerations
Constructor Detail

Population_Managed

protected Population_Managed(java.lang.String identifier,
                             java.lang.String updateSourceProperty)
Parameters:
identifier -
updateSourceProperty - the name of the property in this population's Taxon that will provide the data for updating the environment when necessary.
Method Detail

midGenerationProcessing

public void midGenerationProcessing()
XXX check that we really still want this stuff with pardons.

Overrides:
midGenerationProcessing in class Population_
See Also:
Population_.midGenerationProcessing()

postGenerationCleanup

public void postGenerationCleanup()
First, we invoke the super-method, i.e. Population_.postGenerationCleanup() and then we invoke findAndProcessBestFit(). If the result of this call is false, we log a warning.

Overrides:
postGenerationCleanup in class Population_
See Also:
Population_.postGenerationCleanup()

preGenerationPreparation

public void preGenerationPreparation()
First, we invoke the super-method, i.e. Population_.preGenerationPreparation() and then we invoke Phenome.setData(Object) with a zero value. TODO check that this setData mechanism is still needed.

Overrides:
preGenerationPreparation in class Population_
See Also:
Population_.preGenerationPreparation()

seedMembers

public void seedMembers()
First we get the seed population property from the Taxon system to which we belong by invoking Taxon.getSeedPopulation() and recording the result as number. Then we call seedOrganism(Colony, int) number times. If the population has changed (it should have), we invoke Colony.populationChanged(Object) with "seed members".

Specified by:
seedMembers in interface Theological
Overrides:
seedMembers in class Population_
See Also:
TODO need to do more work here - perhaps seed all colonies (but normally there will be exactly one colony when we are seeding a {@link Population_Managed}). TODO also, we use a different mechanism for seeding here than in the Colony#seedMembers() method (which is what the super-method uses)

setConvergentGenerations

public void setConvergentGenerations(int convergentGenerations)
Parameters:
convergentGenerations -

setMaxColonies

public void setMaxColonies(int maxColonies)
Parameters:
maxColonies - the maxColonies to set. Note that this is not a hard maximum but an approximate maximum.

updateEnvironmentAndColonies

public boolean updateEnvironmentAndColonies(Colony founderColony,
                                            java.lang.Object source)
This is a critical part of the evolutionary process for a Population_Managed and is called by the Population_Managed.ProcessBestInEnvironment.onUpdate(Organism), which in turn is invoked when there is a new best organism by Best_Organism#update(Organism, boolean). First, we determine the Colony to which the given organism belongs and name this founderColony. Next, we invoke the euphemistically titled decimatePoorerColonies(Colony) for founderColony (i.e. we get rid of all the other colonies). A kind of ethnic cleansing. Next, we invoke Susceptible.updateFromSource(Best, Object) on the founderColony's environment, and assuming that all is OK, we invoke makeDaughterColonies(Colony, Environment) which creates a set of (new) daughter colonies, which have environments which are variations of the founderColony's environment.

Specified by:
updateEnvironmentAndColonies in interface Managed
Parameters:
founderColony - the "best" colony which is the only colony to remain and which will be the founder of the new daughter colonies.
source - the source from which the environment will be updated when appropriate.
Returns:
true if the environment was actually updated and at least one new colony was created.
See Also:
Managed.updateEnvironmentAndColonies(Colony, java.lang.Object)

wrapUp

public void wrapUp(java.lang.String cause)
Do some logging regarding this population. Then we invoke the super-method, Population_.wrapUp(String).

Specified by:
wrapUp in interface Population
Overrides:
wrapUp in class Population_
Parameters:
cause - XXX
See Also:
Population_.wrapUp(String)

findAndProcessBestFit

protected boolean findAndProcessBestFit()
Generally speaking, we invoke processBestFit(ProcessBest) with an appropriate processor. See, for example, processBestFit(ProcessBest) method in the class Population_TS.

Returns:
true if all well

getBestInEnvironment

protected Best_Organism getBestInEnvironment()
Returns:
the bestInEnvironment

getConvergentGenerations

protected int getConvergentGenerations()
Returns:
convergentGenerations property.

getMaxColonies

protected int getMaxColonies()
Returns:
the maxColonies. Note that this is not a hard maximum but an approximate maximum.

isEnvironmentStable

protected abstract boolean isEnvironmentStable(Environment env)
Parameters:
env - XXX
Returns:
true if the environment is stable, i.e. has not changed.

logBestFitness

protected abstract void logBestFitness(Organism organism,
                                       Phenotype phenotype)
                                throws ValueException
Parameters:
organism -
phenotype -
Throws:
ValueException - an exception that could be thrown when getting the value. However, in practice, this exception should never be thrown once an organism as been crowned as best.

logBestOrganism

protected abstract void logBestOrganism(Colony colony)

makeDaughterColonies

protected abstract int makeDaughterColonies(Colony founderColony,
                                            Environment founderEnvironment)
Parameters:
founderColony -
founderEnvironment -
Returns:
true if all is well

makeDaughterColonies

protected int makeDaughterColonies(Colony founderColony,
                                   int size,
                                   java.lang.Object addition)
Parameters:
founderColony -
size - the number of possible variations of environment from which to make new colonies.
addition - the object which is newly added and has to be moved into different positions for each new colony.
Returns:
the number of daughter colonies actually created

makeDaughterColony

protected abstract Colony makeDaughterColony(Colony founderColony,
                                             java.lang.Object addition,
                                             int pos)
                                      throws java.lang.CloneNotSupportedException
clone the founderColony to create a new colony with the newClient appropriately positioned in the new colony's environment.

Parameters:
founderColony -
addition -
pos -
Returns:
the new colony.
Throws:
java.lang.CloneNotSupportedException

normalizeGenomes

protected void normalizeGenomes()
This method processes each of the Organisms in the population by normalizing its genome in reference to the "best" genome. The actual work is performed by Organism_.normalizeGenome(Genome, Map, Environment) where the parameters are the bestGenome, a cache, and the environment for this population. TODO this is slow


processBestFit

protected boolean processBestFit(ProcessBest<Organism> bestOfGenerationProcessor)
                          throws ValueException
TODO this needs to be rewritten. This method is called by findAndProcessBestFit() which in turn is called by postGenerationCleanup(). Here is the sequence:
  1. call findBestOrganism(ProcessBest) with bestOfGenerationProcessor as the parameter;
  2. the result is then passed into Best.update(net.sf.tostring0.Identifiable, boolean) on the object returned from getBestInEnvironment(), along with Taxon.isLastGeneration().

Parameters:
bestOfGenerationProcessor - the object that will process organisms as they replace the current best organism for this generation.
Returns:
true if we updated #best.
Throws:
ValueException

processExtendedPhenotypes

protected abstract boolean processExtendedPhenotypes(java.util.Collection<ExPhen> exphens,
                                                     java.lang.Object criterion)
Typical behavior for this method is to loop through the extended phenotypes provided and for each invoke ExPhen.applyToEnvironment(Object), passing in the criterion. If the result is true for any extended phenotype, the returned result will be true.

Parameters:
exphens -
criterion -
Returns:
true if the environment of an extended phenotype has been updated

seedOrganism

protected abstract Organism seedOrganism(Colony colony,
                                         int i)
Parameters:
colony - XXX
i - application-specific parameter
Returns:
a newly created organism based on the integer i

showEnvironment1

protected abstract java.lang.String showEnvironment1(Environment environment)
Parameters:
environment - XXX
Returns:
a String for the first descriptive message about the environment

showEnvironment2

protected abstract java.lang.String showEnvironment2(Environment environment)
Parameters:
environment - XXX
Returns:
a String for the second descriptive message about the environment

thinColonies

protected void thinColonies(int thinFactor)
                     throws FitnessException
Reduce the population of each colony of this population by the thinFactor.

Parameters:
thinFactor - the factor by which each colony's population will be thinned.
Throws:
FitnessException


Copyright © 2010 Rubecula Software, LLC. All Rights Reserved.