我正在尝试找到以下表达式的解决方案
目标函数:
最小化(| x - c0 | + | y - c1 |)
约束:
0 < x < A 0 < y < B
其中 c0, c1, A, B 是正常数
在 http://lpsolve.sourceforge.net/5.1/absolute.htm中给出的转换之后
我将表达式改写为
约束:
(x - c0) <= xbar -1 *(x - c0) <= xbar (y - c1) <= ybar -1 *(y - c1) <= ybar 0 < x < A 0 < y < B
目标函数:
minimize(xbar + ybar)
但是,我无法实现这一点。我尝试了以下代码段
#include "ortools/linear_solver/linear_solver.h"
#include "ortools/linear_solver/linear_expr.h"
MPSolver solver("distanceFinder", MPSolver::GLOP_LINEAR_PROGRAMMING);
MPVariable* x = solver.MakeNumVar(0, A, "x");
MPVariable* y = solver.MakeNumVar(0, B, "y");
const LinearExpr e = x;
const LinearExpr f = y;
LinearExpr X;
LinearExpr Y;
LinearRange Z = slope * e + offset == f; // Where 'slope' & 'offset' are real numbers.
solver.MakeRowConstraint(Z);
const LinearRange r = -1 * (e - c0) <= X;
const LinearRange s = (e - c0]) <= X ;
const LinearRange m = -1 * (f - c1) <= Y;
const LinearRange k = (f - c1) <= Y ;
solver.MakeRowConstraint(r);
solver.MakeRowConstraint(s);
solver.MakeRowConstraint(m);
solver.MakeRowConstraint(k);
MPObjective* const objective = solver.MutableObjective();
objective->MinimizeLinearExpr(X+Y);
我收到错误,E0206 16:41:08.889048 80935 linear_solver.cc:1577] 不存在解决方案。MPSolverInterface::result_status_ = MPSOLVER_INFEASIBLE
我的用例总是产生可行的解决方案(我试图找到点和线之间的最小曼哈顿距离)。
我对使用 GOOGLE-OR 工具非常陌生。请提出我可能忽略的任何更简单的解决方案任何帮助将不胜感激
谢谢,拉姆