-
Notifications
You must be signed in to change notification settings - Fork 3
6. Problem formulation
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:
-
int getdimension(): This function returns the dimension of the objective problem.
-
int geteq(): This function returns the number of equatlity constraints.
-
int getineq(): This function returns the number of inequality constraints.
-
void getleftmargin(double *x): This function returns in the array x the lower bound for the objective problem.
-
void getrightmargin(double *x): This function returns in the array x the upper bound for the objective problem.
-
double funmin(double *x): This function returns the objective function evaluated at the point x.
-
void feq(double *x,double *eq): This function returns the equality constraints in the array eq evaluated at the point x.
-
void fineq(double *x,double *ineq): This function returns the inequality constraints in the array ineq evaluated at the point x.
-
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.