在多目标进化算法中,权重向量的生成非常重要。
Das I, Dennis J E. Normal-boundary intersection: A new method for generating the Pareto surface in nonlinear multicriteria optimization problems[J]. SIAM Journal on Optimization, 1998, 8(3): 631-657.
上述这篇文章提出了生成空间中均匀分布的权重向量的方法。该方法对m维空间进行采样,得到个在空间中均匀分布的权重向量,其中,H>0为每个目标方向上的采样个数,其采样步长为δ=1/H。
当m=3,H=4时,生成的均匀分布的权重向量有个,如下所示:
实现代码如下:
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
int m; // the number of objectives
double stepsize;
double H; // H = 1 / stepsize
cout << "Please input the number of objectives (m): \n";
cin >> m;
cout << "Please input the stepsize (1/H): \n";
cin >> stepsize;
H = 1 / stepsize;
cout << "H = " << H << endl;
vector<int> sequence;
for (unsigned int i = 0; i < H; i++) // the number of zero is (H)
{
sequence.push_back(0);
}
for (unsigned int i = 0; i < (m - 1); i++) // the number of 1 is (H + m - 1 - (m - 1))
{
sequence.push_back(1);
}
vector< vector<double> > ws;
do
{
int s = -1;
vector<double> weight;
for (unsigned int i = 0; i < (H + m - 1); i++)
{
if (sequence[i] == 1)
{
double w = i - s;
w = (w - 1) / H;
s = i;
weight.push_back(w);
}
}
double w = H + m - 1 - s;
w = (w - 1) / H;
weight.push_back(w);
ws.push_back(weight);
} while (next_permutation(sequence.begin(), sequence.end()));
ofstream outfile("weight.txt");
for (unsigned int i = 0; i < ws.size(); i++)
{
for (unsigned int j = 0; j < ws[i].size(); j++)
{
outfile << ws[i][j] << " ";
}
outfile << "\n";
}
return 0;
}