⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 problemdef.c

📁 nsga2具体算法代码,用来多目标遗传算法的学习和研究
💻 C
📖 第 1 页 / 共 2 页
字号:
    g = 0.0;    for (i=1; i<10; 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[0] = f1;    obj[1] = f2;    return;}#endif/*  Test problem BNH    # of real variables = 2    # of bin variables = 0    # of objectives = 2    # of constraints = 2    */#ifdef bnhvoid test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr){    obj[0] = 4.0*(xreal[0]*xreal[0] + xreal[1]*xreal[1]);    obj[1] = pow((xreal[0]-5.0),2.0) + pow((xreal[1]-5.0),2.0);    constr[0] = 1.0 - (pow((xreal[0]-5.0),2.0) + xreal[1]*xreal[1])/25.0;    constr[1] = (pow((xreal[0]-8.0),2.0) + pow((xreal[1]+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 osyvoid test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr){    obj[0] = -(25.0*pow((xreal[0]-2.0),2.0) + pow((xreal[1]-2.0),2.0) + pow((xreal[2]-1.0),2.0) + pow((xreal[3]-4.0),2.0) + pow((xreal[4]-1.0),2.0));    obj[1] = xreal[0]*xreal[0] +  xreal[1]*xreal[1] + xreal[2]*xreal[2] + xreal[3]*xreal[3] + xreal[4]*xreal[4] + xreal[5]*xreal[5];    constr[0] = (xreal[0]+xreal[1])/2.0 - 1.0;    constr[1] = 1.0 - (xreal[0]+xreal[1])/6.0;    constr[2] = 1.0 - xreal[1]/2.0 + xreal[0]/2.0;    constr[3] = 1.0 - xreal[0]/2.0 + 3.0*xreal[1]/2.0;    constr[4] = 1.0 - (pow((xreal[2]-3.0),2.0))/4.0 - xreal[3]/4.0;    constr[5] = (pow((xreal[4]-3.0),2.0))/4.0 + xreal[5]/4.0 - 1.0;    return;}#endif/*  Test problem SRN    # of real variables = 2    # of bin variables = 0    # of objectives = 2    # of constraints = 2    */#ifdef srnvoid test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr){    obj[0] = 2.0 + pow((xreal[0]-2.0),2.0) + pow((xreal[1]-1.0),2.0);    obj[1] = 9.0*xreal[0] - pow((xreal[1]-1.0),2.0);    constr[0] = 1.0 - (pow(xreal[0],2.0) + pow(xreal[1],2.0))/225.0;    constr[1] = 3.0*xreal[1]/10.0 - xreal[0]/10.0 - 1.0;    return;}#endif/*  Test problem TNK    # of real variables = 2    # of bin variables = 0    # of objectives = 2    # of constraints = 2    */#ifdef tnkvoid test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr){    obj[0] = xreal[0];    obj[1] = xreal[1];    if (xreal[1] == 0.0)    {        constr[0] = -1.0;    }    else    {        constr[0] = xreal[0]*xreal[0] + xreal[1]*xreal[1] - 0.1*cos(16.0*atan(xreal[0]/xreal[1])) - 1.0;    }    constr[1] = 1.0 - 2.0*pow((xreal[0]-0.5),2.0) + 2.0*pow((xreal[1]-0.5),2.0);    return;}#endif/*  Test problem CTP1    # of real variables = 2    # of bin variables = 0    # of objectives = 2    # of constraints = 2    */#ifdef ctp1void test_problem (double *xreal, double *xbin, int **gene, double *obj, double *constr){    double g;    g = 1.0 + xreal[1];    obj[0] = xreal[0];    obj[1] = g*exp(-obj[0]/g);    constr[0] = obj[1]/(0.858*exp(-0.541*obj[0]))-1.0;    constr[1] = obj[1]/(0.728*exp(-0.295*obj[0]))-1.0;    return;}#endif/*  Test problem CTP2    # of real variables = 2    # of bin variables = 0    # of objectives = 2    # of constraints = 1    */#ifdef ctp2void 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[1];    obj[0] = xreal[0];    obj[1] = g*(1.0  - sqrt(obj[0]/g));    exp1 = (obj[1]-e)*cos(theta) - obj[0]*sin(theta);    exp2 = (obj[1]-e)*sin(theta) + obj[0]*cos(theta);    exp2 = b*PI*pow(exp2,c);    exp2 = fabs(sin(exp2));    exp2 = a*pow(exp2,d);    constr[0] = exp1/exp2 - 1.0;    return;}#endif/*  Test problem CTP3    # of real variables = 2    # of bin variables = 0    # of objectives = 2    # of constraints = 1    */#ifdef ctp3void 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[1];    obj[0] = xreal[0];    obj[1] = g*(1.0  - sqrt(obj[0]/g));    exp1 = (obj[1]-e)*cos(theta) - obj[0]*sin(theta);    exp2 = (obj[1]-e)*sin(theta) + obj[0]*cos(theta);    exp2 = b*PI*pow(exp2,c);    exp2 = fabs(sin(exp2));    exp2 = a*pow(exp2,d);    constr[0] = exp1/exp2 - 1.0;    return;}#endif/*  Test problem CTP4    # of real variables = 2    # of bin variables = 0    # of objectives = 2    # of constraints = 1    */#ifdef ctp4void 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[1];    obj[0] = xreal[0];    obj[1] = g*(1.0  - sqrt(obj[0]/g));    exp1 = (obj[1]-e)*cos(theta) - obj[0]*sin(theta);    exp2 = (obj[1]-e)*sin(theta) + obj[0]*cos(theta);    exp2 = b*PI*pow(exp2,c);    exp2 = fabs(sin(exp2));    exp2 = a*pow(exp2,d);    constr[0] = exp1/exp2 - 1.0;    return;}#endif/*  Test problem CTP5    # of real variables = 2    # of bin variables = 0    # of objectives = 2    # of constraints = 1    */#ifdef ctp5void 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[1];    obj[0] = xreal[0];    obj[1] = g*(1.0  - sqrt(obj[0]/g));    exp1 = (obj[1]-e)*cos(theta) - obj[0]*sin(theta);    exp2 = (obj[1]-e)*sin(theta) + obj[0]*cos(theta);    exp2 = b*PI*pow(exp2,c);    exp2 = fabs(sin(exp2));    exp2 = a*pow(exp2,d);    constr[0] = exp1/exp2 - 1.0;    return;}#endif/*  Test problem CTP6    # of real variables = 2    # of bin variables = 0    # of objectives = 2    # of constraints = 1    */#ifdef ctp6void 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[1];    obj[0] = xreal[0];    obj[1] = g*(1.0  - sqrt(obj[0]/g));    exp1 = (obj[1]-e)*cos(theta) - obj[0]*sin(theta);    exp2 = (obj[1]-e)*sin(theta) + obj[0]*cos(theta);    exp2 = b*PI*pow(exp2,c);    exp2 = fabs(sin(exp2));    exp2 = a*pow(exp2,d);    constr[0] = exp1/exp2 - 1.0;    return;}#endif/*  Test problem CTP7    # of real variables = 2    # of bin variables = 0    # of objectives = 2    # of constraints = 1    */#ifdef ctp7void 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[1];    obj[0] = xreal[0];    obj[1] = g*(1.0  - sqrt(obj[0]/g));    exp1 = (obj[1]-e)*cos(theta) - obj[0]*sin(theta);    exp2 = (obj[1]-e)*sin(theta) + obj[0]*cos(theta);    exp2 = b*PI*pow(exp2,c);    exp2 = fabs(sin(exp2));    exp2 = a*pow(exp2,d);    constr[0] = exp1/exp2 - 1.0;    return;}#endif/*  Test problem CTP8    # of real variables = 2    # of bin variables = 0    # of objectives = 2    # of constraints = 2    */#ifdef ctp8void 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[1];    obj[0] = xreal[0];    obj[1] = g*(1.0  - sqrt(obj[0]/g));    theta = 0.1*PI;    a = 40.0;    b = 0.5;    c = 1.0;    d = 2.0;    e = -2.0;    exp1 = (obj[1]-e)*cos(theta) - obj[0]*sin(theta);    exp2 = (obj[1]-e)*sin(theta) + obj[0]*cos(theta);    exp2 = b*PI*pow(exp2,c);    exp2 = fabs(sin(exp2));    exp2 = a*pow(exp2,d);    constr[0] = 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[1]-e)*cos(theta) - obj[0]*sin(theta);    exp2 = (obj[1]-e)*sin(theta) + obj[0]*cos(theta);    exp2 = b*PI*pow(exp2,c);    exp2 = fabs(sin(exp2));    exp2 = a*pow(exp2,d);    constr[1] = exp1/exp2 - 1.0;    return;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -