-
Notifications
You must be signed in to change notification settings - Fork 1
/
Global.cpp
172 lines (124 loc) · 4.08 KB
/
Global.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "stdafx.h"
#include "global.h"
//------------- Parameters in test instance ------------------
int nvar, nobj; // the number of variables and objectives
//double lowBound = 0, uppBound = 1; // lower and upper bounds of variables
double lowBound[VAR_MAX_LENGTH], uppBound[VAR_MAX_LENGTH];
char strTestInstance[256]; //the name of the test BOP problem
TDecompositionType tDecompType = _Decomposition_TCH1;
int iCurTestInstance;
//******** Common parameters in MOEAs **********************************************
int total_gen = 250,//250,//250, //500 1500 1000,//500,// // the maximal number of generations
total_run = 2, //30,// // the maximal number of runs
m_population_size = 100;//200, // the population size
//nfes; // the number of function evluations
int divide = 0.8;
//**********************************************************************************
//------------- Parameters in random number ------------------
int seed = 177;
long rnd_uni_init;
//------------- Parameters in MOEA/D -------------------------
vector <double> idealpoint;
double scale[100];
double xHypervolumeRefPoint_TopRight = 2;
double yHypervolumeRefPoint_TopRight = 2;
double xHypervolumeRefPoint_BottomLeft =0;
double yHypervolumeRefPoint_BottomLeft =0;
///15 20
int etax = 20 , etam = 20; // distribution indexes of crossover and mutation
//double realx, realm, realb = 0.9; // crossover, mutation, selection probabilities
//void (*pFunc[11])(double *, double *, const unsigned int);
//the random generator in [0,1) a special method
double rnd_uni(long *idum)
{
long j;
long k;
static long idum2=123456789;
static long iy=0;
static long iv[NTAB];
double temp;
if ( *idum <= 0 ){
if (-(*idum) < 1) *idum=1;
else *idum = -(*idum);
idum2=(*idum);
for (j=NTAB+7;j>=0;j--){
k = (*idum)/IQ1 ;
*idum = IA1*(*idum-k*IQ1)-k*IR1;
if ( *idum < 0 ) *idum += IM1;
if ( j < NTAB ) iv[j] = *idum;
}
iy=iv[0];
}
k=(*idum)/IQ1;
*idum=IA1*(*idum-k*IQ1)-k*IR1;
if (*idum < 0) *idum += IM1;
k=idum2/IQ2 ;
idum2=IA2*(idum2-k*IQ2)-k*IR2;
if (idum2 < 0) idum2 += IM2;
j = iy / NDIV ;
iy = iv[j] - idum2 ;
iv[j] = *idum ;
if (iy < 1) iy += IMM1 ;
if (( temp = AM*iy ) > RNMX ) return RNMX ;
else return temp;
}/*------End of rnd_uni()--------------------------*/
TCompare ParetoCompare(vector <double> & y_obj1, vector <double>& y_obj2) //judge the pareto dominated
{
bool bBetter = false;
bool bWorse = false;
int i = 0;
do {
//#Do the comparison
if(y_obj1[i] < y_obj2[i])
bBetter = true;
if(y_obj2[i] < y_obj1[i])
bWorse = true;
i++;
}while (!(bWorse && bBetter) && (i < nobj));
if (bWorse) {
if (bBetter)
return _Pareto_Nondominated; //#Worse and better
else
return _Pareto_Dominated; //#Worse and not better
} else {
if (bBetter)
return _Pareto_Dominating; //#Not worse and better
else
return _Pareto_Equal; //#Not worse and not better
}
}
void quicksort_increasing(vector <vector<double>> &paretofront, int nPoints)
{
double temp;
for(int i=0; i<nPoints; i++)
{
for(int j=i+1; j<nPoints; j++)
if(paretofront[i][0]>paretofront[j][0])
{
temp = paretofront[i][0];
paretofront[i][0] = paretofront[j][0];
paretofront[j][0] = temp;
temp = paretofront[i][1];
paretofront[i][1] = paretofront[j][1];
paretofront[j][1] = temp;
}
}
}
double hv2(vector <vector<double>> &paretofront)
{
double volume = 0;
//int j=0;
//while(j<paretofront.size() && paretofront[j][1] >= yHypervolumeRefPoint_TopRight )
//{
// j++;
//}
if( paretofront.size() > 0 ) {
volume = ((xHypervolumeRefPoint_TopRight - paretofront[0][0] ) *
( yHypervolumeRefPoint_TopRight - paretofront[0][1] ));
}
for (int i = 1; i < paretofront.size(); i++) { // && paretofront[i][0]<xHypervolumeRefPoint_TopRight
volume += ( (xHypervolumeRefPoint_TopRight - paretofront[i][0] ) *
( paretofront[i - 1][1] - paretofront[i][1] ) ) ;
}
return volume;
}