📄 ant.~h
字号:
*c = (y_coordinate[0][position] * x_coordinate[0][next_position]) - (x_coordinate[0][position] * y_coordinate[0][next_position]);
*d = (float)sqrt(pow(*b,2)+pow(*a,2));
*count_node=position;
do
{
(*count_node)++;
if(*count_node == *total_number)
*count_node = *count_node - *total_number;
*now_distance = fabs((*a * x_coordinate[0][*count_node]- *b * y_coordinate[0][*count_node]+ *c)/ *d);
(*value)--;
if( *now_distance > *the_longest_distance)
{
*node=*count_node;
*the_longest_distance = *now_distance;
}
/*
if(*now_distance > threshold && *now_distance > *the_longest_distance)
{
*node=*count_node;
*the_longest_distance = *now_distance;
}
*/
}while( *value > 1);
}
return *node;
// delete a,b,c,d,now_distance,value,count_node,node,the_longest_distance;
}
//-------------------------------------------------------
short the_best_significant_with_break_point (short *total_number,short **x_coordinate,short **y_coordinate,short position,short next_position,short *Template_Coordinate)
{
// short ttt= Template_Coordinate[next_position];
register short *a= new short ();
register short *b= new short ();
register short *c= new short ();
register float *d= new float ();
float *now_distance = new float ();
short *value =new short(0);
short *count_node= new short();//accumulate the numbers between two nodes
short *node= new short(0);
float *the_longest_distance=new float(0.0);
*value = next_position - position;
if(*value < 0)
*value = *total_number - position + next_position-1 ;
if(*value > 1)
{
*a = y_coordinate[0][Template_Coordinate[next_position]] - y_coordinate[0][Template_Coordinate[position]];
*b = x_coordinate[0][Template_Coordinate[next_position]] - x_coordinate[0][Template_Coordinate[position]];
*c = (y_coordinate[0][Template_Coordinate[position]] * x_coordinate[0][Template_Coordinate[next_position]]) - (x_coordinate[0][Template_Coordinate[position]] * y_coordinate[0][Template_Coordinate[next_position]]);
*d = (float)sqrt(pow(*b,2)+pow(*a,2));
*count_node=position;
do
{
(*count_node)++;
if(*count_node == *total_number)
*count_node = *count_node - *total_number;
*now_distance = fabs((*a * x_coordinate[0][Template_Coordinate[*count_node]]- *b * y_coordinate[0][Template_Coordinate[*count_node]]+ *c)/ *d);
(*value)--;
if( *now_distance > *the_longest_distance)
{
*node=*count_node;
*the_longest_distance = *now_distance;
}
/*
if(*now_distance > threshold && *now_distance > *the_longest_distance)
{
*node=*count_node;
*the_longest_distance = *now_distance;
}
*/
}while( *value > 1);
}
return *node;
// delete a,b,c,d,now_distance,value,count_node,node,the_longest_distance;
}
//-------------------------------------------------------
float Hybrid (short **contour_x_coordinate,short **contour_y_coordinate,short *solution,short *Coordinate,float *ethlon,short *total_number,float *error)
{
srand(time(NULL));
short *Template_solution = new short[solution[0]];
short *Template_Coordinate = new short[solution[0]];
short *value = new short(0);
short *count = new short(0);
short *count1 = new short(0);
short *count2 = new short(0);
// short *count3 = new short (0);
short now_position,next_position,now_candidate,medium_position,Lposition,Nposition,the_best_candidate;
float *now_ethlon = new float(0.0);
float *minimul_ethlon = new float(10000.0);
float *maxmum_ethlon = new float(0.0);
short *threshold = new short (1);
short *replace_number = new short (0);
float *original_ethlon = new float(0.0);
float *Error = new float[2];
Error[0]=Error[1]=0;
*value = random(solution[0])+1;
for(short i=0;i<solution[0];i++)
{
if(i == *value)
continue;
*(Template_solution + *count2) = *(solution + i+1);
(*count2)++;
}
*(Template_solution+ *count2)=*Template_solution;
for(short i=0;i<solution[0];i++)
*(Template_Coordinate + i) = *(Coordinate + i );
/*
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 += initial_Ethlon(contour_x_coordinate,contour_y_coordinate,now_position,next_position);
}
*/
do
{
now_position = *value -1;
medium_position =*value +1;
next_position = *value + 2;
*replace_number=0;
for(short i=0;i<solution[0] -1;i++)
{
*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 += error_Ethlon(total_number,contour_x_coordinate,contour_y_coordinate,now_position,next_position,Error);
//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 Hybrid (short **contour_x_coordinate,short **contour_y_coordinate,short *solution,short *Coordinate,float ethlon,short *total_number,float *error)
{
srand(time(NULL));
short *Template_solution = new short[solution[0]];
short *Template_Coordinate = new short[solution[0]];
short *value = new short(0);
short *count = new short(0);
short *count1 = new short(0);
short *count2 = new short(0);
// short *count3 = new short (0);
short now_position,next_position,now_candidate,medium_position,Lposition,Nposition,the_best_candidate;
float *now_ethlon = new float(0.0);
float *minimul_ethlon = new float(10000.0);
float *maxmum_ethlon = new float(0.0);
short *threshold = new short (1);
short *replace_number = new short (0);
float *original_ethlon = new float(0.0);
float *Error = new float[2];
Error[0]=Error[1]=0;
*value = random(solution[0])+1;
for(short i=0;i<solution[0];i++)
{
if(i == *value)
continue;
*(Template_solution + *count2) = *(solution + i+1);
(*count2)++;
}
*(Template_solution+ *count2)=*Template_solution;
for(short i=0;i<solution[0];i++)
*(Template_Coordinate + i) = *(Coordinate + i );
/*
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 += initial_Ethlon(contour_x_coordinate,contour_y_coordinate,now_position,next_position);
}
*/
do
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -