Package ec.multiobjective

# Class MultiObjectiveFitness

java.lang.Object
ec.Fitness
ec.multiobjective.MultiObjectiveFitness

All Implemented Interfaces:
  `Prototype`, `Setup`, `Serializable`, `Cloneable`, `Comparable<Object>`

Direct Known Subclasses:
  `NSGA2MultiObjectiveFitness`, `SPEA2MultiObjectiveFitness`

public class MultiObjectiveFitness extends 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, and a flag (maximize) indicating whether higher is considered better. By default, isIdealFitness() always returns false; you might want to override that, though it'd be unusual -- what is the ideal fitness from the perspective of a pareto front?

The object also contains maximum and minimum fitness values suggested for the problem, on a per-objective basis. By default the maximum values are all 1.0 and the minimum values are all 0.0, but you can change these. Note that maximum does not mean "best" unless maximize is true.

The class also contains utility methods or computing pareto dominance, Pareto Fronts and Pareto Front Ranks, and distance in multiobjective space. The default comparison operators use Pareto Dominance, though this is often overridden by subclasses.

The fitness() method returns the maximum of the fitness values, which is clearly nonsensical: you should not be using this method.

Subclasses of this class may add certain auxiliary fitness measures which are printed out by MultiObjectiveStatistics along with the multiple objectives. To have these values printed out, override the getAuxiliaryFitnessNames() and getAuxiliaryFitnessValues() methods.

Parameters

base.`num-objectives` (else)`multi.num-objectives` int >= 1 | (the number of fitnesses in the objectives array)
base.`maximize` bool = `true` (default) or `false` | (are higher values considered "better"?)

