0

我目前使用 BLEIC 进行最小化解决方案。我在以下链接http://msdn.microsoft.com/en-us/library/ff628587%28v=vs.93%29.aspx中实现了 MSDN 示例中的一个案例

以下是我的源代码。

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;
}

我的问题是,当我设置不同的初始点时,我得到不同的答案,有时会返回“NAN”案例 1:设置初始点,real_1d_array x = “[3000.0,4500.0]”,返回正确答案 [2000, 3500] 案例 2:设置 real_1d_array x = "[1000.0,1000.0]",返回 [NAN, NAN]

问题是由什么引起的?以及如何解决?

4

1 回答 1

2

我认为原因是它[1000.0,1000.0]不在可行集中。

因为0.3*1000+0.4*1000=700<2000,所以[1000.0,1000.0]违反了约束0.3 * sa + 0.4 * vz >= 2000

于 2012-04-18T15:55:29.037 回答