|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ec.simple.SimpleFitness
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
Field Summary | |
protected float |
fitness
The 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 in the half-open range [0.0,infinity), where 0.0 is <= the worst possible value, and inifity is > the ideal fitness. |
boolean |
isIdealFitness()
Should return true if this is a good enough fitness to end the run |
void |
printFitness(EvolutionState state,
int log,
int verbosity)
Should print the fitness out in a computer-readable fashion, using state.output.println(...,verbosity,log). |
void |
printFitness(EvolutionState state,
java.io.PrintWriter writer)
Should print the fitness out in a computer-readable fashion, using state.output.println(...,verbosity,log). |
void |
printFitnessForHumans(EvolutionState state,
int log,
int verbosity)
Should print the fitness out in a pleasing way to humans, using state.output.println(...,verbosity,log) |
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)
Reads in the fitness from a form printed by printFitness(). |
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 |
public static final java.lang.String FITNESS_PREAMBLE
public static final java.lang.String P_FITNESS
protected float fitness
#ec.Fitness.fitness()
protected boolean isIdeal
Constructor Detail |
public SimpleFitness()
Method Detail |
public Parameter defaultBase()
Prototype
defaultBase
in interface Prototype
public java.lang.Object protoClone() throws java.lang.CloneNotSupportedException
Prototype
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.
public Object protoClone() throws CloneNotSupportedException
{
return super.clone();
}
public Object protoClone() throws CloneNotSupportedException
{
myobj = (MyObject) (super.clone());
// put your deep-cloning code here...
// ...you should use protoClone and not
// protoCloneSimple to clone subordinate objects...
return myobj;
}
public Object protoClone() throws CloneNotSupportedException
{
MyObject myobj = (MyObject)(super.protoClone());
// put your deep-cloning code here...
// ...you should use protoClone and not
// protoCloneSimple to clone subordinate objects...
return myobj;
}
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.
protoClone
in interface Prototype
public final java.lang.Object protoCloneSimple()
Prototype
public final Object protoCloneSimple()
{
try { return protoClone(); }
catch (CloneNotSupportedException e)
{ throw new InternalError(); } // never happens
}
protoCloneSimple
in interface Prototype
public final void setFitness(EvolutionState state, float _f)
setFitness(final EvolutionState state, float _f, boolean _isIdeal)
public final void setFitness(EvolutionState state, float _f, boolean _isIdeal)
public final float fitness()
Fitness
This function should be used only by fitness-proportionate selection and other selection methods which require an absolute fitness value. All other approaches should use the equivalentTo() and betterThan() methods.
If your fitness scheme does not use a metric quantifiable to a single value (for example, MultiObjectiveFitness), you should perform some reasonable translation.
fitness
in interface Fitness
public final void setup(EvolutionState state, Parameter base)
Prototype
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.
setup
in interface Prototype
public final boolean isIdealFitness()
Fitness
isIdealFitness
in interface Fitness
public final boolean equivalentTo(Fitness _fitness)
Fitness
equivalentTo
in interface Fitness
public final boolean betterThan(Fitness _fitness)
Fitness
betterThan
in interface Fitness
public void printFitness(EvolutionState state, int log, int verbosity)
Fitness
printFitness
in interface Fitness
public void printFitness(EvolutionState state, java.io.PrintWriter writer)
Fitness
printFitness
in interface Fitness
public void printFitnessForHumans(EvolutionState state, int log, int verbosity)
Fitness
printFitnessForHumans
in interface Fitness
public void readFitness(EvolutionState state, java.io.LineNumberReader reader) throws java.io.IOException, java.lang.CloneNotSupportedException
Fitness
readFitness
in interface Fitness
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |