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

📄 rtcgpsmop.cpp

📁 基于GPS的多目标优化及动态多目标优化源代码 里面 包含MOP, DMOP的程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    double x1;
    double x2;
    double x3;
    double g;
    
    ASSERT(CSolution::GetGeneLength() == 3);
    ASSERT(CSolution::OBJectiveNum == 3);
    
    x1 = 1 + (ind->Gene[0] * 2.5);
    x2 = -2 + (ind->Gene[1] * 4);
    x3 = ind->Gene[2];
	
    g = x3;
	
    ind->Objective[0] = (1 + g) * (pow(x1,3) * pow(x2,2) - 10 * x1 - 4 * x2);
    ind->Objective[1] = (1 + g) * (pow(x1,3) * pow(x2,2) - 10 * x1 + 4 * x2);
    ind->Objective[2] = 3 * (1 + g) * pow(x1,2);
	
    ind->Objective[0] = ind->Objective[0] + 100;
    ind->Objective[1] = ind->Objective[1] + 100;
    ind->Objective[2] = ind->Objective[2];
    
    
    return 0;
}

int RTCGPSMOP::eval_ZDT1(CSolution *ind)
{    
    int i = 0;
    int n = CSolution::GetGeneLength();
    double f1 = 0;
    double g = 0;
    double h = 0;
	
    ASSERT(CSolution::OBJectiveNum == 2);
    ASSERT(CSolution::GetGeneLength() >= 2);
	
    f1 = ind->Gene[0];
	
    for (i = 1; i < n; i++)
    {
		g += ind->Gene[i];
    }
    g = 1 + 9 * g / (n-1);
    h = 1 - sqrt(f1 / g);
	
    ind->Objective[0] = f1;
    ind->Objective[1] = g * h;
	
    return 0;
}

int RTCGPSMOP::eval_ZDT2(CSolution *ind)
{    
    int i = 0;
    int n = CSolution::GetGeneLength();
    double f1 = 0;
    double g = 0;
    double h = 0;
	
    ASSERT(CSolution::OBJectiveNum == 2);
    ASSERT(CSolution::GetGeneLength() >= 2);
	
    f1 = ind->Gene[0];
	
    for (i = 1; i < n; i++)
    {
		g += ind->Gene[i];
    }
    g = 1 + 9 * g / (n-1);
    h = 1 - pow(f1 / g, 2);
	
    ind->Objective[0] = f1;
    ind->Objective[1] = g * h;
	
    return 0;
}

int RTCGPSMOP::eval_ZDT3(CSolution *ind)
{    
    int i = 0;
    int n = CSolution::GetGeneLength();
    double f1 = 0;
    double g = 0;
    double h = 0;
	
    ASSERT(CSolution::OBJectiveNum == 2);
    ASSERT(CSolution::GetGeneLength() >= 2);
	
    f1 = ind->Gene[0];
	
    for (i = 1; i < n; i++)
    {
		g += ind->Gene[i];
    }
    g = 1 + 9 * g / (n-1);
    h = 1 - sqrt(f1 / g) - (f1 / g) * sin(10 * PI * f1);
	
    ind->Objective[0] = f1;
    ind->Objective[1] = g * h ;
	
    return 0 ;
}

 int RTCGPSMOP::eval_ZDT4(CSolution *ind)
 {    
 	
 //    int i = 0;
 //    int n = CSolution::GetGeneLength();
 //    double f1 = 0;
 //    double g = 0;
 //    double h = 0;
 	
     ASSERT(CSolution::OBJectiveNum == 2);
     ASSERT(CSolution::GetGeneLength() >= 2);
 	
 //    f1 = ind->Gene[0];
 //	
 //    for (i = 1; i < n; i++)
 //    {
 //		double x = ind->Gene[i];
 //		g += x * x - 10 * cos(4 * PI * x);
 //    }
 //    g = 1 + 10 * (n - 1) + g;
 //    h = 1 - sqrt(f1 / g);
 //	
 //    ind->Objective[0] = f1;
 //    ind->Objective[1] = g * h;
 //
 
 int i;
 	double g=0.0;
 	for (i=1;i<CSolution::GetGeneLength();i++)
 		g+=ind->Gene[i]* ind->Gene[i]-10*cos(4*PI*ind->Gene[i]);
 	g += 1+10*(CSolution::GetGeneLength() -1);
 	ind->Objective[0] = ind->Gene[0];
 	double x =ind->Gene[0];
     ind->Objective[1]=g *(1- sqrt(x/g)) ;
 	
     return 0;
 }

int RTCGPSMOP::eval_ZDT6(CSolution *ind)
{    
    int i = 0;
    int n = CSolution::GetGeneLength();
    double f1 = 0;
    double g = 0;
    double h = 0;
	
    ASSERT(CSolution::OBJectiveNum == 2);
    ASSERT(CSolution::GetGeneLength() >= 2);
	
    f1 = 1 - exp(-4 * ind->Gene[0]) * pow(sin(6 * PI * ind->Gene[0]), 6);
	
    for (i = 1; i < n; i++)
    {
		g += ind->Gene[i];
    }
    g = 1 + 9 * pow(g / (n-1), 0.25);
    h = 1 - pow(f1 / g, 2);
	
    ind->Objective[0] = f1;
    ind->Objective[1] = g * h;
	
    return 0;
}

