com.rubecula.darwin.domain.helper
Class FitnessCache

java.lang.Object
  extended by com.rubecula.darwin.domain.helper.Cache_<FitnessCacheKey,java.lang.Double>
      extended by com.rubecula.darwin.domain.helper.FitnessCache
All Implemented Interfaces:
Cache, Cache_MBean, net.sf.tostring0.Identifiable

public class FitnessCache
extends Cache_<FitnessCacheKey,java.lang.Double>

This cache maintains a set of fitness values indexed by Signature/FitnessEngine pair. Normally, the trait map object is the phenotype of an Organism. The purpose is to save time recalculating the fitness when it is unnecessary. The signature of a TraitMap is its "cache key".

Author:
Robin Hillyard

Field Summary
 
Fields inherited from class com.rubecula.darwin.domain.helper.Cache_
LOG
 
Constructor Summary
FitnessCache()
           
 
Method Summary
 void addFitness(TraitMap traits, FitnessEngine fitnessEngine, Environment environment, java.lang.Double fitness)
           
 void flush(TraitMap traits, FitnessEngine engine, Environment environment)
          Flush the cache for the given combination of traits/engine.
 java.lang.Double getFitness(TraitMap traits, FitnessEngine fitnessEngine, Environment environment)
           
 java.lang.String getIdentifier()
           
 void register(FitnessEngine fitnessEngine)
          register the given fitness engine with this cache.
 
Methods inherited from class com.rubecula.darwin.domain.helper.Cache_
add, cached, count, flush, flush, get, isActive, setActive
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FitnessCache

public FitnessCache()
Method Detail

addFitness

public void addFitness(TraitMap traits,
                       FitnessEngine fitnessEngine,
                       Environment environment,
                       java.lang.Double fitness)
Parameters:
traits - the traits being whose fitness has been evaluated.
fitnessEngine - the fitness engine which evaluated the fitness.
environment - the environment the fit object resides in.
fitness - the fitness

flush

public void flush(TraitMap traits,
                  FitnessEngine engine,
                  Environment environment)
Flush the cache for the given combination of traits/engine. Note that you cannot flush the cache for all fitnesses relating to traits only, or fitnesses relating to the engine only.

Parameters:
traits - the traits being whose fitness has been evaluated.
engine - the fitness engine which evaluated the fitness.
environment - the environment the fit object resides in.

getFitness

public java.lang.Double getFitness(TraitMap traits,
                                   FitnessEngine fitnessEngine,
                                   Environment environment)
Parameters:
traits - the traits being whose fitness has been evaluated.
fitnessEngine - the fitness engine which evaluates the fitness.
environment - the environment the fit object resides in.
Returns:
the cached phenotype (or null if none) - unless it is not active in which case always null.

getIdentifier

public java.lang.String getIdentifier()
Returns:
"fitness cache"
See Also:
Identifiable.getIdentifier()

register

public void register(FitnessEngine fitnessEngine)
register the given fitness engine with this cache. Once done, any fitness function changes which occur will cause this cache to be completely flushed.

Parameters:
fitnessEngine -


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