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

📄 eps-dom.cpp

📁 epsMOEA
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    }// Box funtion definitons, here done for minimization casevoidbox_func (individual * ind1){  for (int i = 0; i < MAX; i++)    ind1->box[i] = floor ((ind1->f[i] / EPSILON[i]));}// function to check for Box dominationintbox_dom (individual ind1, individual ind2){  int flag = 1;  int elag = 0;  for (int j = 0; j < MAX; j++)    {      if ((flag == 1) && (ind1.box[j] <= ind2.box[j]))	flag = 1;      else	flag = 0;      if ((ind1.box[j] < ind2.box[j]) || (elag == 1))	elag = 1;    }  if ((flag == 1) && (elag == 1))    return 1;  else    return 0;}//to check whether 2 individuals are in the same box or notintsame_box_check (individual ind1, individual ind2){  int flag = 1;  for (int i = 0; i < MAX; i++)    {      if ((flag == 1) && (ind1.box[i] == ind2.box[i]))	{	  flag = 1;	}      else	{	  flag = 0;	  break;	}    }  return (flag);}// Check for domination (usual sense)intdom_check (individual ind1, individual ind2){  int flag = 1;  int elag = 0;  for (int j = 0; j < MAX; j++)    {      if ((flag == 1) && (ind1.f[j] <= ind2.f[j]))	flag = 1;      else	flag = 0;      if ((ind1.f[j] < ind2.f[j]) || (elag == 1))	elag = 1;    }  if ((flag == 1) && (elag == 1))    return 1;  else    return 0;}// Finds the distance between corner[] and between the decision variable// coordinates of the individualdoubledistance (individual ind1, double point[MAX]){  double dist = 0.0;  for (int i = 0; i < MAX; i++)    {      dist += pow ((ind1.f[i] - point[i]), 2);    }  dist = sqrt (dist);  return (dist);}intcon_update (){  int flg = 0, d = 0;  int update ();    // First Case : the new Child is a feasible solution,  // i.e. it has zero constraint violation   if (newchild.cv <= DELTA)    {      // removing all infeasible solutions from the archive       for (int i = 0; i < archive_size; i++)	{	  if (archive[i].cv > DELTA)	    {	      for (int j = i; j < archive_size - 1; j++)		{		  archive[j] = archive[j + 1];		}	      archive_size--;	      d = 1; // set flag to indicate that some archive members have been deleted	    }	}      // insert the new child in the usual manner into the archive after      // removing the infeasible points.      flg = update ();    }  else    {      // Second Case : New child is infeasible      for (int k = 0; k < archive_size; k++)	{	  if (newchild.cv > archive[k].cv)	    {	      flg = -1;  // reject the child, as there is a better solution in the archive 	    }	}      if (flg == 0)	{	  // removing all those members whose constraint violation	  // is higher than that of the new child	  for (int k = 0; k < archive_size; k++)	    {	      if (newchild.cv < archive[k].cv)		{		  for (int j = k; j < archive_size - 1; j++)		    {		      archive[j] = archive[j + 1];		    }		  archive_size--;		  d = 1; // set flag to indicate that some archive members have been deleted		}	    }	}            if (flg == 0)	{	  archive_size++;	  archive[archive_size - 1] = newchild;	  // new child inserted into archive	  flg=1; // flag to indicate this	}    }  return (flg);}// The Update function, called to update the archive in every iterationintupdate (){  int d = 0, accept_flag, i = 0, no_dom = 0, same_box = 0;  double corner[MAX], da = 0, dc = 0;  double child_dist, archive_dist;  accept_flag = 0;  box_func (&newchild);  // set the box vectors for the child  for (i = 0; i < archive_size; i++)    {      box_func (&archive[i]);  // set the box vectors for the archive members      if (box_dom (archive[i], newchild) == 1)	{	  // new child is box-dominated by an archive member	  accept_flag = -1;	  break;	}    }  if (accept_flag == -1)    return (accept_flag);  // processing stops here  else    {      for (i = 0; i < archive_size; i++)	{	  no_dom = 0;	  if (box_dom (newchild, archive[i]) == 1)	    {	      // new chid box-dominates some archive member	      no_dom++;	      for (int j = i; j < archive_size - 1; j++)		{		  archive[j] = archive[j + 1];		}	      archive_size--;	      d = 1; // flag to denote that archive member has been deleted	      i = 0; // reset counter	    }	}      if (d == 1)	{	  // new child enters the archive	  archive_size++;	  archive[archive_size - 1] = newchild;	  accept_flag = 1;	}      else	{	  // new case: child and archive members dont box-dominate each other	  for (int i = 0; i < archive_size; i++)	    {	      // checking if the any archive member and child are in same box	      if (same_box_check (newchild, archive[i]) == 1)		{		  same_box++;		  // inside same box		  if (dom_check (newchild, archive[i]) == 1)		    {		      archive[i] = newchild;		      accept_flag = 1;		    }		  else		    {		      if (dom_check (archive[i], newchild) == 1)			accept_flag = -1;		      else			{			  // neither dominate (usual sense) each other.			  // NOTE: here, both are in same box			  for (int p = 0; p < MAX; p++)			    {			      //find the corner of the box			      corner[p] = newchild.box[p];			    }			  child_dist = distance (newchild, corner);			  archive_dist = distance (archive[i], corner);			  			  if (child_dist < archive_dist)			    { 			      // child is nearer the corner, so we choose			      // it to enter, note here, we are working with a 			      // minimization problem			      archive[i] = newchild;			      accept_flag = 1;			    }			  else			    accept_flag = -1;			}		    }		}	    }	}      if (d == 0 && accept_flag == 0 && same_box == 0)	{	  // the new child is a totally new non-dominated point	  archive_size++;	  archive[archive_size - 1] = newchild;	}    }  return (accept_flag);}voidgenerate_replace (){  int tournament (int p1, int p2);  int child_flag1, child_flag2;  int ar_parent, pop_parent, ch1_flg = 0, ch2_flg = 0;  int pop_parent1, pop_parent2;  double u = 0.0, rnds;  int x, y, z;  rnds = randomperc ();  pop_parent1 = (rnds < 1) ? (int) (rnds * pop_size) : pop_size - 1;  rnds = randomperc ();  pop_parent2 = (rnds < 1) ? (int) (rnds * pop_size) : pop_size - 1;  pop_parent = tournament (pop_parent1, pop_parent2);  rnds = randomperc ();  ar_parent = (rnds < 1) ? (int) (rnds * archive_size) : archive_size - 1;  if (randomperc () <= pxover)    {      realcross (population[pop_parent], archive[ar_parent]);    }  else    {      newchild1 = population[pop_parent];      newchild2 = archive[ar_parent];    }  real_mutate (&(newchild1));  real_mutate (&(newchild2));  newchild1.init ();  newchild2.init ();}inttournament (int p1, int p2){  if (dom_check (population[p1], population[p2]) == 1)    return p1;  else if (dom_check (population[p2], population[p1]) == 1)    return p2;  else    {      if (randomperc () > 0.5)	return p1;      else	return p2;    }}voidcompete (){  int flag = 0, lg = 0, pp = 0;  double rndp;  for (int i = 0; i < pop_size; i++)    {      if (dom_check (newchild, population[i]) == 1)	{	  population[i] = newchild;	  flag = 1;	  return;	}    }  if (flag == 1)    return;  else    {      for (int i = 0; i < pop_size; i++)	{	  if (dom_check (population[i], newchild) == 1)	    {	      lg = -1;	      return;	    }	}      if (lg == -1)	return;      else	{	  rndp = randomperc ();	  pp = (rndp < 1.0) ? (int) (rndp * pop_size) : pop_size - 1;	  population[pp] = newchild;	}    }}

⌨️ 快捷键说明

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