Integer and binary variables are listed in Generals and Binaries sections.
from optyx import BinaryVariable, IntegerVariablex = IntegerVariable("x", lb=0, ub=10)y = BinaryVariable("y")z = Variable("z", lb=0)prob = Problem("mip")prob.maximize(3* x +5* y + z)prob.subject_to(x +2* y + z <=15)prob.subject_to(x + y >=2)print(prob.to_lp())
\ Model mip
Maximize
obj: 3 x + 5 y + z
Subject To
c0: x + 2 y + z <= 15
c1: x + y >= 2
Bounds
0 <= x <= 10
0 <= y <= 1
0 <= z
Generals
x
Binaries
y
End
4 Supported Features
Feature
Support
Linear objectives
✓
Quadratic objectives
✓
<=, >=, == constraints
✓
Variable bounds
✓
Free variables
✓
Integer variables (Generals)
✓
Binary variables (Binaries)
✓
Matrix constraints
✓
Sparse matrix constraints
✓
Nonlinear objectives
✗ (raises error)
5 Export Methods
The Problem.to_lp() method returns the LP string, while Problem.write(path) writes it to a file.
# String representationlp_string = prob.to_lp()# Write to fileprob.write("model.lp")