Water-filling power allocation: a convex optimization example, solved and checked
The water-filling power allocation is a classic convex optimization problem. Here it is solved by a real solver (CLARABEL) and checked: every constraint, and the optimality certificate. Change the numbers below and solve your own.
Solve your own version free, no account needed
The problem
Split 1 watt of transmit power over four channels with noise levels of 0.2, 0.5, 0.9 and 1.5 watts to maximize the total capacity, the sum of log(1 + power_i / noise_i), with each power in watts. How much power goes to each channel?
How the model was built
The objective as written from the problem, before the numbers are multiplied out:
- The noise levels are fixed facts about each channel; the decisions are only the four powers pi (in watts), which add up to 1 watt.
- Channel i carries log(1 + pi ÷ ni): the more power compared with its noise, the more it carries, with diminishing returns (each extra watt adds less).
- So an extra watt helps most on a quiet channel: power goes to the quietest channels first, up to a common water level, and a channel noisier than that level gets nothing.
- p3 and p4 come back as tiny numbers such as 0.00000004: they are 0 up to the solver's tolerance.
The model
Each line has a plain-language note on the right.
| make as large as possible: total capacity, sum of log(1 + power_i / noise_i) (nats) | |
| limit 1: left side cannot exceed 1 | |
| power allocated to channel 1 with noise 0.2 (watts) cannot be negative | |
| power allocated to channel 2 with noise 0.5 (watts) cannot be negative | |
| power allocated to channel 3 with noise 0.9 (watts) cannot be negative | |
| power allocated to channel 4 with noise 1.5 (watts) cannot be negative |
What is being decided
There are 4 decision variables.
| Variable | Type | Meaning |
|---|---|---|
| p1 | real number | power allocated to channel 1 with noise 0.2 (watts) |
| p2 | real number | power allocated to channel 2 with noise 0.5 (watts) |
| p3 | real number | power allocated to channel 3 with noise 0.9 (watts) |
| p4 | real number | power allocated to channel 4 with noise 1.5 (watts) |
Goal and limits
Maximize total capacity, sum of log(1 + power_i / noise_i) (nats) subject to 5 constraints, of which 4 are simple bounds on a single variable.
Problem type
Conic (convex), complexity level 4: convex nonlinear functions such as log, exp, square roots or powers. Solved with CLARABEL at the Medium solver tier.
The answer at a glance
The optimal value of each decision, as the solver returned it.
Which constraints hold the answer in place
Binding (no slack left): (1) p1 + p2 + p3 + p4 <= 1; (4) p3 >= 0; (5) p4 >= 0. Changing a binding constraint changes the answer; a slack one can move a little without effect.
| # | Constraint | Value | Limit | Slack | Binding |
|---|---|---|---|---|---|
| 1 | p1 + p2 + p3 + p4 <= 1 | 1 | 1 | 2.52302e-09 | yes |
| 2 | p1 >= 0 | 0.649973 | 0 | 0.649973 | |
| 3 | p2 >= 0 | 0.350027 | 0 | 0.350027 | |
| 4 | p3 >= 0 | 5.77313e-08 | 0 | 5.77313e-08 | yes |
| 5 | p4 >= 0 | 3.28869e-09 | 0 | 3.28869e-09 | yes |
Algebraic model (low level)
Decision variables, objective and every constraint written out; this is exactly what the solver receives.
Model code (cvxpy)
The same model in cvxpy, ready to run.
import cvxpy as cp
p1 = cp.Variable(name='p1') # power allocated to channel 1 with noise 0.2 (watts)
p2 = cp.Variable(name='p2') # power allocated to channel 2 with noise 0.5 (watts)
p3 = cp.Variable(name='p3') # power allocated to channel 3 with noise 0.9 (watts)
p4 = cp.Variable(name='p4') # power allocated to channel 4 with noise 1.5 (watts)
objective = cp.Maximize(cp.log(5.0*p1 + 1) + cp.log(2.0*p2 + 1) + cp.log(1.11111111111111*p3 + 1) + cp.log(0.666666666666667*p4 + 1))
constraints = [
p1 + p2 + p3 + p4 <= 1,
p1 >= 0,
p2 >= 0,
p3 >= 0,
p4 >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='CLARABEL')
print(problem.status, problem.value)
print('p1 =', p1.value)
print('p2 =', p2.value)
print('p3 =', p3.value)
print('p4 =', p4.value)Solve your own
This is the model as the app reads it. Change any number and solve it in the free box on the front page (no account needed).
maximize log(1 + p1/0.2) + log(1 + p2/0.5) + log(1 + p3/0.9) + log(1 + p4/1.5)
subject to
p1 + p2 + p3 + p4 <= 1
p1, p2, p3, p4 >= 0
# p1 = power allocated to channel 1 with noise 0.2 (watts)
# p2 = power allocated to channel 2 with noise 0.5 (watts)
# p3 = power allocated to channel 3 with noise 0.9 (watts)
# p4 = power allocated to channel 4 with noise 1.5 (watts)
# objective = total capacity, sum of log(1 + power_i / noise_i) (nats)
# asked: the power allocated to each channel (p1, p2, p3, p4)Checked: the app's answer matches the reference answer in our test set, which two solvers (CLARABEL, SCS) agree on. Built 2026-11-10.
Related examples
Try ProvenDecisions free: type, photograph or say an optimization problem; every answer is checked by a solver.