-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Describe the bug
Using cvxpy 1.3.0 to solve the same example of MIP shown on the main webpage https://www.cvxpy.org/examples/basic/mixed_integer_quadratic_program.html. The code fails though with the following error: SolverError:
You need a mixed-integer solver for this model. Refer to the documentation
https://www.cvxpy.org/tutorial/advanced/index.html#mixed-integer-programs
for discussion on this topic.
I have already installed CVXOPT and GLPK solvers but none seems to be recognised by cvxpy. The only solver that works is ECOS_BB, however this solver is not recommended as it produces errors.
To Reproduce
Generate a random problem
np.random.seed(0)
m, n= 40, 25
A = np.random.rand(m, n)
b = np.random.randn(m)
Construct a CVXPY problem
x = cp.Variable(n, integer=True)
objective = cp.Minimize(cp.sum_squares(A @ x - b))
prob = cp.Problem(objective)
prob.solve()
Expected behavior
The code should output the optimal value x of the MIP.
Output
SolverError:
You need a mixed-integer solver for this model. Refer to the documentation
https://www.cvxpy.org/tutorial/advanced/index.html#mixed-integer-programs
for discussion on this topic.
Quick fix 1: if you install the python package CVXOPT (pip install cvxopt),
then CVXPY can use the open-source mixed-integer solver `GLPK`.
Quick fix 2: you can explicitly specify solver='ECOS_BB'. This may result
in incorrect solutions and is not recommended.
Version
- OS: Mac OS
- CVXPY Version: 1.3.0
Additional context
Add any other context about the problem here.