1 | /* |
---|
2 | Portions copyright 2010 by Sean Luke, Robert Hubley, and George Mason University |
---|
3 | Licensed under the Academic Free License version 3.0 |
---|
4 | See the file "LICENSE" for more information |
---|
5 | */ |
---|
6 | |
---|
7 | package ec.multiobjective.spea2; |
---|
8 | |
---|
9 | import java.io.*; |
---|
10 | import ec.util.*; |
---|
11 | import ec.multiobjective.*; |
---|
12 | import ec.*; |
---|
13 | |
---|
14 | /* |
---|
15 | * SPEA2MultiObjectiveFitness.java |
---|
16 | * |
---|
17 | * Created: Sat Oct 16 11:24:43 EDT 2010 |
---|
18 | * By: Sean Luke |
---|
19 | * Replaces earlier class by: Robert Hubley, with revisions by Gabriel Balan and Keith Sullivan |
---|
20 | */ |
---|
21 | |
---|
22 | /** |
---|
23 | * SPEA2MultiObjectiveFitness is a subclass of MultiObjectiveFitness which adds three auxiliary fitness |
---|
24 | * measures used in SPEA2: strength S(i), kthNNDistance D(i), and a final fitness value R(i) + D(i). |
---|
25 | * Note that so-called "raw fitness" (what Sean calls "Wimpiness" in Essentials of Metaheuristics) is |
---|
26 | * not retained. |
---|
27 | * |
---|
28 | * <p>The fitness comparison operators solely use the 'fitness' value R(i) + D(i). |
---|
29 | */ |
---|
30 | |
---|
31 | public class SPEA2MultiObjectiveFitness extends MultiObjectiveFitness |
---|
32 | { |
---|
33 | public static final String SPEA2_FITNESS_PREAMBLE = "Fitness: "; |
---|
34 | public static final String SPEA2_STRENGTH_PREAMBLE = "Strength: "; |
---|
35 | public static final String SPEA2_DISTANCE_PREAMBLE = "Distance: "; |
---|
36 | |
---|
37 | public String[] getAuxilliaryFitnessNames() { return new String[] { "Strength", "Raw Fitness", "Kth NN Distance" }; } |
---|
38 | public double[] getAuxilliaryFitnessValues() { return new double[] { strength, fitness, kthNNDistance }; } |
---|
39 | |
---|
40 | /** SPEA2 strength (# of nodes it dominates) */ |
---|
41 | public double strength; // S(i) |
---|
42 | |
---|
43 | /** SPEA2 NN distance */ |
---|
44 | public double kthNNDistance; // D(i) |
---|
45 | |
---|
46 | /** Final SPEA2 fitness. Equals the raw fitness R(i) plus the kthNNDistance D(i). */ |
---|
47 | public double fitness; |
---|
48 | |
---|
49 | public String fitnessToString() |
---|
50 | { |
---|
51 | return super.fitnessToString() + "\n" + SPEA2_FITNESS_PREAMBLE + Code.encode(fitness) + "\n" + SPEA2_STRENGTH_PREAMBLE + Code.encode(strength) + "\n" + SPEA2_DISTANCE_PREAMBLE + Code.encode(kthNNDistance); |
---|
52 | } |
---|
53 | |
---|
54 | public String fitnessToStringForHumans() |
---|
55 | { |
---|
56 | return super.fitnessToStringForHumans() + "\n" + "S=" + strength + " D=" + kthNNDistance + " " + SPEA2_FITNESS_PREAMBLE + fitness; |
---|
57 | } |
---|
58 | |
---|
59 | public void readFitness(final EvolutionState state, final LineNumberReader reader) throws IOException |
---|
60 | { |
---|
61 | super.readFitness(state, reader); |
---|
62 | fitness = Code.readDoubleWithPreamble(SPEA2_FITNESS_PREAMBLE, state, reader); |
---|
63 | strength = Code.readDoubleWithPreamble(SPEA2_STRENGTH_PREAMBLE, state, reader); |
---|
64 | kthNNDistance = Code.readDoubleWithPreamble(SPEA2_DISTANCE_PREAMBLE, state, reader); |
---|
65 | } |
---|
66 | |
---|
67 | public void writeFitness(final EvolutionState state, final DataOutput dataOutput) throws IOException |
---|
68 | { |
---|
69 | super.writeFitness(state, dataOutput); |
---|
70 | dataOutput.writeDouble(fitness); |
---|
71 | dataOutput.writeDouble(strength); |
---|
72 | dataOutput.writeDouble(fitness); |
---|
73 | dataOutput.writeDouble(kthNNDistance); |
---|
74 | } |
---|
75 | |
---|
76 | public void readFitness(final EvolutionState state, final DataInput dataInput) throws IOException |
---|
77 | { |
---|
78 | super.readFitness(state, dataInput); |
---|
79 | fitness = dataInput.readDouble(); |
---|
80 | strength = dataInput.readDouble(); |
---|
81 | fitness = dataInput.readDouble(); |
---|
82 | kthNNDistance = dataInput.readDouble(); |
---|
83 | } |
---|
84 | |
---|
85 | /** |
---|
86 | * The selection criteria in SPEA2 uses the computed fitness, and not |
---|
87 | * pareto dominance. |
---|
88 | */ |
---|
89 | public boolean equivalentTo(Fitness _fitness) |
---|
90 | { |
---|
91 | return fitness == ((SPEA2MultiObjectiveFitness)_fitness).fitness; |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | * The selection criteria in SPEA2 uses the computed fitness, and not |
---|
96 | * pareto dominance. |
---|
97 | */ |
---|
98 | public boolean betterThan(Fitness _fitness) |
---|
99 | { |
---|
100 | return fitness < ((SPEA2MultiObjectiveFitness)_fitness).fitness; |
---|
101 | } |
---|
102 | } |
---|