Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCIPAMPL solver does not assign values to all variables #3110

Open
lpierezan opened this issue Jan 27, 2024 · 2 comments
Open

SCIPAMPL solver does not assign values to all variables #3110

lpierezan opened this issue Jan 27, 2024 · 2 comments

Comments

@lpierezan
Copy link

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.

@michaelbynum
Copy link
Contributor

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.

@lpierezan
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants