com.rubecula.darwin.domain.fitness
Class FitnessEngine_

java.lang.Object
  extended by com.rubecula.darwin.domain.fitness.FitnessEngine_
All Implemented Interfaces:
CacheSignature, FitnessEngine, FunctionListener, HasExpressions
Direct Known Subclasses:
FitnessEngine_PepperedMoth, FitnessEngine_Simple, FitnessEngine_TS

public abstract class FitnessEngine_
extends java.lang.Object
implements FitnessEngine, FunctionListener

Defines the base methods and fields for an implementation of FitnessEngine interface. Contains no fields, methods or constructors.

Author:
Robin Hillyard

Field Summary
protected static org.apache.commons.logging.Log LOG
          The logger for this class.
 
Constructor Summary
protected FitnessEngine_()
          No-evaluator form of constructor.
protected FitnessEngine_(com.rubecula.jexpression.Evaluator evaluator, Realm realm)
          Protected Primary Constructor
 
Method Summary
 double calculateFitness(Phenotype phenotype, Environment environment)
          The base implementation of this method (which should normally be appropriate for all usage) simply goes through all possible pairings of trait/ecofactor (the traits belonging to the phenotype and the ecofactors belonging to the environment) and calculates the weighted product of all fitnesses.
protected  int countFitnesses()
           
 boolean equals(java.lang.Object obj)
           
protected  java.util.Set<java.lang.String> fitnessKeys()
           
 ExpressionMap getExpressions()
           
protected  Fitness getFitness(java.lang.String key)
           
protected  java.util.Collection<Fitness> getFitnesses()
           
protected  Realm getRealm()
           
 java.lang.String getSignature()
           
 int hashCode()
           
 void onEnvironmentChange(java.util.Collection<java.lang.String> characterKeys, Environment environment)
          The base implementation of this method (which should normally be appropriate for all usage) simply goes through all possible pairings of trait/ecofactor (from the given traits and the ecofactors belonging to the environment) and gets the appropriate setup.
 void onFunctionChange(Function function)
          Method to notify a Listener that a function has changed.
 Fitness putFitness(java.lang.String key, Fitness fitness)
          Register a fitness pair with this fitness engine.
protected abstract  void registerFitnesses(com.rubecula.jexpression.Evaluator evaluator)
           
 void setFitnessAdjustment(java.util.Collection<java.lang.String> characterKeys, java.lang.Number adjustment)
          The base implementation of this method (which should normally be appropriate for all usage) simply goes through all possible pairings of trait/ecofactor (from the given traits and the ecofactors belonging to the environment) and gets the appropriate setup.
 void setFitnessCache(FitnessCache fitnessCache)
          TODO consider renaming this to addListener(FitnessEngineListener ...) Register the cache for this fitness engine.
 java.lang.String toString()
           
 Fitness unregisterFitness(java.lang.String key)
          Remove the fitness identified by key
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG

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

Constructor Detail

FitnessEngine_

protected FitnessEngine_()
No-evaluator form of constructor.


FitnessEngine_

protected FitnessEngine_(com.rubecula.jexpression.Evaluator evaluator,
                         Realm realm)
Protected Primary Constructor

Parameters:
evaluator - the expression evaluator (or null)
realm - the realm this fitness engine operates in.
Method Detail

calculateFitness

public double calculateFitness(Phenotype phenotype,
                               Environment environment)
                        throws FitnessException
The base implementation of this method (which should normally be appropriate for all usage) simply goes through all possible pairings of trait/ecofactor (the traits belonging to the phenotype and the ecofactors belonging to the environment) and calculates the weighted product of all fitnesses. Weights must be positive. Normally, weights will be unity in which case the resulting fitness is simply the product of all relevant factors. TODO consider narrowing phenotype type to TraitMap.

Specified by:
calculateFitness in interface FitnessEngine
Returns:
the fitness for this phenotype in the context of environment TODO consider narrowing type of phenotype to TraitMap
Throws:
FitnessException
See Also:
FitnessEngine.calculateFitness(com.rubecula.darwin.domain.helper.Phenotype, com.rubecula.darwin.domain.helper.Environment)

