Math & ModelingAdvancedExperiment simulation~25 min

Optimization and Constraint Modeling

Businesses want the most profit from limited materials, engineers want the strongest part for the least metal, and delivery companies want the shortest routes. Optimization is the mathematics of making the best choice when you cannot have everything. Build a linear programming problem by dragging its constraints, watch the objective line find the best corner, see which limits really matter, use calculus to design a fence, a box and a can, and then plan production yourself.

Goal
3
2
Edit constraint
Inequality
1
1
4

Or drag a constraint line on the graph to move it.

1
—
—
—
—
—
—
—
—
—
—
—
—

How to use this simulator

  1. Choose an activity. In the linear programming lab, try the example problems, then drag a constraint line on the graph to move it, or pick a constraint and change its coefficients, inequality and limit.
  2. Press Start to sweep the objective’s level line across the region, or Check next corner to test the corners one at a time. Tap anywhere on the graph to test a single point.
  3. In sensitivity, pick a constraint and change its limit: the graph shows how the best value responds and the table shows slack and binding constraints.
  4. In geometric optimization, change the dimension with the slider or by dragging on the graph; Start runs a step-by-step hill-climbing search.
  5. In the resource-allocation challenge, choose whole-number amounts (sliders or tap the graph), press Check my plan, then compare with the best plan.

Learning objectives

  • Identify the decision variables, objective function and constraints of an optimization problem.
  • Draw the feasible region of a two-variable linear program and find its optimum by the corner-point method.
  • Recognize infeasible problems, unbounded problems and problems with multiple optimal solutions.
  • Explain slack, binding constraints and shadow prices, and how the solution responds to changes.
  • Use derivatives to solve geometric optimization problems with a constraint.
  • Explain why whole-number problems cannot always be solved by rounding.

What optimization is

Every optimization problem has three parts. The decision variables are the things you can choose, such as how many loaves to bake. The objective function is what you want to make as large or as small as possible, such as profit or cost. The constraints are the limits the choice must respect, such as the flour in stock. A choice that satisfies every constraint is feasible; the best feasible choice is theoptimal solution.

Linear programming

When the objective and every constraint are linear (no powers or products of variables), the problem is alinear program. With two variables it can be solved on a graph:

Maximize Z = 3x + 2y subject to x + y ≤ 4, x ≤ 2, y ≤ 3, x ≥ 0, y ≥ 0.

Each inequality allows the points on one side of a line. The overlap of all the allowed sides is thefeasible region, a polygon. The points where Z takes one value, such as 3x + 2y = 6, form a straightlevel line, and all level lines are parallel. Sliding the level line in the direction that increases Z, the last position that still touches the region gives the maximum: here Z = 10 at the corner (2, 2).

Why the answer is at a corner

Because the level lines are straight and parallel, the last point of a polygon they touch is a corner, or a whole edge if they are parallel to it. This gives the corner-point method: list the corners (intersections of constraint lines that satisfy every constraint), evaluate Z at each, and choose the best.

CornerZ = 3x + 2y
(0, 0)0
(2, 0)6
(2, 2)10 (maximum)
(1, 3)9
(0, 3)6

Real problems have thousands of variables, so computers use the simplex method, which walks from corner to neighbouring corner, always improving, or interior-point methods that cut through the middle of the region.

Infeasible, unbounded and multiple optima

  • Infeasible: the constraints contradict each other, so the feasible region is empty. For example x + y ≥ 6 cannot hold if x ≤ 2 and y ≤ 3.
  • Unbounded: the region stretches forever in a direction in which the objective keeps improving, so there is no best value. An open region is not enough on its own: minimizing on the same region may still have an answer.
  • Multiple optima: the level lines are parallel to an edge on the best side of the region, so every point of that edge is optimal.

Binding constraints and sensitivity

At the optimum, a constraint is binding if it holds with equality: the resource is used up. The unused amount is the slack. In the textbook example, x + y ≤ 4 and x ≤ 2 are binding at (2, 2), while y ≤ 3 has slack 1. Raising a non-binding limit changes nothing; raising a binding limit can improve the result. The change in the best value per extra unit of a limit is the shadow price: here 2 for x + y ≤ 4 and 1 for x ≤ 2, and 0 for y ≤ 3. A shadow price tells a manager what one more unit of a resource is worth, and it stays the same only until a different set of constraints becomes binding.

The objective can change too. The optimal corner stays the same over a range of optimality of each coefficient; outside it, the best plan jumps to a neighbouring corner. These trade-offs show how robust a plan is to price changes.

Optimization with calculus

