MTO和Manytasking MATP MOOMFO 中G函數

Manytasking MATP MOOMFO 中G函數

覺得有用的話,歡迎一起討論相互學習~Follow Me

當統一空間[0,1]的決策變量經過Scale爲獨立於Problem的決策變量後,經過偏移和旋轉,然後的過程就是計算G函數了

MMDTLZ evalute函數

public void evaluate(Solution solution) throws JMException {
        double vars[] = scaleVariables(solution);

        double[] xI = new double[numberOfObjectives_ - 1];
        //matp1中 2-1= 1
        double[] xII = new double[numberOfVariables_ - numberOfObjectives_ + 1];
        //matp1中 50-2+1= 49
        for (int i = 0; i < numberOfObjectives_ - 1; i++)
            xI[i] = vars[i];
        //XI中只含有第一個變量
        for (int i = numberOfObjectives_ - 1; i < numberOfVariables_; i++)
            //for(i=1;i<50;i++)
            xII[i - numberOfObjectives_ + 1] = vars[i];
        //XII中含有第二個變量到最後一個變量
        //當i=numberOfObjectives_ - 1時,i - numberOfObjectives_ + 1=0
        //當i=numberOfVariables_-1時,i - numberOfObjectives_ + 1=numberOfVariables_-numberOfObjectives_=48 其實是第49個變量
        xII = transformVariables(xII);
        //旋轉和偏移

        double[] f = new double[numberOfObjectives_];

        double g = evalG(xII);

        for (int i = 0; i < numberOfObjectives_; i++)
            f[i] = 1 + g;

        solution.setGFunValue(1 + g);

        for (int i = 0; i < numberOfObjectives_; i++) {
            for (int j = 0; j < numberOfObjectives_ - (i + 1); j++)
                f[i] *= Math.cos(Math.pow(xI[j], alpha_) * 0.5 * Math.PI);
            if (i != 0) {
                int aux = numberOfObjectives_ - (i + 1);
                f[i] *= Math.sin(Math.pow(xI[aux], alpha_) * 0.5 * Math.PI);
            } // if
        } // for

        for (int i = 0; i < numberOfObjectives_; i++)
            solution.setObjective(startObjPos_ + i, f[i]);
    }

evalG(XII)

double evalG(double[] xII) throws JMException {
        if (gType_.equalsIgnoreCase("sphere"))
            return GFunctions.getSphere(xII);
        else if (gType_.equalsIgnoreCase("rosenbrock"))
            return GFunctions.getRosenbrock(xII);
        else if (gType_.equalsIgnoreCase("ackley"))
            return GFunctions.getAckley(xII);
        else if (gType_.equalsIgnoreCase("griewank"))
            return GFunctions.getGriewank(xII);
        else if (gType_.equalsIgnoreCase("rastrigin"))
            return GFunctions.getRastrigin(xII);
        else if (gType_.equalsIgnoreCase("mean"))
            return GFunctions.getMean(xII);
        else {
            System.out.println("Error: g function type " + gType_ + " invalid");
            return Double.NaN;
        }
    }

重頭戲Gfunction

package momfo.problems.base;

public class GFunctions {
	public static double getSphere(double x[]) {
		double sum = 0;
		for (int i = 0; i < x.length; i++)
			sum += (x[i] * x[i]);
		return sum;
	}

	public static double getRosenbrock(double x[]) {
		double sum = 0;

		for (int i = 0; i < x.length - 1; i++) {
			double t = 100 * (x[i] * x[i] - x[i + 1]) * (x[i] * x[i] - x[i + 1]) + (1 - x[i]) * (1 - x[i]);
			sum += t;
		}

		return sum;
	}

	public static double getAckley(double x[]) {
		double sum1 = 0;
		double sum2 = 0;

		for (int i = 0; i < x.length; i++) {
			sum1 += ((x[i] * x[i]) / x.length);
			sum2 += (Math.cos(2 * Math.PI * x[i]) / x.length);
		}

		return -20 * Math.exp(-0.2 * Math.sqrt(sum1)) - Math.exp(sum2) + 20 + Math.E;

	}

	public static double getGriewank(double x[]) {
		int k = 1;

		double sum = 0;
		double prod = 1;

		for (int i = 0; i < x.length; i++) {
			sum += (x[i] * x[i]);
			prod *= (k * Math.cos(x[i] / Math.sqrt(i + 1)));
		}

		return k + sum / 4000 - prod;

	}


	public static double getRastrigin(double x[]) {

		double result = 0.0;
		double a = 10.0;
		double w = 2 * Math.PI;

		for (int i = 0; i < x.length; i++) {
			result += x[i] * x[i] - a * Math.cos(w * x[i]);
		}
		result += a * x.length;

		return result;
	}


