Linear Programming for MDPs
The primal over values, the dual over occupancy measures, and what each reveals.
Value and policy iteration exploit the structure of the Bellman equation. Linear programming treats an MDP as just another linear program, and gains what the iterative methods lack: polynomial time for every discount, a natural home for constraints on costs, and, with a few hundred features in place of billions of states, an answer that still comes with a guarantee. This lesson proves the LP correct, prices its complexity, solves a constrained MDP by hand, and analyzes approximate linear programming.
What you’ll learn
- Prove that is the unique solution of the primal linear program for any positive state weights, and read an optimal policy off the primal or the dual.
- State the complexity of solving MDPs by linear programming: polynomial time, P-completeness, and strongly polynomial results for a fixed discount.
- Solve a constrained MDP through its dual, and explain why its optimal policy randomizes and how a Lagrange multiplier prices the constraint.
- Formulate the approximate linear program with features, prove its error bound, and explain the role of the state-relevance weights.
Why the linear program is right
Occupancy Measures & the Dual View derived the linear program of a discounted MDP and its dual over occupancy measures. This step proves that they solve the MDP and shows what each side reveals. Fix weights , for example a distribution of starting states that gives every state some mass:
(i) Feasible means superharmonic. The constraints say . The operator is monotone, so applying it again keeps the inequality, and the iterates converge to :
(ii) Optimal and unique. is feasible, and any other feasible is at least everywhere and above it somewhere, so with positive weights its objective is strictly larger.
(iii) Weak duality, then equality. For feasible and , multiply each primal constraint by , sum, and use the dual constraints to collect the terms in . The gap is a sum of nonnegative terms:
The occupancy measure of an optimal policy is dual-feasible, and its objective is its expected discounted return from , which equals : the gap closes, so both are optimal. (iv) At optimal and the gap is zero, so every term vanishes, and forces the bracket to zero (complementary slackness):
You solve (P) with for one start state and for every other state. What can go wrong?
- The linear program becomes infeasible
- Its solution can exceed in states that optimal play from never reaches, so a policy read off its tight constraints can be wrong
- Its solution can fall below in the states without weight
- Nothing: the solution is still everywhere
Show the answer
B. Its solution can exceed in states that optimal play from never reaches, so a policy read off its tight constraints can be wrong
Feasibility still forces , but only and the values its optimal actions lead to are pushed down to . Elsewhere any feasible value at least is optimal for the LP. An inflated value can make a non-optimal action's constraint tight at , so reading the policy off tight constraints may pick it. Positive weights everywhere make the solution unique.
How hard is solving an MDP?
Linear programs are solvable in time polynomial in their size and in the number of bits of their data, by the ellipsoid method or by interior-point methods. Through (P) or (D), every finite MDP can therefore be solved in polynomial time for every , which neither value iteration nor policy iteration can guarantee when is part of the input.
| Method | Polynomial for every ? | Strongly polynomial for a fixed ? |
|---|---|---|
| Value iteration | No: its sweeps grow like , exponential in the bits of | No (Feinberg & Huang, 2014); polynomial in , , (Tseng, 1990) |
| Howard's policy iteration | No: exponential examples as (Hollanders, Delvenne & Jungers, 2012) | Yes (Ye, 2011; Scherrer, 2016) |
| Simplex on (D) with Dantzig's rule, a form of simple policy iteration | No such bound is known, and other simple-policy-iteration rules are exponential (Melekopoglou & Condon, 1994) | Yes (Ye, 2011) |
| Interior-point methods on (P) or (D) | Yes | Yes, for Ye's combinatorial interior-point method (Ye, 2005), the first strongly polynomial algorithm for a fixed |
In practice, generic LP solvers are seldom the fastest way to solve a plain MDP: (P) has constraints, while value and policy iteration exploit sparse transitions and warm starts. The LP earns its place when the problem stops being a plain MDP: when costs are constrained, when values are restricted to a feature space, or when an argument needs duality.
Constraints need the dual: a worked example
A constrained MDP adds cost functions and budgets on their expected discounted totals. Costs are linear in the occupancy measure, so each budget is one more linear inequality in (D), and the problem stays a linear program (Altman, 1999). It has no Bellman equation, so value and policy iteration do not apply directly.
Why randomize? A basic solution of (D) has at most as many positive entries as there are equality and binding inequality constraints, here , so one state can split its mass between two actions. In general, binding cost constraints allow randomization in at most states. Since no deterministic policy is optimal, no greedy step on any value function can produce this one directly.
The Lagrangian view explains what dynamic programming misses. Price each unit of cost at : the rewards in become for staying and for going, an ordinary MDP. From , (go, stay) is worth and staying in is worth 10, so the dual function is smallest at , where the two policies tie and , matching the primal optimum. At an unconstrained solver is indifferent between the two, and only the occupancy measure says how to mix them. Primal–dual RL algorithms run this idea with learned values (Constrained MDPs & Lagrangian Methods).
Lower the budget to 2. The best policy still stays in and leaves with some probability. What is it worth from ?
Show the answer
11.78
With the flow constraints give and , so the value is and the budget reads . Hence , the value is , and . For budgets up to 9 the value is : its slope is exactly , the price of one more unit of budget.
Approximate linear programming
With billions of states, (P) has billions of variables. Approximate linear programming (Schweitzer & Seidmann, 1985; de Farias & Van Roy, 2003) restricts the values to the span of features, with , and keeps every constraint:
The LP minimizes a weighted distance. Every feasible satisfies , hence , as in the exact LP. So , and the LP picks the feasible point closest to in the -weighted norm:
Shift the best fit until it is feasible. Let be within of , and add , which stays in the span. Using and :
The shifted fit is feasible and within of in the max norm, hence in the -weighted norm too, since sums to 1. The minimizer does at least as well:
Three refinements matter in practice.
- Which states to care about. The weights do not change the exact LP, but they shape the approximate one. For the policy greedy for a feasible , the same monotonicity argument gives , where is the discounted state distribution of started from : should resemble where the final policy spends its time.
- Better constants. With a positive Lyapunov function in the span instead of , the bound becomes , where and the norm weights errors by . For some queueing networks these terms stay bounded however many states there are.
- Too many constraints. Sampling constraints from a suitable distribution needs a number of samples that depends on rather than on (de Farias & Van Roy, 2004), and factored models let the constraints be written compactly and enforced exactly (Guestrin, Koller, Parr & Venkataraman, 2003).
Key takeaways
- is the unique solution of the primal LP for any positive weights: feasibility means , hence . The dual is attained by an optimal policy's occupancy measure, and complementary slackness confines optimal occupancies to greedy actions.
- Linear programming solves every finite MDP in polynomial time for any , yet MDPs are P-complete, and strong polynomiality is known only for a fixed (Ye's interior-point method, Howard's policy iteration, simplex with Dantzig's rule).
- Cost budgets are linear in occupancies, so constrained MDPs stay linear programs; their optimal policies randomize in up to one state per binding constraint, and the optimal multiplier is the price of the budget ( in the two-state example).
- The approximate LP restricts , minimizes the -weighted distance to over feasible points, and is within of the best max-norm fit when the constant function is a feature.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Why does every feasible point of the primal LP satisfy ?
- Because the objective pushes down
- Because the constraints say , and repeatedly applying the monotone operator converges to
- Because is the largest feasible point
- Because of strong duality
Show the answer
B. Because the constraints say , and repeatedly applying the monotone operator converges to
. Feasibility alone gives the inequality; the objective then picks the smallest feasible point, which is .
Why can policy iteration not solve the constrained two-state example as it stands?
- The optimal policy randomizes in , and greedy improvement only produces deterministic policies
- The example has too many states
- The discount is too close to 1
- Policy iteration cannot handle costs of any kind
Show the answer
A. The optimal policy randomizes in , and greedy improvement only produces deterministic policies
With one binding budget, the optimum mixes two actions in one state (), worth 14 against 10 for the best deterministic policy within budget. Lagrangian methods fix a price , solve the resulting MDP, and adjust ; at the solver ties, and the mixing weights come from the occupancy measure.
In the constrained example, the optimal value grows by per unit of extra budget, for budgets up to 9. What is ?
- The discount minus
- The probability of going from
- The optimal Lagrange multiplier of the budget constraint: the price of one more unit of budget
- The occupancy of
Show the answer
C. The optimal Lagrange multiplier of the budget constraint: the price of one more unit of budget
Sensitivity of an LP's optimal value to the right-hand side of a constraint is its optimal dual variable. Here it is , the price at which the unconstrained solver is indifferent between staying in and going to .
The bound for the approximate LP assumes what about the features?
- That they are orthonormal
- That there are at least as many features as states
- That they are all nonnegative
- That the constant function lies in their span (or, in the refined bound, a suitable Lyapunov function)
Show the answer
D. That the constant function lies in their span (or, in the refined bound, a suitable Lyapunov function)
The proof shifts the best fit by a constant until it satisfies every constraint, so the constant must be representable. With a Lyapunov function in the span, the same shifting argument gives a bound weighted by .
Further reading
- A. S. Manne, "Linear programming and sequential decisions," Management Science 6(3), 259–267 (1960).
- C. H. Papadimitriou & J. N. Tsitsiklis, "The complexity of Markov decision processes," Mathematics of Operations Research 12(3), 441–450 (1987).
- Y. Ye, "A new complexity result on solving the Markov decision problem," Mathematics of Operations Research 30(3), 733–749 (2005).
- E. Altman, Constrained Markov Decision Processes (Chapman & Hall/CRC, 1999).
- D. P. de Farias & B. Van Roy, "The linear programming approach to approximate dynamic programming," Operations Research 51(6), 850–865 (2003).