∇ProvenDecisions
Ctrl K

Largest circle inside a polygon: a linear programming example, solved and checked

The largest circle inside a polygon 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. You asked for: radius r of the largest inscribed circle. The largest objective value is 0.87868, at a = 0.87868, r = 0.87868, b = 0.87868. All 6 constraints are satisfied (largest violation 4e-16, within the solver's tolerance). Optimal, numerically checked.

Solve your own version free, no account needed

The problem

Find the largest circle that fits inside the region 0 <= x <= 2, 0 <= y <= 2, x + y <= 3. Report its radius.

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 this as large as possible
limit 1: left side must reach at least 0
limit 2: left side cannot exceed 2
limit 3: left side must reach at least 0
limit 4: left side cannot exceed 2
limit 5: left side cannot exceed 3
radius of circle cannot be negative

In matrix form

With its numbers:

What is being decided

There are 3 decision variables.

VariableTypeMeaning
areal numberx-coordinate of circle center
rreal numberradius of circle
breal numbery-coordinate of circle center

Goal and limits

Maximize the objective subject to 6 constraints, of which 1 are simple bounds on a single variable.

Problem type

LP, complexity level 1: a small 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.

a0.87868r0.87868b0.87868

Which constraints hold the answer in place

Binding (no slack left): (1) a - r >= 0; (3) b - r >= 0; (5) a + b + 1.414213562*r <= 3. Changing a binding constraint changes the answer; a slack one can move a little without effect.

#ConstraintValueLimitSlackBinding
1a - r >= 0000yes
2a + r <= 21.7573620.242641
3b - r >= 0000yes
4b + r <= 21.7573620.242641
5a + b + 1.414213562*r <= 3330yes
6r >= 00.8786800.87868

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

a = cp.Variable(name='a')  # x-coordinate of circle center
r = cp.Variable(name='r')  # radius of circle
b = cp.Variable(name='b')  # y-coordinate of circle center

objective = cp.Maximize(r)
constraints = [
    a - r >= 0,
    a + r <= 2,
    b - r >= 0,
    b + r <= 2,
    a + b + 1.4142135623730951*r <= 3,
    r >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='HIGHS')
print(problem.status, problem.value)
print('a =', a.value)
print('r =', r.value)
print('b =', b.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 (0.87868).

Dual variablePricesValue
y1price of constraint 'a - r >= 0' (objective change per extra unit of its right-hand side)-0.292893
y2price of constraint 'a + r <= 2' (objective change per extra unit of its right-hand side)0
y3price of constraint 'b - r >= 0' (objective change per extra unit of its right-hand side)-0.292893
y4price of constraint 'b + r <= 2' (objective change per extra unit of its right-hand side)0
y5price of constraint 'a + b + 1.414213562*r <= 3' (objective change per extra unit of its right-hand side)0.292893

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 r
subject to
a - r >= 0
a + r <= 2
b - r >= 0
b + r <= 2
a + b + 1.4142135623730951 * r <= 3
r >= 0
# a = x-coordinate of circle center
# b = y-coordinate of circle center
# r = radius of circle
# asked: radius r of the largest inscribed circle

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: