Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Lab 9: Product Mix Model in PuLP

Open In Colab

Lab 9: Product Mix Model in PuLP

In this lab you build the weekly production plan of Qahwa House’s central kitchen as a linear program in PuLP, and compare it with the plan the manager would make by instinct.

The question. How many batches of each product should the kitchen make this week? The manager’s instinct: as much as possible of the product with the highest margin, Yemeni Haraz.

How this lab works

  • Run the cells from top to bottom with Shift + Enter. Replace every ... with your code, then run the check cell under it.

  • Extended track: after Part D, try the ★ challenges.

  • Submit before the next lab session: File → Download → Download .ipynb.

You may use an AI assistant for code. If you do, add a short note at the end: what you asked, what you kept and what you changed.

ColumnMeaning
product, kind, batchwhat is made, and what one batch is
price_sarwhat the branches pay the kitchen for one batch (SAR)
variable_cost_sarbeans, flour, dates, saffron and packaging for one batch (SAR)
contribution_sarprice minus variable cost: what one more batch adds to the week’s profit
roast_h, oven_h, labour_hhours of the roaster, the oven and the kitchen staff one batch uses
max_batchesthe most batches the branches can sell in a week

The last row, capacity, holds the hours available each week: 50 roaster hours, 40 oven hours and 160 staff hours (four people, 40 hours each).

Part A: The roastery model

A1. Products and capacities

Split the table: products holds the four product rows with product as the index, and capacity holds the three hours available (the capacity row, columns HOURS, as floats).

A2. The model in words

This week the oven is being serviced: the kitchen makes coffee only, House Blend (HH batches) and Yemeni Haraz (YY batches). In three short lines, write the decision variables, the objective and the constraints (with their numbers, from the table).

Your answer here (double-click to edit).

A3. Solve it with PuLP

Complete the model: the objective and the roaster constraint. The bounds of the variables hold the demand limits. The first solve of a session also prints two lines with HiGHS’s name and licence; you can ignore them.

Part B: The picture behind the answer

B1. The corners

The feasible region of the roastery model has five corners: (0,0)(0,0), (40,0)(40,0), (40,4)(40,4), (10,16)(10,16) and (0,16)(0,16). Add a column contribution to the DataFrame corners with the contribution of each corner.

B2. The graph

Run the cell: it draws the feasible region, the roaster line, the two demand limits and three iso-profit lines.

B3. Per roaster hour

Compute each coffee’s contribution per roaster hour and store it in a Series per_roaster_hour, indexed by product (House Blend and Yemeni Haraz only).

B4. In two sentences: why does the best coffee plan make only 4 batches of Yemeni Haraz, the product with the highest margin?

Your answer here (double-click to edit).

Part C: The whole kitchen

C1. The full model

The oven is back. Build the model with all four products and the three resources, reading every number from products and capacity. Complete the objective and the constraint inside the loop with pulp.lpSum. The code builds the model inside a function, build_mix, that returns the model and its variables, so you can build it again in D3.

C2. The plan and the hours

Store the plan in a Series plan (batches, indexed by product). Then build a DataFrame usage indexed by resource with three columns: used, available and slack.

C3. The branches would buy 30 batches of Saffron Cake a week, yet the plan makes none. In two sentences, explain why, using the resource table.

Your answer here (double-click to edit).

Part D: The manager’s plan

D1. Highest margin first

The manager’s plan fills the demand of the product with the highest margin first: 16 batches of Yemeni Haraz, then 10 of House Blend (the roaster hours left), then 20 of Date Maamoul (the oven is then full), and no Saffron Cake. Compute its weekly contribution manager_profit, and the hours it uses in a Series manager_used (indexed by resource).

D2. The gap

Store in gap how much more the LP plan earns per week, and in gap_year the same over 52 weeks.

D3. Two promises

The branches insist on at least 30 batches of House Blend, and the manager has promised a hotel at least 10 batches of Yemeni Haraz. Build a fresh model with strict, xs = build_mix(products, capacity) (a variable belongs to one model, so we build a new one rather than copy it), add both promises as constraints on its variables xs, solve it, and store its status (a string such as "Optimal") in strict_status.

D4. In one sentence: which constraint makes the two promises impossible, and by how many hours?

Your answer here (double-click to edit).

D5. Your recommendation

Write three sentences for the manager: the plan to follow this week (with numbers), what it earns compared with the “highest margin first” plan, and one assumption of the model that you would check before following it.

Write your recommendation here (double-click to edit).

★ Extended challenges

E1. One more roaster hour. Re-solve the full model with 51 roaster hours instead of 50. How much does the contribution rise, and what happens to the plan?

E2. Whole batches. Pastries come in whole trays. Solve the 51-hour model again with every variable cat="Integer". Compare with E1: what is the extra roaster hour worth now?

E3. A better Saffron Cake. Raise the contribution of Saffron Cake step by step (600, 650, 700, 720 SAR) and re-solve. From which contribution does the plan start making it, and what does it stop making instead?

AI-use log (if you used an AI assistant)

What you asked, what you kept, what you changed.