0
0
SciPydata~10 mins

Integer programming in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the integer linear programming solver from scipy.

SciPy
from scipy.optimize import [1]
Drag options to blanks, or click blank then click option'
Alinprog
Bminimize
Croot
Dcurve_fit
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'minimize' instead of 'linprog'.
Using 'root' which is for root finding, not optimization.
2fill in blank
medium

Complete the code to define the objective function coefficients for minimization.

SciPy
c = [1]
Drag options to blanks, or click blank then click option'
A1, 2, 3
B{1, 2, 3}
C[1, 2, 3]
D(1, 2, 3)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a tuple or set instead of a list.
Not enclosing the numbers in any brackets.
3fill in blank
hard

Fix the error in the code to specify the integer constraint for the variables.

SciPy
bounds = [(0, None), (0, None), (0, None)]
integrality = [1]
Drag options to blanks, or click blank then click option'
A[0, 0, 0]
B[True, True, True]
C[int, int, int]
D[1, 1, 1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using boolean True instead of 1.
Using data types like int instead of numeric flags.
4fill in blank
hard

Fill both blanks to define inequality constraints matrices and vectors.

SciPy
A_ub = [1]
b_ub = [2]
Drag options to blanks, or click blank then click option'
A[[1, 2, 3], [4, 5, 6]]
B[7, 8]
C[[7, 8]]
D[1, 2, 3]
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up matrix and vector shapes.
Using a single list for both constraints and bounds.
5fill in blank
hard

Fill all three blanks to call the solver with integer constraints and print the solution.

SciPy
result = linprog(c=[1], A_ub=[2], b_ub=[3], bounds=bounds, integrality=integrality, method='highs')
print(result.x)
Drag options to blanks, or click blank then click option'
Ac
BA_ub
Cb_ub
Dbounds
Attempts:
3 left
💡 Hint
Common Mistakes
Passing bounds instead of b_ub or A_ub.
Mixing up the order of parameters.