Decision variables that the optimizer will determine.
TipVector Variables
For creating arrays of variables (e.g., x[0], x[1]), use VectorVariable instead of creating individual Variable objects in a loop.
from optyx import Variablex = Variable(name, lb=None, ub=None, domain="continuous", obj=0.0)
1.1 Parameters
Parameter
Type
Description
Default
name
str
Unique identifier for the variable
Required
lb
float | None
Lower bound
None (unbounded)
ub
float | None
Upper bound
None (unbounded)
domain
str
One of "continuous", "integer", "binary"
"continuous"
obj
float
Mutable linear objective coefficient added to the problem objective
0.0
TipInteger/Binary Domains Supported
The "integer" and "binary" domains are fully supported for linear problems via scipy.optimize.milp() (HiGHS backend). Problems with integer/binary variables and a linear objective are automatically routed to the MILP solver. For nonlinear objectives with discrete variables (MIQP/MINLP), a clear error is raised. See the Integer Programming tutorial.
1.2 Properties
Property
Type
Description
.name
str
Variable name
.lb
float | None
Lower bound
.ub
float | None
Upper bound
.domain
str
Variable domain
.obj
float
Mutable linear objective coefficient used on the next solve
1.3 Examples
from optyx import Variable# Unbounded variablex = Variable("x")# Non-negative variabley = Variable("y", lb=0)# Bounded variablez = Variable("z", lb=-10, ub=10)# Binary variable (enforced by the MILP solver for linear models)b = Variable("b", domain="binary")print(f"Binary: lb={b.lb}, ub={b.ub}")
Binary: lb=0.0, ub=1.0
Invalid domains, non-finite bounds, or bounds where lb > ub raise a descriptive validation error immediately. Mutating lb or ub applies the same validation and leaves the previous value unchanged if validation fails.
For linear models, obj can be used alongside the expression passed to minimize() or maximize(). Updating it is reflected on the next solve:
from optyx import Constant, Variable# Explicit constantc = Constant(3.14)print(f"Value: {c.evaluate({})}")# Constants are created automatically from numbersx = Variable("x")expr =2* x +5# 2 and 5 become Constant nodes
Value: 3.14
3 Mathematical Functions
Transcendental and special functions for building expressions.