pyomo icon indicating copy to clipboard operation
pyomo copied to clipboard

SCIPAMPL solver does not assign values to all variables

Open lpierezan opened this issue 1 year ago • 2 comments
trafficstars

Summary

Using the solver obtained by SolverFactory('scip'):

If a variable, active in the Pyomo model, does not appear in any constraint (or appears with a coefficient 0) then after solve, no value was assigned to that variable.

It is expected that all model variables have a value assigned when the solver status returned is an optimal solution.

Steps to reproduce the issue

m = pyo.ConcreteModel()
m.x = pyo.Var(domain = pyo.Binary)
m.y = pyo.Var(domain = pyo.Binary)
m.z = pyo.Var(domain = pyo.Binary)
m.k = pyo.Param(initialize = 0)
m.c = pyo.Constraint(expr = m.k * m.x + m.y <= 1)
m.obj = pyo.Objective(expr = m.y)
opt = pyo.SolverFactory('scip', tee = False)
r = opt.solve(m)
print(r.solver)
assert m.x.value is None
assert m.z.value is None

Information on your system

Pyomo version: 6.7.0 Python version: 3.9.16 Operating system: Win 11 How Pyomo was installed (PyPI, conda, source): pip Solver (if applicable): scip 8.1.0

Additional information

In fact, the nl file doesn't even define the variable.

lpierezan avatar Jan 27 '24 02:01 lpierezan

In my opinion, this is expected behavior. The value of a variable that does not actively participate in a model can be anything within its domain.

michaelbynum avatar Jan 30 '24 22:01 michaelbynum

Hi @michaelbynum , thanks for your reply.

I don't know of any solver that has this behavior. I quickly tested with scip (pyscipopt), gurobi (gurobipy) and highs (highspy): if a viable solution is reported, all variables defined in the model have an assigned value (even if they do not appear in constraints or objective function).

So in this case Pyomo is adding behavior that is, to say the least, quite unusual.

Still using Pyomo, if I change SolverFactory to 'appsi_highs', the behavior changes to what I think is correct, as the MPS writer specifies all the variables defined in the Pyomo model.

In my opinion, it wouldn't be up to Pyomo to decide to "remove" some variables, it would be enough to pass them all to the chosen solver.

lpierezan avatar Jan 31 '24 12:01 lpierezan