title: Absolute value in objective function of linear optimization
body: <p>I'm trying to find the solution for the following expression</p>
  
  <p>Objective function:</p>
  
  <blockquote>
    <p>minimize(| x - c0 | + | y - c1 |)</p>
  </blockquote>
  
  <p>Constraint:    </p>
  
  <blockquote>
  <pre><code>0 &lt; x &lt; A
  0 &lt; y &lt; B
  </code></pre>
  </blockquote>
  
  <p>where c0, c1, A, B are positive constants </p>
  
  <p>Following the conversion given in
    <a href="http://lpsolve.sourceforge.net/5.1/absolute.htm" rel="nofollow noreferrer">http://lpsolve.sourceforge.net/5.1/absolute.htm</a></p>
  
  <p>I reworded the expression to</p>
  
  <p>Constraints:  </p>
  
  <blockquote>
  <pre><code>    (x - c0) &lt;= xbar
  -1 *(x - c0) &lt;= xbar
      (y - c1) &lt;= ybar
  -1 *(y - c1) &lt;= ybar
  
       0 &lt; x &lt; A
       0 &lt; y &lt; B
  </code></pre>
  </blockquote>
  
  <p>Objective function:</p>
  
  <blockquote>
  <pre><code>minimize(xbar + ybar)
  </code></pre>
  </blockquote>
  
  <p>However, I'm not able to implement this.
    I tried the following snippet</p>
  
  <pre><code>#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' &amp; 'offset' are real numbers.
  solver.MakeRowConstraint(Z);
  
  const LinearRange r = -1 * (e - c0) &lt;= X;
  const LinearRange s = (e - c0]) &lt;= X ;
  const LinearRange m = -1 * (f - c1) &lt;= Y;
  const LinearRange k = (f - c1) &lt;= Y ;
  
  solver.MakeRowConstraint(r);
  solver.MakeRowConstraint(s);
  solver.MakeRowConstraint(m);
  solver.MakeRowConstraint(k);
  
  MPObjective* const objective = solver.MutableObjective();
  objective-&gt;MinimizeLinearExpr(X+Y);
  </code></pre>
  
  <p>I'm getting the error, 
    E0206 16:41:08.889048 80935 linear_solver.cc:1577] No solution exists. MPSolverInterface::result_status_ = MPSOLVER_INFEASIBLE</p>
  
  <p>My use cases always produce feasible solutions (I'm trying to find the least manhattan distance between a point and a line).</p>
  
  <p>I'm very new to using GOOGLE-OR tools. Please suggest any simpler solution I might have overlooked
    Any help will be appreciated</p>
  
  <p>Thanks,
  Ram</p>