||
class Tools
{
public static void copy(Point a,Point b)
{
System.arraycopy(a.x,0,b.x,0,Point.size);
}
public static void crossA(Point a,Point b,Point ab,Point ba)
{
int pos=(int)(Math.random()*Point.size);
System.arraycopy(a.x,0,ab.x,0,pos);
System.arraycopy(b.x,0,ba.x,0,pos);
System.arraycopy(a.x,pos,ba.x,pos,Point.size-pos);
System.arraycopy(b.x,pos,ab.x,pos,Point.size-pos);
}
public static void mutA(Point a)
{
int pos=(int)(Math.random()*Point.size);
a.x[pos]=(a.x[pos]+1)%2;
}
public static int getBestPos(Point[] a)
{
Point temp=new Point();
int pos=0;
copy(a[0],temp);
for(int i=1;i<a.length;i++)
{
if(temp.getFitness()<a[i].getFitness())
{
copy(a[i],temp);
pos=i;
}
}
return pos;
}
public static int getBadtPos(Point[] a)
{
Point temp=new Point();
int pos=0;
copy(a[0],temp);
for(int i=1;i<a.length;i++)
{
if(temp.getFitness()>a[i].getFitness())
{
copy(a[i],temp);
pos=i;
}
}
return pos;
}
public static double[] getPvalue(Point[] s)
{
double[] pa=new double[s.length];
for(int i=0;i<s.length;i++)
pa[i]=s[i].getFitness();
return pa;
}
}
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-12-22 13:46
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社