1 problem.Problem

problem.Problem(name=None)

An optimization problem with objective and constraints.

1.1 Example

x = Variable(“x”, lb=0) y = Variable(“y”, lb=0) prob = Problem() prob.minimize(x2 + y2) prob.subject_to(x + y >= 1) solution = prob.solve() print(solution.values) # {‘x’: 0.5, ‘y’: 0.5}

1.2 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.

1.3 Attributes

Name Description
constraints List of constraints.
n_constraints Number of constraints.
n_variables Number of decision variables.
objective The objective function expression.
sense The optimization sense (minimize or maximize).
variables All decision variables in the problem.

1.4 Methods

Name Description
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.

1.4.1 get_bounds

problem.Problem.get_bounds()

Get variable bounds as a list of (lb, ub) tuples.

1.4.1.1 Returns

Name Type Description
list[tuple[float | None, float | None]] List of bounds in variable order.

1.4.2 maximize

problem.Problem.maximize(expr)

Set the objective function to maximize.

1.4.2.1 Parameters

Name Type Description Default
expr Expression Expression to maximize. Must be an optyx Expression, Variable, or numeric constant (int/float). required

1.4.2.2 Returns

Name Type Description
Problem Self for method chaining.

1.4.2.3 Raises

Name Type Description
InvalidOperationError If expr is not a valid expression type.

1.4.2.4 Example

prob.maximize(revenue - cost)

1.4.3 minimize

problem.Problem.minimize(expr)

Set the objective function to minimize.

1.4.3.1 Parameters

Name Type Description Default
expr Expression Expression to minimize. Must be an optyx Expression, Variable, or numeric constant (int/float). required

1.4.3.2 Returns

Name Type Description
Problem Self for method chaining.

1.4.3.3 Raises

Name Type Description
InvalidOperationError If expr is not a valid expression type.

1.4.3.4 Example

prob.minimize(x2 + y2) prob.minimize(x + 2*y - 5)

1.4.4 solve

problem.Problem.solve(method='auto', strict=False, **kwargs)

Solve the optimization problem.

1.4.4.1 Parameters

Name Type Description Default
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. {}

1.4.4.2 Returns

Name Type Description
Solution Solution object with results.

1.4.4.3 Raises

Name Type Description
ValueError If no objective has been set, or if strict=True and the problem contains unsupported features.

1.4.5 subject_to

problem.Problem.subject_to(constraint)

Add a constraint or list of constraints to the problem.

1.4.5.1 Parameters

Name Type Description Default
constraint Constraint | list[Constraint] Constraint or list of constraints to add. Lists are typically produced by vectorized constraints like x >= 0 on VectorVariable. required

1.4.5.2 Returns

Name Type Description
Problem Self for method chaining.

1.4.5.3 Raises

Name Type Description
ConstraintError If constraint is not a valid Constraint type.

1.4.5.4 Example

x = VectorVariable(“x”, 100) prob.subject_to(x >= 0) # Adds 100 constraints