about convert binary strings to decimal values

shijun zhang shijunzh at 263.net
Mon Oct 9 23:26:09 EDT 2000


Hello! If I use GABin2DecGenome and GABin2DecPhenotype to convert binary strings to decimal values,there are no problem!
But when I want use GA2DBinaryStringGenome class to evolve and the work of converting binary to decimal finished in object 
function, the result is incorrect!
my object function is as the fellow:
y = 100*(x1^2 - x2)^2+(1-x1)^2    with the constraint:-2.048<x1<2.048,-2.048<x2<2.048
 
the constructor is: 
GA2DBinaryStringGenome genome(10,2, Objective);

my object function is as the follow:
float  Objective(GAGenome& g) {
  GA2DBinaryStringGenome & genome = (GA2DBinaryStringGenome &)g;
  float amin=-2.048,amax=2.048;
  float score=0.0;
  float temp[2],x[2];
  int width=10,height=2;
  for (int i=0;i<height;i++){
	temp[i]=0;
	for (int j=0;j<width;j++)
		temp[i]+=pow(2,width-j-1)*genome.gene(j,i);
  }
	x[0]=(amax-amin)*temp[0]/(pow(2,width)-1)+amin;
	x[1]=(amax-amin)*temp[1]/(pow(2,width)-1)+amin;
	score=100*(x[0]*x[0]-x[1])*(x[0]*x[0]-x[1])+(1-x[0])*(1-x[0]);
  return score;
}
 My work enviroment is Visualstdio 6.0 in win2000.
I need your help!
                  your sincerely!
                  Shijun Zhang 
                  shijunzh at sina.com







-------------- next part --------------
A non-text attachment was scrubbed...
Name: mex1.C
Type: application/octet-stream
Size: 5458 bytes
Desc: not available
Url : http://mailman.mit.edu/pipermail/galib/attachments/20001010/e62c86fe/attachment.obj


More information about the galib mailing list