ec.multiobjective
Class MultiObjectiveFitness

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

public class MultiObjectiveFitness
extends java.lang.Object
implements Fitness

MultiObjectiveFitness is a subclass of Fitness which implements basic multi-objective mechanisms suitable for being used with a variety of multi-objective selection mechanisms, including ones using pareto-optimality.

The object contains two items: an array of floating point values representing the various multiple fitnesses (ranging from 0.0 (worst) to 1.0 inclusive), and a flag (criterionIsAnd) which indicates whether or not the ideal multiple fitness is one with all its fitness values = 1.0, or one with at least one of its fitness values = 1.0.

Parameters
base.numobjectives
(else)multi.numobjectives
int >= 1
(the number of fitnesses in the multifitness array)
base.criterion-is-and
bool = true (default) or false
(is the ideal individual one whose fitness values are all 1.0 (as opposed to one which contains at least one fitness value of 1.0))

Default Base
multi.fitness

See Also:
Serialized Form

Field Summary
 boolean criterionIsAnd
          is the ideal individual critereon one which does an AND over the "idealness" of each of the fitnesses (as opposed to an OR)?
static java.lang.String FITNESS_POSTAMBLE
           
static java.lang.String FITNESS_PREAMBLE
           
 float[] multifitness
          The various fitnesses.
static java.lang.String P_CRITERIONISAND
          criterionIsAnd parameter
static java.lang.String P_FITNESS
          base parameter for defaults
static java.lang.String P_NUMFITNESSES
          parameter for size of multifitness
 
Constructor Summary
MultiObjectiveFitness()
           
 
Method Summary
 boolean betterThan(Fitness _fitness)
          Returns true if I'm better than _fitness.
 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 true if this fitness is the "ideal" fitness.
 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

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

P_CRITERIONISAND

public static final java.lang.String P_CRITERIONISAND
criterionIsAnd parameter

criterionIsAnd

public boolean criterionIsAnd
is the ideal individual critereon one which does an AND over the "idealness" of each of the fitnesses (as opposed to an OR)?

multifitness

public float[] multifitness
The various fitnesses.
Constructor Detail

MultiObjectiveFitness

public MultiObjectiveFitness()
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 final 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

protoCloneSimple

public final 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 final 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 final 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 final boolean isIdealFitness()
Returns true if this fitness is the "ideal" fitness.
Specified by:
isIdealFitness in interface Fitness

equivalentTo

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