ec.multiobjective.spea2
Class SPEA2MultiObjectiveFitness

java.lang.Object
  |
  +--ec.multiobjective.spea2.SPEA2MultiObjectiveFitness
All Implemented Interfaces:
java.lang.Cloneable, Fitness, Prototype, java.io.Serializable, Setup

public class SPEA2MultiObjectiveFitness
extends java.lang.Object
implements Fitness

SPEA2MultiObjectiveFitness is a subclass of Fitness which implements basic multiobjective fitness functions along with support for the ECJ SPEA2 (Strength Pareto Evolutionary Algorithm) extensions.

The object contains two items: an array of floating point values representing the various multiple fitnesses (ranging from 0.0 (worst) to infinity (best)), and a single SPEA2 fitness value which represents the individual's overall fitness ( a function of the number of individuals it dominates and it's raw score where 0.0 is the best).

Parameters
base.numobjectives
(else)multi.numobjectives
int >= 1
(the number of fitnesses in the multifitness array)

Default Base
spea2.fitness

See Also:
Serialized Form

Field Summary
static java.lang.String FITNESS_POSTAMBLE
           
static java.lang.String FITNESS_PREAMBLE
           
 float[] multifitness
          The various fitnesses.
static java.lang.String P_FITNESS
          base parameter for defaults
static java.lang.String P_NUMFITNESSES
          parameter for size of multifitness
static java.lang.String SPEA2FIT_PREAMBLE
           
 double SPEA2Fitness
          SPEA2 overall fitness
 double SPEA2kthNNDistance
          SPEA2 NN distance
 double SPEA2RawFitness
          SPEA2 RAW fitness
 double SPEA2Strength
          SPEA2 strength (# of nodes it dominates)
 
Constructor Summary
SPEA2MultiObjectiveFitness()
           
 
Method Summary
 boolean betterThan(Fitness _fitness)
          Returns true if I'm better than _fitness.
 float calcDistance(SPEA2MultiObjectiveFitness otherFit)
          Returns the sum of the squared differences between the vector fitness values.
 Parameter defaultBase()
          Returns the default base for this prototype.
 boolean equivalentTo(Fitness _fitness)
          Returns true if I'm equivalent in fitness (neither better nor worse) to _fitness.
 float fitness()
          Returns the Max() of multifitnesses, which adheres to Fitness.java's protocol for this method.
 boolean isIdealFitness()
          Returns false.
 void printFitness(EvolutionState state, int log, int verbosity)
          Prints the fitness in the computer-readable form:
 void printFitness(EvolutionState state, java.io.PrintWriter writer)
          Prints the fitness in the computer-readable form:
 void printFitnessForHumans(EvolutionState state, int log, int verbosity)
          Prints the fitness in the human-readable form:
 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 setup(EvolutionState state, Parameter base)
          Sets up.
 
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

FITNESS_POSTAMBLE

public static final java.lang.String FITNESS_POSTAMBLE

SPEA2FIT_PREAMBLE

public static final java.lang.String SPEA2FIT_PREAMBLE

P_FITNESS

public static final java.lang.String P_FITNESS
base parameter for defaults

P_NUMFITNESSES

public static final java.lang.String P_NUMFITNESSES
parameter for size of multifitness

multifitness

public float[] multifitness
The various fitnesses.

SPEA2Fitness

public double SPEA2Fitness
SPEA2 overall fitness

SPEA2Strength

public double SPEA2Strength
SPEA2 strength (# of nodes it dominates)

SPEA2RawFitness

public double SPEA2RawFitness
SPEA2 RAW fitness

SPEA2kthNNDistance

public double SPEA2kthNNDistance
SPEA2 NN distance
Constructor Detail

SPEA2MultiObjectiveFitness

public SPEA2MultiObjectiveFitness()
Method Detail

defaultBase

public final 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

calcDistance

public float calcDistance(SPEA2MultiObjectiveFitness otherFit)
Returns the sum of the squared differences between the vector fitness values.

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

fitness

public float fitness()
Returns the Max() of multifitnesses, which adheres to Fitness.java's protocol for this method. Though you should not rely on a selection or statistics method which requires this.
Specified by:
fitness in interface Fitness

setup

public void setup(EvolutionState state,
                  Parameter base)
Sets up. This must be called at least once in the prototype before instantiating any fitnesses that will actually be used in evolution.
Specified by:
setup in interface Prototype

isIdealFitness

public boolean isIdealFitness()
Returns false. In this multiobjective implementation we have no idea what is ideal (since scores go between 0-infinity) so we punt this to our subclasses and always return false.
Specified by:
isIdealFitness in interface Fitness

equivalentTo

public boolean equivalentTo(Fitness _fitness)
Returns true if I'm equivalent in fitness (neither better nor worse) to _fitness. The rule I'm using is this: If one of us is better in one or more criteria, and we are equal in the others, then equivalentTo is false. If each of us is better in one or more criteria each, or we are equal in all criteria, then equivalentTo is true.
Specified by:
equivalentTo in interface Fitness

betterThan

public boolean betterThan(Fitness _fitness)
Returns true if I'm better than _fitness. The rule I'm using is this: if I am better in one or more criteria, and we are equal in the others, then betterThan is true, else it is false.
Specified by:
betterThan in interface Fitness

printFitness

public void printFitness(EvolutionState state,
                         int log,
                         int verbosity)
Prints the fitness in the computer-readable form:

Fitness: [fitness values encoded with ec.util.Code, separated by spaces]

Specified by:
printFitness in interface Fitness

printFitness

public void printFitness(EvolutionState state,
                         java.io.PrintWriter writer)
Prints the fitness in the computer-readable form:

Fitness: [fitness values encoded with ec.util.Code, separated by spaces]

Specified by:
printFitness in interface Fitness

printFitnessForHumans

public void printFitnessForHumans(EvolutionState state,
                                  int log,
                                  int verbosity)
Prints the fitness in the human-readable form:

Fitness: [fitness values separated by spaces]

Specified by:
printFitnessForHumans in interface Fitness

readFitness

public void readFitness(EvolutionState state,
                        java.io.LineNumberReader reader)
                 throws java.io.IOException,
                        java.lang.CloneNotSupportedException
Description copied from interface: Fitness
Reads in the fitness from a form printed by printFitness().
Specified by:
readFitness in interface Fitness