problem.Problem
problem.Problem(name= None )
An optimization problem with objective and constraints.
Example
x = Variable(“x”, lb=0) y = Variable(“y”, lb=0) prob = Problem() prob.minimize(x2 + y 2) prob.subject_to(x + y >= 1) solution = prob.solve() print(solution.values) # {‘x’: 0.5, ‘y’: 0.5}
Note
The Problem class is not thread-safe. Compiled callables are cached per instance and reused across multiple solve() calls for performance. Any mutation (adding constraints, changing objective) invalidates the cache.
Methods
get_bounds
Get variable bounds as a list of (lb, ub) tuples.
maximize
Set the objective function to maximize.
minimize
Set the objective function to minimize.
solve
Solve the optimization problem.
subject_to
Add a constraint or list of constraints to the problem.
get_bounds
problem.Problem.get_bounds()
Get variable bounds as a list of (lb, ub) tuples.
maximize
problem.Problem.maximize(expr)
Set the objective function to maximize.
Parameters
expr
Expression
Expression to maximize. Must be an optyx Expression, Variable, or numeric constant (int/float).
required
Example
prob.maximize(revenue - cost)
minimize
problem.Problem.minimize(expr)
Set the objective function to minimize.
Parameters
expr
Expression
Expression to minimize. Must be an optyx Expression, Variable, or numeric constant (int/float).
required
Example
prob.minimize(x2 + y 2) prob.minimize(x + 2*y - 5)
solve
problem.Problem.solve(method= 'auto' , strict= False , ** kwargs)
Solve the optimization problem.
Parameters
method
str
Solver method. Options: - “auto” (default): Automatically select the best method: - Linear problems → linprog (HiGHS) - Unconstrained, n ≤ 3 → Nelder-Mead - Unconstrained, n > 1000 → L-BFGS-B - Unconstrained, else → BFGS - Bounds only → L-BFGS-B - Equality constraints → trust-constr - Inequality only → SLSQP - “linprog”: Force LP solver (scipy.optimize.linprog) - “SLSQP”: Sequential Least Squares Programming - “trust-constr”: Trust-region constrained optimization - “L-BFGS-B”: Limited-memory BFGS with bounds - “BFGS”: Broyden-Fletcher-Goldfarb-Shanno - “Nelder-Mead”: Derivative-free simplex method
'auto'
strict
bool
If True, raise ValueError when the problem contains features that the solver cannot handle exactly (e.g., integer/binary variables with SciPy). If False (default), emit a warning and use the best available approximation.
False
**kwargs
Additional arguments passed to the solver.
{}
Raises
ValueError
If no objective has been set, or if strict=True and the problem contains unsupported features.
subject_to
problem.Problem.subject_to(constraint)
Add a constraint or list of constraints to the problem.
Parameters
constraint
Constraint | list [Constraint ]
Constraint or list of constraints to add. Lists are typically produced by vectorized constraints like x >= 0 on VectorVariable.
required
Example
x = VectorVariable(“x”, 100) prob.subject_to(x >= 0) # Adds 100 constraints