	public static double getMean(double x[]) {
		double mean = 0;
		for (int i = 0; i < x.length; i++)
			mean += Math.abs(x[i]);

		mean /= x.length;

		return 9 * mean;
	}

}

在這裏插入圖片描述

以下圖像數據點[-100,98]之間的99個均勻數據點

//生成N*dim的testXII double[N][dim]數組
    //由於XII是solution去掉開頭維度的且恢復爲solution最大值和最小值範圍向量
    //例如對於MATP1 問題即是一個解向量第二維到第50維度的子向量構成的新向量,對應維度的最大值和最小值都是problem定義的
    int N = 100;//即我們總共取100個點
    int dim = 49;//因爲對於MATP1問題來說,決策變量個數減去目標個數加一=50-2+1=49
    double problemup = 100;//問題的上界,對於MATP1問題而言上界是100
    double problemlw = -100;//問題的下界,對於MATP1問題而言下界是-100
    double[][] testXII = new double[N][dim];
        for (int i = 0; i < testXII.length; i++) {
        for (int j = 0; j < testXII[i].length; j++)
            testXII[i][j] = (double) i / N * (problemup - problemlw)+(problemlw);
    }
        tools.printdoubleTwoDarray(testXII);
    double[] outputofSphere = new double[N];
    double[] outputofRosenbrocknew = new double[N];
    double[] outputofAckley = new double[N];
    double[] outputofGriewank = new double[N];
    double[] outputofRastrigin = new double[N];
    double[] outputofMean = new double[N];
    GFunctions Gfunc = new GFunctions();
        for (int i = 0; i < testXII.length; i++) {
        outputofSphere[i] = Gfunc.getSphere(testXII[i]);
        outputofRosenbrocknew[i]=Gfunc.getRosenbrock(testXII[i]);
        outputofAckley[i]=Gfunc.getAckley(testXII[i]);
        outputofGriewank[i]=Gfunc.getGriewank(testXII[i]);
        outputofRastrigin[i]=Gfunc.getRastrigin(testXII[i]);
        outputofMean[i]=Gfunc.getMean(testXII[i]);
    }
    float[] rgb1 = {0, 0, 0};//黑色-circle
    float[] rgb2 = {(float) 0, (float) 0, (float) 255};//藍黑-concave
    float[] rgb3 = {(float) 255, (float) 0, (float) 0};//紅色-concave
    float[] rgb4 = {(float) 0, (float) 255, (float) 0};//綠色-circle
    float[] rgb5 = {(float) 255, (float) 255, (float) 0};//黃色-convex
    float[] rgb6 = {(float) 255, (float) 0, (float) 255};//紫色-circle


    float alpha = (float) 1;
    Scatter scatter1 = tools.SetponintOneD(testXII,outputofSphere, rgb1, alpha, 5);
    Scatter scatter2 = tools.SetponintOneD(testXII,outputofRosenbrocknew, rgb2, alpha, 5);
    Scatter scatter3 = tools.SetponintOneD(testXII,outputofAckley, rgb3, alpha, 5);
    Scatter scatter4 = tools.SetponintOneD(testXII,outputofGriewank, rgb4, alpha, 5);
    Scatter scatter5 = tools.SetponintOneD(testXII,outputofRastrigin, rgb5, alpha, 5);
    Scatter scatter6 = tools.SetponintOneD(testXII,outputofMean, rgb6, alpha, 5);

    Chart chart = new Chart(Quality.Advanced, "awt");
    // add scatters
//        chart.getScene().add(scatter1);
//        chart.getScene().add(scatter2);
//        chart.getScene().add(scatter3);
//        chart.getScene().add(scatter4);
//        chart.getScene().add(scatter5);
        chart.getScene().add(scatter6);
        Settings.getInstance().setHardwareAccelerated(true);
        Settings.getInstance().getGLCapabilities();
    //open chart
        ChartLauncher.openChart(chart, new Rectangle(0, 0, 600, 600), "Gfunction");

在這裏插入圖片描述

Sphere(球形)

在這裏插入圖片描述

Rosenbrock(羅森布洛克)

在這裏插入圖片描述

Ackley(阿克利)

在這裏插入圖片描述

Griewank

在這裏插入圖片描述

Rastrigin

在這裏插入圖片描述

Mean

在這裏插入圖片描述

MOP MFO Benchmarks

https://www.researchgate.net/publication/317543380_Evolutionary_Multitasking_for_Multiobjective_Continuous_Optimization_Benchmark_Problems_Performance_Metrics_and_Baseline_Results

在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述

設置Solution G函數值

for (int i = 0; i < numberOfObjectives_; i++)
           f[i] = 1 + g;

solution.setGFunValue(1 + g);
發佈了266 篇原創文章 · 獲贊 172 · 訪問量 37萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章