📄 ant.~h
字号:
register double *b= new double ();
register double *c= new double ();
register double *d= new double ();
register double *e= new double ();
*a = contour_y_coordinate[0][next_position] - contour_y_coordinate[0][position];
*b = contour_x_coordinate[0][next_position] - contour_x_coordinate[0][position];
*c = (contour_y_coordinate[0][position] * contour_x_coordinate[0][next_position])-(contour_x_coordinate[0][position] * contour_y_coordinate[0][next_position]);
*d = (double)sqrt(pow(*b,2)+pow(*a,2));
for(short i=position+1;i<next_position;i++)
{
*e= (*a * contour_x_coordinate[0][i]) - (*b * contour_y_coordinate[0][i])+ *c;
*ethlon +=*medium=fabs((*e / *d));
error[0]+=pow(*medium,2);
if(*medium>error[1])
error[1]=*medium;
}
}
else
*ethlon=0;
return *ethlon;
// delete ethlon,value,medium;
}
//-------------------------------------------------------
// Linear Equation : ax+by+c=0
float Ethlon (short *total_number,short *x_coordinate,short *y_coordinate,short **tour_table,short Ant,short *count_tour_node,short *Coordinate,short *initial_number)
{
float *ethlon= new float(0.0);
register short *a= new short ();
register short *b= new short ();
register short *c= new short ();
register float *d= new float ();
short *value =new short(0.0);
short *count_node= new short();//accumulate the numbers between two nodes
if(count_tour_node[Ant] > 2) //if *test is equal to 0,that are not noly two points,beging and end point.
{
for(short i=0;i<count_tour_node[Ant]-1;i++)
{
*value = *(Coordinate+tour_table[Ant][i+1])- *(Coordinate+tour_table[Ant][i]);
*a = *(y_coordinate+ *(Coordinate+tour_table[Ant][i+1])) - *(y_coordinate+ *(Coordinate+tour_table[Ant][i]));
*b = *(x_coordinate+ *(Coordinate+tour_table[Ant][i+1])) - *(x_coordinate+ *(Coordinate+tour_table[Ant][i]));
*c = (*(y_coordinate+ *(Coordinate+tour_table[Ant][i])) * *(x_coordinate+*(Coordinate+tour_table[Ant][i+1])))-(*(x_coordinate+ *(Coordinate+tour_table[Ant][i])) * *(y_coordinate+*(Coordinate+tour_table[Ant][i+1])));
*d = (float)sqrt(pow(*b,2)+pow(*a,2));
*count_node=*(Coordinate+tour_table[Ant][i]);
if(*value < 0)
*value = *total_number - *(Coordinate+tour_table[Ant][i]) + *(Coordinate+tour_table[Ant][i+1])-1;
do
{
(*count_node)++;
if(*count_node == *total_number)
*count_node = *count_node - *total_number;
*ethlon += fabs((*a * *(x_coordinate + *count_node)- *b * *(y_coordinate + *count_node)+ *c)/ *d);
(*value)--;
}while( *value > 1);
}
*value = *(Coordinate+tour_table[Ant][count_tour_node[Ant]-1])- *(Coordinate+tour_table[Ant][1]);
*a = *(y_coordinate+ *(Coordinate+tour_table[Ant][count_tour_node[Ant]-1])) - *(y_coordinate+ *(Coordinate+tour_table[Ant][1]));
*b = *(x_coordinate+ *(Coordinate+tour_table[Ant][count_tour_node[Ant]-1])) - *(x_coordinate+ *(Coordinate+tour_table[Ant][1]));
*c = (*(y_coordinate+ *(Coordinate+tour_table[Ant][1])) * *(x_coordinate+*(Coordinate+tour_table[Ant][count_tour_node[Ant]-1])))-(*(x_coordinate+ *(Coordinate+tour_table[Ant][1])) * *(y_coordinate+*(Coordinate+tour_table[Ant][count_tour_node[Ant]-1])));
*d = (float)sqrt(pow(*b,2)+pow(*a,2));
*count_node=*(Coordinate+tour_table[Ant][1]);
if(*value < 0)
*value = *total_number - *(Coordinate+tour_table[Ant][1]) + *(Coordinate+tour_table[Ant][count_tour_node[Ant]-1])-1;
do
{
(*count_node)++;
if(*count_node == *total_number)
*count_node = *count_node - *total_number;
*ethlon += fabs((*a * *(x_coordinate + *count_node)- *b * *(y_coordinate + *count_node)+ *c)/ *d);
(*value)--;
}while( *value > 1);
}
else
*ethlon = (float)10000;
return *ethlon;
// delete ethlon,a,b,c,d,value,count_node;
}
//-------------------------------------------------------
// Linear Equation : ax+by+c=0
float Ethlon (short *total_number,short **x_coordinate,short **y_coordinate,short position,short next_position )
{
register short *a= new short ();
register short *b= new short ();
register short *c= new short ();
register float *d= new float ();
float *ethlon = new float ();
short *value =new short(0.0);
short *count_node= new short();//accumulate the numbers between two nodes
*value = next_position - position;
if(*value < 0)
*value = *total_number - position + next_position ;
if(*value > 1)
{
*a = y_coordinate[0][next_position] - y_coordinate[0][position];
*b = x_coordinate[0][next_position] - x_coordinate[0][position];
*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;
*ethlon += fabs((*a * x_coordinate[0][*count_node]- *b * y_coordinate[0][*count_node]+ *c)/ *d);
(*value)--;
}while( *value > 1);
}
return *ethlon;
// delete ethlon,a,b,c,d,value,count_node;
}
//-------------------------------------------------------
float Initial_Ethlon_in_Segment_Bound (short *total_number,short **x_coordinate,short **y_coordinate,short position,short next_position ,float *error)
{
register short *a= new short ();
register short *b= new short ();
register short *c= new short ();
register double *d= new double ();
double *ethlon = new double ();
short *value =new short(0.0);
short *count_node= new short();//accumulate the numbers between two nodes
double *medium = new double(0.0);
*value = next_position - position;
if(*value < 0)
*value = *total_number - position + next_position ;
if(*value > 1)
{
*a = y_coordinate[0][next_position] - y_coordinate[0][position];
*b = x_coordinate[0][next_position] - x_coordinate[0][position];
*c = (y_coordinate[0][position] * x_coordinate[0][next_position]) - (x_coordinate[0][position] * y_coordinate[0][next_position]);
*d = (double)sqrt(pow(*b,2)+pow(*a,2));
*count_node=position;
do
{
(*count_node)++;
if(*count_node == *total_number)
*count_node = *count_node - *total_number;
*ethlon += *medium =fabs((*a * x_coordinate[0][*count_node]- *b * y_coordinate[0][*count_node]+ *c)/ *d);
error[0]+=pow(*medium,2);
if(*medium>error[1])
error[1]=*medium;
(*value)--;
}while( *value > 1);
}
return *ethlon;
// delete ethlon,a,b,c,d,value,count_node;
}
//-------------------------------------------------------
float Initial_Ethlon_in_Type_3 (short *total_number,short **x_coordinate,short **y_coordinate,short position,short next_position)
{
register short *a= new short ();
register short *b= new short ();
register short *c= new short ();
register double *d= new double ();
double *ethlon = new double ();
short *value =new short(0.0);
short *count_node= new short();//accumulate the numbers between two nodes
// double *medium = new double(0.0);
*value = next_position - position;
if(*value < 0)
*value = *total_number - position + next_position ;
if(*value > 1)
{
*a = y_coordinate[0][next_position] - y_coordinate[0][position];
*b = x_coordinate[0][next_position] - x_coordinate[0][position];
*c = (y_coordinate[0][position] * x_coordinate[0][next_position]) - (x_coordinate[0][position] * y_coordinate[0][next_position]);
*d = (double)sqrt(pow(*b,2)+pow(*a,2));
*count_node=position;
do
{
(*count_node)++;
if(*count_node == *total_number)
*count_node = *count_node - *total_number;
*ethlon += fabs((*a * x_coordinate[0][*count_node]- *b * y_coordinate[0][*count_node]+ *c)/ *d);
// error[0]+=pow(*medium,2);
// if(*medium>error[1])
// error[1]=*medium;
(*value)--;
}while( *value > 1);
}
return *ethlon;
// delete ethlon,a,b,c,d,value,count_node;
}
//-------------------------------------------------------
// Linear Equation : ax+by+c=0
float Ethlon (short **x_coordinate,short **y_coordinate,short Last_position,short Middle_position,short Next_position)
{
register short *a= new short ();
register short *b= new short ();
register short *c= new short ();
register float *d= new float ();
float *ethlon = new float ();
*a = y_coordinate[0][Next_position] - y_coordinate[0][Last_position];
*b = x_coordinate[0][Next_position] - x_coordinate[0][Last_position];
*c = (y_coordinate[0][Last_position] * x_coordinate[0][Next_position]) - (x_coordinate[0][Last_position] * y_coordinate[0][Next_position]);
*d = (float)sqrt(pow(*b,2)+pow(*a,2));
*ethlon = fabs((*a * x_coordinate[0][Middle_position]- *b * y_coordinate[0][Middle_position]+ *c)/ *d);
return *ethlon;
// delete ethlon,a,b,c,d;
}
//-------------------------------------------------------
void Get_Chain_Code(int number,short *chain_code,short *count)
{
switch(number)
{
case 0:
chain_code[*count] = 3;
break;
case 1:
chain_code[*count] = 2;
break;
case 2:
chain_code[*count] = 1;
break;
case 3:
chain_code[*count] = 0;
break;
case 4:
chain_code[*count] = 7;
break;
case 5:
chain_code[*count] = 6;
break;
case 6:
chain_code[*count] = 5;
break;
case 7:
chain_code[*count] = 4;
break;
}
}
//-------------------------------------------------------
short the_best_significant (short *total_number,short **x_coordinate,short **y_coordinate,short position,short 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][next_position] - y_coordinate[0][position];
*b = x_coordinate[0][next_position] - x_coordinate[0][position];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -