Here's a simple optimization problem:
import cvxpy as cp
import numpy as np
w = np.array([700, 700, 700, 700, 700, 700, 700, 700, 700, 700])
b = 7000
n = len(w)
# Define and solve the CVXPY problem.
x = cp.Variable(n, boolean=True)
prob = cp.Problem(cp.Minimize(w.T@x), [w.T@x >= b])
prob.solve()
# Print result.
print("\nThe optimal value is", prob.value)
print("A solution x is")
print(np.round(x.value))
I want to solve this as an ILP and thus get a result of $x \in {0, 1}^n$. It is fairly easy to see that this will just give x = [1,1,1,1,1,1,1,1,1,1]
as optimal x
and optimal value as 7000, and it is indeed what I get. However, if I add [1800, 1800]
such that w = [700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1800, 1800]
, then the optimal value should still be approximately 7000 (all the 700's) but the solver gives 7100 and includes the two 1800's.
I know that it's just approximating the optimal result but in this case it should find the true optimum.