Maximizing Profit through Linear Optimization

Lightworks Company produces two products, Product A and Product B.
- Product A requires 1 unit of frame parts and 2 units of electrical components.
- Product B requires 3 units of frame parts and 2 units of electrical components.
- Lightworks has 200 units of frame parts and 300 units of electrical components.
- Each unit of Product A gives a profit of $2.
- Each unit of Product B gives a profit of $4, but only up to 50 units. Any more than 50 units yields no additional profit.
- x = units of Product A produced,
- y = units of Product B produced.

# Coefficients of the objective function (this has been negated because linprog minimizes by default)
c = [-2, -4] # We are maximizing profit, so we negate the coefficients.
# Coefficients of the inequality constraints
A = [[1, 3], # Coefficients for frame parts constraint
[2, 2]] # Coefficients for electrical components constraint
# Right-hand side of the inequality constraints
b = [200, 300] # Limits on frame parts and electrical components
# Bounds for the variables: x (Product A) and y (Product B)
x_bounds = (0, None) # Non-negativity constraint for Product A
y_bounds = (0, 50) # Limit Product B to 50 units“We’ve set up the model in Python, the following line of code will give us the solution”, Ananya exclaimed triumphantly!
# Solving the Linear Programming problem
res = linprog(c, A_ub=A, b_ub=b, bounds=[x_bounds, y_bounds], method='simplex')
# Displaying the results
print('Optimal number of Product A to produce:', res.x[0])
print('Optimal number of Product B to produce:', res.x[1])
print('Maximum Profit:', -res.fun) # Negate again to get the maximized profitAs the Davengers looked at the code, Ananya continues explaining the code:
“This line of code — res = linprog(c, A_ub=A, b_ub=b, bounds=[x_bounds, y_bounds], method='simplex'—is where all the magic happens.
Basically, linprog is a function from the SciPy library that helps us solve Linear Programming problems.
We define the objective function coefficients (c), the constraints (A_ub and b_ub), and the bounds on the decision variables (bounds).
Then, we tell the model to use the Simplex Method to find the best solution. It calculates the optimal number of units to produce for Products A and B, all while respecting the resource constraints we’ve set.
The result gets stored in res, which includes the optimal solution and maximum profit. Easy, right?”
The Results
After running the code, Ananya smiles and reads out the results:

“This basically means that Lightworks should produce 125 units of Product A and 25 units of Product B to achieve a maximum profit of $350.”
Aarav, grinning, says, “See? I knew we had this! Lightworks owes us big time for this optimization masterclass.”
Sakshi laughs, “Aarav, you should thank Ananya, not yourself. You barely lifted a finger, and were busy staring at me.” Everyone laughs out loud!
Vikram, keeping things serious, adds, “Good work, team. $350 profit is the best outcome given the constraints on resources.”
“Three cheers to all of us!”, exclaimed Arjun, and the Davengers celebrated!
- 10 Statistical Concepts Every Aspiring Data Scientist Should Know — The Davangers’ Guide!
- How to Formulate a Linear Programming Problem — the Davengers way
- On LinkedIn.
- Career Counselling and Mentorship: Topmate
- Join my Whatsapp Group where I share resources, links, and updates.
Comments
Post a Comment