[galib] GA for GAP

Ramya Narayanaswamy narayanaswamy.2 at wright.edu
Wed May 12 21:29:44 EDT 2004


Hello All,
I am trying to use Genetic Algorithm from the GALib for solving 
Generalized Assignment Problem. I have a running code for MKP which is 
a 1Dimensional array which uses GALib. Now is have a problem calling 
the obejctive function and defining in GA2DBinS.h. My code is some what 
like this

for(int i=0; i<5; i++) //reading the cost function values
{
for(int j=0; j<15; j++)
{
in>>c[i][j];
}
}
for(i=0; i<5; i++) //reading the resource allocation values
{
for(int j=0; j<15; j++)
{
in>> a[i][j];
}
}





GA2DBinarystringGenome genome(width, height, Objective);



// Objective function. The most imoratant part. Basically a child is 
evaluated by this function before //getting into the population
float Objective(GAGenome& g)
{
GA2DBinaryStringGenome & genome = (GA2DBinaryStringGenome &)g;
float score=0.0;
float feasible1[i]=0.0;// left hand side of current first constraint
float feasible2[j]=0.0;// left hand side of current second constraint
//* First constraints are calculated to see if the reported solution is 
good!
for(int i=0; i<genome.widht(); i++)
{
for(int j=0; j<genome.height(); j++)
{
feasible1[i] += genome.gene(i,j);
}
}
for(int j=0; j<genome.height(); j++)
{
for(int i=0; i<genome.width(); i++)
{
feasible2[j] += genome.gene(i,j)*a[i][j];
}
}
for(int i=0; i<genome.width(); i++) // Score of the child is returned
{
for(int j=0;j<genome.height(); j++)
{

score += genome.gene(i,j)* c[i,j];
}
}
return score;
}
}

The errors which it gives while compiling are

error C2065: 'GA2DBinarystringGenome' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'genome'
error C2065: 'genome' : undeclared identifier
error C2601: 'Objective' : local function definitions are illegal.

If some body has some suggestions or any solutions for this kindly let 
me know as it would really help me as i am stuck. Thanks in advance.
Ramya Narayanaswamy


More information about the galib mailing list