I have a GA source code in C and I want to change its objective function. My objective function has a lot of details and I have opened that file in my project too, but I want to call it in this part of the program by the format of the following objective function and remove this one. Is there anyone who lets me know how I can change it?
objfunc(critter)
/* objective function used in Goldberg's book */
/* fitness function is f(x) = x**n,
normalized to range between 0 and 1,
where x is the chromosome interpreted as an
integer, and n = 10 */
struct individual *critter;
{
unsigned mask=1; /* mask for current bit */
unsigned bitpos; /* current bit position */
unsigned tp;
double pow(), bitpow, coef;
int j, k, stop;
int n = 10;
I have this objective function:
for( i = 0; i < Candidate; i++) {
total_fixed_cost += Y_fix[i] * FixedCost[i];
}
int Z_fix[int linknum] = Z_fix;
int OriginalLinkCost[linknum] = OriginalLinkCost;
int linknum;
int total_fixed_cost;
for( linknum = 0; linknum < LinkNumber; linknum++ )
{
Capacity[linknum] = Capacity[linknum] + Z_fix[linknum] * Capacity[linknum];
CapExpCost += w * int LinkLength[linknum] * ( Z_fix[linknum] * Capacity[linknum] );
OriginalLinkCost += Alpha * TravelTime[linknum] * ( 1 + a[linknum] * pow ( ( BackgrdVolume[linknum] / Capacity[linknum] ) , b[linknum] ) );
}
I wanted to use it in the form of the objective function I have introduced before.
Is it OK that I just write this?
objfunc(critter)
struct individual *critter;
{
unsigned mask=1; /* mask for current bit */
unsigned bitpos; /* current bit position */
unsigned tp;
double pow();
int i, j, k, stop;
critter->fitness = 0.0;
/* loop thru number of bytes holding chromosome */
for(k = 0; k < chromsize; k++)
{
if(k == (chromsize-1))
stop = lchrom-(k*UINTSIZE);
else
stop = UINTSIZE;
/* loop thru bits in current byte */
int Y_fix[Candidate] = Y_fix;
tp = critter->chrom[k];
for(j = 0; j < stop; j++)
{
bitpos = j + UINTSIZE*k;
/* test for current bit 0 or 1 */
if((tp&mask) == 1)
{
for( i = 0; i < Candidate; i++) {
total_fixed_cost += Y_fix[i] * FixedCost[i];
}
int Z_fix[int linknum] = Z_fix;
int OriginalLinkCost[linknum] = OriginalLinkCost;
int linknum;
int total_fixed_cost;