When the objective is a smooth curve rather than a straight line, the best value of a function f(x) on an interval is at a point where the slope is zero, f′(x) = 0, or at an end of the interval. The usual method is: write the constraint, use it to express the objective in one variable, differentiate, solve f′(x) = 0, and check it is a maximum or minimum (for example with the second derivative).

  • Fenced field: with perimeter P, A(x) = x(P/2 − x), so A′(x) = P/2 − 2x = 0 gives x = P/4: a square.
  • Open box: cutting squares of side x from an L × W sheet gives V(x) = x(L − 2x)(W − 2x); V′(x) = 0 is a quadratic equation.
  • Can: for a fixed volume V, S(r) = 2πr² + 2V/r is smallest when h = 2r.

Computers often optimize numerically instead. Hill climbing (gradient ascent) repeatedly steps in the direction of the slope, with steps that shrink as the slope flattens near the top. The simulator’s Start button runs this search.

Whole-number plans

Many decisions must be whole numbers: crates, trucks, staff. The best corner of the linear program may be fractional, and simply rounding can break a constraint or miss the best whole-number plan. Integer programmingsearches the allowed whole-number points; for small problems you can check the points near the best corner. Its best value can never beat the fractional optimum, which is why the fractional answer is a useful bound.

Formula reference

IdeaFormula and meaning
Linear programMaximize or minimize Z = c₁x + c₂y subject to aᵢx + bᵢy ≤ (or ≥) cᵢ, x ≥ 0, y ≥ 0
Level linec₁x + c₂y = k; all level lines are parallel and Z improves in the direction (c₁, c₂) when maximizing
Slackcᵢ − (aᵢx + bᵢy) for a ≤ constraint; zero slack means the constraint is binding
Shadow priceChange in the best Z per one-unit increase of a limit cᵢ
Stationary pointf′(x) = 0; a maximum if f″(x) < 0, a minimum if f″(x) > 0
Fenced fieldA = x(P/2 − x), best x = P/4, A = P²/16
Open boxV = x(L − 2x)(W − 2x), best x = [(L + W) − √(L² − LW + W²)] / 6
Closed canS = 2πr² + 2V/r, best r = ∛(V/2π), h = 2r
Hill climbingxₙ₊₁ = xₙ + η·f′(xₙ) to maximize (minus to minimize), with a step size η

Real-world applications

  • Manufacturing: choosing a production mix that makes the most profit from limited machines, materials and labour.
  • Transport and logistics: airline crew scheduling, delivery routes and shipping goods at least cost.
  • Diet and agriculture: the cheapest feed or meal plan that meets nutritional minimums.
  • Engineering design: shapes that use the least material for the required strength or capacity.
  • Energy: deciding which power stations to run to meet demand at least cost.
  • Machine learning: training a model means minimizing an error function, usually by gradient descent.

Interesting facts

  • Leonid Kantorovich developed linear programming in 1939 to plan production in the Soviet Union, and later shared the 1975 Nobel Memorial Prize in Economics for it.
  • George Dantzig invented the simplex method in 1947 while working on planning problems for the US Air Force.
  • The famous “diet problem” of finding the cheapest adequate diet was one of the first large problems solved with the simplex method.
  • Bees build hexagonal cells; mathematicians proved in 1999 (the honeycomb conjecture) that hexagons divide a plane into equal areas with the least total wall length.

Common misconceptions

  • “The best point is in the middle of the region.” For linear objectives it is always on the boundary, at a corner or along an edge.
  • “An unbounded region means no optimum.” Only if the objective improves along a direction the region extends in.
  • “Every constraint affects the answer.” Non-binding constraints have slack; changing them a little changes nothing.
  • “Rounding the best fractional answer gives the best whole-number answer.” It can break a constraint or miss a better point.
  • “f′(x) = 0 always gives the maximum.” It can be a minimum or neither, and the best value can be at an end of the interval.

What the simulator simplifies

The linear programs have two variables so they can be drawn; real ones have thousands and are solved by the simplex or interior-point methods rather than by listing corners. Every problem includes x ≥ 0 and y ≥ 0. The shadow price is measured by re-solving with a slightly larger limit, which is exact except at the exact point where the binding constraints change. The geometric models ignore wasted material, seams and thickness, and the challenges assume fixed prices and resource use per unit.

Important terms

Decision variable
A quantity you can choose, such as x and y.
Objective function
The quantity to maximize or minimize.
Constraint
A limit that every allowed choice must satisfy.
Feasible region
The set of all choices that satisfy every constraint.
Corner (vertex)
A point of the feasible region where two constraint lines meet.
Binding constraint
A constraint that holds with equality at the optimum (zero slack).
Shadow price
How much the best value changes per extra unit of a limit.
Infeasible / unbounded
No allowed choice exists / the objective can improve without limit.

Key takeaways

  • Optimization means choosing decision variables to make an objective as good as possible within constraints.
  • A linear program’s optimum, if it exists, is at a corner of the feasible region.
  • Problems can be infeasible, unbounded or have many optimal solutions.
  • Only binding constraints limit the best value; their shadow prices measure how much.
  • For smooth objectives, the best value is where the derivative is zero or at an end of the allowed range.

Knowledge check

Optimization and Constraint Modeling: test your understanding

Answer each question to get instant feedback and an explanation. Use the simulator to check your thinking.

10 questions3 basic4 intermediate3 advanced

0 of 10 answered

  1. Q1BasicIn a linear programming problem, what is the feasible region?
    Show answer

    Answer: B. The set of all points that satisfy every constraint

    Each constraint keeps one side of a line. The feasible region is where all those allowed sides overlap: every point in it is a plan you are allowed to choose.

  2. Q2IntermediateMaximize Z = 3x + 2y subject to x + y ≤ 4, x ≤ 2, y ≤ 3, x ≥ 0, y ≥ 0. What is the maximum?
    Show answer

    Answer: C. Z = 10 at (2, 2)

    The corners are (0, 0), (2, 0), (2, 2), (1, 3) and (0, 3), giving Z = 0, 6, 10, 9 and 6. The largest is 10 at (2, 2). The point (4, 0) breaks x ≤ 2.

  3. Q3IntermediateWhy is it enough to check only the corners of the feasible region in a linear program?
    Show answer

    Answer: A. Because the objective is linear, so if a best value exists it is reached at a corner

    Level lines of a linear objective are parallel straight lines. Sliding them in the improving direction, the last contact with a polygon is at a corner (or along a whole edge, which includes corners).

  4. Q4IntermediateThe objective’s level lines are parallel to one edge of the feasible region, and that edge is on the improving side. What happens?
    Show answer

    Answer: D. Every point on that edge is optimal (multiple optima)

    The best level line touches the region along the whole edge, so all its points give the same best value, including the two corners at its ends.

  5. Q5BasicA problem has constraints x + y ≥ 6, x ≤ 2 and y ≤ 3. What can you say?
    Show answer

    Answer: B. It is infeasible: no point satisfies all three

    With x ≤ 2 and y ≤ 3, x + y is at most 5, so x + y ≥ 6 can never hold at the same time. There is no feasible point to optimize over.

  6. Q6IntermediateWhen is a maximization linear program called unbounded?
    Show answer

    Answer: C. When feasible points exist with arbitrarily large objective values

    An open (unbounded) feasible region is not enough on its own: the objective must also keep improving in a direction the region extends in forever. Then there is no maximum.

  7. Q7AdvancedAt the optimum, a constraint has zero slack. What is it called, and what does relaxing it do?
    Show answer

    Answer: D. Binding; relaxing it can improve the best value, by its shadow price per unit

    A binding constraint is used up exactly. Loosening its limit by one unit moves the optimal corner and changes the best value by the shadow price, as long as the same constraints stay binding.

  8. Q8BasicA farmer has 40 m of fence to enclose a rectangular field. Which dimensions give the largest area?
    Show answer

    Answer: A. 10 m × 10 m

    With 2x + 2y = 40, the area is A = x(20 − x). A′(x) = 20 − 2x = 0 gives x = 10, so the best shape is a 10 m square with area 100 m². 20 m × 20 m would need 80 m of fence.

  9. Q9AdvancedA closed can must hold a fixed volume V using as little metal as possible. In the simple model S = 2πr² + 2V/r, what shape is best?
    Show answer

    Answer: B. Height equal to the diameter (h = 2r)

    S′(r) = 4πr − 2V/r² = 0 gives V = 2πr³, and since V = πr²h this means h = 2r: the can is as tall as it is wide. Real cans differ because lids and seams cost more.

  10. Q10AdvancedIn a factory problem the best corner is (6.5, 11), but only whole numbers of crates can be made. What is the right approach?
    Show answer

    Answer: D. Check the allowed whole-number points near the corner; rounding may break a constraint or miss the best plan

    Rounding up can break a limit, and rounding down is allowed but not always best. Integer programming searches the allowed whole-number points; in the simulator the best whole-number plan is (6, 11).

References and further reading

  1. Strang, G., & Herman, E. (2016). Calculus Volume 1, Section 4.7: Applied Optimization Problems. OpenStax. openstax.org (opens in a new tab)
  2. Vanderbei, R. J. (2020). Linear Programming: Foundations and Extensions (5th ed.). Springer.
  3. Hillier, F. S., & Lieberman, G. J. (2021). Introduction to Operations Research (11th ed.). McGraw-Hill.
  4. Dantzig, G. B. (1963). Linear Programming and Extensions. Princeton University Press.

This simulator is a simplified educational model. Found an error? Let us know. See our educational disclaimer.