简体   繁体   中英

alglib BLEIC optimizer

I currently use BLEIC for minimization solution. I implement a case from MSDN example in the following link http://msdn.microsoft.com/en-us/library/ff628587%28v=vs.93%29.aspx

The following is my source code.

void function1_grad(const real_1d_array &x, double &func, real_1d_array &grad, void *ptr)
{
//
// this callback calculates f(x0,x1) = 20*x0 + 15*x1
// and its derivatives df/d0 and df/dx1
// set goal (20 * sa + 15 * vz);

func = 20 * x[0] + 15 * x[1];
grad[0] = 20;
grad[1] = 15;
}

int main(int argc, char **argv)
{

// using BLEIC optimizer.

//set initial point, wild guess middle point
real_1d_array x = "[3000.0,4500.0]";

//set scale
real_1d_array s = "[10.0,10.0]";

//set boundry
// 0 <= vz <= 9000,
// 0 <= sa <= 6000);

real_1d_array bndl = "[+0.0,+0.0]";
real_1d_array bndu = "[+6000.0,+9000.0]";

//set linear constrain
// 0.3 * sa + 0.4 * vz >= 2000,
// 0.4 * sa + 0.2 * vz >= 1500,
// 0.2 * sa + 0.3 * vz >= 500);

real_2d_array c = "[[0.3,0.4,2000.0],[0.4,0.2,1500.0],[0.2,0.3,500.0]]";

//set >= (1 ), = (0), <= (-1)
integer_1d_array ct = "[1,1,1]";

minbleicstate state;
minbleicreport rep;

//
// These variables define stopping conditions for the underlying CG algorithm.
// They should be stringent enough in order to guarantee overall stability
// of the outer iterations.
//
// We use very simple condition (gradian base) - |g|<=epsg
//
double epsg = 0.00001;
double epsf = 0;
double epsx = 0;

//
// These variables define stopping conditions for the outer iterations:
// * epso controls convergence of outer iterations; algorithm will stop
// when difference between solutions of subsequent unconstrained problems
// will be less than 0.0001
// * epsi controls amount of infeasibility allowed in the final solution
//
double epso = 0.0001;
double epsi = 0.0001;

//
// Now we are ready to actually optimize something:
// * first we create optimizer
// * we add boundary constraints
// * we add linear constraints
// * we set scale
// * we tune stopping conditions
// * and, finally, optimize and obtain results...
//
minbleiccreate(x, state);
minbleicsetbc(state, bndl, bndu);
minbleicsetlc(state, c, ct);
minbleicsetscale(state,s);
minbleicsetinnercond(state, epsg, epsf, epsx);
minbleicsetoutercond(state, epso, epsi);
alglib::minbleicoptimize(state, function1_grad);
minbleicresults(state, x, rep);

//
// ...and evaluate these results  
//
printf("%d\n", int(rep.terminationtype)); // EXPECTED: 4
printf("%s\n", x.tostring(2).c_str()); // EXPECTED: [2,4]
//Sleep(5000);
return 0;
}

My question is when I set different initial points I get different answers, sometimes return "NAN" case 1: set initial point, real_1d_array x = "[3000.0,4500.0]", return correct answer [2000, 3500] case 2: set real_1d_array x = "[1000.0,1000.0]", return [NAN, NAN]

What is the problem resulted from? and how to fix it?

I think the reason is that [1000.0,1000.0] is not in feasible set.

Because 0.3*1000+0.4*1000=700<2000 , so [1000.0,1000.0] violates constraint 0.3 * sa + 0.4 * vz >= 2000 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM