void box_func (individual * ind1); // prototype of the box function
// Create the random pop
void create_random_pop ()
{
double ran;
for (int i = 0; i < pop_size; i++)
{
for (int j = 0; j < N_of_x; j++)
{
ran = randomperc ();
population[i].xreal[j] = ran * supremumx[j] + (1.0 - ran) * infimumx[j];
}
population[i].init ();
}
}
// Strict Domination check function for population members indexed by m and n
// returns 1 ( 0 ) meaning m dominates (does not dominate) n in minimization sense
// only for population members _to_be_called_in_ create_archive()
int
strict_dom_check (int m, int n)
{
int flag = 1;
for (int p = 0; p < MAX; p++)
{
if ((flag == 1) && (population[m].f[p] < population[n].f[p]))
flag = 1;
else
{
flag = 0;
break;
}
}
return (flag);
}
// Create the initial archive
// Consists of the non-dominated (strict domination) members
// of the population
void
create_archive ()
{
int flag = 0;
for (int i = 0; i < pop_size; i++)
{
flag = 0;
for (int j = 0; j < pop_size; j++)
{
if (strict_dom_check (j, i) == 1)
flag = -1;
}
if (flag == 0)
{
archive[archive_size] = population[i];
archive_size++;
}
}
}
// Prints the population members, whenever called
void
print_pop ()
{
cout << "\n Printing real values of the function values\n";
for (int i = 0; i < pop_size; i++)
{
for (int j = 0; j < MAX; j++)
cout << population[i].f[j] << "\t";
cout << "\n";
}
}
// Prints the function values of the archive members, when called
void
print_archive ()
{
cout << "\n Printing the function values of the archive members\n";
for (int i = 0; i < archive_size; i++)
{
for (int j = 0; j < MAX; j++)
cout << archive[i].f[j] << "\t";
cout << "\n";
}
}
// Prints into files the population and archive members
// Also prints the Box vectors and Decision Variables of the archive members
void
print_func_values ()
{
FILE *fpop, *farch, *fvar, *fbox;
fpop = fopen ("popltn.out", "w");
farch = fopen ("a", "w");
fvar = fopen ("ar_variables.out", "w");
fbox = fopen ("box_vectors.out", "w");
cout << "\n\n The size of the archive is " << archive_size << "\n";
cout << " The final archive is in file archive.out\n\n";
for (int i = 0; i < pop_size; i++)
{
for (int j = 0; j < MAX; j++)
fprintf (fpop, "%f\t", population[i].f[j]);
fprintf (fpop, "\n");
}
for (int i = 0; i < archive_size; i++)
{
for (int j = 0; j < MAX; j++)
{
fprintf (farch, "%f\t", archive[i].f[j]);
fprintf (fbox, "%f\t", archive[i].box[j] * EPSILON[j]);
}
// Main function starts here
int
main (int argc, char **argv)
{
void generate_replace ();
void compete ();
int update ();
// returns 0 if not accepted and 1 if the child is accepted
int con_update ();
time_t start, end;
time (&start);
// Take the start time reading
int child_flag1 = 0, flg = 0, child_flag2 = 0;
input_param ();
// Input the necessary parameters
// cout << "\n Enter the seed : ";
// cin >> seed;
seed = (double)atof(argv[1]);
warmup_random (seed);
// set up the random no. generator
create_random_pop ();
create_archive ();
// cout << "\n Enter the No of Generations Needed : ";
// No of function evaluations = max_no_gen * 2
// cin >> max_no_gen;
max_no_gen = (int)atoi(argv[2]);
cout << "\n Starting loop........";
for (int no_gen = 0; no_gen < max_no_gen; no_gen++)
{
generate_replace ();
cout << "\n GEN = " << no_gen + 1;
cout << "\n NO of members in Archive at present :" << archive_size <<
"\n";
newchild = newchild1;
child_flag1 = con_update ();
compete ();
newchild = newchild2;
child_flag2 = con_update ();
compete ();
}
/* printing the values of the functions */
print_func_values ();
time (&end);
cout << "\n\n Total Time taken == " << difftime (end,
start) << " seconds.\n\n";
return (0);
}
// Box funtion definitons, here done for minimization case
void
box_func (individual * ind1)
{
for (int i = 0; i < MAX; i++)
ind1->box[i] = floor ((ind1->f[i] / EPSILON[i]));
}
// function to check for Box domination
int
box_dom (individual ind1, individual ind2)
{
int flag = 1;
int elag = 0;
for (int j = 0; j < MAX; j++)
{
if ((flag == 1) && (ind1.box[j] <= ind2.box[j]))
flag = 1;
else
flag = 0;
//to check whether 2 individuals are in the same box or not
int
same_box_check (individual ind1, individual ind2)
{
int flag = 1;
for (int i = 0; i < MAX; i++)
{
if ((flag == 1) && (ind1.box[i] == ind2.box[i]))
{
flag = 1;
}
else
{
flag = 0;
break;
}
}
return (flag);
}
Normally when you have a big project, you should write small portions of the code, test and fix all the errors before you continue. That way if you get an error, it's normally in the last code you wrote. Makes it much easier to fix.
If you could add code tags and format your code it would make it much easier to read.
42[Error] syntax error before "individual"
43[Error] syntax error before '{' token
55[Error] 'for' loop initial declaration used outside C99 mode
56[Error] `xreal' undeclared (first use in this function)
56[Error] (Each undeclared identifier is reported only once
83[Error] syntax error before '}' token
2) From your error messages, it looks though you're trying to use a C compiler to compile C++ code, hence the compiler is calling your class definition a syntax error. Check that you're using the right tools to compile your code.
3) Why are you making all your data members public?
4) function1 and function2 are not exactly helpful names. It helps to give your methods names that sensibly indicate what they do; it will make your code more comprehensible to you and anyone else.