-
Notifications
You must be signed in to change notification settings - Fork 517
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
APPSI Solver Error: cannot remove variable q2 - it is still being used by constraints or the objective #2888
Comments
Isn't this correct? The new variable in the model is not the same one that is used in the constraints/objective. |
Just to be clear, when a variable is deleted and a new one is created with the same name, it is not the same variable:
|
There is a better example.
|
Thanks. This helps. I'll get this fixed. |
Hi @michaelbynum . Any progress on this? |
Hi @michaelbynum . #2903 didn't fix this issue. from pyomo.environ import *
from pyomo.solvers.tests.models.QCP_simple import QCP_simple
QCP_model = QCP_simple()
QCP_model._generate_model()
model = QCP_model.model
model.q3 = Var(bounds=(-2, None))
model.obj = Objective(expr=model.x + model.q1 - model.q2 - model.q3, sense=maximize)
opt = SolverFactory('appsi_gurobi') # or 'appsi_cplex'
result = opt.solve(QCP_model.model,tee=True)
print(result)
model.del_component('q3')
model.q3 = Var(bounds=(-2, None))
model.del_component('obj')
model.obj = Objective(expr=model.x + model.q1 - model.q2 - model.q3, sense=maximize)
# opt = SolverFactory('appsi_gurobi')
result = opt.solve(QCP_model.model,tee=True)
print(result) Output
|
Strange. I just ran this, and I did not get an error. |
Yes. It's strange. I reinstalled
|
You are on the main branch? |
Yes. I am on the main branch. I found the problem. from pyomo.environ import *
from pyomo.solvers.tests.models.QCP_simple import QCP_simple
QCP_model = QCP_simple()
QCP_model._generate_model()
model = QCP_model.model
model.q3 = Var(bounds=(-2, None))
model.obj = Objective(expr=model.x + model.q1 - model.q2 - model.q3, sense=maximize)
opt = SolverFactory('appsi_cplex') # or 'appsi_cplex'
result = opt.solve(QCP_model.model, tee=True)
print(result)
model.del_component('q3')
model.q3 = Var(bounds=(-2, None))
model.del_component('obj')
model.obj = Objective(expr=model.x + model.q1 - model.q2 - model.q3, sense=maximize)
opt = SolverFactory('appsi_cplex')
result = opt.solve(QCP_model.model, tee=True)
print(result) However, the key of |
Correct. You should not have to reconstruct the solver. That defeats the purpose of Appsi. Something is wrong. It's hard to debug when I can't reproduce the issue though. |
I tried to start from the beginning.
The error still showed up. |
@michaelbynum Any suggestions to further test on this? |
It suddenly works as expected. Thanks for your help. |
It worked well after I rebuilt it in the new virtual environment. Thanks for your effort. |
Summary
APPSI solver will report the
cannot remove variable q2 - it is still being used by constraints or the objective
error if the variable is deleted and defined again.Steps to reproduce the issue
Error Message
Information on your system
Pyomo version: 6.6.1.dev0
Python version: 3.9.10
Operating system: macOS Monterey Version 12.1
How Pyomo was installed (PyPI, conda, source): source
Solver (if applicable):appsi_cplex, appsi_gurobi
Additional information
The text was updated successfully, but these errors were encountered: