All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jeco.core.problems.zdt.ZDT2 Maven / Gradle / Ivy

The newest version!
package jeco.core.problems.zdt;

import java.util.ArrayList;

import jeco.core.operator.comparator.SolutionDominance;
import jeco.core.problem.Solution;
import jeco.core.problem.Solutions;
import jeco.core.problem.Variable;

public class ZDT2 extends ZDT {

    public ZDT2(Integer numberOfVariables) {
        super(numberOfVariables);
        for (int i = 0; i < numberOfVariables; i++) {
            lowerBound[i] = 0.0;
            upperBound[i] = 1.0;
        }
    } // ZDT1

    public ZDT2() {
        this(30);
    }

    public void evaluate(Solution> solution) {
        ArrayList> variables = solution.getVariables();
        double f1 = variables.get(0).getValue();
        double g = 0;
        for (int j = 1; j < numberOfVariables; ++j) {
            g += variables.get(j).getValue();
        }
        g *= 9.0;
        g /= numberOfVariables - 1;
        g += 1.0;
        double h = 1 - (f1 / g) * (f1 / g);
        solution.getObjectives().set(0, f1);
        solution.getObjectives().set(1, g * h);
    }

    public Solutions> computeParetoOptimalFront(int n) {
        Solutions> result = new Solutions>();

        double temp;
        for (int i = 0; i < n; ++i) {
            Solution> sol = new Solution>(numberOfObjectives);
            temp = 0.0 + (1.0 * i) / (n - 1);
            sol.getVariables().add(new Variable(temp));
            for (int j = 1; j < numberOfVariables; ++j) {
                sol.getVariables().add(new Variable(0.0));
            }

            evaluate(sol);
            result.add(sol);
        }

        result.reduceToNonDominated(new SolutionDominance>());
        return result;
    }
    public ZDT2 clone() {
    	ZDT2 clone = new ZDT2(this.numberOfVariables);
    	for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy