com.rubecula.darwin.domain.world
Class Colony_

java.lang.Object
  extended by net.sf.tostring0.AToString
      extended by com.rubecula.darwin.domain.world.Colony_
All Implemented Interfaces:
Censusible, Colony, EnvironmentListener, Insular, Countable, Theological, Visualizable, java.lang.Cloneable, net.sf.tostring0.Identifiable, net.sf.tostring0.IToString
Direct Known Subclasses:
Colony_Mayrian

public abstract class Colony_
extends net.sf.tostring0.AToString
implements Colony, EnvironmentListener

Author:
Robin Hillyard TODO this is a huge type file. Consider splitting it up somehow.

Field Summary
protected  Environment _environment
          The environment in which this population exists.
protected  java.lang.String _identifier
          The string by which this population may be identified.
 int _index
          TODO consider removing this the index of this colony within its population.
protected  java.util.List<Organism> _organisms
          collection of organisms in this population.
protected  org.apache.commons.math.random.RandomGenerator _random
          A random number generator for this population.
static org.apache.commons.logging.Log LOG
          The logger for this class.
static java.lang.String S_COLON
           
protected  int sequence
          A sequence number for creating identifiers.
 
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 Colony_(java.lang.String identifier, Environment environment, org.apache.commons.math.random.RandomGenerator random)
           
 
Method Summary
 boolean addOrganism(Organism organism)
          Note that this method does NOT invoke the populationChanged() method.
protected  void ageOrganisms()
          This method ages all current organisms.
 boolean censusMe(Census census, java.lang.Object context)
          Method to census this object.
 void cleanupGeneration()
           Method to clean this colony up after processing the current generation.
 java.lang.Object clone()
           
 java.lang.String createIdentifier()
          Method to yield an unique identifier within this colony.
 void cullMembers()
          TEST
protected  boolean doCensusDetail(Census census, java.lang.Object context)
           
 java.util.Collection<? extends Censusible> getCensusibleChildren()
          Method to return a list of censusible children of this object.
 int getCount()
           
protected abstract  java.lang.String getDaughterId()
           
protected  int getDaughterSequence()
           
 Environment getEnvironment()
          Method to get the environment in which this colony thrives.
 java.lang.String getIdentifier()
           
protected  int getIndex()
           
 java.util.Collection<Individual> getIndividuals()
           
protected  int getNDaughters()
           
 java.util.Collection<Organism> getOrganisms()
           
 Population getPopulation()
           
protected  void getProgenyAsexual()
           
protected  boolean getProgenySexual()
           
protected  org.apache.commons.math.random.RandomGenerator getRandom()
           
 Realm getRealm()
          TODO consider eliminating this method
 double getSaturation()
          Get the current saturation for this colony.
 Sink getSink()
           
protected  java.util.Collection<VisualizableListener> getVisualizableListeners()
          Convenience method.
 double grantPardons(double fittestOriginal, int pardonsPerColony)
           
 boolean isIsolated()
           
 void markDeadOrganisms(Viability viability)
           
protected  void neonatalCare()
          Register all births with the Registry (if any); Mark dead organisms (with true parameter).
 void normalizeGenomes(Organism bestOrganism)
           
 void onEnvironmentChange(Environment env)
          This method is called on a environment listener to notify it that the environment p has changed.
 void populationChanged(java.lang.Object context)
          Method to respond to the fact that the population of Organisms in this Colony have changed.
protected  boolean removeDeadOrganisms()
           
 void seedMembers()
          Method to seed a this Evolvable which a certain number of members.
 void setIndex(int index)
          Set the index of this population within its parent Taxon System.
 void setIsolated(boolean isolated)
           
 void setNDaughters(int size)
          Set the number of daughter colonies we expect this colony to have.
 void setPopulation(Population population)
           
 boolean setupGeneration()
           Method to set up this colony for the current generation.
 boolean spin(int n)
           
 void thin(int thinFactor)
          Thin (decimate) the organisms of this colony by a factor of thinFactor.
protected  void visualizableChanged(Visualizable source, java.lang.Object context)
          This method should be called whenever this population (or an environment) has changed, for example after seeding, or getting the next generation.
 
Methods inherited from class net.sf.tostring0.AToString
toString, toString, toStringBrief, toStringId
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_environment

protected Environment _environment
The environment in which this population exists. This should be final but we need to set it in clone().


_identifier

protected java.lang.String _identifier
The string by which this population may be identified. This should be final but is needed to be non-final by the clone() method.


_random

protected final org.apache.commons.math.random.RandomGenerator _random
A random number generator for this population.


_organisms

protected transient java.util.List<Organism> _organisms
collection of organisms in this population. Note that this is non-final only for the sake of the clone() method.


sequence

protected transient int sequence
A sequence number for creating identifiers.


_index

public transient int _index
TODO consider removing this the index of this colony within its population.


LOG

public static final org.apache.commons.logging.Log LOG
The logger for this class.


S_COLON

public static final java.lang.String S_COLON
See Also:
Constant Field Values
Constructor Detail

Colony_

protected Colony_(java.lang.String identifier,
                  Environment environment,
                  org.apache.commons.math.random.RandomGenerator random)
Parameters:
identifier - the name of this colony
environment - the environment in which this colony exists
random - a random number source used by the colony for reproduction
Method Detail

addOrganism

public boolean addOrganism(Organism organism)
Note that this method does NOT invoke the populationChanged() method. The caller MUST call that method once a set of additions has been made.

Specified by:
addOrganism in interface Colony
Returns:
true if we added the organism
See Also:
Colony.addOrganism(com.rubecula.darwin.domain.helper.Organism)

censusMe

public boolean censusMe(Census census,
                        java.lang.Object context)
Description copied from interface: Censusible
Method to census this object.

Specified by:
censusMe in interface Censusible
Parameters:
census - the census object which will present the results of taking this census
context - an arbitrary object which can be used by the census object to provide appropriate context for this object.
Returns:
true if we should continue censusing this object at deeper levels. If the result is false, then we do not call Censusible.getCensusibleChildren().
See Also:
Censusible.censusMe(com.rubecula.darwin.domain.helper.Census, java.lang.Object)

cleanupGeneration

public final void cleanupGeneration()

Method to clean this colony up after processing the current generation. Called by Population_.nextGeneration(). Some individuals will be culled (according to the mortality implementation, etc.).

Normally, this method will not be overridden by sub-classes because it contains critical logic. If you want to do additional logic, you would normally override one or more of the following methods:

Here is the exact sequence of events for this method:

  1. increment sequence
  2. call removeDeadOrganisms()
  3. call populationChanged(Object)

Specified by:
cleanupGeneration in interface Colony
See Also:
Generational.nextGeneration()

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException
See Also:
Object.clone()

createIdentifier

public java.lang.String createIdentifier()
Description copied from interface: Colony
Method to yield an unique identifier within this colony.

Specified by:
createIdentifier in interface Colony
Returns:
a string which represents the next integer in a sequence. TODO use the generation number for id TODO consider putting this in a factory class
See Also:
Colony.createIdentifier()

cullMembers

public void cullMembers()
TEST

Specified by:
cullMembers in interface Theological
See Also:
Theological.cullMembers()

getCensusibleChildren

public java.util.Collection<? extends Censusible> getCensusibleChildren()
Description copied from interface: Censusible
Method to return a list of censusible children of this object.

Specified by:
getCensusibleChildren in interface Censusible
Returns:
either null or an ArrayList of censusible objects.
See Also:
Censusible.getCensusibleChildren()

getCount

public int getCount()
Specified by:
getCount in interface Countable
Returns:
the number of organisms in this population.
See Also:
Collection.size()

getEnvironment

public Environment getEnvironment()
Description copied from interface: Colony
Method to get the environment in which this colony thrives.

Specified by:
getEnvironment in interface Colony
Returns:
the environment.
See Also:
Colony.getEnvironment()

getIdentifier

public java.lang.String getIdentifier()
Specified by:
getIdentifier in interface net.sf.tostring0.Identifiable
See Also:
Identifiable.getIdentifier()

getIndividuals

public java.util.Collection<Individual> getIndividuals()
Specified by:
getIndividuals in interface Visualizable
Returns:
a collection of individuals which make up this Visualizable
See Also:
Visualizable.getIndividuals()

getOrganisms

public java.util.Collection<Organism> getOrganisms()
Specified by:
getOrganisms in interface Colony
Returns:
an Iterator of Organism objects.
See Also:
Colony.getOrganisms()

getPopulation

public Population getPopulation()
Specified by:
getPopulation in interface Colony
Returns:
the population
See Also:
Colony.getPopulation()

getRealm

public Realm getRealm()
TODO consider eliminating this method

Specified by:
getRealm in interface Visualizable
Returns:
the realm in which this Visualizable object exists.
See Also:
Visualizable.getRealm()

getSaturation

public double getSaturation()
Get the current saturation for this colony. Technically, this is the value of N/K in the Verhulst equation of population dynamics. In general, this value will depend on this colony, its environment and the populations of any other colonies sharing the same environment. This implementation ignores any other colonies which share the colony's environment.