int RTCGPSMOP::eval_SPHERE(CSolution *ind)
{    
    int i;
    int n = CSolution::GetGeneLength();
    int m = CSolution::OBJectiveNum;
	
/*    for (j = 0; j < m; j++)
    {
        double f = 0.0;
        for (i = 0; i < n; i++)
        {
            double x = -1000 + 2000 * ind->Gene[(i + j) % n];
            if (i == 0)
			{
                x = x - 1;
			}
            f += x * x;
        }
        ind->Objective[j] = f;
    }
	
    for (j = 0; j < m; j++)
    {
        double f = 0.0;
        for (i = 0; i < n; i++)
        {
            double x = ind->Gene[(i + j) % n];
            if (i == j)
			{
                x = x - 1;
			}
            f += x * x;
        }
        ind->Objective[j] = f;
    }

*/

    //计算适应值
	ind->Objective[0]= (ind->Gene[0]-1 ) *(ind->Gene[0]-1 );
    for ( i=1;i<CSolution::GetGeneLength();i++)
	{
         ind->Objective[0]+=(ind->Gene[i])*(ind->Gene[i]);
	}
	ind->Objective[1]= (ind->Gene[0]) *(ind->Gene[0] ) +(ind->Gene[1]-1 ) *(ind->Gene[1]-1 ) ;
    for ( i=2;i<CSolution::GetGeneLength();i++)
	{
         ind->Objective[1]+=(ind->Gene[i])*(ind->Gene[i]); 
	}
	ind->Objective[2]= (ind->Gene[0]) *(ind->Gene[0] ) +(ind->Gene[1] ) *(ind->Gene[1] )+(ind->Gene[2]-1 ) *(ind->Gene[2]-1) ;
    for ( i=3;i<CSolution::GetGeneLength();i++)
	{
         ind->Objective[2]+=(ind->Gene[i])*(ind->Gene[i]);
	}

	return 0;
}

int RTCGPSMOP::eval_KURS(CSolution *ind)
{    
    int i;
    int n = CSolution::GetGeneLength();
    double f = 0;
    
    ASSERT(CSolution::OBJectiveNum == 2);
    
    for (i = 0; i < n; i++)
    {
		double x = -10 + 20 * ind->Gene[i];
        f += pow(fabs(x), 0.8) + 5 * pow(sin(x), 3) + 3.5828;
    }
	
    ind->Objective[0] = f;
    
    f = 0;
    for (i = 0; i < n-1; i++)
    {
		double x = -10 + 20 * ind->Gene[i];
		double x1 = -10 + 20 * ind->Gene[i+1];
		f += 1 - exp(-0.2 * sqrt(pow(x, 2) + pow(x1, 2)));
    }
	
    ind->Objective[1] = f;
	
    return 0;
}


int RTCGPSMOP::eval_KURN(CSolution *ind)
{    
    ASSERT(CSolution::OBJectiveNum == 2);
    ind->Objective[0] =  (-10) * exp(-0.2 * sqrt(ind->Gene[0]*ind->Gene[0] + ind->Gene[1]*ind->Gene[1]))
		+ (-10) * exp(-0.2 * sqrt(ind->Gene[1]*ind->Gene[1] + ind->Gene[2]*ind->Gene[2]));
    ind->Objective[1]= pow(fabs(ind->Gene[0]),0.8) + 5 * sin( ind->Gene[0] *ind->Gene[0]*ind->Gene[0])
		+ pow(fabs(ind->Gene[1]),0.8) + 5 * sin( ind->Gene[1] *ind->Gene[1]*ind->Gene[1])
		+ pow(fabs(ind->Gene[2]),0.8) + 5 * sin( ind->Gene[2] *ind->Gene[2]*ind->Gene[2]);
	
    return 0;
}

int RTCGPSMOP::eval_QV(CSolution *ind)
{    
    int i;
    int n = CSolution::GetGeneLength();
    double F1 = 0;
    double F2 = 0;
    
    ASSERT(CSolution::OBJectiveNum == 2);
    
    for (i = 0; i < n; i++)
    {
        double x = -5 + 10 * ind->Gene[i];
        F1 += (x)*(x) - 10*cos(2*PI*(x)) + 10;
        F2 += (x-1.5)*(x-1.5) - 10*cos(2*PI*(x-1.5)) + 10;
    }
    F1 = pow((F1/n),0.25);
    F2 = pow((F2/n),0.25);
	
    ind->Objective[0] = F1;
    ind->Objective[1] = F2;
	
    return 0;
}
int RTCGPSMOP::init_Common(CSolution *p_ind)
{
    for (int i=0;i<CSolution::GetGeneLength();i++)
	{
		p_ind->Gene[i] =CRandom::Random(0.0,1.0);
	}
	return 0;
}

