com.rubecula.darwin.domain.world
Class Organism_

java.lang.Object
  extended by net.sf.tostring0.AToString
      extended by com.rubecula.darwin.domain.world.Organism_
All Implemented Interfaces:
Censusible, EnvironmentListener, Genetic, Mortal, Organism, ComparableValue, Individual, Valuable, java.lang.Cloneable, java.lang.Comparable<Valuable>, net.sf.tostring0.Identifiable, net.sf.tostring0.IToString
Direct Known Subclasses:
Organism_Asexual, Organism_Sexual

public abstract class Organism_
extends net.sf.tostring0.AToString
implements Organism, java.lang.Cloneable

Abstract class defining the base methods and fields of an implementation of Organism interface. TODO this is a huge type file. Consider splitting up.

Author:
Robin Hillyard

Field Summary
protected  java.lang.String _identifier
          An identifier for this organism.
protected  Nuclear _nuclear
          The cell (in effect the nuclear DNA) to which this organism conforms.
protected static org.apache.commons.logging.Log LOG
          The logger for this class.
 
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 Organism_(java.lang.String identifier, Colony colony, Nuclear nuclear)
          Construct a new organism with the following attributes:
 
Method Summary
 void age()
          Age this organism by one year.
 boolean censusMe(Census census, java.lang.Object context)
          There are two paths through this method: 1) if context is an instance of OrganismCensusContext, then we call doCensusInContext(OrganismCensusContext) and consider ourselves done (no need for going deeper through children); 2) otherwise, we output information about this Organism and return true (OK not yet done -- need to iterate through children).
 java.lang.Object clone()
           
 int compareTo(Valuable o)
           
 boolean equals(java.lang.Object obj)
           
 int getAge()
           
 java.util.Collection<? extends Censusible> getCensusibleChildren()
          Method to return a list of censusible children of this object.
 Colony getColony()
          Method to determine to which population this organism currently belongs.
 java.lang.Number getFitness(FitnessEngine fitnessEngine)
           
 Genome getGenome()
           
 java.lang.String getIdentifier()
           
protected  Mortality getMortality()
          Get the mortality for this mortal object (from the system of the colony to which this organism belongs).
 Nuclear getNuclear()
           
 Phenotype getPhenotype()
          Get the phenotype by expressing the genome in the context of the colony.
 java.lang.Number getValue()
          Get the fitness for this Organism, either from the cache for the fitness engine, or by calculation.
 Visualizable getVisualizable()
          TEST
 int hashCode()
           
 boolean isMortal(double fitness)
          TODO calculate fitness within this method rather than have it passed in.
 boolean isNew()
          TEST
 boolean isViable()
           
 boolean isVisible()
          TEST
 void normalizeGenome(Genome referenceGenome, java.util.Map<java.lang.String,Genome> cache, Environment environment)
          TODO consider adding this to the Organism interface.
 void onEnvironmentChange(Environment env)
          flush the fitness cache completely.
 void setColony(Colony colony)
          Reset the owning colony of this organism.
 boolean setViability(Viability viability)
           
 void setViable(boolean viable)
           
 
Methods inherited from class net.sf.tostring0.AToString
toString, toString, toStringBrief, toStringId
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.rubecula.darwin.domain.helper.Organism
createMate, createPairBond, getAsexualProgeny
 
Methods inherited from interface net.sf.tostring0.IToString
toString, toStringBrief, toStringId
 

Field Detail

LOG

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


_nuclear

protected final Nuclear _nuclear
The cell (in effect the nuclear DNA) to which this organism conforms.


_identifier

protected final java.lang.String _identifier
An identifier for this organism.

Constructor Detail

Organism_

protected Organism_(java.lang.String identifier,
                    Colony colony,
                    Nuclear nuclear)
Construct a new organism with the following attributes:

Parameters:
identifier - a string by which to identify this organism (may be null).
colony - the Population to which this specific organism belongs
nuclear - the Genome to which this organism (and all its relatives) adheres.
Method Detail

age

public void age()
Age this organism by one year.

Specified by:
age in interface Mortal
See Also:
Mortal.age()

censusMe

public boolean censusMe(Census census,
                        java.lang.Object context)
There are two paths through this method: 1) if context is an instance of OrganismCensusContext, then we call doCensusInContext(OrganismCensusContext) and consider ourselves done (no need for going deeper through children); 2) otherwise, we output information about this Organism and return true (OK not yet done -- need to iterate through children).

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(Census, java.lang.Object)

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

compareTo

public int compareTo(Valuable o)
Specified by:
compareTo in interface java.lang.Comparable<Valuable>
See Also:
Comparable.compareTo(java.lang.Object)

equals

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

getAge

public int getAge()
Specified by:
getAge in interface Mortal
Returns:
the current age of this organism
See Also:
Mortal.getAge()

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

getColony

public Colony getColony()
Description copied from interface: Organism
Method to determine to which population this organism currently belongs. Getter/setter typically called by reflection.

Specified by:
getColony in interface Organism
Returns:
the value of field colony.
See Also:
Organism.getColony()

getFitness

public java.lang.Number getFitness(FitnessEngine fitnessEngine)
                            throws FitnessException
Specified by:
getFitness in interface Organism
Parameters:
fitnessEngine -
Returns:
the fitness of this Organism in its Environment.
Throws:
FitnessException
See Also:
Organism.getFitness(com.rubecula.darwin.domain.helper.FitnessEngine)

getGenome

public Genome getGenome()
Specified by:
getGenome in interface Genetic
Returns:
the genome for this genetic object.
See Also:
Genetic.getGenome()

getIdentifier

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

getNuclear

public Nuclear getNuclear()
Specified by:
getNuclear in interface Organism
Returns:
the nuclear object underlying this organism

getPhenotype

public Phenotype getPhenotype()
Get the phenotype by expressing the genome in the context of the colony.

Specified by:
getPhenotype in interface Organism
Returns:
the phenotype for this organism.
See Also:
Organism.getPhenotype()

getValue

public java.lang.Number getValue()
                          throws ValueException
Get the fitness for this Organism, either from the cache for the fitness engine, or by calculation. The higher the value, the fitter is the organism.

Specified by:
getValue in interface Valuable
Returns:
the fitness of this Organism by invoking getFitness(FitnessEngine) and passing it the fitness engine for the phenome for the system for the colony.
Throws:
ValueException
See Also:
Valuable.getValue()

getVisualizable

public Visualizable getVisualizable()
TEST

Specified by:
getVisualizable in interface Individual
Returns:
the Visualizable object of which this Individual is a member.
See Also:
Individual.getVisualizable()

hashCode

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

isMortal

public boolean isMortal(double fitness)
TODO calculate fitness within this method rather than have it passed in.

Specified by:
isMortal in interface Organism
Parameters:
fitness - the fitness of the organism whose mortality we are discovering.
Returns:
true if the organism's number is up (i.e. to be eliminated).

isNew

public boolean isNew()
TEST

Specified by:
isNew in interface Individual
Returns:
true if this individual has not yet been visualized.
See Also:
Individual.isNew()

isViable

public boolean isViable()
Specified by:
isViable in interface Mortal
Returns:
true if this organism is part of a population model (generally this is true, except temporarily when an organism is first born or newly dead)
See Also:
Mortal.isViable()

isVisible

public boolean isVisible()
TEST

Specified by:
isVisible in interface Individual
Returns:
true if this individual should be visualized.
See Also:
Individual.isVisible()

normalizeGenome

public void normalizeGenome(Genome referenceGenome,
                            java.util.Map<java.lang.String,Genome> cache,
                            Environment environment)
TODO consider adding this to the Organism interface.

Specified by:
normalizeGenome in interface Organism
Parameters:
referenceGenome - the genome to which this Organism's genome will be normalized
cache - map of bases -> genome pairs
environment - the environment to which this Organism belongs.

onEnvironmentChange

public void onEnvironmentChange(Environment env)
flush the fitness cache completely. Note that is is not sufficient to flush just the value for the genome because some genomes may have been lost from the gene pool, but not flushed from the cache, thus they would never get flushed and cause the wrong fitness values to be picked up later when an identical genome comes along which, because of the environment change, would have a different fitness value. TODO find a way to flush all only once on an environment change and then in this method we could then revert to simple flushing the cache for the genome, provided that we remove values from cache when they no longer exist in the gene pool.

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

setColony

public void setColony(Colony colony)
Reset the owning colony of this organism. This is only ever done

Specified by:
setColony in interface Organism
Parameters:
colony - the new population to which this organism now belongs.
See Also:
Organism.setColony(Colony)

setViability

public boolean setViability(Viability viability)
                     throws FitnessException
Specified by:
setViability in interface Organism
Parameters:
viability - the determinant of viability for this Organism
Returns:
true if setViable(boolean) was invoked on this Organism.
Throws:
FitnessException

setViable

public void setViable(boolean viable)
Specified by:
setViable in interface Mortal
Parameters:
viable - if false, then we (temporarily) mark this organism as not being part of a population model.
See Also:
Mortal.setViable(boolean)

getMortality

protected Mortality getMortality()
Get the mortality for this mortal object (from the system of the colony to which this organism belongs).

Returns:
the mortality of the system of the colony.


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