∇ProvenDecisions
Ctrl K

Maximum flow problem: a linear programming example, solved and checked

The maximum flow problem is a classic linear programming problem. Here it is solved by a real solver (HIGHS) and checked: every constraint, the dual, and the optimality certificate. Change the numbers below and solve your own.

Answer. The largest objective value is 15, at f = 15, f_sa = 10, f_sb = 5, f_at = 5, f_bt = 10, f_ab = 5. All 15 constraints are satisfied exactly. Exactly proven optimal.

Solve your own version free, no account needed

The problem

Arcs and capacities (units per hour): s->a 10, s->b 5, a->b 15, a->t 5, b->t 10. What is the maximum flow from s to t, in units per hour?

How the model was built

The objective as written from the problem, before the numbers are multiplied out:

The model

Each line has a plain-language note on the right.

make as large as possible: total flow from s to t (units per hour)
limit 1: left side must equal the right side
limit 2: left side must equal the right side
limit 3: left side must equal the right side
limit 4: left side must equal the right side
flow on arc s->a (units per hour) is at most 10
flow on arc s->b (units per hour) is at most 5
flow on arc a->b (units per hour) is at most 15
flow on arc a->t (units per hour) is at most 5
flow on arc b->t (units per hour) is at most 10
total flow from s to t (units per hour) cannot be negative
flow on arc s->a (units per hour) cannot be negative
flow on arc s->b (units per hour) cannot be negative
flow on arc a->b (units per hour) cannot be negative
flow on arc a->t (units per hour) cannot be negative
flow on arc b->t (units per hour) cannot be negative

In matrix form

With its numbers:

What is being decided

There are 6 decision variables.

VariableTypeMeaning
freal numbertotal flow from s to t (units per hour)
f_sareal numberflow on arc s->a (units per hour)
f_sbreal numberflow on arc s->b (units per hour)
f_atreal numberflow on arc a->t (units per hour)
f_btreal numberflow on arc b->t (units per hour)
f_abreal numberflow on arc a->b (units per hour)

Goal and limits

Maximize total flow from s to t (units per hour) subject to 15 constraints, of which 11 are simple bounds on a single variable.

Problem type

LP, complexity level 2: a linear program. Solved with HIGHS at the Medium solver tier.

The answer at a glance

The optimal value of each decision, as the solver returned it.

f15f_sa10f_sb5f_at5f_bt10f_ab5

Which constraints hold the answer in place

Binding (no slack left): constraints 1, 2, 3, 4, 5, 6, 8, 9 (see the table). Changing a binding constraint changes the answer; a slack one can move a little without effect.

#ConstraintValueLimitSlackBinding
1f = f_sa + f_sb15150yes
2f = f_at + f_bt15150yes
3f_sa = f_ab + f_at10100yes
4f_ab + f_sb = f_bt10100yes
5f_sa <= 1010100yes
6f_sb <= 5550yes
7f_ab <= 1551510
8f_at <= 5550yes
9f_bt <= 1010100yes
10f >= 015015
11f_sa >= 010010
12f_sb >= 0505
13f_ab >= 0505
14f_at >= 0505
15f_bt >= 010010

Why this is optimal

A proof you can check by hand. Multiply each constraint in the table by its weight and add them up: the result is an upper limit on the objective that holds for every plan meeting the constraints. Our answer reaches that limit exactly, so no plan does better. Every step was checked in exact fractions, not rounded decimals.

#ConstraintWeight
1f = f_sa + f_sb1
5f_sa ≤ 101
6f_sb ≤ 51

Algebraic model (low level)

Decision variables, objective and every constraint written out; this is exactly what the solver receives.

Standard form

As a linear program: minimize cᵀx subject to A x ≤ b (the inequality rows) and A_eq x = b_eq (the equations); a maximization is written as minimizing the negative.

Model code (cvxpy)

The same model in cvxpy, ready to run.

import cvxpy as cp

f = cp.Variable(name='f')  # total flow from s to t (units per hour)
f_sa = cp.Variable(name='f_sa')  # flow on arc s->a (units per hour)
f_sb = cp.Variable(name='f_sb')  # flow on arc s->b (units per hour)
f_at = cp.Variable(name='f_at')  # flow on arc a->t (units per hour)
f_bt = cp.Variable(name='f_bt')  # flow on arc b->t (units per hour)
f_ab = cp.Variable(name='f_ab')  # flow on arc a->b (units per hour)

objective = cp.Maximize(f)
constraints = [
    f == f_sa + f_sb,
    f == f_at + f_bt,
    f_sa == f_ab + f_at,
    f_ab + f_sb == f_bt,
    f_sa <= 10,
    f_sb <= 5,
    f_ab <= 15,
    f_at <= 5,
    f_bt <= 10,
    f >= 0,
    f_sa >= 0,
    f_sb >= 0,
    f_ab >= 0,
    f_at >= 0,
    f_bt >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='HIGHS')
print(problem.status, problem.value)
print('f =', f.value)
print('f_sa =', f_sa.value)
print('f_sb =', f_sb.value)
print('f_at =', f_at.value)
print('f_bt =', f_bt.value)
print('f_ab =', f_ab.value)

The dual problem

Every constraint of the original (primal) problem gets a price, and every primal variable becomes a constraint on those prices. Strong duality: primal and dual optima are equal (15).

Dual variablePricesValue
y1price of constraint 'f = f_sa + f_sb' (objective change per extra unit of its right-hand side)1
y2price of constraint 'f = f_at + f_bt' (objective change per extra unit of its right-hand side)0
y3price of constraint 'f_sa = f_ab + f_at' (objective change per extra unit of its right-hand side)0
y4price of constraint 'f_ab + f_sb = f_bt' (objective change per extra unit of its right-hand side)0
y5price of constraint 'f_sa <= 10' (objective change per extra unit of its right-hand side)1
y6price of constraint 'f_sb <= 5' (objective change per extra unit of its right-hand side)1
y7price of constraint 'f_ab <= 15' (objective change per extra unit of its right-hand side)0
y8price of constraint 'f_at <= 5' (objective change per extra unit of its right-hand side)0
y9price of constraint 'f_bt <= 10' (objective change per extra unit of its right-hand side)0

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 f
subject to
f = f_sa + f_sb
f = f_at + f_bt
f_sa = f_ab + f_at
f_sb + f_ab = f_bt
f_sa <= 10
f_sb <= 5
f_ab <= 15
f_at <= 5
f_bt <= 10
f, f_sa, f_sb, f_ab, f_at, f_bt >= 0
# f = total flow from s to t (units per hour)
# f_sa = flow on arc s->a (units per hour)
# f_sb = flow on arc s->b (units per hour)
# f_ab = flow on arc a->b (units per hour)
# f_at = flow on arc a->t (units per hour)
# f_bt = flow on arc b->t (units per hour)
# objective = total flow from s to t (units per hour)

Change the numbers and solve it

Checked: the app's answer matches the reference answer in our test set, which two solvers (HIGHS, CLARABEL) agree on. Built 2026-11-10.

Related examples

All 50 solved examples

Try ProvenDecisions free: type, photograph or say an optimization problem; every answer is checked by a solver.

What do you want to optimize?

Type the math, describe it in words, snap a photo or say it. ProvenDecisions builds the model, solves it, checks it and walks you through it.

One constraint per line, or separated by commas. Add integer: x, y or binary: z for whole-number decisions. LaTeX works too.

Try: