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

📄 ant.~h

📁 利用蚂蚁演算法侦测物件支配点研究之原始码
💻 ~H
📖 第 1 页 / 共 5 页
字号:
                now_position = *value -1;
                medium_position =*value +1;
                next_position = *value + 2;
                *replace_number=0;
                for(short i=0;i<solution[0] -1;i++)
                   {
//                     if(i==7)
//                        int test=0;
                     *minimul_ethlon=10000.0;
                      if(now_position == *value)
                         now_position++;
                      if(now_position < 0)
                         now_position = now_position + solution[0] -1;
                      if(now_position > (solution[0] -1))
                         now_position = now_position - solution[0];
                      if(next_position > (solution[0] -1))
                         next_position = next_position - solution[0];
                      if(next_position == *value)
                         next_position++;
                      if(medium_position > (solution[0] -1))
                         medium_position = medium_position - solution[0];
                      *count1 = *(Template_Coordinate + next_position) - *(Template_Coordinate + now_position)-1;
                      if(*count1 < 0)
                         *count1 = *total_number - *(Template_Coordinate + now_position) + *(Template_Coordinate + next_position) -1;
                      now_candidate = *(Template_Coordinate + now_position) +1;
                      Lposition = *(Template_Coordinate + now_position);
                      Nposition = *(Template_Coordinate + next_position);
                      do
                        {
                           *now_ethlon = Ethlon(total_number,contour_x_coordinate,contour_y_coordinate,Lposition,now_candidate);
                           *now_ethlon += Ethlon(total_number,contour_x_coordinate,contour_y_coordinate,now_candidate,Nposition);
                           if(*now_ethlon < *minimul_ethlon)
                              {
                                  *minimul_ethlon =*now_ethlon;
                                  the_best_candidate = now_candidate;
                              }
                           now_candidate++;
                           if(now_candidate >= *total_number)
                              now_candidate = now_candidate - *total_number;
                           (*count1)--;
                        }while((*count1)>0);
                      if(*(Template_Coordinate +medium_position) != the_best_candidate)
                           *(Template_Coordinate +medium_position)=the_best_candidate;
                      else
                          (*replace_number)++;
                      now_position++;
                      medium_position++;
                      next_position++;
                   }
               (*count)++;
             }while(*count < 5 && *replace_number < (solution[0] -1) );

          *now_ethlon=0.0;
/*
          *original_ethlon=0.0;
          for(short i=0;i< solution[0]-2 ;i++)
              {
                  now_position=*(Coordinate+solution[i+1]);
                  next_position=*(Coordinate+solution[i+2]);
                  *original_ethlon += initial_Ethlon(contour_x_coordinate,contour_y_coordinate,now_position,next_position);
              }
*/
          //now_position=*(Coordinate+(solution[0]-1));
          //next_position=0;
          //*original_ethlon+=initial_Ethlon(contour_x_coordinate,contour_y_coordinate,now_position,next_position);
/*
          if(*value==17)
             int test=0;
*/
          for(short i=0;i< solution[0]-1 ;i++)
              {
                  now_position=*(Template_Coordinate+ Template_solution[i]);
                  next_position=*(Template_Coordinate+Template_solution[i+1]);
                  *now_ethlon += error_Ethlon(total_number,contour_x_coordinate,contour_y_coordinate,now_position,next_position,Error);
              }
//          now_position=*(Template_Coordinate+ (Template_solution[solution[0]-1]));
//          next_position=*(Template_Coordinate+Template_solution[0]);
//          *now_ethlon += initial_Ethlon(contour_x_coordinate,contour_y_coordinate,now_position,next_position);
          //now_position=*(Template_Coordinate+(solution[0]-1));
          //next_position=0;
          //*now_ethlon+=initial_Ethlon(contour_x_coordinate,contour_y_coordinate,now_position,next_position);
          if(*now_ethlon < ethlon)
             {
                  error[0]= Error[0];
                  error[1]= Error[1];
                  for(short i=0;i<solution[0];i++)
                      *(solution + i +1) = *(Template_solution + i) ;
                 // solution[solution[0]-1]=solution[1];
                  solution[0]=solution[0]-1;
                  //(*test)++;

                  for(short i=0;i<solution[0];i++)
                     *(Coordinate + i) = *(Template_Coordinate + i);

             }
          return  *now_ethlon;
//          delete  Template_solution,Template_Coordinate,count,count1,count2,Error;
//          delete  now_ethlon,minimul_ethlon,replace_number,original_ethlon,value,maxmum_ethlon;
      }

//-------------------------------------------------------
   float Improvement_Hybrid (short **contour_x_coordinate,short **contour_y_coordinate,short *solution,short *Coordinate,float ethlon,short *total_number,float Threshold,float *error)
      {
          short *Template_solution = new short[solution[0]];
          short *Template_Coordinate = new short[solution[0]];
//          short *Template_2_Coordinate = new short[solution[0]];
          short *count = new short(0);
          short *count1 = new short(0);
          short *count2 = new short(0);
//          short *count3 = new short (0);
          short Lposition,Nposition,the_best_candidate,medium_position,now_position,next_position,the_large_distance,now_distance;
          float *now_ethlon = new float(0.0);
          float *min_ethlon = new float(1000.0);
          short *replace_number = new short (0);
          float *original_ethlon = new float(0.0);
          float *Error = new float[2];
          Error[0]=Error[1]=0;
          the_large_distance=0;
          for(short i=0;i<solution[0];i++)
             {
                *(Template_solution + i) = *(solution + i+1);
                *(Template_Coordinate + i) = *(Coordinate + i );
             }
//          *Template_2_Coordinate = *Template_Coordinate;
          for(short i=0;i<solution[0]-2;i++)
             {
                Lposition = *(Template_Coordinate + i);
                Nposition = *(Template_Coordinate + i+2);
                now_distance= Nposition-Lposition;
                the_best_candidate=the_best_significant (total_number,contour_x_coordinate,contour_y_coordinate,Lposition,Nposition);
                if(the_best_candidate==0)
                   {
                     *replace_number=i+1;
                     *min_ethlon=0.0;
                     break;
                   }
                *(Template_Coordinate +i+1)=the_best_candidate;
                *original_ethlon = Ethlon(contour_x_coordinate,contour_y_coordinate,Lposition,the_best_candidate,Nposition);
                if(*original_ethlon<*min_ethlon && now_distance > the_large_distance)
                   {
                     *min_ethlon=*original_ethlon;
                     the_large_distance=now_distance;
                     *replace_number=i+1;
                   }
             }
          Lposition = *(Template_Coordinate +solution[0]-2);
          Nposition = *(Template_Coordinate);
          now_distance=*total_number-Lposition;
          the_best_candidate=the_best_significant (total_number,contour_x_coordinate,contour_y_coordinate,Lposition,Nposition);
          *(Template_Coordinate +solution[0]-1)=the_best_candidate;
          *original_ethlon = Ethlon(contour_x_coordinate,contour_y_coordinate,Lposition,the_best_candidate,Nposition);
          if(*original_ethlon<*min_ethlon && now_distance > the_large_distance)
             {
               *min_ethlon=*original_ethlon;
               *replace_number=solution[0]-1;
             }
          for(short i=0;i<solution[0];i++)
             {
                if(i == *replace_number)
                   continue;
                *(Template_solution + *count2) = *(solution + i+1);
                *(Template_Coordinate + *count2) = *(Template_Coordinate + i);
                (*count2)++;
             }
/*
          for(short i=0;i<solution[0]-2;i++)
             {
                Lposition = *(Template_Coordinate + i);
                Nposition = *(Template_Coordinate + i+2);
                now_distance= Nposition-Lposition;
                the_best_candidate=the_best_significant (total_number,contour_x_coordinate,contour_y_coordinate,Lposition,Nposition);
                *(Template_Coordinate +i+1)=the_best_candidate;
             }
          Lposition = *(Template_Coordinate +solution[0]-2);
          Nposition = *(Template_Coordinate);
          now_distance=*total_number-Lposition;
          the_best_candidate=the_best_significant (total_number,contour_x_coordinate,contour_y_coordinate,Lposition,Nposition);
          *(Template_Coordinate +solution[0]-1)=the_best_candidate;
*/
          for(short i=0;i< solution[0]-2 ;i++)
              {
                  now_position=*(Template_Coordinate+ i);
                  next_position=*(Template_Coordinate+i+1);
                  *now_ethlon += error_Ethlon(total_number,contour_x_coordinate,contour_y_coordinate,now_position,next_position,Error);
              }
          now_position=*(Template_Coordinate+(solution[0]-2) );
          next_position=*(Template_Coordinate);
          *now_ethlon += error_Ethlon(total_number,contour_x_coordinate,contour_y_coordinate,now_position,next_position,Error);
          if(*now_ethlon < ethlon && *min_ethlon < Threshold)
             {
                  error[0]=Error[0];
                  error[1]=Error[1];
                  for(short i=0;i<solution[0]-1;i++)
                      {
                         *(solution + i +1) = *(Template_solution + i) ;
                         *(Coordinate+i)=*(Template_Coordinate+ i);
                      }
                  *(solution +(solution[0]-1))=*(solution +1);
                  solution[0]=solution[0]-1;
             }
          return  *now_ethlon;
//          delete  Template_solution,Template_Coordinate,count,count1,count2;
//          delete  now_ethlon,min_ethlon,replace_number,original_ethlon;
      }
