📄 ant.~h
字号:
class AntTool
{
private:
public:
//-------------------------------------------------------
short Bending_Value (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 short *d= new short ();
register short *e= new short ();
register short *f= new short ();
register short *g= new short ();
// 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);
short *the_longest_distance=new short(1000);
*value = next_position - position;
if(*value < 0)
*value = *total_number - position + next_position-1 ;
if(*value > 1)
{
*count_node=position;
do
{
(*count_node)++;
if(*count_node == *total_number)
*count_node = *count_node - *total_number;
*a = x_coordinate[0][position] - x_coordinate[0][(*count_node)];
*b = y_coordinate[0][position] - y_coordinate[0][(*count_node)];
*c = x_coordinate[0][next_position] - x_coordinate[0][(*count_node)];
*d = y_coordinate[0][next_position] - y_coordinate[0][(*count_node)];
*e = abs(*a + *c);
*f = abs(*b + *d);
if(*e > *f)
*g = *e;
else
*g = *f;
(*value)--;
if( *g < *the_longest_distance)
{
*node=*count_node;
*the_longest_distance = *g;
}
/*
if(*now_distance > threshold && *now_distance > *the_longest_distance)
{
*node=*count_node;
*the_longest_distance = *now_distance;
}
*/
}while( *value > 1);
}
return *node;
// delete value,count_node,node,the_longest_distance;
}
//--------------------------------------------------------
void Convert_to_WhiteImage(TImage * Input_Image)
{
Byte * y_address = new Byte();
Byte * x_address = new Byte();
for(short i=1;i<Input_Image->Height-1;i++)
{
y_address = (Byte*)Input_Image->Picture->Bitmap->ScanLine[i];
for(short j=1;j<Input_Image->Width-1;j++)
{
x_address =y_address+ 3*j;
x_address[0]=x_address[1]=x_address[2]=(Byte)255;
int test=0;
}
}
Input_Image->Refresh();
}
//-------------------------------------------------------
void coordinate(int now_x,int now_y,int number,int *data)
{
switch(number)
{
case 0:
*data=now_x-1;
*(data+1)=now_y-1;
break;
case 1:
*data=now_x;
*(data+1)=now_y-1;
break;
case 2:
*data=now_x+1;
*(data+1)=now_y-1;
break;
case 3:
*data=now_x+1;
*(data+1)=now_y;
break;
case 4:
*data=now_x+1;
*(data+1)=now_y+1;
break;
case 5:
*data=now_x;
*(data+1)=now_y+1;
break;
case 6:
*data=now_x-1;
*(data+1)=now_y+1;
break;
case 7:
*data=now_x-1;
*(data+1)=now_y;
break;
}
}
//-------------------------------------------------------
void coordinate(short *x_coordinate_1,short *y_coordinate_1,short **contour_x_coordinate,short **contour_y_coordinate,short **tour_table,short ant_number,short *total_number,short *Coordinate)
{
short *number = new short(0);
for(short i=*(Coordinate+tour_table[ant_number][0]);i<*total_number;i++)
{
x_coordinate_1[*number]=contour_x_coordinate[0][i];
y_coordinate_1[*number]=contour_y_coordinate[0][i];
(*number)++;
}
for(short i=0;i<*(Coordinate+tour_table[ant_number][0]);i++)
{
x_coordinate_1[*number]=contour_x_coordinate[0][i];
y_coordinate_1[*number]=contour_y_coordinate[0][i];
(*number)++;
}
x_coordinate_1[*number]=contour_x_coordinate[0][tour_table[ant_number][0]];
y_coordinate_1[*number]=contour_y_coordinate[0][tour_table[ant_number][0]];
// delete number;
}
//-------------------------------------------------------
void Count_Tour_Nodes(short **tour_table,short *count_tour_node,short *total_number,short ant_number)
{
short *number = new short(1);
for(short i=1;i<*total_number;i++)
{
if(tour_table[ant_number][i] != -1)
(*number)++;
else
break;
}
*(count_tour_node+ant_number)= *number;
// delete number;
}
//-------------------------------------------------------
float Distance_of_point_to_line(short *foward_and_backward_node, short *break_point_x_coordinate,short *break_point_y_coordinate, short current_node)
{
float *a = new float();
float *b = new float();
float *c = new float();
float *d = new float();
float *e = new float();
*a = (float)break_point_y_coordinate[foward_and_backward_node[1]] - (float)break_point_y_coordinate[foward_and_backward_node[0]];
*b = (float)break_point_x_coordinate[foward_and_backward_node[1]] - (float)break_point_x_coordinate[foward_and_backward_node[0]];
*c = (break_point_y_coordinate[foward_and_backward_node[0]] * break_point_x_coordinate[foward_and_backward_node[1]])
-(break_point_x_coordinate[foward_and_backward_node[0]] * break_point_y_coordinate[foward_and_backward_node[1]]);
*d = (float)sqrt(pow(*b,2)+pow(*a,2));
*e= (*a * break_point_x_coordinate[current_node]) - (*b * break_point_y_coordinate[current_node])+ *c;
return fabs((*e / *d));
// delete a,b,c,d,e;
}
//-------------------------------------------------------
float Distance_of_point_to_line(short *foward_and_backward_node, short **break_point_x_coordinate,short **break_point_y_coordinate, short current_node)
{
float *a = new float();
float *b = new float();
float *c = new float();
float *d = new float();
float *e = new float();
*a = (float)break_point_y_coordinate[0][foward_and_backward_node[1]] - (float)break_point_y_coordinate[0][foward_and_backward_node[0]];
*b = (float)break_point_x_coordinate[0][foward_and_backward_node[1]] - (float)break_point_x_coordinate[0][foward_and_backward_node[0]];
*c = (break_point_y_coordinate[0][foward_and_backward_node[0]] * break_point_x_coordinate[0][foward_and_backward_node[1]])
-(break_point_x_coordinate[0][foward_and_backward_node[0]] * break_point_y_coordinate[0][foward_and_backward_node[1]]);
*d = (float)sqrt(pow(*b,2)+pow(*a,2));
*e= (*a * break_point_x_coordinate[0][current_node]) - (*b * break_point_y_coordinate[0][current_node])+ *c;
return fabs((*e / *d));
// delete a,b,c,d,e;
}
//-------------------------------------------------------
void Elitist(float **pheromone,short *solution,short *coordinate)
{
for(short i=1;i<(*solution)+1;i++)
pheromone[coordinate[solution[i]]][coordinate[solution[i+1]]] += ((float)1/ (*solution));
}
//-------------------------------------------------------
void Elitist_in_Segment_bound(float **pheromone,float *the_least_ethlon,short *solution, short *initial_number)
{
short *renewed_position = new short(0);
for(short i=1;i<(*solution)+1;i++)
{
*renewed_position = solution[i+1]-solution[i];
if((*renewed_position)<0)
*renewed_position += *initial_number;
pheromone[solution[i]][*renewed_position] += ((float)1/ *the_least_ethlon);
}
}
//-------------------------------------------------------
float error_Ethlon (short *total_number,short **contour_x_coordinate,short **contour_y_coordinate,short position,short next_position,float *error)
{
float *ethlon= new float(0.0);
short *value = new short(0);
float *medium = new float(0.0);
*value = next_position - position;
if(*value < 0)
*value = *total_number - position + next_position ;
if(*value > 1)
{
register float *a= new float ();
register float *b= new float ();
register float *c= new float ();
register float *d= new float ();
register float *e= new float ();
*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 = (float)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 if(*value == 1 || *value == 0)
*ethlon=0;
else
*ethlon=10000;
return *ethlon;
// delete ethlon,value,medium;
}
//-------------------------------------------------------
float error_Ethlon_Type_3 (short *total_number,short **contour_x_coordinate,short **contour_y_coordinate,short position,short next_position,float *error)
{
double *ethlon= new double(0.0);
short *value = new short(0);
double *medium = new double(0.0);
*value = next_position - position;
if(*value < 0)
*value = *total_number - position + next_position ;
if(*value > 1)
{
register double *a= new double ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -