ec.simple
Class SimpleFitness

java.lang.Object
  extended byec.simple.SimpleFitness
All Implemented Interfaces:
java.lang.Cloneable, Fitness, Prototype, java.io.Serializable, Setup

public class SimpleFitness
extends java.lang.Object
implements Fitness

A simple default fitness, consisting of a single floating-point value which ranges from 0 (worst), and where fitness A is superior to fitness B if and only if A > B. Fitness values may range from [0.0,infinity), so in theory "infinity" could be the ideal fitness -- but in fact you can have any maximum ideal fitness because when you set a fitness, you specify whether or not it is the ideal.

Default Base
simple.fitness

See Also:
Serialized Form

Field Summary
protected  float fitness
           
static java.lang.String FITNESS_PREAMBLE
           
protected  boolean isIdeal
           
static java.lang.String P_FITNESS
           
 
Constructor Summary
SimpleFitness()
           
 
Method Summary
 boolean betterThan(Fitness _fitness)
          Should return true if this fitness is clearly better than _fitness; You may assume that _fitness is of the same class as yourself.
 Parameter defaultBase()
          Returns the default base for this prototype.
 boolean equivalentTo(Fitness _fitness)
          Should return true if this fitness is in the same equivalence class as _fitness, that is, neither is clearly bettter or worse than the other.
 float fitness()
          Should return an absolute fitness value ranging from negative infinity to infinity, NOT inclusive (thus infinity, negative infinity, and NaN are NOT valid fitness values).
 boolean isIdealFitness()
          Should return true if this is a good enough fitness to end the run
 void printFitness(EvolutionState state, int log, int verbosity)
          Presently does not encode the fact that the fitness is ideal or not
 void printFitness(EvolutionState state, java.io.PrintWriter writer)
          Presently does not encode the fact that the fitness is ideal or not
 void printFitnessForHumans(EvolutionState state, int log, int verbosity)
          Presently does not print the fact that the fitness is ideal or not
 java.lang.Object protoClone()
          Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.
 java.lang.Object protoCloneSimple()
          This should be implemented in a the top-level Prototype ONLY; in fact, it should probably be declared final.
 void readFitness(EvolutionState state, java.io.LineNumberReader reader)
          Presently does not decode the fact that the fitness is ideal or not
 void setFitness(EvolutionState state, float _f)
          Deprecated.  
 void setFitness(EvolutionState state, float _f, boolean _isIdeal)
           
 void setup(EvolutionState state, Parameter base)
          Sets up the object by reading it from the parameters stored in state, built off of the parameter base base.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FITNESS_PREAMBLE

public static final java.lang.String FITNESS_PREAMBLE
See Also:
Constant Field Values

P_FITNESS

public static final java.lang.String P_FITNESS
See Also:
Constant Field Values

fitness

protected float fitness

isIdeal

protected boolean isIdeal
Constructor Detail

SimpleFitness

public SimpleFitness()
Method Detail

defaultBase

public Parameter defaultBase()
Description copied from interface: Prototype
Returns the default base for this prototype. This should generally be implemented by building off of the static base() method on the DefaultsForm object for the prototype's package. This should be callable during setup(...).

Specified by:
defaultBase in interface Prototype

protoClone

public java.lang.Object protoClone()
                            throws java.lang.CloneNotSupportedException
Description copied from interface: Prototype
Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.

The question here is whether or not this means to perform a "deep" or "light" ("shallow") clone, or something in-between. You may need to deep-clone parts of your object rather than simply copying their references, depending on the situation:

Implementations.

If you know that your superclasses will never change their protoClone() implementations, you might try inlining them in your overridden protoClone() method. But this is dangerous (though it yields a small net increase).

In general, you want to keep your deep cloning to an absolute minimum, so that you don't have to call protoClone() but one time.

The approach taken here is the fastest that I am aware of while still permitting objects to be specified at runtime from a parameter file. It would be faster to use the "new" operator; but that would require hard-coding that we can't do. Although using java.lang.Object.clone() entails an extra layer that deals with stripping away the "protected" keyword and also wrapping the exception handling (which is a BIG hit, about three times as slow as using "new"), it's still MUCH faster than using java.lang.Class.newInstance(), and also much faster than rolling our own Clone() method.

Specified by:
protoClone in interface Prototype
Throws:
java.lang.CloneNotSupportedException

protoCloneSimple