//-------------------------------------------------------
   float Improvement_Hybrid_BV (short **contour_x_coordinate,short **contour_y_coordinate,short *solution,short *Coordinate,float ethlon,short *total_number,float Threshold)
      {
          short *Template_solution = new short[solution[0]];
          short *Template_Coordinate = new short[solution[0]];
//          short *Template_2_Coordinate = new short[solution[0]];
          short *count = new short(0);
          short *count1 = new short(0);
          short *count2 = new short(0);
//          short *count3 = new short (0);
          short Lposition,Nposition,the_best_candidate,medium_position,now_position,next_position,the_large_distance,now_distance;
          float *now_ethlon = new float(0.0);
          float *min_ethlon = new float(1000.0);
          short *replace_number = new short (0);
          float *original_ethlon = new float(0.0);
          the_large_distance=0;
          for(short i=0;i<solution[0];i++)
             {
                *(Template_solution + i) = *(solution + i+1);
                *(Template_Coordinate + i) = *(Coordinate + i );
             }
//          *Template_2_Coordinate = *Template_Coordinate;
          for(short i=0;i<solution[0]-2;i++)
             {
                Lposition = *(Template_Coordinate + i);
                Nposition = *(Template_Coordinate + i+2);
                now_distance= Nposition-Lposition;
                the_best_candidate=Bending_Value(total_number,contour_x_coordinate,contour_y_coordinate,Lposition,Nposition);
                *(Template_Coordinate +i+1)=the_best_candidate;
                *original_ethlon = Ethlon(contour_x_coordinate,contour_y_coordinate,Lposition,the_best_candidate,Nposition);
                if(*original_ethlon<*min_ethlon && now_distance )
                   {
                     *min_ethlon=*original_ethlon;
                     the_large_distance=now_distance;
                     *replace_number=i+1;
                   }
             }
          Lposition = *(Template_Coordinate +solution[0]-2);
          Nposition = *(Template_Coordinate);
          now_distance=*total_number-Lposition;
          the_best_candidate=Bending_Value (total_number,contour_x_coordinate,contour_y_coordinate,Lposition,Nposition);
          *(Template_Coordinate +solution[0]-1)=the_best_candidate;
          *original_ethlon = Ethlon(contour_x_coordinate,contour_y_coordinate,Lposition,the_best_candidate,Nposition);
          if(*original_ethlon<*min_ethlon&& now_distance )
             {
               *min_ethlon=*original_ethlon;
               *replace_number=solution[0]-1;
             }
          for(short i=0;i<solution[0];i++)
             {

⌨️ 快捷键说明

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