多目标遗传算法 ------ NSGA-II (部分源码解析)目标函数 problemdef.c
/* Test problem definitions */ # include <stdio.h>
# include <stdlib.h>
# include <math.h> # include "global.h"
# include "rand.h" # define sch1
/* # define sch2 */
/* # define fon */
/* # define kur */
/* # define pol */
/* # define vnt */
/* # define zdt1 */
/* # define zdt2 */
/* # define zdt3 */
/* # define zdt4 */
/* # define zdt5 */
/* # define zdt6 */
/* # define bnh */
/* # define osy */
/* # define srn */
/* # define tnk */
/* # define ctp1 */
/* # define ctp2 */
/* # define ctp3 */
/* # define ctp4 */
/* # define ctp5 */
/* # define ctp6 */
/* # define ctp7 */
/* # define ctp8 */ /* Test problem SCH1
# of real variables = 1
# of bin variables = 0
# of objectives = 2
# of constraints = 0
*/ #ifdef sch1
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
obj[] = pow(xreal[],2.0);
obj[] = pow((xreal[]-2.0),2.0);
return;
}
#endif /* Test problem SCH2
# of real variables = 1
# of bin variables = 0
# of objectives = 2
# of constraints = 0
*/ #ifdef sch2
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
if (xreal[]<=1.0)
{
obj[] = -xreal[];
obj[] = pow((xreal[]-5.0),2.0);
return;
}
if (xreal[]<=3.0)
{
obj[] = xreal[]-2.0;
obj[] = pow((xreal[]-5.0),2.0);
return;
}
if (xreal[]<=4.0)
{
obj[] = 4.0-xreal[];
obj[] = pow((xreal[]-5.0),2.0);
return;
}
obj[] = xreal[]-4.0;
obj[] = pow((xreal[]-5.0),2.0);
return;
}
#endif /* Test problem FON
# of real variables = n
# of bin variables = 0
# of objectives = 2
# of constraints = 0
*/ #ifdef fon
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
double s1, s2;
int i;
s1 = s2 = 0.0;
for (i=; i<nreal; i++)
{
s1 += pow((xreal[i]-(1.0/sqrt((double)nreal))),2.0);
s2 += pow((xreal[i]+(1.0/sqrt((double)nreal))),2.0);
}
obj[] = 1.0 - exp(-s1);
obj[] = 1.0 - exp(-s2);
return;
}
#endif /* Test problem KUR
# of real variables = 3
# of bin variables = 0
# of objectives = 2
# of constraints = 0
*/ #ifdef kur
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
int i;
double res1, res2;
res1 = -0.2*sqrt((xreal[]*xreal[]) + (xreal[]*xreal[]));
res2 = -0.2*sqrt((xreal[]*xreal[]) + (xreal[]*xreal[]));
obj[] = -10.0*( exp(res1) + exp(res2));
obj[] = 0.0;
for (i=; i<; i++)
{
obj[] += pow(fabs(xreal[i]),0.8) + 5.0*sin(pow(xreal[i],3.0));
}
return;
}
#endif /* Test problem POL
# of real variables = 2
# of bin variables = 0
# of objectives = 2
# of constraints = 0
*/ #ifdef pol
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
double a1, a2, b1, b2;
a1 = 0.5*sin(1.0) - 2.0*cos(1.0) + sin(2.0) - 1.5*cos(2.0);
a2 = 1.5*sin(1.0) - cos(1.0) + 2.0*sin(2.0) - 0.5*cos(2.0);
b1 = 0.5*sin(xreal[]) - 2.0*cos(xreal[]) + sin(xreal[]) - 1.5*cos(xreal[]);
b2 = 1.5*sin(xreal[]) - cos(xreal[]) + 2.0*sin(xreal[]) - 0.5*cos(xreal[]);
obj[] = 1.0 + pow((a1-b1),2.0) + pow((a2-b2),2.0);
obj[] = pow((xreal[]+3.0),2.0) + pow((xreal[]+1.0),2.0);
return;
}
#endif /* Test problem VNT
# of real variables = 2
# of bin variables = 0
# of objectives = 3
# of constraints = 0
*/ #ifdef vnt
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
obj[] = 0.5*(xreal[]*xreal[] + xreal[]*xreal[]) + sin(xreal[]*xreal[] + xreal[]*xreal[]);
obj[] = (pow((3.0*xreal[] - 2.0*xreal[] + 4.0),2.0))/8.0 + (pow((xreal[]-xreal[]+1.0),2.0))/27.0 + 15.0;
obj[] = 1.0/(xreal[]*xreal[] + xreal[]*xreal[] + 1.0) - 1.1*exp(-(xreal[]*xreal[] + xreal[]*xreal[]));
return;
}
#endif /* Test problem ZDT1
# of real variables = 30
# of bin variables = 0
# of objectives = 2
# of constraints = 0
*/ #ifdef zdt1
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
double f1, f2, g, h;
int i;
f1 = xreal[];
g = 0.0;
for (i=; i<; i++)
{
g += xreal[i];
}
g = 9.0*g/29.0;
g += 1.0;
h = 1.0 - sqrt(f1/g);
f2 = g*h;
obj[] = f1;
obj[] = f2;
return;
}
#endif /* Test problem ZDT2
# of real variables = 30
# of bin variables = 0
# of objectives = 2
# of constraints = 0
*/ #ifdef zdt2
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
double f1, f2, g, h;
int i;
f1 = xreal[];
g = 0.0;
for (i=; i<; i++)
{
g += xreal[i];
}
g = 9.0*g/29.0;
g += 1.0;
h = 1.0 - pow((f1/g),2.0);
f2 = g*h;
obj[] = f1;
obj[] = f2;
return;
}
#endif /* Test problem ZDT3
# of real variables = 30
# of bin variables = 0
# of objectives = 2
# of constraints = 0
*/ #ifdef zdt3
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
double f1, f2, g, h;
int i;
f1 = xreal[];
g = 0.0;
for (i=; i<; i++)
{
g += xreal[i];
}
g = 9.0*g/29.0;
g += 1.0;
h = 1.0 - sqrt(f1/g) - (f1/g)*sin(10.0*PI*f1);
f2 = g*h;
obj[] = f1;
obj[] = f2;
return;
}
#endif /* Test problem ZDT4
# of real variables = 10
# of bin variables = 0
# of objectives = 2
# of constraints = 0
*/ #ifdef zdt4
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
double f1, f2, g, h;
int i;
f1 = xreal[];
g = 0.0;
for (i=; i<; i++)
{
g += xreal[i]*xreal[i] - 10.0*cos(4.0*PI*xreal[i]);
}
g += 91.0;
h = 1.0 - sqrt(f1/g);
f2 = g*h;
obj[] = f1;
obj[] = f2;
return;
}
#endif /* Test problem ZDT5
# of real variables = 0
# of bin variables = 11
# of bits for binvar1 = 30
# of bits for binvar2-11 = 5
# of objectives = 2
# of constraints = 0
*/ #ifdef zdt5
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
int i, j;
int u[];
int v[];
double f1, f2, g, h;
for (i=; i<; i++)
{
u[i] = ;
}
for (j=; j<; j++)
{
if (gene[][j] == )
{
u[]++;
}
}
for (i=; i<; i++)
{
for (j=; j<; j++)
{
if (gene[i][j] == )
{
u[i]++;
}
}
}
f1 = 1.0 + u[];
for (i=; i<; i++)
{
if (u[i] < )
{
v[i] = + u[i];
}
else
{
v[i] = ;
}
}
g = ;
for (i=; i<; i++)
{
g += v[i];
}
h = 1.0/f1;
f2 = g*h;
obj[] = f1;
obj[] = f2;
return;
}
#endif /* Test problem ZDT6
# of real variables = 10
# of bin variables = 0
# of objectives = 2
# of constraints = 0
*/ #ifdef zdt6
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
double f1, f2, g, h;
int i;
f1 = 1.0 - (exp(-4.0*xreal[]))*pow((sin(4.0*PI*xreal[])),6.0);
g = 0.0;
for (i=; i<; i++)
{
g += xreal[i];
}
g = g/9.0;
g = pow(g,0.25);
g = 1.0 + 9.0*g;
h = 1.0 - pow((f1/g),2.0);
f2 = g*h;
obj[] = f1;
obj[] = f2;
return;
}
#endif /* Test problem BNH
# of real variables = 2
# of bin variables = 0
# of objectives = 2
# of constraints = 2
*/ #ifdef bnh
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
obj[] = 4.0*(xreal[]*xreal[] + xreal[]*xreal[]);
obj[] = pow((xreal[]-5.0),2.0) + pow((xreal[]-5.0),2.0);
constr[] = 1.0 - (pow((xreal[]-5.0),2.0) + xreal[]*xreal[])/25.0;
constr[] = (pow((xreal[]-8.0),2.0) + pow((xreal[]+3.0),2.0))/7.7 - 1.0;
return;
}
#endif /* Test problem OSY
# of real variables = 6
# of bin variables = 0
# of objectives = 2
# of constraints = 6
*/ #ifdef osy
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
obj[] = -(25.0*pow((xreal[]-2.0),2.0) + pow((xreal[]-2.0),2.0) + pow((xreal[]-1.0),2.0) + pow((xreal[]-4.0),2.0) + pow((xreal[]-1.0),2.0));
obj[] = xreal[]*xreal[] + xreal[]*xreal[] + xreal[]*xreal[] + xreal[]*xreal[] + xreal[]*xreal[] + xreal[]*xreal[];
constr[] = (xreal[]+xreal[])/2.0 - 1.0;
constr[] = 1.0 - (xreal[]+xreal[])/6.0;
constr[] = 1.0 - xreal[]/2.0 + xreal[]/2.0;
constr[] = 1.0 - xreal[]/2.0 + 3.0*xreal[]/2.0;
constr[] = 1.0 - (pow((xreal[]-3.0),2.0))/4.0 - xreal[]/4.0;
constr[] = (pow((xreal[]-3.0),2.0))/4.0 + xreal[]/4.0 - 1.0;
return;
}
#endif /* Test problem SRN
# of real variables = 2
# of bin variables = 0
# of objectives = 2
# of constraints = 2
*/ #ifdef srn
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
obj[] = 2.0 + pow((xreal[]-2.0),2.0) + pow((xreal[]-1.0),2.0);
obj[] = 9.0*xreal[] - pow((xreal[]-1.0),2.0);
constr[] = 1.0 - (pow(xreal[],2.0) + pow(xreal[],2.0))/225.0;
constr[] = 3.0*xreal[]/10.0 - xreal[]/10.0 - 1.0;
return;
}
#endif /* Test problem TNK
# of real variables = 2
# of bin variables = 0
# of objectives = 2
# of constraints = 2
*/ #ifdef tnk
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
obj[] = xreal[];
obj[] = xreal[];
if (xreal[] == 0.0)
{
constr[] = -1.0;
}
else
{
constr[] = xreal[]*xreal[] + xreal[]*xreal[] - 0.1*cos(16.0*atan(xreal[]/xreal[])) - 1.0;
}
constr[] = 1.0 - 2.0*pow((xreal[]-0.5),2.0) + 2.0*pow((xreal[]-0.5),2.0);
return;
}
#endif /* Test problem CTP1
# of real variables = 2
# of bin variables = 0
# of objectives = 2
# of constraints = 2
*/ #ifdef ctp1
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
double g;
g = 1.0 + xreal[];
obj[] = xreal[];
obj[] = g*exp(-obj[]/g);
constr[] = obj[]/(0.858*exp(-0.541*obj[]))-1.0;
constr[] = obj[]/(0.728*exp(-0.295*obj[]))-1.0;
return;
}
#endif /* Test problem CTP2
# of real variables = 2
# of bin variables = 0
# of objectives = 2
# of constraints = 1
*/ #ifdef ctp2
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
double g;
double theta, a, b, c, d, e;
double exp1, exp2;
theta = -0.2*PI;
a = 0.2;
b = 10.0;
c = 1.0;
d = 6.0;
e = 1.0;
g = 1.0 + xreal[];
obj[] = xreal[];
obj[] = g*(1.0 - sqrt(obj[]/g));
exp1 = (obj[]-e)*cos(theta) - obj[]*sin(theta);
exp2 = (obj[]-e)*sin(theta) + obj[]*cos(theta);
exp2 = b*PI*pow(exp2,c);
exp2 = fabs(sin(exp2));
exp2 = a*pow(exp2,d);
constr[] = exp1/exp2 - 1.0;
return;
}
#endif /* Test problem CTP3
# of real variables = 2
# of bin variables = 0
# of objectives = 2
# of constraints = 1
*/ #ifdef ctp3
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
double g;
double theta, a, b, c, d, e;
double exp1, exp2;
theta = -0.2*PI;
a = 0.1;
b = 10.0;
c = 1.0;
d = 0.5;
e = 1.0;
g = 1.0 + xreal[];
obj[] = xreal[];
obj[] = g*(1.0 - sqrt(obj[]/g));
exp1 = (obj[]-e)*cos(theta) - obj[]*sin(theta);
exp2 = (obj[]-e)*sin(theta) + obj[]*cos(theta);
exp2 = b*PI*pow(exp2,c);
exp2 = fabs(sin(exp2));
exp2 = a*pow(exp2,d);
constr[] = exp1/exp2 - 1.0;
return;
}
#endif /* Test problem CTP4
# of real variables = 2
# of bin variables = 0
# of objectives = 2
# of constraints = 1
*/ #ifdef ctp4
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
double g;
double theta, a, b, c, d, e;
double exp1, exp2;
theta = -0.2*PI;
a = 0.75;
b = 10.0;
c = 1.0;
d = 0.5;
e = 1.0;
g = 1.0 + xreal[];
obj[] = xreal[];
obj[] = g*(1.0 - sqrt(obj[]/g));
exp1 = (obj[]-e)*cos(theta) - obj[]*sin(theta);
exp2 = (obj[]-e)*sin(theta) + obj[]*cos(theta);
exp2 = b*PI*pow(exp2,c);
exp2 = fabs(sin(exp2));
exp2 = a*pow(exp2,d);
constr[] = exp1/exp2 - 1.0;
return;
}
#endif /* Test problem CTP5
# of real variables = 2
# of bin variables = 0
# of objectives = 2
# of constraints = 1
*/ #ifdef ctp5
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
double g;
double theta, a, b, c, d, e;
double exp1, exp2;
theta = -0.2*PI;
a = 0.1;
b = 10.0;
c = 2.0;
d = 0.5;
e = 1.0;
g = 1.0 + xreal[];
obj[] = xreal[];
obj[] = g*(1.0 - sqrt(obj[]/g));
exp1 = (obj[]-e)*cos(theta) - obj[]*sin(theta);
exp2 = (obj[]-e)*sin(theta) + obj[]*cos(theta);
exp2 = b*PI*pow(exp2,c);
exp2 = fabs(sin(exp2));
exp2 = a*pow(exp2,d);
constr[] = exp1/exp2 - 1.0;
return;
}
#endif /* Test problem CTP6
# of real variables = 2
# of bin variables = 0
# of objectives = 2
# of constraints = 1
*/ #ifdef ctp6
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
double g;
double theta, a, b, c, d, e;
double exp1, exp2;
theta = 0.1*PI;
a = 40.0;
b = 0.5;
c = 1.0;
d = 2.0;
e = -2.0;
g = 1.0 + xreal[];
obj[] = xreal[];
obj[] = g*(1.0 - sqrt(obj[]/g));
exp1 = (obj[]-e)*cos(theta) - obj[]*sin(theta);
exp2 = (obj[]-e)*sin(theta) + obj[]*cos(theta);
exp2 = b*PI*pow(exp2,c);
exp2 = fabs(sin(exp2));
exp2 = a*pow(exp2,d);
constr[] = exp1/exp2 - 1.0;
return;
}
#endif /* Test problem CTP7
# of real variables = 2
# of bin variables = 0
# of objectives = 2
# of constraints = 1
*/ #ifdef ctp7
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
double g;
double theta, a, b, c, d, e;
double exp1, exp2;
theta = -0.05*PI;
a = 40.0;
b = 5.0;
c = 1.0;
d = 6.0;
e = 0.0;
g = 1.0 + xreal[];
obj[] = xreal[];
obj[] = g*(1.0 - sqrt(obj[]/g));
exp1 = (obj[]-e)*cos(theta) - obj[]*sin(theta);
exp2 = (obj[]-e)*sin(theta) + obj[]*cos(theta);
exp2 = b*PI*pow(exp2,c);
exp2 = fabs(sin(exp2));
exp2 = a*pow(exp2,d);
constr[] = exp1/exp2 - 1.0;
return;
}
#endif /* Test problem CTP8
# of real variables = 2
# of bin variables = 0
# of objectives = 2
# of constraints = 2
*/ #ifdef ctp8
void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr)
{
double g;
double theta, a, b, c, d, e;
double exp1, exp2;
g = 1.0 + xreal[];
obj[] = xreal[];
obj[] = g*(1.0 - sqrt(obj[]/g));
theta = 0.1*PI;
a = 40.0;
b = 0.5;
c = 1.0;
d = 2.0;
e = -2.0;
exp1 = (obj[]-e)*cos(theta) - obj[]*sin(theta);
exp2 = (obj[]-e)*sin(theta) + obj[]*cos(theta);
exp2 = b*PI*pow(exp2,c);
exp2 = fabs(sin(exp2));
exp2 = a*pow(exp2,d);
constr[] = exp1/exp2 - 1.0;
theta = -0.05*PI;
a = 40.0;
b = 2.0;
c = 1.0;
d = 6.0;
e = 0.0;
exp1 = (obj[]-e)*cos(theta) - obj[]*sin(theta);
exp2 = (obj[]-e)*sin(theta) + obj[]*cos(theta);
exp2 = b*PI*pow(exp2,c);
exp2 = fabs(sin(exp2));
exp2 = a*pow(exp2,d);
constr[] = exp1/exp2 - 1.0;
return;
}
#endif
以上, 为NSGA-II 源码中给出的几个测试函数, 其中无限制条件的测试函数不需解释, 对有限制条件的做一定说明。
根据比对, 可以直到算法中, 将所有的约束条件都转换为 >=0 。
所以, 违反限制条件的 约束函数值 均小于 0 。
TNK 测试函数有一定特殊性, 因为其中存在 无意义的个体, 即 X2 为0 , 这里对该情况下的 约束 函数1 直接赋值为 -1 。
代码,如下:
if (xreal[] == 0.0)
{
constr[] = -1.0;
}
多目标遗传算法 ------ NSGA-II (部分源码解析)目标函数 problemdef.c的更多相关文章
- 多目标遗传算法 ------ NSGA-II (部分源码解析)介绍
NSGA(非支配排序遗传算法).NSGA-II(带精英策略的快速非支配排序遗传算法),都是基于遗传算法的多目标优化算法,是基于pareto最优解讨论的多目标优化. 在官网: http://www.ii ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析) 交叉操作 crossover.c
遗传算法中的交叉操作是 对NSGA-II 源码分析的 最后一部分, 这一部分也是我 从读该算法源代码和看该算法论文理解偏差最大的 函数模块. 这里,首先提一下,遗传算法的 交叉操作.变异操作都 ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析)状态报告 打印 report.c
/* Routines for storing population data into files */ # include <stdio.h> # include <stdlib ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析) 拥挤距离计算 crowddist.c
/* Crowding distance computation routines */ # include <stdio.h> # include <stdlib.h> # ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析)README 算法的部分英文解释
This is the Readme file for NSGA-II code. About the Algorithm--------------------------------------- ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析) 实数、二进制编码的变异操作 mutation.c
遗传算法的变异操作 /* Mutation routines */ # include <stdio.h> # include <stdlib.h> # include < ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析)两个个体支配判断 dominance.c
/* Domination checking routines */ # include <stdio.h> # include <stdlib.h> # include &l ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析)二元锦标赛选择 tourselect.c
tourselect.c 文件中共有两个函数: selection (population *old_pop, population *new_pop) individual* tournament ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析) 临时种群生成新父代种群 fillnds.c
/* Nond-domination based selection routines */ # include <stdio.h> # include <stdlib.h> ...
随机推荐
- servlet请求转发
来源:http://www.2cto.com/kf/201610/554591.html 请求转发:Servlet(源组件)先对客户请求做一些预处理操作(数据处理),然后把请求转发给其他Web组件(目 ...
- Python轻松爬取Rosimm写真网站全部图片
RosimmImage 爬取Rosimm写真网站图片 有图有真相 def main_start(url): """ 爬虫入口,主要爬取操作 ""&qu ...
- 2017[BUAA软工]第0次个人作业
第一部分:结缘计算机 1.你为什么选择计算机专业?你认为你的条件如何?和这些博主比呢? ●其实填写志愿之前并不知道要学什么专业,当初选择计算机是因为计算机就业前景好.方向多.计算机应用的领域无处不在, ...
- 快速简化Android截屏工作
1.安装Notepad++v6.9 2.插件管理器里Plugin Manager安装AndroidLogger 3.AndroidLogger里的capture功能抓取Android的当前屏幕截图到w ...
- Window安装Redis并设置为开机启动
一.下载windows版本的Redis 去官网找了很久,发现原来在官网上可以下载的windows版本的,现在官网以及没有下载地址,只能在github上下载,官网只提供linux版本的下载 官网下载地址 ...
- hive数据类型
- [转] python 模块学习 hashlib
转自: http://www.cnblogs.com/BeginMan/p/3328172.html 一.hashlib概述 涉及加密服务:14. Cryptographic Services 其中 ...
- 关于python 自带csv库的使用心得 附带操作实例以及excel下乱码的解决
因为上次帮我们产品处理过一个文件,他想生成能excel处理操作的.但是上次由于时间非常紧张,所以并没有处理好. 正好无聊就来好好研究一下 ,找算法要了几个 csv文件.来好好玩一玩. 全篇使用了pyt ...
- awk、sed、grep三大shell文本处理工具之sed的应用
sed 流编辑器 对文本中的行,逐行处理 非交互式的编辑器 是一个编辑器 1.工作流程 1)将文件的第一行读入到自己的缓存空间(模式空间--pattern space),删除掉换行符 2)匹配,看一下 ...
- Oracle JDK迁移指南
Oracle JDK迁移指南 https://docs.oracle.com/en/java/javase/11/migrate/index.html#JSMIG-GUID-C25E2B1D-6C24 ...