//MATP1
MMDTLZ prob = new MMDTLZ(2, 50, 1, -100,100);
prob.setGType("sphere");
上面的
经常使用,evaluate,和 evalG 两个评价函数,还有两个设置函数 setGType 和 GetHTypepublic MMDTLZ(int numberOfObjectives, int numberOfVariables, int alpha, double lg, double ug) {
numberOfObjectives_ = numberOfObjectives;
numberOfVariables_ = numberOfVariables;
gType_ = "sphere";
alpha_ = alpha;
int num = numberOfVariables_ - numberOfObjectives_ + 1;
// System.out.println(num);
shiftValues_ = new double[num];
rotationMatrix_ = new double[num][num];
upperLimit_ = new double[numberOfVariables_];
lowerLimit_ = new double[numberOfVariables_];
for (int var = 0; var < numberOfObjectives_ - 1; var++) {
lowerLimit_[var] = 0.0;
upperLimit_[var] = 1.0;
} // for
for (int var = numberOfObjectives_ - 1; var < numberOfVariables; var++) {
lowerLimit_[var] = lg;
upperLimit_[var] = ug;
}
for (int i = 0; i < num; i++)
shiftValues_[i] = 0;
for (int i = 0; i < num; i++) {
for (int j = 0; j < num; j++) {
if (i != j)
rotationMatrix_[i][j] = 0;
else
rotationMatrix_[i][j] = 1;
}
}
if (numberOfObjectives == 2)
hType_ = "circle";
else
hType_ = "sphere";
}
//MATP1
MMDTLZ prob = new MMDTLZ(2, 50, 1, -100,100);
prob.setGType("sphere");
public MMDTLZ(int numberOfObjectives, int numberOfVariables, int alpha, double lg, double ug) {
numberOfObjectives_ = numberOfObjectives;
numberOfVariables_ = numberOfVariables;
gType_ = "sphere";
// MMDTLZ prob = new MMDTLZ(2, 50, 1, -100,100);
// prob.setGType("sphere");
alpha_ = alpha;
int num = numberOfVariables_ - numberOfObjectives_ + 1;
//以MATP1为例
//num=50-2+1=49
// System.out.println(num);
shiftValues_ = new double[num];//49
rotationMatrix_ = new double[num][num];//(49,49)
upperLimit_ = new double[numberOfVariables_];//50
lowerLimit_ = new double[numberOfVariables_];//50
for (int var = 0; var < numberOfObjectives_ - 1; var++) {
lowerLimit_[var] = 0.0;
upperLimit_[var] = 1.0;
} // for
//初始化将(目标值维度-1)的决策变量数值范围限制在0-1之间,即如果是一个双目标问题,则只有x_0即第一个决策变量的值是0-1的范围之间
for (int var = numberOfObjectives_ - 1; var < numberOfVariables; var++) {
lowerLimit_[var] = lg;
upperLimit_[var] = ug;
}
//对于1-49维度的值上下界都根据问题进行指定,例如此处为MATP1问题则(-100,100)之间
for (int i = 0; i < num; i++)
shiftValues_[i] = 0;
//0-48维shiftValues_数值初始化为0
for (int i = 0; i < num; i++) {
for (int j = 0; j < num; j++) {
if (i != j)
rotationMatrix_[i][j] = 0;
else
rotationMatrix_[i][j] = 1;
}
}
//对于这个49*49维度的矩阵非对角线上的值设置为0,对角线上的值设置为1
if (numberOfObjectives == 2)
hType_ = "circle";//由与Manytasking的优化问题,目标数都为2,因此hType_为都"circle"
else
hType_ = "sphere";
}
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;
reandMatrixFromFile
函数读取的,偏移向量是通过readShiftValuesFromFile
函数读取的“[3]Jmetal Problem 和 Problem Set 的变量范围[9] >[4]MATP ManyTask Multitask Problem 和 Solution 的变量范围[10] >[5]MATP1 生成测试 SolutionSet[11]
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]);
}
xII = transformVariables(xII);
//跳转到Problem父类中的transformVariables函数,因为MMDTLZ本身就是Problem的子类
protected double[] transformVariables(double x[]) {
shiftVariables(x);
return rotateVariables(x);
//先进行偏移,然后进行旋转
}
protected void shiftVariables(double x[]) {
for (int i = 0; i < x.length; i++)
x[i] -= shiftValues_[i];
}
protected double[] rotateVariables(double x[]) {
int len = x.length;
double res[] = new double[len];
for (int i = 0; i < len; i++) {
double[] y = rotationMatrix_[i];
double sum = 0;
for (int j = 0; j < len; j++)
sum += x[j] * y[j];
res[i] = sum;
}
return res;
}
“Manytasking MATP MOOMFO 中 G 函数[12]
for (int i = 0; i < numberOfObjectives_; i++)
f[i] = 1 + g;
solution.setGFunValue(1 + g);
//本质是一个DTLZ4的评价函数计算方法
//1. 此时f[i]中保存着(1+g)的值
//2. 对于MATP中的所有问题而言,目标函数的个数是两个,所以numberOfobjective=2
//i=0时, numberOfObjectives_ - (i + 1)=2-1=1 j<1 即j=0,即j只会等于0
//i=1时,numberOfObjectives_ - (i + 1)=2-2=0 j<0 此时不会进入for循环而直接进入if语句,
// aux = numberOfObjectives_ - (i + 1)=2-(2)=0
//alpha=1
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
[1]地址可以下载: http://www.bdsc.site/websites/MTO/MO-ManyTask-Benchmarks.rar
[2]反向解析_1 Manytasking optimization MATP: https://blog.csdn.net/u013555719/article/details/103569252
[3]旋转矩阵: https://www.cnblogs.com/zhoug2020/p/7842808.html
[4]Jmetal Problem和Problem Set的变量范围: https://blog.csdn.net/u013555719/article/details/103595998
[5]MATP ManyTask Multitask Problem和Solution的变量范围: https://blog.csdn.net/u013555719/article/details/103599862
[6]MATP1生成测试SolutionSet: https://blog.csdn.net/u013555719/article/details/103603894
[7]Manytasking MATP MOOMFO 中G函数: https://blog.csdn.net/u013555719/article/details/103615605
[8][旋转矩阵]: https://www.cnblogs.com/zhoug2020/p/7842808.html
[9]Jmetal Problem和Problem Set的变量范围: https://blog.csdn.net/u013555719/article/details/103595998
[10]MATP ManyTask Multitask Problem和Solution的变量范围: https://blog.csdn.net/u013555719/article/details/103599862
[11]MATP1生成测试SolutionSet: https://blog.csdn.net/u013555719/article/details/103603894
[12]Manytasking MATP MOOMFO 中G函数: https://blog.csdn.net/u013555719/article/details/103615605