Adapting an optimization model to changing conditions without rebuilding
Published
May 28, 2026
1 Overview
Real-world optimization rarely involves a single solve. Conditions change — new regulations appear, equipment breaks down, capacity shifts — and the model must adapt. Optyx lets you modify a problem in place and re-solve without rebuilding from scratch.
Warm starting nonlinear solves from the previous solution
Resetting the solver state for a clean start
2 Part 1: Linear Production Planning
A factory produces two products with limited machine hours and raw materials. We solve the base plan, then adjust it as conditions change.
2.1 Setup
from optyx import Variable, Problemfrom optyx.constraints import Constrainta = Variable("a", lb=0, ub=100) # Units of product Ab = Variable("b", lb=0, ub=100) # Units of product Bprob = Problem(name="factory_production")prob.maximize(5* a +8* b) # $5/unit A, $8/unit B# We use Constraint() with a name so we can remove them by name later.# For constraints you never need to remove, simple subject_to(expr) works fine.mh = Constraint(expr=(a +2* b -120), sense="<=", name="machine_hours")prob.subject_to(mh)rm = Constraint(expr=(3* a +2* b -150), sense="<=", name="raw_material")prob.subject_to(rm)print(prob.summary())
Variable bounds are re-read on every solve. Changing v.lb or v.ub between solves is always safe — no need to invalidate caches manually.
3 Part 2: Warm Starting (Nonlinear)
For nonlinear problems, Optyx automatically stores the previous solution and uses it as the starting point for the next solve. This can dramatically reduce iterations when the problem changes only slightly.
3.1 Setup
x = Variable("x", lb=0, ub=10)y = Variable("y", lb=0, ub=10)nlp = Problem(name="warm_start_demo")nlp.minimize((x -3) **2+ (y -4) **2)nlp.subject_to(x + y >=5)