TL;DR
A constrained Markov decision process is a decision problem over time, the kind studied in reinforcement learning, with two scores instead of one. The agent earns a reward, and it also incurs a cost, and the cost must stay under a fixed budget. The goal is the best reward among all behaviours that respect the budget. Plain reward maximization can pick a behaviour that is very profitable and very expensive, and the constraint is what rules that behaviour out.
Builds on: Markov Decision Process, Occupancy Measure, Lagrangian Duality · Leads to: safe learning in robotics
Where it's used
A warehouse robot with a battery. A robot picks orders for as many minutes as its battery allows. The reward is orders completed, and the cost is energy drawn from the battery. The designer wants the highest order rate with energy use kept under a limit that protects the battery's life. A plain MDP would push the robot to run its fastest motors all the time, which breaks the energy limit.
A data-centre cooling controller. Each interval the controller picks a fan mode. Reward is computing throughput, and cost is power draw. The facility has a contracted average power limit, and the question is how much throughput is available while meeting it. The worked example near the end uses numbers of this kind.
Safety in automated driving or medicine dosing. Here the cost is a safety signal, such as the chance of a near-collision or a dose above a safe level. The policy is allowed to be aggressive on reward only as long as the expected safety cost stays under a threshold. Researchers use constrained formulations to state that threshold directly instead of folding it into a single reward with an arbitrary weight.
How it works
Take one tiny instance. There is one decision. The agent chooses action A or action B, and the episode ends. Action A gives reward 10 and cost 4. Action B gives reward 4 and cost 0. The budget on expected cost is 2. Let be the probability of choosing A. Since the episode ends after one step, there is nothing to discount, so the discount factor is 0.
- Describe the behaviour. A behaviour is a Policy (Reinforcement Learning), and here it is a single number: the share of A. Check: means always B, and means always A.
- Compute the two expected scores. The expected reward is . Expected cost is . Check: at reward is 10 and cost is 4, and at reward is 4 and cost is 0.
- Apply the budget. Feasible behaviours satisfy , so . Check: gives cost 2, which is exactly the budget, and gives cost 2.4, which breaks it.
- Pick the best feasible behaviour. Reward rises with , so the best choice is the largest feasible value, . Its reward is . Check: the unconstrained best, , earns 10 but costs 4, so it is ruled out.
- Price the budget. Subtract a penalty from the reward for each unit of cost above the budget, the same idea as a Lagrange multiplier. Use a price . The penalized score is . At the score is for every , because the dependence on cancels. Check: .
Step 5 is the important idea. The budget can be handled by a price. Once the price is right, the choice between A and B no longer changes the score, and that common score, 7, is exactly the best feasible reward from step 4.
flowchart LR A["Maximize reward subject to cost at most budget"] --> B["Add penalty lambda times cost above budget"] B --> C["For a fixed lambda, pick the best behaviour"] C --> D["Choose the lambda that gives the lowest score"] D --> E["That score is the best feasible reward"]
The plot shows the two expected scores for every share . The budget line cuts the feasible range.
- reward
- cost
- budget
The math
Here is the expected value when the agent follows from its start state. The symbol is the discount factor, which weights later steps less. In the tiny instance , so only the first step counts.
Step 1 in symbols: the behaviour
A policy gives the probability of action in state . In the tiny instance there is one state and two actions, so the policy is the single number .
Step 2 in symbols: the two scores
The expected scores are linear in the policy's probabilities. For the tiny instance:
A useful fact follows from the discounted sum. Write the normalized occupancy , which is the discounted share of time spent in each pair. Then both scores are weighted sums over :
This is why the problem is simpler than it looks. In the occupancy variables the constraint and the objective are both linear, so the problem becomes a linear program over a convex set of occupancy measures, and that set is described by the flow equations of the MDP.
Step 3 in symbols: the budget
The feasible set is . In the tiny instance, gives .
Step 4 in symbols: the best feasible choice
This is a constrained optimization problem. The best feasible reward is
For the tiny instance, .
Step 5 in symbols: the price of the budget
The Lagrangian is
and the dual function is . Two facts follow directly. For any feasible and any , , so each is an upper bound on . Minimizing over gives the tightest such bound, . This is the dual problem from Lagrangian Duality.
For the tiny instance, , so
The minimum is at , where . There is no gap, which is strong duality. The optimal behaviour is any mixture that makes the -term vanish, and the feasibility constraint then picks .
Why the answer can be a mixture
Without a constraint, an MDP has an optimal deterministic policy. With a constraint, the best point often lies on the edge of the feasible set, and that edge can only be reached by randomizing. The tiny instance shows this: is a 50/50 mixture of A and B, and neither pure choice is feasible-and-best.
Worked examples
Use the same two actions, A with reward 10 and cost 4, and B with reward 4 and cost 0. Change the budget to .
- Feasibility: gives . Every behaviour is feasible.
- Reward is , which rises with , so the best choice is .
- The best reward is , and the cost is , exactly the budget.
- Dual check: . For the -term is non-negative, so and . For , . The minimum value is 10, reached for every in , and the smallest such price is .
Interpretation: when the budget is loose, the price is zero and the constraint does nothing. A constrained problem with a slack constraint is the same as an unconstrained MDP.
Use one state with actions A (reward 10, cost 4) and B (reward 4, cost 0), discount , and budget . A policy picks A with probability at every step.
- The discount sum for a constant per-step reward is .
- Expected reward per step is , so .
- Expected cost per step is , so .
- Budget: , so .
- Reward is increasing in , so the best choice is , and .
- Dual: .
- For the best is 0, so . For the best is 1, so .
- The two lines meet at , where both equal . Check: and .
- The primal optimum is 14 and the dual minimum is 14. There is no gap, and the optimal policy is .
Interpretation: discounting doubles the total cost as well as the total reward, so the budget of 4 caps at 0.5 here. The price is the reward traded away for each unit of discounted cost.
A data-centre controller picks one of two fan modes at each interval. High mode gives throughput 8 and draws power 6. Low mode gives throughput 3 and draws power 1. The site must keep average power at or below 3. Treat each interval as a separate decision, so , and let be the share of intervals in High mode.
- Throughput is .
- Power is .
- Power limit: , so .
- Best throughput is at : .
- Check the power at that point: , exactly the limit.
- Price the limit with : the penalized score is .
- At the -term vanishes, so every mix scores . That matches the primal best of 5.
- Interpretation: the controller runs High mode 40 percent of the time. Pure High mode would give more throughput but breaks the power limit, so the best policy is a mixture.
Try it: the site raises its power limit from 3 to 4. What is the best average throughput? Answer: the power constraint becomes , so . Throughput is . Check the power: , exactly the new limit.
Common mistakes and tradeoffs
It is tempting to think that a constraint is just a large penalty in the reward. In fact a penalty with a fixed weight can give the wrong answer, because the right weight depends on the budget. The Lagrange multiplier is the weight that makes the penalty exactly strong enough to satisfy the budget, and finding it is part of solving the problem. In the tiny instance a weight of 1 would not be right, and the answer is only reached at .
It is tempting to think that the optimal policy is always deterministic, as in an ordinary MDP. In fact a constrained problem can need a randomized policy, because the best feasible point can sit on the boundary between two pure policies. The cooling example needs a 40/60 mix of High and Low, and no pure policy achieves the best throughput under the power limit.
It is tempting to think that the constraint holds in every single step. In fact a CMDP constrains the expected discounted total, or the long-run average, of the cost. An individual step can exceed the budget as long as the expected sum stays under it. Designers who need a hard limit on each step must use a different formulation.
When to use it: use a CMDP when there are two quantities to balance, such as reward and safety, throughput and power, or accuracy and compute, and the second one has a hard limit. When not to use it: if the cost can be folded into the reward with a weight that is clearly right, a plain MDP is simpler. Alternatives include reward shaping, where a penalty is added to the reward directly, and safety filters that override the policy when a state is unsafe. Those are simpler but do not give a guaranteed budget.
History
The idea of making decisions step by step under uncertainty began with dynamic programming. Markov decision processes were set out in the 1950s, with Richard Bellman's work on recursive optimal choice as the basis. Lagrange multipliers for constrained optimization are much older, from the work of Joseph-Louis Lagrange in the late 1700s.
Constraints were added to the Markov setting as a separate line of research. Eitan Altman's book Constrained Markov Decision Processes (1999) set out the linear-programming view in the occupancy variables and the duality results that make the problem tractable. The idea caught on in the 2010s, when reinforcement learning became practical for control tasks where safety mattered, and researchers needed a way to state a safety limit without tuning a reward weight by trial and error.
Recap
- An MDP has one score, reward. A constrained MDP adds a cost and a budget that the cost must respect.
- The occupancy measure turns both scores into weighted sums, so the problem becomes linear in the occupancy variables.
- The Lagrangian turns the budget into a price , and minimizing over gives a bound that is tight under strong duality.
- The best constrained policy can be a mixture of pure policies, because the answer often lies on the edge of the feasible set.
What to read next: Safe Learning in Robotics builds on this framework to study safety in control systems.