Stack Overflow Asked by Erwinwin on December 16, 2020
I am new to python optimization using qpsolvers
and I have problem with running the following code:
import numpy as np
from qpsolvers import solve_qp
P = np.array([4.,5.,5.,8.]).reshape(2,2)
q = np.array([-3.,2.]).reshape(1,2)[0]
G = np.array([1,1,-2,-3,1,0,0,1,-1,0,0,-1]).reshape(6,2)
h = np.array([2400.,-1100.,1200.,1500.,-300.,0.])
A = None
b = None
sol = solve_qp(P,q,G,h,A,b,solver='quadprog')
I got this error:
sol = solve_qp(P,q,G,h,A,b,solver='quadprog')
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/qpsolvers/__init__.py", line 262, in solve_qp
return quadprog_solve_qp(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/qpsolvers/quadprog_.py", line 90, in quadprog_solve_qp
if "matrix G is not positive definite" in e:
TypeError: argument of type 'ValueError' is not iterable
I am really not sure what cause the problem. Any help for this will be appreciated. Thanks!
Hi I think this is an issue both with the qpsolvers
code and your example.
The qpsolvers
error is that it has if "matrix G is not positive definite" in e:
instead of if "matrix G is not positive definite" in str(e):
.
If you correct this then the error ValueError: Buffer dtype mismatch, expected 'double' but got 'long'
remains. This is because all of you inputs are floats apart from G
. If you replace it with G = np.array([1., 1., -2., 3., 1., 0., 0., 1., -1., 0., 0., -1.]).reshape(6,2)
then I think this should resolve your issue.
Answered by Maddo on December 16, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP