Fundamental Theorem of Linear Programming
Steps to Solve LP Problems
- Define variables
- Write the objective function
- Write constraints
- Graph the feasible region
- Find corner points
- Evaluate objective function at each corner point
- Compare values to find optimum
Example: Formulate LP Problem
A furniture maker produces tables and chairs. Each table requires 2 hours of carpentry and 1 hour of finishing. Each chair requires 1 hour of carpentry and 1 hour of finishing. There are 100 hours of carpentry and 80 hours of finishing available. Profit per table is âš500 and per chair is âš300. Formulate as LP problem.
Types of Solutions
Example: Check Feasibility
Check if the following constraints define a non-empty feasible region: , ,
Reading a constraint as a half-plane
Every inequality divides the first quadrant into two halves, and only one of them survives. Take the carpentry limit from the workshop example. Its boundary line passes through and , so it is easy to draw with two points. To decide which side to shade, substitute any point not on the line â the origin is the usual choice. It gives , which is true, so the feasible side is the one containing the origin.
Repeat that for the finishing constraint : the line runs through and , and the origin again passes the test. The non-negativity pair and then restricts everything to the first quadrant. The feasible region is the intersection of these four half-planes, a four-sided polygon with vertices at , , and . Two of those vertices, and , sit on the carpentry line where the resource is fully used; the point touches only the finishing line, leaving 20 carpentry hours idle.
Locating the corner points on paper
Vertices appear only where two boundary lines cross, so a reliable drawing routine lists the boundary lines first: , , the vertical axis and the horizontal axis. Four lines give up to six pairwise intersections, and you test each one against every constraint before keeping it. Solving together with by subtraction gives and then , which satisfies both inequalities, so is a genuine vertex.
Two candidate points fail the test and are discarded. The intersection of with the vertical axis is , but exceeds 80, so it lies outside the finishing constraint. The intersection of with the horizontal axis is , but exceeds 100, so it violates carpentry. Discarding infeasible intersections before evaluating the objective is what prevents a maximum from being reported at a point the problem never allowed.
Evaluating the objective at each corner
With the vertex list in hand, the objective becomes four multiplications. The table shows every constraint value alongside the profit, so any arithmetic slip is visible immediately.
| Corner | Carpentry used | Finishing used | Profit |
|---|---|---|---|
| 0 | 0 | 0 | |
| 100 | 50 | 25000 | |
| 100 | 80 | 28000 | |
| 80 | 80 | 24000 |
The largest entry is 28000 rupees at : 20 tables and 60 chairs. Note that the winning point uses both resources fully, while leaves 30 finishing hours idle because it produces tables and nothing else. A quick way to anticipate the answer without the table is to compare slopes â the objective has slope , which sits between the slopes and of the two constraint lines, so the optimum must land where those two lines meet.
corners = [(0, 0), (50, 0), (20, 60), (0, 80)]
def profit(x, y):
return 500 * x + 300 * y
best = max(corners, key=lambda p: profit(*p))
for x, y in corners:
print(f"x={x:>3} y={y:>3} carpentry={2*x + y:>4} finishing={x + y:>4} Z={profit(x, y)}")
print("optimum:", best, "Z =", profit(*best))
# optimum: (20, 60) Z = 28000
Enumerating vertices with a solver
Hand listing works for two variables and two constraints, but it does not scale. The function below takes any set of lines written as , adds the two axes, forms every pairwise intersection, rejects the ones that break a constraint, and returns the best remaining point.
def solve_lp(lines, profit):
"""lines: [(a, b, c)] meaning a*x + b*y <= c. Returns (point, value)."""
boundary = lines + [(1, 0, 0), (0, 1, 0)]
pts = set()
for i in range(len(boundary)):
for j in range(i + 1, len(boundary)):
a1, b1, c1 = boundary[i]
a2, b2, c2 = boundary[j]
det = a1 * b2 - a2 * b1
if abs(det) < 1e-9:
continue
x = (c1 * b2 - c2 * b1) / det
y = (a1 * c2 - a2 * c1) / det
inside = all(a * x + b * y <= c + 1e-9 for a, b, c in lines)
if x >= -1e-9 and y >= -1e-9 and inside:
pts.add((round(x, 6), round(y, 6)))
if not pts:
return None, None
best = max(pts, key=lambda p: profit(*p))
return best, profit(*best)
money = lambda x, y: 500 * x + 300 * y
base = [(2, 1, 100), (1, 1, 80)]
print(solve_lp(base, money)) # ((20.0, 60.0), 28000.0)
print(solve_lp([(1, 1, 5), (-1, -1, -10)], money)) # (None, None)
The second call passes the contradictory pair and from the feasibility example above, and the function reports an empty vertex set instead of a bogus optimum â the programmatic version of noticing that no point can satisfy both.
Pricing an extra hour of a scarce resource
Once a corner solution is available, sensitivity analysis becomes a second solve. Raise the carpentry budget from 100 hours to 120, keep finishing at 80, and the new intersection of the two constraint lines moves to , giving profit . The gain is 4000 rupees for 20 extra hours, so the shadow price of carpentry is 200 rupees per hour in this range.
That number has a limit: it holds only while the same pair of constraints defines the optimum. Push carpentry far enough and the vertex reaches , after which extra carpentry hours buy nothing because finishing or demand becomes the binding limit. Reporting a shadow price together with the range over which it is valid is the difference between a useful model and a misleading one.
Key Takeaways
- Every linear constraint is a half-plane, and testing the origin against each boundary line tells you which side to shade before the feasible polygon is built.
- The optimum of a bounded linear program always sits at a corner, so the whole solution reduces to finding the vertices and comparing the objective on each one.
- Candidate intersections that break any constraint must be discarded first, otherwise the reported maximum can come from a point the problem never permitted.
- Re-solving after a small resource increase gives the shadow price, which measures the value of one extra unit of a scarce input but only until the binding pair of constraints changes.
Common Mistakes
Evaluating the objective only where the axes meet the constraint lines and skipping the intersection of the two constraint lines
Fix: List every pairwise intersection of the boundary lines, including the crossing of the two resource constraints, then test each candidate against all inequalities.
Shading the wrong side of a boundary because the origin lies on the line itself
Fix: Pick a test point that is not on the line, such as a point with a large positive x value, and substitute it before choosing the feasible side.
Reporting a shadow price as if it stayed valid for any resource increase
Fix: Re-solve at a second resource level and state the range over which the same corner remains optimal before quoting the per-unit value.