Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ alglib-BLEIC优化器_C++_Optimization_Linear Programming_Alglib - Fatal编程技术网

C++ alglib-BLEIC优化器

C++ alglib-BLEIC优化器,c++,optimization,linear-programming,alglib,C++,Optimization,Linear Programming,Alglib,我目前使用BLEIC作为最小化解决方案。我在下面的链接中实现了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/d

我目前使用BLEIC作为最小化解决方案。我在下面的链接中实现了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;
}
void function 1\u grad(常量实数1d\u数组和x、双精度和函数、实数1d\u数组和grad、void*ptr)
{
//
//这个回调函数计算f(x0,x1)=20*x0+15*x1
//及其衍生物df/d0和df/dx1
//设定目标(20*sa+15*vz);
func=20*x[0]+15*x[1];
梯度[0]=20;
梯度[1]=15;
}
int main(int argc,字符**argv)
{
//使用BLEIC优化器。
//设置初始点,任意猜测中间点
实数数组x=“[3000.04500.0]”;
//设定比例
real_1d_数组s=“[10.0,10.0]”;
//定界

//0=(1),=(0),我认为原因是
[1000.01000.0]
不在可行范围内

因为
0.3*1000+0.4*1000=700=2000