MILP Factory › Example
Machine Learning from ScratchAll chapters MILP Factory › ExampleOne section · Sections in this chapter4 / 8 ↓
Reading tools Definitions & inline links
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
Let's work through a concrete factory optimization example step by step. Consider a factory that produces two products using two machines with the following specifications:
Problem Setup:
- Product 1: requires 2 hours on Machine A, 4 hours on Machine B, profit of $3 per unit
- Product 2: requires 3 hours on Machine A, 2 hours on Machine B, profit of $2 per unit
- Machine A: 12 hours available
- Machine B: 16 hours available
- Additional constraint: We can only produce products in whole units (integer constraint)
Step 1: Define Variables
Let = number of units of Product 1 to produce Let = number of units of Product 2 to produce
Step 2: Formulate the Problem
Our objective is to maximize profit:
Subject to constraints:
- Machine A capacity:
- Machine B capacity:
- Non-negativity:
- Integer constraint:
Step 3: Solve the LP Relaxation First
If we ignore the integer constraint, we can solve this as a linear program. We need to find where the constraint boundaries intersect, which gives us the optimal solution.
From Machine A constraint: , we can express as:
From Machine B constraint: , we can express as:
To find the intersection point where both constraints are binding (satisfied with equality), we set the two expressions equal:
Multiplying both sides by 3 to eliminate the denominator:
Expanding the right side:
Rearranging terms to collect on one side:
Simplifying:
Solving for :
Substituting back into the Machine A constraint (with equality) to find :
Simplifying:
Solving for :
Verification: Let's verify this solution satisfies both constraints:
- Machine A: ✓
- Machine B: ✓
So the LP relaxation gives us with profit:
The optimal profit is \13$.
Step 4: Apply Branch-and-Bound
Since we need integer solutions, we use branch-and-bound:
Branch 1:
- New constraint:
- With fixed, from Machine A: , so , giving
- From Machine B: , so , giving
- The binding constraint is , so the solution is (this is already an integer solution)
- Profit =
Branch 2:
- New constraint:
- From Machine B: , with :
- Simplifying: , so , giving
- Since (non-negativity), we have
- Solution: (integer solution)
- Profit =
Branch 1.1: and
- With and :
- Verification: Machine A: ✓
- Verification: Machine B: ✓
- Solution: (integer solution)
- Profit =
Branch 1.2: and
- With and :
- Verification: Machine A: ✓
- Verification: Machine B: ✓
- Solution: (integer solution)
- Profit =
Step 5: Compare Integer Solutions
We have found three feasible integer solutions:
- Solution 1: , Profit =
- Solution 2: , Profit =
- Solution 3: , Profit =
Since we're maximizing profit, the optimal integer solution is Solution 3: with a profit of \13$.
Note: In this example, the LP relaxation solution happens to be an integer solution, so the integer constraint doesn't reduce the optimal value. This is not always the case. Often, integer constraints force us to accept a lower objective value than the LP relaxation.
Let's visualize this example to see the LP relaxation solution compared to the integer solutions:


LP Relaxation Solution: x₁ = 3, x₂ = 2, Profit = \$13 Optimal Integer Solution: x₁ = 3, x₂ = 2, Profit = \$13
Note: In this case, the LP relaxation happens to give an integer solution. However, the integer constraint ensures we only consider feasible integer points