Skip to content

6. Problem formulation

Ioannis G. Tsoulos edited this page Jun 22, 2019 · 1 revision

An example of coding the objective problem in ANSI C++ is presented below:

int getdimension() {return 13; }

int geteq() { return 0; }

int getineq() { return 9; }

void getleftmargin(double *x)

{

for(int i=0;i<13;i++) x[i]=0.0;

}

void getrightmargin(double *x)

{

for(int i=0;i<13;i++) x[i]=1.0;

x[9]=x[10]=x[11]=100.0;

}

double funmin(double *x)

{

double sum1=0.0,sum2=0.0,sum3=0.0;

for(int i=0;i<4;i++) sum1=sum1+x[i];

for(int i=0;i<4;i++) sum2=sum2+x[i]*x[i];

for(int i=4;i<13;i++) sum3=sum3+x[i];

return 5*sum1-5*sum2-sum3;

}

void feq(double *x,double *eq) { }

void fineq(double *x,double *ineq) {

double x1=x[0],x2=x[1],x3=x[2],x4=x[3],x5=x[4],x6=x[5],x7=x[6],x8=x[7],

   x9=x[8],x10=x[9],x11=x[10],x12=x[11],x13=x[12];

ineq[0]=-(10-(2x1+2x2+x10+x11));

ineq[1]=-(10-(2x1+2x3+x10+x12));

ineq[2]=-(10-(2x2+2x3+x11+x12));

ineq[3]=-(8*x1-x10);

ineq[4]=-(8*x2-x11);

ineq[5]=-(8*x3-x12);

ineq[6]=-(2*x4+x5-x10);

ineq[7]=-(2*x6+x7-x11);

ineq[8]=-(2*x8+x9-x12);

}

void done(double *x) {}

The following functions were used:

  1. int getdimension(): This function returns the dimension of the objective problem.

  2. int geteq(): This function returns the number of equatlity constraints.

  3. int getineq(): This function returns the number of inequality constraints.

  4. void getleftmargin(double *x): This function returns in the array x the lower bound for the objective problem.

  5. void getrightmargin(double *x): This function returns in the array x the upper bound for the objective problem.

  6. double funmin(double *x): This function returns the objective function evaluated at the point x.

  7. void feq(double *x,double *eq): This function returns the equality constraints in the array eq evaluated at the point x.

  8. void fineq(double *x,double *ineq): This function returns the inequality constraints in the array ineq evaluated at the point x.

  9. void done(double *x). The method done will be called after the termination of the genetic algorithm. The parameter x is the best value discovered by the genetic algorithm.

Clone this wiki locally