Bird
0
0

Find the bug in this code:

medium📝 Debug Q7 of 15
SciPy - Advanced Optimization

Find the bug in this code:

from scipy.optimize import milp

c = [-1, -2]
bounds = [(0, None), (0, None)]
integrality = [1, 0]

result = milp(c, bounds=bounds, integrality=integrality)
print(result.x)
ABounds are incorrectly specified as tuples
BIntegrality array must be boolean, not integers
CNo constraints provided, so problem is unbounded
DObjective function coefficients must be positive
Step-by-Step Solution
Solution:
  1. Step 1: Check constraints presence

    No constraints are given, only bounds, so solution space is large.
  2. Step 2: Assess problem boundedness

    Without constraints limiting variables, problem may be unbounded or trivial.
  3. Final Answer:

    No constraints provided, so problem is unbounded -> Option C
  4. Quick Check:

    Constraints needed to bound solution [OK]
Quick Trick: Bounds alone may not bound problem; constraints needed [OK]
Common Mistakes:
  • Assuming bounds alone constrain problem fully
  • Thinking tuples are invalid for bounds
  • Believing integrality must be boolean type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes