qpOASES
qpOASES copied to clipboard
Issue with infinity bounds in python interface
Dear developers,
I was wondering how to set unbounded (infinity) constraints in python (I couldn't find anything in the documentation or examples about this). I notices that when using something like
ub = np.array([np.inf])
then I run into the undesired behavior that changing such a bound in a hotstart sequence does not affect the result. I included a MWE below. The problem consists of the convex objective obj = (x - 1)^2 + (y - 1)^2
with x,y >= 0
and 0 <= x + y <= inf
. This fails when using the above. However, when I use a large enough float for an upper bound then it works. I'd be happy to hear what I'm doing wrong here.
Thank you in advance, Jonas
import numpy as np
from qpoases import PyQProblem as QProblem
from qpoases import PyOptions as Options
from qpoases import PyPrintLevel as PrintLevel
#Setup data of first QP.
H = np.array([2.0, 0.0, 0.0, 2.0 ]).reshape((2,2))
A = np.array([1.0, 1.0]).reshape((2,1))
g = np.array([-2.0, -2.0 ])
lb = np.array([0.0, 0.0])
ub = np.array([np.inf, np.inf])
lbA = np.array([0.0])
ubA = np.array([np.inf])
#ubA = np.array([100.0]) # Uncomment this in order for it to work
# Setting up QProblem object.
example = QProblem(2, 1)
# Solve first QP.
nWSR = np.array([10])
example.init(H, g, A, lb, ub, lbA, ubA, nWSR)
xOpt = np.zeros(2)
example.getPrimalSolution(xOpt)
print("Initial solution:")
print("xOpt = [ %e, %e ]; objVal = %e\n" % (xOpt[0],xOpt[1],example.getObjVal()))
# Solve second QP.
nWSR = np.array([10])
print("Set ubA[0] = 0.0 and resolve (should force x_0 to 0.0):")
ubA[0] = 0.0
example.hotstart( g, lb, ub, lbA, ubA, nWSR)
# Get and print solution of second QP.
example.getPrimalSolution(xOpt)
print("xOpt = [ %e, %e ]; objVal = %e" % (xOpt[0],xOpt[1],example.getObjVal()))
To avoid computations involving INF-floats, it is customary also in qpOASES to use large bounds instead of infinity. Typical values are -1.0e+20 and +1.0e+20.