Simple Algorithm
Reinforcement Learning · Fixed Point · 28 min

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 V⋆V^\star 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 2/(1−γ)2/(1-\gamma) 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 μ(s)>0\mu(s)>0, for example a distribution of starting states that gives every state some mass:

(P)min⁡V∈RS ∑sμ(s)V(s)s.t.  V(s)≥r(s,a)+γ∑s′P(s′∣s,a) V(s′)∀(s,a)(D)max⁡x≥0 ∑s,ax(s,a) r(s,a)s.t.  ∑ax(s′,a)−γ∑s,aP(s′∣s,a) x(s,a)=μ(s′)∀s′\begin{aligned}\text{(P)}\quad&\min_{V\in\R^S}\ \sum_s\mu(s)V(s)&&\text{s.t. }\ V(s)\ge r(s,a)+\gamma\sum_{s'}P(s'\mid s,a)\,V(s')\quad\forall(s,a)\\[2pt]\text{(D)}\quad&\max_{x\ge0}\ \sum_{s,a}x(s,a)\,r(s,a)&&\text{s.t. }\ \sum_ax(s',a)-\gamma\sum_{s,a}P(s'\mid s,a)\,x(s,a)=\mu(s')\quad\forall s'\end{aligned}
(P) has SS variables and SASA constraints; (D) has SASA variables and SS equality constraints. The feasible points of (D) are the unnormalized discounted occupancy measures x(s,a)=∑tγtPr⁡(St=s,At=a)x(s,a)=\sum_t\gamma^t\Pr(S_t=s,A_t=a) of stationary policies started from μ\mu.
DerivationProof
  1. V≥T⋆V≥(T⋆)2V≥⋯⟶V⋆V\ge\mathcal T^\star V\ge(\mathcal T^\star)^2V\ge\cdots\longrightarrow V^\star

    (i) Feasible means superharmonic. The constraints say V≥T⋆VV\ge\mathcal T^\star V. The operator is monotone, so applying it again keeps the inequality, and the iterates converge to V⋆V^\star:

  2. ∑sμ(s)V(s)−∑sμ(s)V⋆(s)=∑sμ(s)(V(s)−V⋆(s))>0\sum_s\mu(s)V(s)-\sum_s\mu(s)V^\star(s)=\sum_s\mu(s)\big(V(s)-V^\star(s)\big)>0

    (ii) Optimal and unique. V⋆=T⋆V⋆V^\star=\mathcal T^\star V^\star is feasible, and any other feasible VV is at least V⋆V^\star everywhere and above it somewhere, so with positive weights its objective is strictly larger.

  3. ∑sμ(s)V(s)−∑s,ax(s,a) r(s,a)=∑s,ax(s,a)[V(s)−r(s,a)−γ∑s′P(s′∣s,a)V(s′)] ≥ 0\sum_s\mu(s)V(s)-\sum_{s,a}x(s,a)\,r(s,a)=\sum_{s,a}x(s,a)\Big[V(s)-r(s,a)-\gamma\sum_{s'}P(s'\mid s,a)V(s')\Big]\ \ge\ 0

    (iii) Weak duality, then equality. For feasible VV and xx, multiply each primal constraint by x(s,a)≥0x(s,a)\ge0, sum, and use the dual constraints to collect the terms in VV. The gap is a sum of nonnegative terms:

  4. x(s,a)>0 ⟹ V⋆(s)=r(s,a)+γ∑s′P(s′∣s,a)V⋆(s′)=Q⋆(s,a)x(s,a)>0\ \Longrightarrow\ V^\star(s)=r(s,a)+\gamma\sum_{s'}P(s'\mid s,a)V^\star(s')=Q^\star(s,a)

    The occupancy measure of an optimal policy is dual-feasible, and its objective is its expected discounted return from μ\mu, which equals ∑sμ(s)V⋆(s)\sum_s\mu(s)V^\star(s): the gap closes, so both are optimal. (iv) At optimal xx and V⋆V^\star the gap is zero, so every term vanishes, and x(s,a)>0x(s,a)>0 forces the bracket to zero (complementary slackness):

Check your understanding

You solve (P) with μ(s0)=1\mu(s_0)=1 for one start state and μ(s)=0\mu(s)=0 for every other state. What can go wrong?

  1. The linear program becomes infeasible
  2. Its solution can exceed V⋆V^\star in states that optimal play from s0s_0 never reaches, so a policy read off its tight constraints can be wrong
  3. Its solution can fall below V⋆V^\star in the states without weight
  4. Nothing: the solution is still V⋆V^\star everywhere
Show the answer

B. Its solution can exceed V⋆V^\star in states that optimal play from s0s_0 never reaches, so a policy read off its tight constraints can be wrong

Feasibility still forces V≥V⋆V\ge V^\star, but only V(s0)V(s_0) and the values its optimal actions lead to are pushed down to V⋆V^\star. Elsewhere any feasible value at least V⋆V^\star is optimal for the LP. An inflated value can make a non-optimal action's constraint tight at s0s_0, 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 BB 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 γ<1\gamma<1, which neither value iteration nor policy iteration can guarantee when γ\gamma is part of the input.

MethodPolynomial for every γ\gamma?Strongly polynomial for a fixed γ\gamma?
Value iterationNo: its sweeps grow like 1/(1−γ)1/(1-\gamma), exponential in the bits of γ\gammaNo (Feinberg & Huang, 2014); polynomial in SS, AA, BB (Tseng, 1990)
Howard's policy iterationNo: exponential examples as γ→1\gamma\to1 (Hollanders, Delvenne & Jungers, 2012)Yes (Ye, 2011; Scherrer, 2016)
Simplex on (D) with Dantzig's rule, a form of simple policy iterationNo 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)YesYes, for Ye's combinatorial interior-point method (Ye, 2005), the first strongly polynomial algorithm for a fixed γ\gamma
Whether any algorithm is strongly polynomial when γ\gamma is part of the input is open; it is a special case of strongly polynomial linear programming (How Fast Is Policy Iteration?).

In practice, generic LP solvers are seldom the fastest way to solve a plain MDP: (P) has SASA 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 ci(s,a)c_i(s,a) and budgets CiC_i 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 2+1=32+1=3, so one state can split its mass between two actions. In general, kk binding cost constraints allow randomization in at most kk 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 λ\lambda: the rewards in s2s_2 become 2−λ2-\lambda for staying and −λ-\lambda for going, an ordinary MDP. From s1s_1, (go, stay) is worth 9(2−λ)9(2-\lambda) and staying in s1s_1 is worth 10, so the dual function d(λ)=max⁡π(Jr(π)−λJc(π))+4.5λd(\lambda)=\max_\pi\big(J_r(\pi)-\lambda J_c(\pi)\big)+4.5\lambda is smallest at λ⋆=8/9\lambda^\star=8/9, where the two policies tie and d(λ⋆)=10+4=14d(\lambda^\star)=10+4=14, matching the primal optimum. At λ⋆\lambda^\star 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).

Predict before you look

Lower the budget to 2. The best policy still stays in s2s_2 and leaves s1s_1 with some probability. What is it worth from s1s_1?

Show the answer

11.78

With x2g=0x_{2g}=0 the flow constraints give x2s=9x1gx_{2s}=9x_{1g} and x1s=10(1−x1g)x_{1s}=10(1-x_{1g}), so the value is 10+8x1g10+8x_{1g} and the budget reads 9x1g≤29x_{1g}\le2. Hence x1g=2/9x_{1g}=2/9, the value is 10+16/9=106/9≈11.7810+16/9=106/9\approx11.78, and π(go∣s1)=1/36\pi(\text{go}\mid s_1)=1/36. For budgets up to 9 the value is 10+89C10+\frac89C: its slope is exactly λ⋆=8/9\lambda^\star=8/9, 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 KK features, V=ΦwV=\Phi w with Φ∈RS×K\Phi\in\R^{S\times K}, and keeps every constraint:

min⁡w∈RK c⊤Φws.t.Φw ≥ TaΦwfor every action a\min_{w\in\R^K}\ c^\top\Phi w\qquad\text{s.t.}\quad\Phi w\ \ge\ \mathcal T^a\Phi w\quad\text{for every action }a
Here (TaV)(s)=r(s,a)+γ∑s′P(s′∣s,a)V(s′)(\mathcal T^aV)(s)=r(s,a)+\gamma\sum_{s'}P(s'\mid s,a)V(s'), and cc, a probability distribution over states, holds the state-relevance weights. There are only KK variables, but still SASA constraints.
DerivationProof
  1. w~∈arg min⁡w feasible ∥Φw−V⋆∥1,c\tilde w\in\argmin_{w\ \text{feasible}}\ \norm{\Phi w-V^\star}_{1,c}

    The LP minimizes a weighted distance. Every feasible Φw\Phi w satisfies Φw≥T⋆Φw\Phi w\ge\mathcal T^\star\Phi w, hence Φw≥V⋆\Phi w\ge V^\star, as in the exact LP. So c⊤Φw=c⊤V⋆+∥Φw−V⋆∥1,cc^\top\Phi w=c^\top V^\star+\norm{\Phi w-V^\star}_{1,c}, and the LP picks the feasible point closest to V⋆V^\star in the cc-weighted L1L^1 norm:

  2. T⋆(Φw⋆+k1)≤Φw⋆+((1+γ)ε+γk)1≤Φw⋆+k1whenk=(1+γ) ε1−γ\mathcal T^\star(\Phi w^\star+k\mathbf 1)\le\Phi w^\star+\big((1+\gamma)\varepsilon+\gamma k\big)\mathbf 1\le\Phi w^\star+k\mathbf 1\quad\text{when}\quad k=\frac{(1+\gamma)\,\varepsilon}{1-\gamma}

    Shift the best fit until it is feasible. Let Φw⋆\Phi w^\star be within ε=min⁡w∥V⋆−Φw∥∞\varepsilon=\min_w\norm{V^\star-\Phi w}_\infty of V⋆V^\star, and add k1k\mathbf 1, which stays in the span. Using T⋆(V+k1)=T⋆V+γk1\mathcal T^\star(V+k\mathbf 1)=\mathcal T^\star V+\gamma k\mathbf 1 and T⋆Φw⋆≤V⋆+γε1≤Φw⋆+(1+γ)ε1\mathcal T^\star\Phi w^\star\le V^\star+\gamma\varepsilon\mathbf 1\le\Phi w^\star+(1+\gamma)\varepsilon\mathbf 1:

  3. ∥Φw~−V⋆∥1,c≤∥Φw⋆+k1−V⋆∥1,c≤2ε1−γ\norm{\Phi\tilde w-V^\star}_{1,c}\le\norm{\Phi w^\star+k\mathbf 1-V^\star}_{1,c}\le\frac{2\varepsilon}{1-\gamma}

    The shifted fit is feasible and within ε+k=2ε1−γ\varepsilon+k=\frac{2\varepsilon}{1-\gamma} of V⋆V^\star in the max norm, hence in the cc-weighted norm too, since cc sums to 1. The minimizer does at least as well:

Three refinements matter in practice.

  • Which states to care about. The weights cc do not change the exact LP, but they shape the approximate one. For the policy π\pi greedy for a feasible Φw\Phi w, the same monotonicity argument gives ∥V⋆−Vπ∥1,ν≤11−γ∥Φw−V⋆∥1,μπ,ν\norm{V^\star-V^\pi}_{1,\nu}\le\frac{1}{1-\gamma}\norm{\Phi w-V^\star}_{1,\mu_{\pi,\nu}}, where μπ,ν=(1−γ)ν⊤(I−γPπ)−1\mu_{\pi,\nu}=(1-\gamma)\nu^\top(I-\gamma P^\pi)^{-1} is the discounted state distribution of π\pi started from ν\nu: cc should resemble where the final policy spends its time.
  • Better constants. With a positive Lyapunov function Ψ\Psi in the span instead of 1\mathbf 1, the bound becomes 2 c⊤Ψ1−βΨmin⁡w∥V⋆−Φw∥∞,1/Ψ\frac{2\,c^\top\Psi}{1-\beta_\Psi}\min_w\norm{V^\star-\Phi w}_{\infty,1/\Psi}, where βΨ=γmax⁡smax⁡a∑s′P(s′∣s,a)Ψ(s′)/Ψ(s)<1\beta_\Psi=\gamma\max_s\max_a\sum_{s'}P(s'\mid s,a)\Psi(s')/\Psi(s)<1 and the norm weights errors by 1/Ψ1/\Psi. 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 KK rather than on SS (de Farias & Van Roy, 2004), and factored models let the constraints be written compactly and enforced exactly (Guestrin, Koller, Parr & Venkataraman, 2003).

Key takeaways

  • V⋆V^\star is the unique solution of the primal LP for any positive weights: feasibility means V≥T⋆VV\ge\mathcal T^\star V, hence V≥V⋆V\ge V^\star. 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 γ\gamma, yet MDPs are P-complete, and strong polynomiality is known only for a fixed γ\gamma (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 (8/98/9 in the two-state example).
  • The approximate LP restricts V=ΦwV=\Phi w, minimizes the cc-weighted distance to V⋆V^\star over feasible points, and is within 21−γ\frac{2}{1-\gamma} 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.

Question 1

Why does every feasible point of the primal LP satisfy V≥V⋆V\ge V^\star?

  1. Because the objective pushes VV down
  2. Because the constraints say V≥T⋆VV\ge\mathcal T^\star V, and repeatedly applying the monotone operator T⋆\mathcal T^\star converges to V⋆V^\star
  3. Because V⋆V^\star is the largest feasible point
  4. Because of strong duality
Show the answer

B. Because the constraints say V≥T⋆VV\ge\mathcal T^\star V, and repeatedly applying the monotone operator T⋆\mathcal T^\star converges to V⋆V^\star

V≥T⋆V≥(T⋆)2V≥⋯→V⋆V\ge\mathcal T^\star V\ge(\mathcal T^\star)^2V\ge\cdots\to V^\star. Feasibility alone gives the inequality; the objective then picks the smallest feasible point, which is V⋆V^\star.

Question 2

Why can policy iteration not solve the constrained two-state example as it stands?

  1. The optimal policy randomizes in s1s_1, and greedy improvement only produces deterministic policies
  2. The example has too many states
  3. The discount is too close to 1
  4. Policy iteration cannot handle costs of any kind
Show the answer

A. The optimal policy randomizes in s1s_1, and greedy improvement only produces deterministic policies

With one binding budget, the optimum mixes two actions in one state (π(go∣s1)=1/11\pi(\text{go}\mid s_1)=1/11), worth 14 against 10 for the best deterministic policy within budget. Lagrangian methods fix a price λ\lambda, solve the resulting MDP, and adjust λ\lambda; at λ⋆\lambda^\star the solver ties, and the mixing weights come from the occupancy measure.

Question 3

In the constrained example, the optimal value grows by 8/98/9 per unit of extra budget, for budgets up to 9. What is 8/98/9?

  1. The discount minus 1/901/90
  2. The probability of going from s1s_1
  3. The optimal Lagrange multiplier of the budget constraint: the price of one more unit of budget
  4. The occupancy of s2s_2
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 λ⋆=8/9\lambda^\star=8/9, the price at which the unconstrained solver is indifferent between staying in s1s_1 and going to s2s_2.

Question 4

The bound ∥V⋆−Φw~∥1,c≤21−γmin⁡w∥V⋆−Φw∥∞\norm{V^\star-\Phi\tilde w}_{1,c}\le\frac{2}{1-\gamma}\min_w\norm{V^\star-\Phi w}_\infty for the approximate LP assumes what about the features?

  1. That they are orthonormal
  2. That there are at least as many features as states
  3. That they are all nonnegative
  4. 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 Ψ\Psi in the span, the same shifting argument gives a bound weighted by 1/Ψ1/\Psi.

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).