Hello,
I'm using your QP. I have a set of solvable inputs. With the solver I get around 20% failure when output.Solution contains NaN. How can I tune (some threshold) the accuracy of the solver, so that I can get solution in 100% of solvable inputs?
My inputs are in format of
minimize 1/2 * x^T D x + d^T x
where A x >= b
I'm calling:
var output = solveQP(Dmat, dvec, Amat, bvec, meq, factorized);
One example of solvable input that returns NaN:
JSON.stringify(Dmat)
"[[],[0,2,0,0,0,0,0],[0,0,2,0,0,0,0],[0,0,0,2,0,0,0],[0,0,0,0,2,0,0],[0,0,0,0,0,2,0],[0,0,0,0,0,0,2]]"
JSON.stringify(dvec)
"[0,-10,-10,-30,-20,-30,-20]"
JSON.stringify(Amat)
"[[],[0,1,-1,0,0,0,0,-1,0,0,1,0,0,0,0,0],[0,0,0,1,-1,0,0,-1,0,0,0,1,0,0,0,0],[0,0,0,1,-1,0,0,0,-1,0,0,0,1,0,0,0],[0,0,0,1,-1,0,0,0,0,-1,0,0,0,1,0,0],[0,0,0,0,0,1,-1,0,-1,0,0,0,0,0,1,0],[0,0,0,0,0,1,-1,0,0,-1,0,0,0,0,0,1]]"
JSON.stringify(bvec)
"[0,3.999,-4.001,4.999,-5.001,0.999,-1.001,-7.001,-1.001,-2.001,-0.001,-0.001,-0.001,-0.001,-0.001,-0.001]"
JSON.stringify(meq)
"0"
JSON.stringify(factorized)
"[0,0]"
This returns:
factorized = [0, 0]
output = {"solution":[,NaN,NaN,NaN,NaN,NaN,NaN],"Lagrangian":[,NaN,0,NaN,0,NaN,0,0,0,0,0,0,0,0,NaN,0],"value":[,NaN],"unconstrained_solution":[0,-4.999999999999999,-4.999999999999999,-14.999999999999996,-9.999999999999998,-14.999999999999996,-9.999999999999998],"iterations":[,6,1],"iact":[,3,5,1,14,0,0,0,0,0,0,0,0,0,0,0],"message":""}
If there is more than one possible solution with equal minimum value, it's enough to get any solution.
The constraints are of three types:
- x2 + x3 + x4 = 5,
this returned NaNs for many inputs, so I substituted it with two inequalities:
x2 + x3 + x4 >= 4.999 and
x2 + x3 + x4 <= 5.001
This substitution helped a lot.
- sum of some variables <= some positive integer (eg. 7 as in bvec[7])
this I substituted with:
sum of some variables <= some positive integer + epsilon
eg.
sum of some variables <= 7.001
- each variable >= 0
that I substituted with:
each variable >= -epsilon
eg.
each variable >= -0.001
The best I would like to get only integers in solution but I'm noticed you wrote the solver that returns reals.