// DTLZ3.java
//
// Author:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
//
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package org.uma.jmetal.problem.multiobjective.dtlz;
import org.uma.jmetal.problem.impl.AbstractDoubleProblem;
import org.uma.jmetal.solution.DoubleSolution;
import org.uma.jmetal.util.JMetalException;
import java.util.ArrayList;
import java.util.List;
/**
* Class representing problem DTLZ3
*/
@SuppressWarnings("serial")
public class DTLZ3 extends AbstractDoubleProblem {
/**
* Creates a default DTLZ3 problem (12 variables and 3 objectives)
*/
public DTLZ3() {
this(12, 3);
}
/**
* Creates a DTLZ3 problem instance
*
* @param numberOfVariables Number of variables
* @param numberOfObjectives Number of objective functions
*/
public DTLZ3(Integer numberOfVariables, Integer numberOfObjectives) throws JMetalException {
setNumberOfVariables(numberOfVariables);
setNumberOfObjectives(numberOfObjectives);
setName("DTLZ3");
List<Double> lowerLimit = new ArrayList<>(getNumberOfVariables()) ;
List<Double> upperLimit = new ArrayList<>(getNumberOfVariables()) ;
for (int i = 0; i < getNumberOfVariables(); i++) {
lowerLimit.add(0.0);
upperLimit.add(1.0);
}
setLowerLimit(lowerLimit);
setUpperLimit(upperLimit);
}
/** Evaluate() method */
public void evaluate(DoubleSolution solution) {
int numberOfVariables = getNumberOfVariables();
int numberOfObjectives = getNumberOfObjectives();
double[] f = new double[numberOfObjectives];
double[] x = new double[numberOfVariables] ;
for (int i = 0; i < numberOfVariables; i++) {
x[i] = solution.getVariableValue(i) ;
}
int k = getNumberOfVariables() - getNumberOfObjectives() + 1;
double g = 0.0;
for (int i = numberOfVariables - k; i < numberOfVariables; i++) {
g += (x[i] - 0.5) * (x[i] - 0.5) - Math.cos(20.0 * Math.PI * (x[i] - 0.5));
}
g = 100.0 * (k + g);
for (int i = 0; i < numberOfObjectives; i++) {
f[i] = 1.0 + g;
}
for (int i = 0; i < numberOfObjectives; i++) {
for (int j = 0; j < numberOfObjectives - (i + 1); j++) {
f[i] *= java.lang.Math.cos(x[j] * 0.5 * java.lang.Math.PI);
}
if (i != 0) {
int aux = numberOfObjectives - (i + 1);
f[i] *= java.lang.Math.sin(x[aux] * 0.5 * java.lang.Math.PI);
}
}
for (int i = 0; i < numberOfObjectives; i++) {
solution.setObjective(i, f[i]);
}
}
}