int RTCGPSMOP::Fix_Common(CSolution *p_ind)
{
    for (int i=0;i<CSolution::GetGeneLength();i++)
	{
		if (p_ind->Gene[i] <0 ) 
		{
			p_ind->Gene[i] =CRandom::Random(0.0, fabs(p_ind->Gene[0]));//CRandom::Random(0.0,0.2);
		}
		if (p_ind->Gene[i] >1)
		{
			p_ind->Gene[i] =CRandom::Random(1.0- fmod(p_ind->Gene[0],1.0), 1.0);
		}

	}
	return 0;
}
int RTCGPSMOP::Fix_Common2(CSolution *p_ind)
{
    for (int i=0;i<CSolution::GetGeneLength();i++)
	{
		if (p_ind->Gene[i] <0 ) 
		{
			p_ind->Gene[i] =0;//CRandom::Random(0.0,0.2);
		}
		if (p_ind->Gene[i] >1)
		{
			p_ind->Gene[i] =1;
		}

	}
	return 0;
}

int RTCGPSMOP::Fix_ZDT4(CSolution *p_ind)
{
		if (p_ind->Gene[0] <0 ) 
		{
			p_ind->Gene[0] =CRandom::Random(0.0, fabs(p_ind->Gene[0]));//CRandom::Random(0.0,0.2);
		}
		if (p_ind->Gene[0] >1)
		{
			p_ind->Gene[0] =CRandom::Random(1.0- fmod(p_ind->Gene[0],1.0), 1.0);
		}

    for (int i=0;i<CSolution::GetGeneLength();i++)
	{
		if (p_ind->Gene[i] <-5 ) 
		{
			p_ind->Gene[i] =CRandom::Random(-5.0, -5.0- fmod(p_ind->Gene[0],5.0));//CRandom::Random(0.0,0.2);
		}
		if (p_ind->Gene[i] >5)
		{
			p_ind->Gene[i] =CRandom::Random(5.0- fmod(p_ind->Gene[0],5.0), 5.0);
		}

	}
	return 0;
}


int RTCGPSMOP::init_COMET(CSolution *p_ind)
{
    p_ind->Gene[0] =CRandom::Random(1.0,3.5);
    p_ind->Gene[1] =CRandom::Random(-2.0,2.0);
	return 0;
}

int RTCGPSMOP::Fix_COMET(CSolution *p_ind)
{
	if ((p_ind->Gene[0] <1 ) ||(p_ind->Gene[0] >3.5 ))
		p_ind->Gene[0] =CRandom::Random(1.0,3.5);
	
    if ((p_ind->Gene[1] <-2 ) ||(p_ind->Gene[1] >2 ))  
		p_ind->Gene[1] =CRandom::Random(-2.0,2.0);
	return 0;
}

int RTCGPSMOP::init_ZDT4(CSolution *p_ind)
{
	p_ind->Gene[0]=CRandom::Random(0.0,1.0);
    for (int i=1;i<CSolution::GetGeneLength();i++)
	{
	p_ind->Gene[i] =CRandom::Random(-5.0,5.0);
		//		p_ind->Gene[i] =CRandom::Random(0.0,1.0);
	}
	return 0;
}

int RTCGPSMOP::init_SPHERE(CSolution *p_ind)
{
    for (int i=0;i<CSolution::GetGeneLength();i++)
	{
		p_ind->Gene[i] =CRandom::Random(0.0,1.0);
	}
	return 0;
}

int RTCGPSMOP::init_KUR(CSolution *p_ind)
{
    for (int i=0;i<CSolution::GetGeneLength();i++)
	{
		p_ind->Gene[i] =CRandom::Random(-5.0,5.0);
	}
	return 0;
}

int RTCGPSMOP::Fix_KUR(CSolution *p_ind)
{
    for (int i=0;i<CSolution::GetGeneLength();i++)
	{
		if ((p_ind->Gene[i] <-5 ) ||(p_ind->Gene[i] >5 )) 
			p_ind->Gene[i] =CRandom::Random(-5.0,5.0);
	}
	return 0;
}

int RTCGPSMOP::init_QV(CSolution *p_ind)
{
    for (int i=0;i<CSolution::GetGeneLength();i++)
	{
		p_ind->Gene[i] =CRandom::Random(-5.0,5.0);
	}
	return 0;
	
}

int RTCGPSMOP::Fix_QV(CSolution *p_ind)
{
    for (int i=0;i<CSolution::GetGeneLength();i++)
	{
//		if ((p_ind->Gene[i] <-5 ) ||(p_ind->Gene[i] >5 )) 
//			p_ind->Gene[i] =CRandom::Random(-5.0,5.0);
		if (p_ind->Gene[i] <-5 ) 
		{
			p_ind->Gene[i] =CRandom::Random(-5.0, -5.0- fmod(p_ind->Gene[0],5.0));//CRandom::Random(0.0,0.2);
		}
		if (p_ind->Gene[i] >5)
		{
			p_ind->Gene[i] =CRandom::Random(5.0- fmod(p_ind->Gene[0],5.0), 5.0);
		}
	}
	return 0;
}

⌨️ 快捷键说明

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