public java.lang.Object protoCloneSimple()
Description copied from interface: Prototype
This should be implemented in a the top-level Prototype ONLY; in fact, it should probably be declared final. It should be implemented as follows:

        public final Object protoCloneSimple()
        {
        try { return protoClone(); }
        catch (CloneNotSupportedException e) 
        { throw new InternalError(); } // never happens
        } 
        

Specified by:
protoCloneSimple in interface Prototype

setFitness

public void setFitness(EvolutionState state,
                       float _f)
Deprecated.  

Deprecated -- now redefined to set the fitness but ALWAYS say that it's not ideal. If you need to specify that it's ideal, you should use the new function setFitness(final EvolutionState state, float _f, boolean _isIdeal).


setFitness

public void setFitness(EvolutionState state,
                       float _f,
                       boolean _isIdeal)

fitness

public float fitness()
Description copied from interface: Fitness
Should return an absolute fitness value ranging from negative infinity to infinity, NOT inclusive (thus infinity, negative infinity, and NaN are NOT valid fitness values). This shouldd be interpreted as: negative infinity is worse than the WORST possible fitness, and positive infinity is better than the IDEAL fitness.

You are free to restrict this range any way you like: for example, your fitness values might fall in the range [-5.32, 2.3]

Selection methods relying on fitness proportionate information will assume the fitness is non-negative and should throw an error if it is not. Thus if you plan on using FitProportionateSelection, BestSelection, or GreedyOverselection, for example, your fitnesses should assume that 0 is the worst fitness and positive fitness are better. If you're using other selection methods (Tournament selection, various ES selection procedures, etc.) your fitness values can be anything.

Similarly, if you're writing a selection method and it needs positive fitnesses, you should check for negative values and issue an error; and if your selection method doesn't need an absolute fitness value, it should use the equivalentTo() and betterThan() methods instead.

If your fitness scheme does not use a metric quantifiable to a single positive value (for example, MultiObjectiveFitness), you should perform some reasonable translation.

Specified by:
fitness in interface Fitness

setup

public void setup(EvolutionState state,
                  Parameter base)
Description copied from interface: Prototype
Sets up the object by reading it from the parameters stored in state, built off of the parameter base base. If an ancestor implements this method, be sure to call super.setup(state,base); before you do anything else.

For prototypes, setup(...) is typically called once for the prototype instance; cloned instances do not receive the setup(...) call. setup(...) may be called more than once; the only guarantee is that it will get called at least once on an instance or some "parent" object from which it was ultimately cloned.

Specified by:
setup in interface Prototype

isIdealFitness

public boolean isIdealFitness()
Description copied from interface: Fitness
Should return true if this is a good enough fitness to end the run

Specified by:
isIdealFitness in interface Fitness

equivalentTo

public boolean equivalentTo(Fitness _fitness)
Description copied from interface: Fitness
Should return true if this fitness is in the same equivalence class as _fitness, that is, neither is clearly bettter or worse than the other. You may assume that _fitness is of the same class as yourself. worseThan(), equivalentTo() and betterThan() should be disjoint sets.

Specified by:
equivalentTo in interface Fitness

betterThan

public boolean betterThan(Fitness _fitness)
Description copied from interface: Fitness
Should return true if this fitness is clearly better than _fitness; You may assume that _fitness is of the same class as yourself. worseThan(), equivalentTo() and betterThan() should be disjoint sets.

Specified by:
betterThan in interface Fitness

printFitness

public void printFitness(EvolutionState state,
                         int log,
                         int verbosity)
Presently does not encode the fact that the fitness is ideal or not

Specified by:
printFitness in interface Fitness

printFitness

public void printFitness(EvolutionState state,
                         java.io.PrintWriter writer)
Presently does not encode the fact that the fitness is ideal or not

Specified by:
printFitness in interface Fitness

printFitnessForHumans

public void printFitnessForHumans(EvolutionState state,
                                  int log,
                                  int verbosity)
Presently does not print the fact that the fitness is ideal or not

Specified by:
printFitnessForHumans in interface Fitness

readFitness

public void readFitness(EvolutionState state,
                        java.io.LineNumberReader reader)
                 throws java.io.IOException,
                        java.lang.CloneNotSupportedException
Presently does not decode the fact that the fitness is ideal or not

Specified by:
readFitness in interface Fitness
Throws:
java.io.IOException
java.lang.CloneNotSupportedException