这是我在写Manytask optimization时的笔记,代码地址可以下载
打开文件夹如下目录,选择benchmark中的任意一个测试函数集,此时我们选择MATP1
package momfo.problems.benchmarks;
import java.io.IOException;
import momfo.core.Problem;
import momfo.core.ProblemSet;
import momfo.problems.base.*;
public class MATP1 {
public static ProblemSet getProblem() throws IOException {int taskNumber=50;
ProblemSet problemSet = new ProblemSet(taskNumber);
for(int i=1;i<=taskNumber;i++)
problemSet.add(getT(i).get(0));
return problemSet;
}
public static ProblemSet getT(int taskID) throws IOException {
ProblemSet problemSet = new ProblemSet(1);MMDTLZ prob = new MMDTLZ(2, 50, 1, -100,100);
prob.setGType("sphere");
double[][] matrix = IO.readMatrixFromFile("MData/M1/M1_"+taskID+".txt");
double shiftValues[] = IO.readShiftValuesFromFile("SVData/S1/S1_"+taskID+".txt");
prob.setRotationMatrix(matrix);
prob.setShiftValues(shiftValues);
((Problem)prob).setName("MATP1-"+taskID);
problemSet.add(prob);
return problemSet;
}
}
int taskNumber=50;
表示MATP1问题设置的任务个数是50,初始化problemSet作为一个容器以承载每一个被初始化后的实际MATP1问题。
for(int i=1;i<=taskNumber;i++) problemSet.add(getT(i).get(0));
意味着此时需要关注的是getT
函数,从
MMDTLZ prob = new MMDTLZ(2, 50, 1, -100,100);
prob.setGType("sphere");
看出MATP_1是一个双目标的问题,并且决策变量个数为50,决策变量最小值为-100,最大值为100,而G函数的类型为sphere
,而只要是双目标的函数使用的H函数都是circle
```java
// MMDTLZ
if (numberOfObjectives == 2)
hType_ = "circle";
else
hType_ = "sphere";
double[][] matrix = IO.readMatrixFromFile("MData/M1/M1_"+taskID+".txt");
double shiftValues[] = IO.readShiftValuesFromFile("SVData/S1/S1_"+taskID+".txt");
``* 可知matrix[][]其中保存有旋转函数,根据taskID具有不同的旋转角度,shiftValues则保存了偏移向量,通过不同的旋转函数和偏移向量可以保证MATP问题中的不同任务即使具有相同的帕累托前沿,但是对应的决策变量距离和位置却完全不同。 ![](https://article.cdnof.com/2307/76e11966-7f13-489c-a642-76a982548a96.png) ## 注意在MATP2中仅仅设置G函数的形状为
sphere和
alpha`值1。(后期通关观察得知,alpha值是用于计算cos函数的)
public class MATP2 {
public static ProblemSet getProblem() throws IOException {
int taskNumber=50;
ProblemSet problemSet = new ProblemSet(taskNumber);
for(int i=1;i<=taskNumber;i++)
problemSet.add(getT(i).get(0));
return problemSet;
}
public static ProblemSet getT(int taskID) throws IOException {
ProblemSet problemSet = new ProblemSet(1);
MMZDT prob = new MMZDT(50, 1, -100,100);
prob.setGType("mean");
prob.setHType("concave");
double[][] matrix = IO.readMatrixFromFile("MData/M2/M2_"+taskID+".txt");
double shiftValues[] = IO.readShiftValuesFromFile("SVData/S2/S2_"+taskID+".txt");
prob.setRotationMatrix(matrix);
prob.setShiftValues(shiftValues);
((Problem)prob).setName("MATP2-"+taskID);
problemSet.add(prob);
return problemSet;
}
}
public MMZDT(int numberOfVariables, int k, double lg, double ug) {
numberOfObjectives_ = 2;
numberOfVariables_ = numberOfVariables;
k_ = k;
gType_ = "sphere";
f1Type_ = "linear";
hType_ = "convex";
package momfo.problems.benchmarks;
import java.io.IOException;
import momfo.core.Problem;
import momfo.core.ProblemSet;
import momfo.problems.base.*;
public class MATP3 {
public static ProblemSet getProblem() throws IOException {
int taskNumber=50;
ProblemSet problemSet = new ProblemSet(taskNumber);
for(int i=1;i<=taskNumber;i++)
problemSet.add(getT(i).get(0));
return problemSet;
}
public static ProblemSet getT(int taskID) throws IOException {
ProblemSet problemSet = new ProblemSet(1);
MMZDT prob = new MMZDT(10, 1, -5,5);
prob.setGType("rosenbrock");
prob.setHType("concave");
double[][] matrix = IO.readMatrixFromFile("MData/M3/M3_"+taskID+".txt");
double shiftValues[] = IO.readShiftValuesFromFile("SVData/S3/S3_"+taskID+".txt");
prob.setRotationMatrix(matrix);
prob.setShiftValues(shiftValues);
((Problem)prob).setName("MATP3-"+taskID);
problemSet.add(prob);
return problemSet;
}
}
import java.io.IOException;
import momfo.core.Problem;
import momfo.core.ProblemSet;
import momfo.problems.base.*;
public class MATP4 {
public static ProblemSet getProblem() throws IOException {
int taskNumber=50;
ProblemSet problemSet = new ProblemSet(taskNumber);
for(int i=1;i<=taskNumber;i++)
problemSet.add(getT(i).get(0));
return problemSet;
}
public static ProblemSet getT(int taskID) throws IOException {
ProblemSet problemSet = new ProblemSet(1);
MMDTLZ prob = new MMDTLZ(2, 50, 1, -2,2);
prob.setGType("rastrigin");
double[][] matrix = IO.readMatrixFromFile("MData/M4/M4_"+taskID+".txt");
double shiftValues[] = IO.readShiftValuesFromFile("SVData/S4/S4_"+taskID+".txt");
prob.setRotationMatrix(matrix);
prob.setShiftValues(shiftValues);
((Problem)prob).setName("MATP4-"+taskID);
problemSet.add(prob);
return problemSet;
}
}
//MMDTLZ
if (numberOfObjectives == 2)
hType_ = "circle";
else
hType_ = "sphere";
package momfo.problems.benchmarks;
import java.io.IOException;
import momfo.core.Problem;
import momfo.core.ProblemSet;
import momfo.problems.base.*;
public class MATP5 {
public static ProblemSet getProblem() throws IOException {
int taskNumber=50;
ProblemSet problemSet = new ProblemSet(taskNumber);
for(int i=1;i<=taskNumber;i++)
problemSet.add(getT(i).get(0));
return problemSet;
}
public static ProblemSet getT(int taskID) throws IOException {
ProblemSet problemSet = new ProblemSet(1);
MMZDT prob = new MMZDT(50, 1, -1,1);
prob.setGType("ackley");
prob.setHType("convex");
double[][] matrix = IO.readMatrixFromFile("MData/M5/M5_"+taskID+".txt");
double shiftValues[] = IO.readShiftValuesFromFile("SVData/S5/S5_"+taskID+".txt");
prob.setRotationMatrix(matrix);
prob.setShiftValues(shiftValues);
((Problem)prob).setName("MATP5-"+taskID);
problemSet.add(prob);
return problemSet;
}
}
package momfo.problems.benchmarks;
import java.io.IOException;
import momfo.core.Problem;
import momfo.core.ProblemSet;
import momfo.problems.base.*;
public class MATP6 {
public static ProblemSet getProblem() throws IOException {
int taskNumber=50;
ProblemSet problemSet = new ProblemSet(taskNumber);
for(int i=1;i<=taskNumber;i++)
problemSet.add(getT(i).get(0));
return problemSet;
}
public static ProblemSet getT(int taskID) throws IOException {
ProblemSet problemSet = new ProblemSet(1);
MMDTLZ prob = new MMDTLZ(2, 50, 1, -50,50);
prob.setGType("griewank");
double[][] matrix = IO.readMatrixFromFile("MData/M6/M6_"+taskID+".txt");
double shiftValues[] = IO.readShiftValuesFromFile("SVData/S6/S6_"+taskID+".txt");
prob.setRotationMatrix(matrix);
prob.setShiftValues(shiftValues);
((Problem)prob).setName("MATP6-"+taskID);
problemSet.add(prob);
return problemSet;
}
}
float[] rgb1 = {0, 0, 0};//黑色-circle
float[] rgb2 = {(float) 0, (float) 0, (float) 139};//蓝黑-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) 139, (float) 69, (float) 19};//巧克力色-circle
float alpha = (float) 1;
Scatter scatter1 = tools.Setpoint(TruePFT1_Matrix, rgb1, alpha, 20);
Scatter scatter2 = tools.Setpoint(TruePFT2_Matrix, rgb2, alpha, 15);
Scatter scatter3 = tools.Setpoint(TruePFT3_Matrix, rgb3, alpha, 8);
Scatter scatter4 = tools.Setpoint(TruePFT4_Matrix, rgb4, alpha, 10);
Scatter scatter5 = tools.Setpoint(TruePFT5_Matrix, rgb5, alpha, 6);
Scatter scatter6 = tools.Setpoint(TruePFT6_Matrix, rgb6, alpha, 5);
手机扫一扫
移动阅读更方便
你可能感兴趣的文章