equals

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

getExpressions

public ExpressionMap getExpressions()
Specified by:
getExpressions in interface HasExpressions
Returns:
a map of String / EvalExpressionMutable pairs. The String key for each EvalExpressionMutable is the name by which that expression will be known in the user interface.
See Also:
HasExpressions.getExpressions()

getSignature

public java.lang.String getSignature()
Specified by:
getSignature in interface CacheSignature
Returns:
a "signature" for this object which can be used to form part of a cache key. The signature is similar in a sense to the hash code but typically, it is based more on mutable components of an object than is the hash code.
See Also:
CacheSignature.getSignature()

hashCode

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

onEnvironmentChange

public void onEnvironmentChange(java.util.Collection<java.lang.String> characterKeys,
                                Environment environment)
The base implementation of this method (which should normally be appropriate for all usage) simply goes through all possible pairings of trait/ecofactor (from the given traits and the ecofactors belonging to the environment) and gets the appropriate setup. If the setup is non-null, we invoke it with the object that is passed in to this method.

Specified by:
onEnvironmentChange in interface FitnessEngine
Parameters:
environment -
characterKeys - XXX
See Also:
FitnessEngine.onEnvironmentChange(java.util.Collection, com.rubecula.darwin.domain.helper.Environment)

onFunctionChange

public void onFunctionChange(Function function)
Description copied from interface: FunctionListener
Method to notify a Listener that a function has changed.

Specified by:
onFunctionChange in interface FunctionListener
See Also:
FunctionListener.onFunctionChange(com.rubecula.darwin.foundation.Function)

putFitness

public Fitness putFitness(java.lang.String key,
                          Fitness fitness)
Description copied from interface: FitnessEngine
Register a fitness pair with this fitness engine.

Specified by:
putFitness in interface FitnessEngine
Parameters:
key - a key by which the fitness may be retrieved
fitness - the fitness evaluator
Returns:
true if registration was successful.
See Also:
FitnessEngine.putFitness(java.lang.String, com.rubecula.darwin.domain.helper.Fitness)

setFitnessAdjustment

public void setFitnessAdjustment(java.util.Collection<java.lang.String> characterKeys,
                                 java.lang.Number adjustment)
The base implementation of this method (which should normally be appropriate for all usage) simply goes through all possible pairings of trait/ecofactor (from the given traits and the ecofactors belonging to the environment) and gets the appropriate setup. If the setup is non-null, we invoke it with the object that is passed in to this method.

Specified by:
setFitnessAdjustment in interface FitnessEngine
Parameters:
characterKeys -
adjustment - the object to be passed in to the setup method.
See Also:
FitnessEngine.calculateFitness(com.rubecula.darwin.domain.helper.Phenotype, com.rubecula.darwin.domain.helper.Environment)

setFitnessCache

public void setFitnessCache(FitnessCache fitnessCache)
Description copied from interface: FitnessEngine
TODO consider renaming this to addListener(FitnessEngineListener ...) Register the cache for this fitness engine.

Specified by:
setFitnessCache in interface FitnessEngine
See Also:
FitnessEngine.setFitnessCache(com.rubecula.darwin.domain.helper.FitnessCache)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

unregisterFitness

public Fitness unregisterFitness(java.lang.String key)
Description copied from interface: FitnessEngine
Remove the fitness identified by key

Specified by:
unregisterFitness in interface FitnessEngine
Returns:
the old value of Fitness for the key
See Also:
FitnessEngine.unregisterFitness(java.lang.String)

countFitnesses

protected int countFitnesses()

fitnessKeys

protected java.util.Set<java.lang.String> fitnessKeys()

getFitness

protected Fitness getFitness(java.lang.String key)

getFitnesses

protected java.util.Collection<Fitness> getFitnesses()

getRealm

protected Realm getRealm()
Returns:
the realm

registerFitnesses

protected abstract void registerFitnesses(com.rubecula.jexpression.Evaluator evaluator)


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