Search code examples
c++opencvmathlinear-programming

Why does cv::solveLP() impose the constraint x>=0 and what to do if your solution space can be negative?


I have a delaunay triangulation.

Each point has an absolute coordinate in R2. Each edge has a known x, y distance between each point. There is error, and so the solution of absolute coordinates cannot satisfy the system, it's over-determined.

I would like to find the solution of absolute coordinates that minimizes the inf norm of this system.

I have been using openCV HEAVILY for this project and so I intended to use cv::solveLP(). However, the answer cv::solveLP produced was way off.

After looking at the documentation, I saw that solveLP() imposes the constraint x >= 0. It seems this is not an option you can change. I realize that many real world LP problems revolve around numbers of objects, and often x >= 0 makes sense. But why would they impose this constraint without giving you the option?

Is there a way to still use this function for a solution where x can take on negative values?


Solution

  • As I have discovered and as discussed in the comments, this solver-imposed constraint is done for efficiency and it is solver-specific. Dantzig, the inventer of linear programming used this in his original simplex algorithm. Not all solvers impose this constraint, but the cv::solveLP() does. If you expected the optimum will not occur in the positive orthant you can apply a linear shift to your input vector (in the case of cv::solveLP() this shift should be done to the b vector) such that the optimum will occur in non-negative space.

    However, knowing how far to shift your data is not trivial and insufficiently shifted data will result in cv::solveLP() solving on the intersection of your solution space and the positive orthant. If this region is non-empty then an optimum will exist in this region and the solver will return a reasonable looking but possibly incorrect answer, making it difficult to realize what you've done wrong.