base.`maximize`.iinvalid input: '<'/i
bool = `true` (default) or `false` (are higher values considered "better"?). Overrides the all-objecgive maximization setting.
base.`max`
double (`1.0` default) (maximum fitness value for all objectives)
base.`max`.i
double (`1.0` default) (maximum fitness value for objective i. Overrides the all-objective maximum fitness.)
base.`min`
double (`0.0` (default) (minimum fitness value for all objectives)
base.`min`.i
double = `0.0` (default) (minimum fitness value for objective i. Overrides the all-objective minimum fitness.)

Default Base
multi.fitness

See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `FITNESS_POSTAMBLE`
  `boolean[]`
  `maximize`
  Maximization.
  `double[]`
  `maxObjective`
  Desired maximum fitness values.
  `double[]`
  `minObjective`
  Desired minimum fitness values.
  `static final String`
  `MULTI_FITNESS_POSTAMBLE`
  `protected double[]`
  `objectives`
  The various fitnesses.
  `static final String`
  `P_MAXIMIZE`
  Is higher better?
  `static final String`
  `P_MAXOBJECTIVE`
  parameter for max fitness values
  `static final String`
  `P_MINOBJECTIVE`
  parameter for min fitness values
  `static final String`
  `P_NUMOBJECTIVES`
  parameter for size of objectives

  ### Fields inherited from class ec.Fitness

  `context, FITNESS_PREAMBLE, P_FITNESS, trials`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MultiObjectiveFitness()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `betterThan(Fitness fitness)`
  Returns true if I'm better than _fitness.
  `Object`
  `clone()`
  Creates a new individual cloned from a prototype, and suitable to begin use in its own evolutionary context.
  `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.
  `double`
  `fitness()`
  Returns the Max() of objectives, which adheres to Fitness.java's protocol for this method.
  `String`
  `fitnessToString()`
  Print to a string the fitness in a fashion intended to be parsed in again via readFitness(...).
  `String`
  `fitnessToStringForHumans()`
  Print to a string the fitness in a fashion readable by humans, and not intended to be parsed in again.
  `String[]`
  `getAuxilliaryFitnessNames()`
  Returns auxilliary fitness value names to be printed by the statistics object.
  `double[]`
  `getAuxilliaryFitnessValues()`
  Returns auxilliary fitness values to be printed by the statistics object.
  `int`
  `getNumObjectives()`
  `double`
  `getObjective(int i)`
  `double[]`
  `getObjectives()`
  Returns the objectives as an array.
  `static int[]`
  `getRankings(ArrayList<Individual> inds)`
  Returns the Pareto rank for each individual.
  `static ArrayList<Individual>`
  `getSortedParetoFront(ArrayList<Individual> inds)`
  Returns the Pareto Front of the provided Individuals, sorted by objective 0, breaking ties with objective 1, and so on...
  `boolean`
  `isIdealFitness()`
  Returns true if this fitness is the "ideal" fitness.
  `boolean`
  `isMaximizing()`
  `boolean`
  `isMaximizing(int objective)`
  `double`
  `manhattanObjectiveDistance(MultiObjectiveFitness other)`
  Returns the Manhattan difference between two Fitnesses in Objective space.
  `boolean`
  `paretoDominates(MultiObjectiveFitness other)`
  Returns true if I'm better than _fitness.
  `static ArrayList<Individual>`
  `partitionIntoParetoFront(ArrayList<Individual> inds, ArrayList<Individual> front, ArrayList<Individual> nonFront)`
  Divides an array of Individuals into the Pareto front and the "nonFront" (everyone else).
  `static ArrayList<ArrayList<Individual>>`
  `partitionIntoRanks(ArrayList<Individual> inds)`
  Divides inds into pareto front ranks (each an ArrayList), and returns them, in order, stored in an ArrayList.
  `void`
  `readFitness(EvolutionState state, DataInput dataInput)`
  Reads the binary form of an individual from a DataInput.
  `void`
  `readFitness(EvolutionState state, LineNumberReader reader)`
  Reads in the fitness from a form outputted by fitnessToString() and thus printFitnessForHumans(...).
  `void`
  `setObjectives(EvolutionState state, double[] newObjectives)`
  `void`
  `setToBestOf(EvolutionState state, Fitness[] fitnesses)`
  Sets the fitness to be the same value as the best of the provided fitnesses.
  `void`
  `setToMeanOf(EvolutionState state, Fitness[] fitnesses)`
  Sets the fitness to be the same value as the mean of the provided fitnesses.
  `void`
  `setToMedianOf(EvolutionState state, Fitness[] fitnesses)`
  Sets the fitness to be the median of the provided fitnesses.
  `void`
  `setup(EvolutionState state, Parameter base)`
  Sets up.
  `double`
  `sumSquaredObjectiveDistance(MultiObjectiveFitness other, boolean normalize)`
  Returns the sum of the squared difference between two Fitnesses in Objective space.
  `void`
  `writeFitness(EvolutionState state, DataOutput dataOutput)`
  Writes the binary form of an individual out to a DataOutput.

  ### Methods inherited from class ec.Fitness

  `compareTo, contextIsBetterThan, getContext, merge, printFitness, printFitness, printFitness, printFitnessForHumans, printFitnessForHumans, readTrials, setContext, setContext, writeTrials`

  ### Methods inherited from class java.lang.Object

  `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### MULTI_FITNESS_POSTAMBLE

    public static final String MULTI_FITNESS_POSTAMBLE
    See Also:
      - Constant Field Values

  - ### FITNESS_POSTAMBLE

    public static final String FITNESS_POSTAMBLE
    See Also:
      - Constant Field Values

  - ### P_NUMOBJECTIVES

    public static final String P_NUMOBJECTIVES
    parameter for size of objectives
    See Also:
      - Constant Field Values

  - ### P_MAXOBJECTIVE

    public static final String P_MAXOBJECTIVE
    parameter for max fitness values
    See Also:
      - Constant Field Values

  - ### P_MINOBJECTIVE

    public static final String P_MINOBJECTIVE
    parameter for min fitness values
    See Also:
      - Constant Field Values

  - ### P_MAXIMIZE

    public static final String P_MAXIMIZE
    Is higher better?
    See Also:
      - Constant Field Values

  - ### maxObjective

    public double[] maxObjective
    Desired maximum fitness values. By default these are 1.0. Shared.

  - ### minObjective

    public double[] minObjective
    Desired minimum fitness values. By default these are 0.0. Shared.

  - ### maximize

    public boolean[] maximize
    Maximization. Shared.

  - ### objectives

    protected double[] objectives
    The various fitnesses.

- ## Constructor Details

  - ### MultiObjectiveFitness

    public MultiObjectiveFitness()

- ## Method Details

  - ### getAuxilliaryFitnessNames

    public String[] getAuxilliaryFitnessNames()
    Returns auxilliary fitness value names to be printed by the statistics object. By default, an empty array is returned, but various algorithms may override this to provide additional columns.

  - ### getAuxilliaryFitnessValues

    public double[] getAuxilliaryFitnessValues()
    Returns auxilliary fitness values to be printed by the statistics object. By default, an empty array is returned, but various algorithms may override this to provide additional columns.

  - ### isMaximizing

    public boolean isMaximizing()

  - ### isMaximizing

    public boolean isMaximizing(int objective)

  - ### getNumObjectives

    public int getNumObjectives()

  - ### getObjectives

    public double[] getObjectives()
    Returns the objectives as an array. Note that this is the *actual array*. Though you could set values in this array, you should NOT do this -- rather, set them using setObjectives().

  - ### getObjective

    public double getObjective(int i)

  - ### setObjectives

    public void setObjectives(EvolutionState state, double[] newObjectives)

  - ### 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(...).

  - ### clone

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

    Typically this should be a full "deep" clone. However, you may share certain elements with other objects rather than clone hem, depending on the situation:

    - If you hold objects which are shared with other instances, don't clone them.
    - If you hold objects which must be unique, clone them.
    - If you hold objects which were given to you as a gesture of kindness, and aren't owned by you, you probably shouldn't clone them.
    - DON'T attempt to clone: Singletons, Cliques, or Populations, or Subpopulation.
    - Arrays are not cloned automatically; you may need to clone an array if you're not sharing it with other instances. Arrays have the nice feature of being copyable by calling clone() on them.

    Implementations.

    - If no ancestor of yours implements clone(), and you have no need to do clone deeply, and you are abstract, then you should not declare clone().
    - If no ancestor of yours implements clone(), and you have no need to do clone deeply, and you are not abstract, then you should implement it as follows:

      ``

           public Object clone()
               {
               try
                   {
                   return super.clone();
                   }
               catch ((CloneNotSupportedException e)
                   { throw new InternalError(); } // never happens
               }

    - If no ancestor of yours implements clone(), but you need to deep-clone some things, then you should implement it as follows:

      ``

           public Object clone()
               {
               try
                   {
                   MyObject myobj = (MyObject) (super.clone());

                   // put your deep-cloning code here...
                   }
               catch ((CloneNotSupportedException e)
                   { throw new InternalError(); } // never happens
               return myobj;
               }

    - If an ancestor has implemented clone(), and you also need to deep clone some things, then you should implement it as follows:

      ``

           public Object clone()
               {
               MyObject myobj = (MyObject) (super.clone());

               // put your deep-cloning code here...

               return myobj;
               }

    Specified by:
      `clone` in interface `Prototype`
    Overrides:
      `clone` in class `Fitness`

  - ### fitness

    public double fitness()
    Returns the Max() of objectives, 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 class `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`
    Specified by:
      `setup` in interface `Setup`
    Overrides:
      `setup` in class `Fitness`

  - ### isIdealFitness

    public boolean isIdealFitness()
    Returns true if this fitness is the "ideal" fitness. Default always returns false. You may want to override this.
    Specified by:
      `isIdealFitness` in class `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. Multiobjective optimization algorithms may choose to override this to do something else.
    Specified by:
      `equivalentTo` in class `Fitness`

  - ### betterThan

    public boolean betterThan(Fitness fitness)
    Returns true if I'm better than _fitness. The DEFAULT 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. Multiobjective optimization algorithms may choose to override this to do something else.
    Specified by:
      `betterThan` in class `Fitness`

  - ### paretoDominates

    public boolean paretoDominates(MultiObjectiveFitness other)
    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.

  - ### partitionIntoParetoFront

    public static ArrayList<Individual> partitionIntoParetoFront(ArrayList<Individual> inds, ArrayList<Individual> front, ArrayList<Individual> nonFront)
    Divides an array of Individuals into the Pareto front and the "nonFront" (everyone else). The Pareto front is returned. You may provide ArrayLists for the front and a nonFront. If you provide null for the front, an ArrayList will be created for you. If you provide null for the nonFront, non-front individuals will not be added to it. This algorithm is O(n^2).

  - ### getSortedParetoFront

    public static ArrayList<Individual> getSortedParetoFront(ArrayList<Individual> inds)
    Returns the Pareto Front of the provided Individuals, sorted by objective 0, breaking ties with objective 1, and so on...

    This would be useful for printing out statistics.

  - ### partitionIntoRanks

    public static ArrayList<ArrayList<Individual>> partitionIntoRanks(ArrayList<Individual> inds)
    Divides inds into pareto front ranks (each an ArrayList), and returns them, in order, stored in an ArrayList.

  - ### getRankings

    public static int[] getRankings(ArrayList<Individual> inds)
    Returns the Pareto rank for each individual. Rank 0 is the best rank, then rank 1, and so on. This is O(n) but it has a high constant overhead because it allocates a hashmap and does some autoboxing.

  - ### sumSquaredObjectiveDistance

    public double sumSquaredObjectiveDistance(MultiObjectiveFitness other, boolean normalize)
    Returns the sum of the squared difference between two Fitnesses in Objective space.

  - ### manhattanObjectiveDistance

    public double manhattanObjectiveDistance(MultiObjectiveFitness other)
    Returns the Manhattan difference between two Fitnesses in Objective space.

  - ### fitnessToString

    public String fitnessToString()
    Description copied from class: `Fitness`
    Print to a string the fitness in a fashion intended to be parsed in again via readFitness(...). The fitness and evaluated flag should not be included. The default form simply calls toString(), which is almost certainly wrong, and you'll probably want to override this to something else. When overriding, you may wish to check to see if the 'trials' variable is non-null, and issue an error if so.
    Overrides:
      `fitnessToString` in class `Fitness`

  - ### fitnessToStringForHumans

    public String fitnessToStringForHumans()
    Description copied from class: `Fitness`
    Print to a string the fitness in a fashion readable by humans, and not intended to be parsed in again. The default form simply calls toString(), but you'll probably want to override this to something else.
    Overrides:
      `fitnessToStringForHumans` in class `Fitness`

  - ### readFitness

    public void readFitness(EvolutionState state, LineNumberReader reader) throws IOException
    Description copied from class: `Fitness`
    Reads in the fitness from a form outputted by fitnessToString() and thus printFitnessForHumans(...). The default version of this method exits the program with an "unimplemented" error.
    Overrides:
      `readFitness` in class `Fitness`
    Throws:
      `IOException`

  - ### writeFitness

    public void writeFitness(EvolutionState state, DataOutput dataOutput) throws IOException
    Description copied from class: `Fitness`
    Writes the binary form of an individual out to a DataOutput. This is not for serialization: the object should only write out the data relevant to the object sufficient to rebuild it from a DataInput. The default version exits the program with an "unimplemented" error; you should override this, and be certain to also write the 'trials' variable as well.
    Overrides:
      `writeFitness` in class `Fitness`
    Throws:
      `IOException`

  - ### readFitness

    public void readFitness(EvolutionState state, DataInput dataInput) throws IOException
    Description copied from class: `Fitness`
    Reads the binary form of an individual from a DataInput. This is not for serialization: the object should only read in the data written out via printIndividual(state,dataInput). The default version exits the program with an "unimplemented" error; you should override this, and be certain to also write the 'trials' variable as well.
    Overrides:
      `readFitness` in class `Fitness`
    Throws:
      `IOException`

  - ### setToBestOf

    public void setToBestOf(EvolutionState state, Fitness[] fitnesses)
    Description copied from class: `Fitness`
    Sets the fitness to be the same value as the best of the provided fitnesses. This method calls setToMeanOf(...), so if that method is unimplemented, this method will also fail.
    Overrides:
      `setToBestOf` in class `Fitness`

  - ### setToMeanOf

    public void setToMeanOf(EvolutionState state, Fitness[] fitnesses)
    Description copied from class: `Fitness`
    Sets the fitness to be the same value as the mean of the provided fitnesses. The default version of this method exits with an "unimplemented" error; you should override this.
    Overrides:
      `setToMeanOf` in class `Fitness`

  - ### setToMedianOf

    public void setToMedianOf(EvolutionState state, Fitness[] fitnesses)
    Description copied from class: `Fitness`
    Sets the fitness to be the median of the provided fitnesses. This method calls setToMeanOf(...), so if that method is unimplemented, this method will also fail.
    Overrides:
      `setToMedianOf` in class `Fitness`