How do I solve an MIP model with FICO Xpress, via Pyomo?
In addition, I want to set parameters of Xpress like miptol
and miprelstop
. How do I do that in Pyomo?
How do I solve an MIP model with FICO Xpress, via Pyomo?
In addition, I want to set parameters of Xpress like miptol
and miprelstop
. How do I do that in Pyomo?
In order to mark a variable as binary, you have to define it to be within
the Binary
constraint:
model.z = pyo.Var(bounds=(0, 1)), within=pyo.Binary)
Setting controls is done with the options
attribute of the solver. Here is a short sample that creates a simple model, sets options, and solves.
import pyomo.environ as pyo
model = pyo.ConcreteModel()
model.x = pyo.Var(bounds=(0, 1))
model.y = pyo.Var(bounds=(0, 1))
model.z = pyo.Var(bounds=(0, 1), within=pyo.Binary)
model.c = pyo.Constraint(expr = model.z >= 0.5)
model.obj = pyo.Objective(expr = model.x - 2 * model.y + 3 * model.z,
sense = pyo.minimize)
opt = pyo.SolverFactory('xpress_direct')
opt.options['miprelstop'] = 1e-9
opt.options['miptol'] = 0.5
results = opt.solve(model)
print('x =', pyo.value(model.x))
print('y =', pyo.value(model.y))
print('z =', pyo.value(model.z))
This outputs (among other things)
x = 0.0
y = 1.0
z = 1.0
which shows that the binary condition on z
was respected (otherwise, the optimal value for z
would have been 0.5). It also shows the modified parameter values in the output log.