From algebra to a linear program: how do equations become a model?
Turn word problems into a linear program, find its best corner on a graph, and hand it to a real solver
A word problem, its model, and the best corner
- NeedAt 19:00 on 3 September 2025 Prairie Town's gas plants must cover at least 145 MW.
- Combined-cycle$40/MWh; it made 90 MW at 18:00 and can climb by at most 40 MW an hour.
- Peaker$100/MWh; it makes at most 100 MW.
- minimize 40x + 100y
- x + y ≥ 145 (cover the gap)
- x ≤ 130 (ramp: 90 + 40), x ≤ 150, y ≤ 100
- x ≥ 0, y ≥ 0
With JavaScript on, you build this model yourself, then two more, and hand one to a real solver.
- Dispatch: the 145 MW follows the real hourly shapes of 3 September 2025 on the Southwest Power Pool grid (EIA-930), scaled as in lesson 0.
- Planning: 2.1 and 3.0 GWh per MW-year are U.S. 2025 capacity factors, solar 24.0% and wind 33.8% (EIA, Electric Power Monthly, Table 6.07.B), rounded.
- All prices, costs, sizes and limits are illustrative.
- Solver: HiGHS 1.15, running in your browser.
What you just did, as diagrams
- Formulate it
- Every story becomes decisions (letters), a goal (a sum to minimize or maximize) and rules (inequalities).
- Feasible region
- The plans that keep every rule; with two decisions it is a shape on a plane.
- Best corner
- When a linear program has a best plan, one sits at a corner of the region.
- Signs matter
- ≤ where the story says ≥ lets the model skip its job, and the answer still looks optimal.
- A x ≤ b
- One common solver form: the costs c, a rule table A and limits b, with every rule written as ≤. x + y ≥ 145 enters as −x − y ≤ −145.
Go deeper · AnalystWhy the best plan sits at a corner
- Same cost, same line. All plans with the same cost \(C\) lie on one straight line, \(40x + 100y = C\): the dashed line of step 5.
- Slide it. Lowering \(C\) slides the line towards the origin without turning it.
- The last touch. The cheapest allowed plan is the last point of the region the line touches. A straight line leaves a region with straight edges at a corner: here \((130, 15)\), at $6,700.
- A tie. If the cost line is parallel to an edge, it leaves along the whole edge. With equal costs of $40 and $40, the corners \((45, 100)\) and \((130, 15)\) both cost $5,800, and so does every plan on the edge between them.
- No best plan. If the region is open in the direction the goal pulls, the solver reports the model as unbounded.
Go deeper · ModelerThe same model in a modelling language
Modelling languages let you write rules as algebra instead of arrays; they build \(A\), \(b\) and \(c\) for the solver. The dispatch model in JuMP (Julia), with HiGHS as the solver:
using JuMP, HiGHS
m = Model(HiGHS.Optimizer)
@variable(m, 0 <= x <= 150) # combined-cycle, MW
@variable(m, 0 <= y <= 100) # peaker, MW
@constraint(m, cover, x + y >= 145)
@constraint(m, ramp, x <= 90 + 40)
@objective(m, Min, 40x + 100y) # $ for the hour
optimize!(m)
value(x), value(y) # (130.0, 15.0)In Python, Pyomo and linopy (the layer under PyPSA) play the same role. Bridge B3 reads formulations written this way for many hours and plants at once, and the Modeler lesson M1 builds one for a whole day.
Go deeperWhat these small models leave out
- One hour at a time: multi-period models link adjacent hours through ramp limits (B3, M1). Day-ahead models often cover a whole day; real-time dispatch updates the plan many times an hour.
- The ramp here limits only the climb; a real ramp limit also slows the drop, and B3 writes both sides.
- Gas above the need is matched by spilling wind or sun; a model with exports or storage would track where it goes.
- Plants are always available and can run at any level; real units have minimum outputs and start-up costs, which need on-off decisions (M2).
- Prices and capacity factors are fixed numbers; real studies vary them (lesson 12 and the Modeler tier).
- Two decisions fit on a graph; real models have thousands to millions, which is why solvers exist.
Check yourself
Myth or fact? “A solver handles x < 130 just as well as x ≤ 130.”
- Myth
- Fact
Answer
Myth. With a strict < there may be no best plan: 129.9, 129.99 and so on are each better than the last. Linear programs use ≤, ≥ and =, never a strict < or >.
Myth or fact? “If a linear program has a best plan, one of its corners is a best plan.”
- Myth
- Fact
Answer
Fact, for regions with corners, as here. When two corners tie, every plan on the edge between them is best as well.
Myth or fact? “If the solver says ‘optimal’, the model is right.”
- Myth
- Fact
Answer
Myth. With the cover rule flipped to ≤, “optimal” meant making nothing for $0. Optimal is about the model, not the story: B3 teaches the checks.
The battery's losses rule is d ≤ 0.9c. As a row of A x ≤ b, with x = (c, d):
- (−0.9, 1) and b = 0
- (0.9, 1) and b = 0
- (0, 1) and b = 0.9
- (1, −0.9) and b = 0
Answer
(−0.9, 1) with b = 0: move 0.9c to the left, −0.9c + d ≤ 0. A zero on the right is common when a rule links two decisions.
“The peaker is either off, or on at 50 to 100 MW.” Is this still a linear program?
- Yes, write 50 ≤ y ≤ 100
- No: it needs an on-off decision
- Yes, write y ≥ 0
- No: it needs a curved cost
Answer
No. “Off or at least 50” leaves a gap between 0 and 50, which no set of straight-line rules can describe; an on-off (binary) decision can. That is a mixed-integer program (M2).
Numbers, sources and what’s next
Numbers to remember
| Number | What it means | Source |
|---|---|---|
| 24.0% | Capacity factor of U.S. utility-scale solar in 2025: about 2.1 GWh a year per MW. | EIA, Electric Power Monthly, Table 6.07.B · 2025 final, issue of 23 Oct 2026 |
| 33.8% | Capacity factor of the U.S. wind fleet in 2025: about 3.0 GWh a year per MW. | EIA, Electric Power Monthly, Table 6.07.B · 2025 final, issue of 23 Oct 2026 |
| 8,760 h | Hours in a non-leap year: MW × 8,760 h × capacity factor = MWh a year. | 365 × 24 |
Next
Sources and further reading
- EIA. Hourly Electric Grid Monitor (Form EIA-930): the Southwest Power Pool data behind Prairie Town's day, 2025.
- EIA. Electric Power Monthly, Table 6.07.B: capacity factors of non-fossil generators.
- Huangfu, Q., Hall, J. A. J. (2018). Parallelizing the dual revised simplex method. Mathematical Programming Computation 10: the paper behind the HiGHS solver.
- HiGHS documentation, and the modelling languages JuMP and Pyomo.
- Need a refresher first? Toolbox K4, linear equations and inequalities.
Spotted an error, or stuck? Write to hlli@ksu.edu. Corrections are made in place and dated here.
Text licensed CC BY 4.0, code MIT: teachers and students may reuse and adapt it, with credit to Honglin Li.