com.rubecula.darwin.domain.world
Class Population_

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

public abstract class Population_
extends Evolvable_
implements Population, Visualizable

Abstract class defining the base methods and fields for an instance of the Population interface.

Author:
Robin Hillyard

Field Summary
 java.util.List<Colony> _colonies
          A list of colonies.
 int _index
          the index of this population within its taxon.
static org.apache.commons.logging.Log LOG
          The logger for this class.
static java.lang.String 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_(java.lang.String identifier)
          (Protected) constructor for Population_ where:
 
Method Summary
 int addColony(Colony colony)
          Add a colony to this population.
 boolean censusMe(Census census, java.lang.Object context)
          TODO perhaps census the colonies too? or is that taken care of with children mechanism?
 void cullMembers()
          Method to cull all members of an Evolvable so we can make a fresh start.
protected abstract  java.lang.Object determineResult()
           
 boolean equals(java.lang.Object obj)
           
 java.util.Collection<? extends Censusible> getCensusibleChildren()
          Method to return a list of censusible children of this object.
 java.util.Collection<Colony> getColonies()
           
 Colony getColony(int index)
          TODO consider using the id of the colony instead of the index.
 int getCount()
           
 int getGeneration()
           
 java.util.Collection<Individual> getIndividuals()
          TODO is this ever actually called? Maybe we don't need this method for Population.
 Realm getRealm()
           
 int getSequence()
          TODO consider eliminating this and using only the generation from super-type
 Sink getSink()
           
 Taxon getTaxon()
          Method to get the Taxon to which this population belongs.
 int getTotal()
           
 int hashCode()
           
 boolean isFinished()
          This implementation simply returns the value of the finished field.
protected  void midGenerationProcessing()
           
 boolean nextGeneration()
           Method to get a new generation of this population.
protected  void postGenerationCleanup()
           
protected  void preGenerationPreparation()
           
 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 setTaxon(Taxon taxon)
          Set the taxon to which this population belongs.
 java.lang.String toString(boolean showDetail, boolean showClass, boolean showIdentifier, boolean includeParent, boolean includeChildren, java.lang.String prefix, boolean recurse, int maxElements, int maxChars)
           
 void wrapUp(java.lang.String cause)
          Do nothing.
 
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

_colonies

public final java.util.List<Colony> _colonies
A list of colonies. TODO make it a map


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

_index

public transient int _index
the index of this population within its taxon. TODO check to see if obsolete

Constructor Detail

Population_

protected Population_(java.lang.String identifier)
(Protected) constructor for Population_ where:

Parameters:
identifier - is the string which will identify this population;
Method Detail

addColony

public int addColony(Colony colony)
Description copied from interface: Population
Add a colony to this population.

Specified by:
addColony in interface Population
Parameters:
colony -
Returns:
result of calling
See Also:
on {@link #_colonies}.

censusMe

public boolean censusMe(Census census,
                        java.lang.Object context)
TODO perhaps census the colonies too? or is that taken care of with children mechanism?

Specified by:
censusMe in interface Censusible
Parameters:
census - the census object
context -
Returns:
true if we should continue censusing the children of this object

cullMembers

public void cullMembers()
Description copied from interface: Theological
Method to cull all members of an Evolvable so we can make a fresh start. The complementary method to Theological.seedMembers().

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

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class Evolvable_
See Also:
Object.equals(java.lang.Object)

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()

getColonies

public java.util.Collection<Colony> getColonies()
Specified by:
getColonies in interface Population
Returns:
the colonies

getColony

public Colony getColony(int index)
Description copied from interface: Population
TODO consider using the id of the colony instead of the index.

Specified by:
getColony in interface Population
Returns:
the indexth colony from the list
See Also:
Population.getColony(int)

getCount

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

getGeneration

public int getGeneration()
Specified by:
getGeneration in interface Evolvable
Overrides:
getGeneration in class Evolvable_
Returns:
the sequence number of the current generation.
See Also:
Evolvable.getGeneration()

getIndividuals

public java.util.Collection<Individual> getIndividuals()
TODO is this ever actually called? Maybe we don't need this method for Population.

Specified by:
getIndividuals in interface Visualizable
Returns:
a collection of individuals which make up this Visualizable
See Also:
Visualizable.getIndividuals()

getRealm

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

getSequence

public int getSequence()
TODO consider eliminating this and using only the generation from super-type

Specified by:
getSequence in interface Population
Returns:
the sequence

getSink

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

getTaxon

public Taxon getTaxon()
Description copied from interface: Population
Method to get the Taxon to which this population belongs.

Specified by:
getTaxon in interface Population
Returns:
this population's Taxon system.
See Also:
Population.getTaxon()

getTotal

public int getTotal()
Specified by:
getTotal in interface Population
Returns:
the total number of organisms in all colonies of this population

hashCode

public int hashCode()
Overrides:
hashCode in class Evolvable_
See Also:
Object.hashCode()

isFinished

public boolean isFinished()
This implementation simply returns the value of the finished field.

Specified by:
isFinished in interface Terminal
Overrides:
isFinished in class Evolvable_
Returns:
true if generation is >= to Evolvable_.maxGenerations. For a more complex condition, an evolvable could override this definition.
See Also:
Terminal.isFinished()

nextGeneration

public final boolean nextGeneration()

Method to get a new generation of this population. 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:

  1. increment sequence
  2. call preGenerationPreparation()
  3. call Colony.setupGeneration() (once for each colony)
  4. call midGenerationProcessing()
  5. call (once for each colony)
  6. call postGenerationCleanup()
  7. call isFinished()

Specified by:
nextGeneration in interface Generational
Overrides:
nextGeneration in class Evolvable_
Returns:
a value which is formed from anding together the results of several of this method and with the complement of the value returned by isFinished()
See Also:
Generational.nextGeneration()

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: Population
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 Population
Parameters:
index - the index to set

setTaxon

public void setTaxon(Taxon taxon)
Set the taxon to which this population belongs. This is normally set when the population is added to the taxon.

Specified by:
setTaxon in interface Population
Parameters:
taxon -

toString

public java.lang.String toString(boolean showDetail,
                                 boolean showClass,
                                 boolean showIdentifier,
                                 boolean includeParent,
                                 boolean includeChildren,
                                 java.lang.String prefix,
                                 boolean recurse,
                                 int maxElements,
                                 int maxChars)
Specified by:
toString in interface net.sf.tostring0.IToString
Overrides:
toString in class net.sf.tostring0.AToString
See Also:
AToString.toString(boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, int, int)

wrapUp

public void wrapUp(java.lang.String cause)
Do nothing. If you want to do something when the evolution is finished, override this method.

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

determineResult

protected abstract java.lang.Object determineResult()
Returns:
XXX

midGenerationProcessing

protected void midGenerationProcessing()

postGenerationCleanup

protected void postGenerationCleanup()

preGenerationPreparation

protected void preGenerationPreparation()


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