/* Copyright 2006 by Sean Luke and George Mason University Licensed under the Academic Free License version 3.0 See the file "LICENSE" for more information */ package ec.app.moosuite; import ec.util.*; import ec.*; import ec.multiobjective.MultiObjectiveFitness; import ec.simple.*; import ec.vector.*; /** Several standard Multi-objective benchmarks are implemented:

Parameters
base.type
String, one of: zdt1, zdt2, zdt3, zdt4, zdt6, sphere, sch, fon, qv, pol, kur, f1, f2, unconstrained-f3
The multi-objective optimization problem to test against.
@author Gabriel Catalin Balan */ public class MooSuite extends Problem implements SimpleProblemForm { /** * */ private static final long serialVersionUID = 1L; public static final String P_WHICH_PROBLEM = "type"; public static final String P_ZDT1 = "zdt1"; public static final String P_ZDT2 = "zdt2"; public static final String P_ZDT3 = "zdt3"; public static final String P_ZDT4 = "zdt4"; public static final String P_ZDT6 = "zdt6"; public static final String P_SPHERE = "sphere"; public static final String P_SCH = "sch"; public static final String P_FON = "fon"; public static final String P_QV = "qv"; public static final String P_POL = "pol"; public static final String P_KUR_NSGA2 = "kur-nsga2"; public static final String P_KUR_SPEA2 = "kur-spea2"; public static final String P_F1 = "f1"; public static final String P_F2 = "f2"; public static final String P_F3 = "unconstrained-f3"; //Some of the following problems requires an exact number of decision variables (genes). This is mentioned in comment preceding the problem. public static final int PROB_SPHERE = 0; public static final int PROB_ZDT1 = 1; public static final int PROB_ZDT2 = 2; public static final int PROB_ZDT3 = 3; public static final int PROB_ZDT4 = 4; public static final int PROB_ZDT6 = 6; public static final int PROB_FON = 7; public static final int PROB_POL = 8; public static final int PROB_KUR_NSGA2 = 9; public static final int PROB_KUR_SPEA2 = 10; public static final int PROB_QV = 11; public static final int PROB_SCH = 12; public static final int PROB_F2 = 13; public static final int PROB_F3 = 14; public int problemType = PROB_ZDT1; // defaults on zdt1 public void setup(final EvolutionState state, final Parameter base) { super.setup(state, base); String wp = state.parameters.getStringWithDefault( base.push( P_WHICH_PROBLEM ), null, "" ); if( wp.compareTo( P_ZDT1) == 0 ) problemType = PROB_ZDT1; else if ( wp.compareTo( P_ZDT2) == 0 ) problemType = PROB_ZDT2; else if ( wp.compareTo( P_ZDT3) == 0 ) problemType = PROB_ZDT3; else if ( wp.compareTo( P_ZDT4) == 0 ) problemType = PROB_ZDT4; else if ( wp.compareTo( P_ZDT6) == 0 ) problemType = PROB_ZDT6; else if ( wp.compareTo( P_FON) == 0 ) problemType = PROB_FON; else if ( wp.compareTo( P_POL) == 0 ) problemType = PROB_POL; else if ( wp.compareTo( P_QV) == 0 ) problemType = PROB_QV; else if ( wp.compareTo( P_KUR_NSGA2) == 0 ) problemType = PROB_KUR_NSGA2; else if ( wp.compareTo( P_KUR_SPEA2) == 0 ) problemType = PROB_KUR_SPEA2; else if( wp.compareTo( P_SPHERE) == 0) problemType = PROB_SPHERE; else if( wp.compareTo( P_F2) == 0) problemType = PROB_F2; else if( wp.compareTo( P_F3) == 0) problemType = PROB_F3; else if( wp.compareTo( P_SCH) == 0 || wp.compareTo( P_F1) == 0 ) problemType = PROB_SCH; else state.output.fatal( "Invalid value for parameter, or parameter not found.\n" + "Acceptable values are:\n" + " " + P_ZDT1 + "\n" + " " + P_ZDT2 + "\n" + " " + P_ZDT3 + "\n" + " " + P_ZDT4 + "\n" + " " + P_ZDT6 + "\n" + " " + P_POL + "\n" + " " + P_FON + "\n" + " " + P_KUR_NSGA2 + "\n" + " " + P_KUR_SPEA2 + "\n" + " " + P_SPHERE + "\n" + " " + P_SCH + "(or " + P_F1 + ")\n"+ " " + P_F2 + "\n", base.push( P_WHICH_PROBLEM ) ); } private static final double TWO_PI = Math.PI*2;//QV uses it. private static final double TEN_PI = Math.PI*10;//ZDT3 uses it. private static final double FOUR_PI = Math.PI*4;//ZDT4 uses it. private static final double SIX_PI = Math.PI*6;//ZDT6 uses it. private static final double ONE_OVER_SQRT_3 = 1d/Math.sqrt(3);//FON uses it. private static final double A1 = 0.5*Math.sin(1) - 2*Math.cos(1) + Math.sin(2)- 1.5*Math.cos(2);//POL uses it private static final double A2 = 1.5*Math.sin(1) - Math.cos(1) + 2* Math.sin(2)- 0.5*Math.cos(2);//POL uses it public void evaluate(final EvolutionState state, final Individual ind, final int subpopulation, final int threadnum) { if( !( ind instanceof DoubleVectorIndividual ) ) state.output.fatal( "The individuals for this problem should be DoubleVectorIndividuals." ); DoubleVectorIndividual temp = (DoubleVectorIndividual)ind; double[] genome = temp.genome; int numDecisionVars = genome.length; float[] objectives = ((MultiObjectiveFitness)ind.fitness).getObjectives(); double f, g, h, sum; switch(problemType) { case PROB_ZDT1: f = genome[0]; objectives[0] = (float)f; sum = 0; for(int i = 1; i< numDecisionVars; ++i) sum += genome[i]; g = 1d+9d*sum/(numDecisionVars-1); h = 1d-Math.sqrt(f/g); objectives[1] = (float)(g*h); break; case PROB_ZDT2: f = genome[0]; objectives[0] = (float)f; sum = 0; for(int i = 1; i< numDecisionVars; i++) sum += genome[i]; g = 1.0+9.0*sum/(float)(numDecisionVars-1); h = 1.0-(f/g)*(f/g); objectives[1] = (float)(g*h); break; case PROB_ZDT3: f = genome[0]; objectives[0] = (float)f; sum = 0; for(int i = 1; i< numDecisionVars; i++) sum += genome[i]; g = 1.0+9.0*sum/(numDecisionVars-1); double foverg = f/g; h = 1.0-Math.sqrt(foverg) - foverg * Math.sin(TEN_PI * f); objectives[1] = (float)(g*h); break; case PROB_ZDT4: f = genome[0]; objectives[0] = (float)f; sum = 0; for(int i = 1; i< numDecisionVars; ++i) sum += genome[i]*genome[i]- 10*Math.cos(FOUR_PI * genome[i]); g = 1+10*(numDecisionVars-1)+sum; h = 1-Math.sqrt(f/g); objectives[1] = (float)(g*h); break; case PROB_ZDT6: f = 1 - (Math.exp(-4 * genome[0]) * Math.pow(Math.sin(SIX_PI * genome[0]), 6)); objectives[0] = (float)f; sum = 0; for (int i = 1; i < numDecisionVars; ++i) sum += genome[i]; g = 1d + 9 * Math.pow(sum / (numDecisionVars - 1), 0.25); h = 1d - Math.pow(f / g, 2); objectives[1] = (float) (g * h); break; case PROB_SPHERE: int numObjectives = objectives.length; for(int j=0; j