Specified by:
getSaturation in interface Colony
Returns:
a number between 0 and 1 (although it is possible to have a super-saturated environment where the saturation is greater than 1.
See Also:
Colony.getSaturation()

getSink

public Sink getSink()
Specified by:
getSink in interface Visualizable
Returns:
an output destination for informational messages
See Also:
Visualizable.getSink()

grantPardons

public double grantPardons(double fittestOriginal,
                           int pardonsPerColony)
                    throws FitnessException
Specified by:
grantPardons in interface Colony
Parameters:
fittestOriginal - XXX
pardonsPerColony -
Returns:
the fittest value that we have now
Throws:
FitnessException
See Also:
Colony.grantPardons(double, int)

isIsolated

public boolean isIsolated()
Specified by:
isIsolated in interface Insular
Returns:
the value of the isolated flag. True if females from this population cannot find mates in other populations.
See Also:
Insular.isIsolated()

markDeadOrganisms

public void markDeadOrganisms(Viability viability)
                       throws FitnessException
Specified by:
markDeadOrganisms in interface Colony
Parameters:
viability - the viability which will determine whether an organism is viable or not.
Throws:
FitnessException
See Also:
Colony.markDeadOrganisms(com.rubecula.darwin.domain.world.Viability)

normalizeGenomes

public void normalizeGenomes(Organism bestOrganism)
Specified by:
normalizeGenomes in interface Colony
Parameters:
bestOrganism -
See Also:
Colony.normalizeGenomes(com.rubecula.darwin.domain.helper.Organism)

onEnvironmentChange

public void onEnvironmentChange(Environment env)
Description copied from interface: EnvironmentListener
This method is called on a environment listener to notify it that the environment p has changed.

Specified by:
onEnvironmentChange in interface EnvironmentListener
Parameters:
env - the environment which has changed.
See Also:
EnvironmentListener.onEnvironmentChange(com.rubecula.darwin.domain.helper.Environment)

populationChanged

public void populationChanged(java.lang.Object context)
Method to respond to the fact that the population of Organisms in this Colony have changed.

Specified by:
populationChanged in interface Colony
Parameters:
context - something that characterizes what caused the population change
See Also:
Colony.populationChanged(java.lang.Object)

seedMembers

public void seedMembers()
Description copied from interface: Theological
Method to seed a this Evolvable which a certain number of members.

Specified by:
seedMembers in interface Theological
See Also:
Theological.seedMembers()

setIndex

public void setIndex(int index)
Description copied from interface: Colony
Set the index of this population within its parent Taxon System. TODO consider removing this and always use List.indexOf(Object).

Specified by:
setIndex in interface Colony
Parameters:
index -
See Also:
Colony.setIndex(int)

setIsolated

public void setIsolated(boolean isolated)
Specified by:
setIsolated in interface Colony
Parameters:
isolated - the isolated to set
See Also:
Colony.setIsolated(boolean)

setNDaughters

public void setNDaughters(int size)
Description copied from interface: Colony
Set the number of daughter colonies we expect this colony to have.

Specified by:
setNDaughters in interface Colony
See Also:
Colony.setNDaughters(int)

setPopulation

public void setPopulation(Population population)
Specified by:
setPopulation in interface Colony
Parameters:
population - the population to set
See Also:
Colony.setPopulation(com.rubecula.darwin.domain.helper.Population)

setupGeneration

public final boolean setupGeneration()

Method to set up this colony for the current generation. Called by Population_.nextGeneration(). Some individuals will be culled (according to the mortality implementation, etc.); while each mating pair will produce some progeny.

Normally, this method will not be overridden by sub-classes because it contains critical logic. If you want to do additional logic, you would normally override one or more of the following methods:

Here is the exact sequence of events for this method (each step depends on the success of the previous step):

  1. increment sequence
  2. call ageOrganisms()
  3. call markDeadOrganisms(Viability) with false parameter
  4. call getProgenySexual() or getProgenyAsexual() according to the whether the system's genome is diploid or haploid.
  5. call neonatalCare()
  6. call populationChanged(Object)

Specified by:
setupGeneration in interface Colony
Returns:
true if everything worked as expected.
See Also:
Generational.nextGeneration()

spin

public boolean spin(int n)
Specified by:
spin in interface Colony
Parameters:
n - the odds against the result being true.
Returns:
true if the next random number in range 0..n-1 turns out to be a zero.
See Also:
Colony.spin(int)

thin

public void thin(int thinFactor)
          throws FitnessException
Description copied from interface: Colony
Thin (decimate) the organisms of this colony by a factor of thinFactor. Literal decimation would occur if the thinFactor was 10.

Specified by:
thin in interface Colony
Parameters:
thinFactor -
Throws:
FitnessException
See Also:
Colony.thin(int)

ageOrganisms

protected void ageOrganisms()
This method ages all current organisms.


doCensusDetail

protected boolean doCensusDetail(Census census,
                                 java.lang.Object context)
Parameters:
census - the census object
context -
Returns:
true if we should continue censusing the children of this object

getDaughterId

protected abstract java.lang.String getDaughterId()
Returns:
a suitable name for a daughter colony.

getDaughterSequence

protected int getDaughterSequence()
Returns:
the daughterSequence

getIndex

protected int getIndex()
Returns:
the index

getNDaughters

protected int getNDaughters()
Returns:
the nDaughters

getProgenyAsexual

protected void getProgenyAsexual()

getProgenySexual

protected boolean getProgenySexual()

getRandom

protected org.apache.commons.math.random.RandomGenerator getRandom()
Returns:
the RNG as set by the consructor.

getVisualizableListeners

protected java.util.Collection<VisualizableListener> getVisualizableListeners()
Convenience method. If the system has not yet been set, an empty list is returned. TODO not sure why the population or system would be null when this is called.

Returns:
the collection of VisualizableListener objects

neonatalCare

protected void neonatalCare()
                     throws FitnessException
Register all births with the Registry (if any); Mark dead organisms (with true parameter).

Throws:
FitnessException

removeDeadOrganisms

protected boolean removeDeadOrganisms()
Returns:
true if we killed anyone off

visualizableChanged

protected void visualizableChanged(Visualizable source,
                                   java.lang.Object context)
This method should be called whenever this population (or an environment) has changed, for example after seeding, or getting the next generation.

Parameters:
source - the source of the change (either this population or its environment).
context - the context of the change


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