📄 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 sch1void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr){ obj[0] = pow(xreal[0],2.0); obj[1] = pow((xreal[0]-2.0),2.0); return;}#endif/* Test problem SCH2 # of real variables = 1 # of bin variables = 0 # of objectives = 2 # of constraints = 0 */#ifdef sch2void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr){ if (xreal[0]<=1.0) { obj[0] = -xreal[0]; obj[1] = pow((xreal[0]-5.0),2.0); return; } if (xreal[0]<=3.0) { obj[0] = xreal[0]-2.0; obj[1] = pow((xreal[0]-5.0),2.0); return; } if (xreal[0]<=4.0) { obj[0] = 4.0-xreal[0]; obj[1] = pow((xreal[0]-5.0),2.0); return; } obj[0] = xreal[0]-4.0; obj[1] = pow((xreal[0]-5.0),2.0); return;}#endif/* Test problem FON # of real variables = n # of bin variables = 0 # of objectives = 2 # of constraints = 0 */#ifdef fonvoid test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr){ double s1, s2; int i; s1 = s2 = 0.0; for (i=0; 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[0] = 1.0 - exp(-s1); obj[1] = 1.0 - exp(-s2); return;}#endif/* Test problem KUR # of real variables = 3 # of bin variables = 0 # of objectives = 2 # of constraints = 0 */#ifdef kurvoid test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr){ int i; double res1, res2; res1 = -0.2*sqrt((xreal[0]*xreal[0]) + (xreal[1]*xreal[1])); res2 = -0.2*sqrt((xreal[1]*xreal[1]) + (xreal[2]*xreal[2])); obj[0] = -10.0*( exp(res1) + exp(res2)); obj[1] = 0.0; for (i=0; i<3; i++) { obj[1] += 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 polvoid 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[0]) - 2.0*cos(xreal[0]) + sin(xreal[1]) - 1.5*cos(xreal[1]); b2 = 1.5*sin(xreal[0]) - cos(xreal[0]) + 2.0*sin(xreal[1]) - 0.5*cos(xreal[1]); obj[0] = 1.0 + pow((a1-b1),2.0) + pow((a2-b2),2.0); obj[1] = pow((xreal[0]+3.0),2.0) + pow((xreal[1]+1.0),2.0); return;}#endif/* Test problem VNT # of real variables = 2 # of bin variables = 0 # of objectives = 3 # of constraints = 0 */#ifdef vntvoid test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr){ obj[0] = 0.5*(xreal[0]*xreal[0] + xreal[1]*xreal[1]) + sin(xreal[0]*xreal[0] + xreal[1]*xreal[1]); obj[1] = (pow((3.0*xreal[0] - 2.0*xreal[1] + 4.0),2.0))/8.0 + (pow((xreal[0]-xreal[1]+1.0),2.0))/27.0 + 15.0; obj[2] = 1.0/(xreal[0]*xreal[0] + xreal[1]*xreal[1] + 1.0) - 1.1*exp(-(xreal[0]*xreal[0] + xreal[1]*xreal[1])); return;}#endif/* Test problem ZDT1 # of real variables = 30 # of bin variables = 0 # of objectives = 2 # of constraints = 0 */#ifdef zdt1void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr){ double f1, f2, g, h; int i; f1 = xreal[0]; g = 0.0; for (i=1; i<30; i++) { g += xreal[i]; } g = 9.0*g/29.0; g += 1.0; h = 1.0 - sqrt(f1/g); f2 = g*h; obj[0] = f1; obj[1] = f2; return;}#endif/* Test problem ZDT2 # of real variables = 30 # of bin variables = 0 # of objectives = 2 # of constraints = 0 */#ifdef zdt2void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr){ double f1, f2, g, h; int i; f1 = xreal[0]; g = 0.0; for (i=1; i<30; 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[0] = f1; obj[1] = f2; return;}#endif/* Test problem ZDT3 # of real variables = 30 # of bin variables = 0 # of objectives = 2 # of constraints = 0 */#ifdef zdt3void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr){ double f1, f2, g, h; int i; f1 = xreal[0]; g = 0.0; for (i=1; i<30; 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[0] = f1; obj[1] = f2; return;}#endif/* Test problem ZDT4 # of real variables = 10 # of bin variables = 0 # of objectives = 2 # of constraints = 0 */#ifdef zdt4void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr){ double f1, f2, g, h; int i; f1 = xreal[0]; g = 0.0; for (i=1; i<10; 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[0] = f1; obj[1] = 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 zdt5void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr){ int i, j; int u[11]; int v[11]; double f1, f2, g, h; for (i=0; i<11; i++) { u[i] = 0; } for (j=0; j<30; j++) { if (gene[0][j] == 1) { u[0]++; } } for (i=1; i<11; i++) { for (j=0; j<4; j++) { if (gene[i][j] == 1) { u[i]++; } } } f1 = 1.0 + u[0]; for (i=1; i<11; i++) { if (u[i] < 5) { v[i] = 2 + u[i]; } else { v[i] = 1; } } g = 0; for (i=1; i<11; i++) { g += v[i]; } h = 1.0/f1; f2 = g*h; obj[0] = f1; obj[1] = f2; return;}#endif/* Test problem ZDT6 # of real variables = 10 # of bin variables = 0 # of objectives = 2 # of constraints = 0 */#ifdef zdt6void 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[0]))*pow((sin(4.0*PI*xreal[0])),6.0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -