Objectives, Decision Variables, Constraints, and Feasibility › Example: Allocating Two Products Across Two Resources

Michael BrenndoerferOctober 29, 20265 min read
Machine Learning from ScratchAll chapters
Part 14 of 15Constrained Optimization
Chapter 84Objectives, Decision Variables, Constraints, and Feasibility › Example: Allocating Two Products Across Two Resources
Reading section 6 of 10 · Example: Allocating Two Products Across Two Resources · 5 minSection 6 of 10 · 5 min

Section 6 of 10 · 5 min read

Objectives, Decision Variables, Constraints, and Feasibility › Example: Allocating Two Products Across Two ResourcesSection view · Sections in this chapter6 / 10 ↓
Reading tools Definitions, links & notes

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Notes & comments

We now solve the packaging problem completely by hand, then repeat the exercise with whole pallets, and finally measure the gap between the two. Hand-solving is not busywork: it gives us a reference value against which every solver call in the next section can be audited.

The first step is to find the feasible set, because without it we have no candidates to score. Each resource inequality becomes an equality on its boundary line. The machine constraint 2x1+x2≤82x_1 + x_2 \leq 8 has boundary x2=8−2x1x_2 = 8 - 2x_1, which meets the x1x_1-axis at x1=4x_1 = 4 and the x2x_2-axis at x2=8x_2 = 8. The labour constraint x1+2x2≤8x_1 + 2x_2 \leq 8 has boundary x2=4−x1/2x_2 = 4 - x_1/2, meeting the axes at x1=8x_1 = 8 and x2=4x_2 = 4. The non-negativity domains cut everything to the first quadrant, so the feasible region is the quadrilateral with corners

(0,0),(4,0),(8/3, 8/3),(0,4).(0,0), \qquad (4,0), \qquad (8/3,\, 8/3), \qquad (0,4).

The corner (4,0)(4,0) comes from the first line at x2=0x_2 = 0; the corner (0,4)(0,4) comes from the second line at x1=0x_1 = 0; the corner (8,0)(8,0) implied by the second line is cut off by the first line and is therefore not feasible. To find the intersection we solve the two equalities. Doubling the first gives 4x1+2x2=164x_1 + 2x_2 = 16. Subtracting the second, x1+2x2=8x_1 + 2x_2 = 8, yields 3x1=83x_1 = 8, so x1=8/3x_1 = 8/3, and substituting back gives x2=8−2(8/3)=8/3x_2 = 8 - 2(8/3) = 8/3. Both are positive, so this point is in the feasible set.

Evaluating the objective at each corner:

Corner evaluation for the two-product allocation problem.
Cornerx1x_1x2x_2Machine slackLabour slackProfit 40x1+30x240x_1 + 30x_2
A00880
B4004160
C8/38/300560/3 ≈ 186.67
D0440120

The largest value is 560/3≈186.67560/3 \approx 186.67 at corner C, where both resources are exactly exhausted. Checking the algebra: 40⋅83=320340 \cdot \tfrac{8}{3} = \tfrac{320}{3} and 30⋅83=240330 \cdot \tfrac{8}{3} = \tfrac{240}{3}, and the sum is 3203+2403=5603\tfrac{320}{3} + \tfrac{240}{3} = \tfrac{560}{3}. Because the objective is linear and the feasible set is a polygon, the maximum must occur at a corner, so we have solved the continuous problem exactly without any software. The slack columns are worth reading alongside the profit: at C both are zero, which is the geometric signature of a vertex formed by two binding constraints.

Now suppose pallets cannot be split. We enumerate every lattice point with 0≤x1≤40 \leq x_1 \leq 4 and 0≤x2≤40 \leq x_2 \leq 4 and keep those satisfying both inequalities 2x1+x2≤82x_1 + x_2 \leq 8 and x1+2x2≤8x_1 + 2x_2 \leq 8. The feasible lattice points are exactly those whose coordinates satisfy both resource limits, because nonnegativity and the resource limits rule out any coordinate above 4, independently of the objective. The top candidates, ranked by profit 40x1+30x240x_1 + 30x_2, are:

Top feasible integer plans ranked by profit for the two-product allocation problem.
x1x_1x2x_2Machine slackLabour slackProfit
3201180
2310170
4004160
3113150
2222140

The best integer plan is x1=3x_1 = 3, x2=2x_2 = 2 with profit 40⋅3+30⋅2=18040 \cdot 3 + 30 \cdot 2 = 180, leaving one labour-hour idle (8−(3+2⋅2)=18 - (3 + 2\cdot 2) = 1) and no machine-hours idle (8−(2⋅3+2)=08 - (2\cdot 3 + 2) = 0). Note how close the top candidates are: (2,3)(2,3) earns 170 and (3,2)(3,2) earns 180, a ten-unit difference produced by swapping which resource is left slack. Rounding the continuous optimum 2.667,2.6672.667, 2.667 to (3,3)(3,3) would have been a mistake, since 2⋅3+3=9>82 \cdot 3 + 3 = 9 > 8 violates the machine constraint; rounding down to (2,2)(2,2) loses 40 units of profit. Rounding is a heuristic with no general feasibility or optimality guarantee; this example shows infeasibility when rounding up and lost profit when rounding down.

Finally we quantify how much the integer restriction costs. In minimization form the integer optimum is zinc=−180z_{\text{inc}} = -180 and the LP relaxation bound is zLB=−560/3z_{\text{LB}} = -560/3; using profit values directly gives the same relative gap,

gap=zinc−zLB∣zinc∣(relative gap definition)=(−180)−(−560/3)∣−180∣(substitute incumbent and bound)=20/3180=127(simplify numerator and denominator)≈0.0370.(evaluate)\begin{aligned} \text{gap} &= \frac{z_{\text{inc}} - z_{\text{LB}}}{\lvert z_{\text{inc}} \rvert} && \text{(relative gap definition)} \\ &= \frac{(-180) - (-560/3)}{\lvert -180 \rvert} && \text{(substitute incumbent and bound)} \\ &= \frac{20/3}{180} = \frac{1}{27} && \text{(simplify numerator and denominator)} \\ &\approx 0.0370. && \text{(evaluate)} \end{aligned}

The gap relative to the integer profit is 1/27≈3.70%1/27\approx3.70\%. This quantifies the initial LP bound's looseness. Enumeration has already established that 180 is the exact integer optimum for this tiny model. A MILP solver that certifies that optimum can tighten its search bound to 180 and report a zero final gap.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy