I'm trying to find the solution for the following expression
Objective function:
minimize(| x - c0 | + | y - c1 |)
Constraint:
0 < x < A 0 < y < B
where c0, c1, A, B are positive constants
Following the conversion given in http://lpsolve.sourceforge.net/5.1/absolute.htm
I reworded the expression to
Constraints:
(x - c0) <= xbar -1 *(x - c0) <= xbar (y - c1) <= ybar -1 *(y - c1) <= ybar 0 < x < A 0 < y < B
Objective function:
minimize(xbar + ybar)
However, I'm not able to implement this. I tried the following snippet
#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);
I'm getting the error, E0206 16:41:08.889048 80935 linear_solver.cc:1577] No solution exists. MPSolverInterface::result_status_ = MPSOLVER_INFEASIBLE
My use cases always produce feasible solutions (I'm trying to find the least manhattan distance between a point and a line).
I'm very new to using GOOGLE-OR tools. Please suggest any simpler solution I might have overlooked Any help will be appreciated
Thanks, Ram