0
0
SciPydata~30 mins

Linear programming (linprog) in SciPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Linear Programming with scipy.linprog
📖 Scenario: You are managing a small factory that produces two products: chairs and tables. You want to maximize your profit while considering the limits on materials and labor hours.
🎯 Goal: Build a linear programming model using scipy.optimize.linprog to find the best number of chairs and tables to produce to maximize profit.
📋 What You'll Learn
Create variables for the number of chairs and tables
Set up the profit coefficients for each product
Define the constraints for materials and labor
Use scipy.optimize.linprog to solve the problem
Print the optimal number of chairs and tables to produce
💡 Why This Matters
🌍 Real World
Factories and businesses use linear programming to maximize profits or minimize costs while respecting resource limits.
💼 Career
Understanding linear programming is useful for roles in operations research, supply chain management, and data science.
Progress0 / 4 steps
1
Set up profit coefficients and variables
Create a list called profit_coeffs with values -20 and -30 representing the negative profit per chair and table respectively (negative because linprog minimizes).
SciPy
Need a hint?

Remember, linprog minimizes, so use negative profits to maximize.

2
Define constraints for materials and labor
Create a list of lists called constraints_matrix with these rows: [1, 2] for wood usage and [3, 2] for labor hours. Also create a list called constraints_limits with values 100 and 90 representing the maximum wood and labor available.
SciPy
Need a hint?

Each row in constraints_matrix corresponds to a resource limit.

3
Use linprog to solve the optimization problem
Import linprog from scipy.optimize. Then create a variable called result by calling linprog with profit_coeffs as the objective, constraints_matrix as A_ub, and constraints_limits as b_ub. Use default bounds.
SciPy
Need a hint?

Use c= for objective coefficients, A_ub= and b_ub= for inequality constraints.

4
Print the optimal production quantities
Print the string Optimal chairs: followed by the first value in result.x and the string Optimal tables: followed by the second value in result.x. Use two separate print statements.
SciPy
Need a hint?

Access the solution with result.x and print the values.