Handle ConstraintList with persistent solver
I want to try using persistent solver for an algorithm that iteratively adds new constraints to the problem, and want to avoid having to completely rebuild the file given to the solver before each iterations.
Before using persistent solver as described on https://pyomo.readthedocs.io/en/stable/solvers/persistent_solvers.html, I used a ConstraintList
object to iteratively add my new constraints without having to name them individually. I thought this was a very elegant solution and I want to see if there is a way to notify the persistent solver when a new constraint is added to the ConstraintList
.
In the docs, it is writtent that
m.c2 = pe.Constraint(expr=m.y >= m.x)
opt.add_constraint(m.c2)
where m.c2
is a constraint to be added to the model with persistent solver. What would be the equivalent line to notify the persistent solver that a change was done to the ConstraintList
, once that a constraint was added in it?
pyomo
add a comment |
I want to try using persistent solver for an algorithm that iteratively adds new constraints to the problem, and want to avoid having to completely rebuild the file given to the solver before each iterations.
Before using persistent solver as described on https://pyomo.readthedocs.io/en/stable/solvers/persistent_solvers.html, I used a ConstraintList
object to iteratively add my new constraints without having to name them individually. I thought this was a very elegant solution and I want to see if there is a way to notify the persistent solver when a new constraint is added to the ConstraintList
.
In the docs, it is writtent that
m.c2 = pe.Constraint(expr=m.y >= m.x)
opt.add_constraint(m.c2)
where m.c2
is a constraint to be added to the model with persistent solver. What would be the equivalent line to notify the persistent solver that a change was done to the ConstraintList
, once that a constraint was added in it?
pyomo
add a comment |
I want to try using persistent solver for an algorithm that iteratively adds new constraints to the problem, and want to avoid having to completely rebuild the file given to the solver before each iterations.
Before using persistent solver as described on https://pyomo.readthedocs.io/en/stable/solvers/persistent_solvers.html, I used a ConstraintList
object to iteratively add my new constraints without having to name them individually. I thought this was a very elegant solution and I want to see if there is a way to notify the persistent solver when a new constraint is added to the ConstraintList
.
In the docs, it is writtent that
m.c2 = pe.Constraint(expr=m.y >= m.x)
opt.add_constraint(m.c2)
where m.c2
is a constraint to be added to the model with persistent solver. What would be the equivalent line to notify the persistent solver that a change was done to the ConstraintList
, once that a constraint was added in it?
pyomo
I want to try using persistent solver for an algorithm that iteratively adds new constraints to the problem, and want to avoid having to completely rebuild the file given to the solver before each iterations.
Before using persistent solver as described on https://pyomo.readthedocs.io/en/stable/solvers/persistent_solvers.html, I used a ConstraintList
object to iteratively add my new constraints without having to name them individually. I thought this was a very elegant solution and I want to see if there is a way to notify the persistent solver when a new constraint is added to the ConstraintList
.
In the docs, it is writtent that
m.c2 = pe.Constraint(expr=m.y >= m.x)
opt.add_constraint(m.c2)
where m.c2
is a constraint to be added to the model with persistent solver. What would be the equivalent line to notify the persistent solver that a change was done to the ConstraintList
, once that a constraint was added in it?
pyomo
pyomo
asked Nov 12 '18 at 20:51
V. Brunelle
177113
177113
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Here is how you create your constraint list
m.Cut_Defn = pyomo.ConstraintList(noruleinit=True)
And then you can add constraints in your constraint list:
m.Cut_Defn.add(some_number >= your_variable + some_other_number)
If you solve before the .add()
then you'll find another solution than solving after the .add()
. So you can think like: it implements the new constraints on the fly, and you have to resolve your model, if you want that constraints to be in your optimization.
Can you confirm/prove/show me the docs that the method.add(
from a constraint list will update the model that was previously uploaded only once in the persistent solver instance? It is very important since solving with those constraints gives the same result as solving without these (and I can confirm that they will change the results). And I didn't forget to solve after changing the constraint list.
– V. Brunelle
Nov 13 '18 at 19:51
I can't really prove you if it will update, but you can try something like: Assume your objective to minimize is x, and you have a constraint, which says x>=10, and if you add x<=11 in your constraint list, and if you resolve that model, u should get in-feasibility error from your solver. So that you can understand it adds the constraint.
– oakca
Nov 14 '18 at 14:57
you might find an interesting answer to my question on the Pyomo forum here: groups.google.com/forum/#!topic/pyomo-forum/TI0bWesN62o Thanks for the time and help!
– V. Brunelle
Nov 14 '18 at 19:33
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269913%2fhandle-constraintlist-with-persistent-solver%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here is how you create your constraint list
m.Cut_Defn = pyomo.ConstraintList(noruleinit=True)
And then you can add constraints in your constraint list:
m.Cut_Defn.add(some_number >= your_variable + some_other_number)
If you solve before the .add()
then you'll find another solution than solving after the .add()
. So you can think like: it implements the new constraints on the fly, and you have to resolve your model, if you want that constraints to be in your optimization.
Can you confirm/prove/show me the docs that the method.add(
from a constraint list will update the model that was previously uploaded only once in the persistent solver instance? It is very important since solving with those constraints gives the same result as solving without these (and I can confirm that they will change the results). And I didn't forget to solve after changing the constraint list.
– V. Brunelle
Nov 13 '18 at 19:51
I can't really prove you if it will update, but you can try something like: Assume your objective to minimize is x, and you have a constraint, which says x>=10, and if you add x<=11 in your constraint list, and if you resolve that model, u should get in-feasibility error from your solver. So that you can understand it adds the constraint.
– oakca
Nov 14 '18 at 14:57
you might find an interesting answer to my question on the Pyomo forum here: groups.google.com/forum/#!topic/pyomo-forum/TI0bWesN62o Thanks for the time and help!
– V. Brunelle
Nov 14 '18 at 19:33
add a comment |
Here is how you create your constraint list
m.Cut_Defn = pyomo.ConstraintList(noruleinit=True)
And then you can add constraints in your constraint list:
m.Cut_Defn.add(some_number >= your_variable + some_other_number)
If you solve before the .add()
then you'll find another solution than solving after the .add()
. So you can think like: it implements the new constraints on the fly, and you have to resolve your model, if you want that constraints to be in your optimization.
Can you confirm/prove/show me the docs that the method.add(
from a constraint list will update the model that was previously uploaded only once in the persistent solver instance? It is very important since solving with those constraints gives the same result as solving without these (and I can confirm that they will change the results). And I didn't forget to solve after changing the constraint list.
– V. Brunelle
Nov 13 '18 at 19:51
I can't really prove you if it will update, but you can try something like: Assume your objective to minimize is x, and you have a constraint, which says x>=10, and if you add x<=11 in your constraint list, and if you resolve that model, u should get in-feasibility error from your solver. So that you can understand it adds the constraint.
– oakca
Nov 14 '18 at 14:57
you might find an interesting answer to my question on the Pyomo forum here: groups.google.com/forum/#!topic/pyomo-forum/TI0bWesN62o Thanks for the time and help!
– V. Brunelle
Nov 14 '18 at 19:33
add a comment |
Here is how you create your constraint list
m.Cut_Defn = pyomo.ConstraintList(noruleinit=True)
And then you can add constraints in your constraint list:
m.Cut_Defn.add(some_number >= your_variable + some_other_number)
If you solve before the .add()
then you'll find another solution than solving after the .add()
. So you can think like: it implements the new constraints on the fly, and you have to resolve your model, if you want that constraints to be in your optimization.
Here is how you create your constraint list
m.Cut_Defn = pyomo.ConstraintList(noruleinit=True)
And then you can add constraints in your constraint list:
m.Cut_Defn.add(some_number >= your_variable + some_other_number)
If you solve before the .add()
then you'll find another solution than solving after the .add()
. So you can think like: it implements the new constraints on the fly, and you have to resolve your model, if you want that constraints to be in your optimization.
answered Nov 13 '18 at 10:20
oakca
17911
17911
Can you confirm/prove/show me the docs that the method.add(
from a constraint list will update the model that was previously uploaded only once in the persistent solver instance? It is very important since solving with those constraints gives the same result as solving without these (and I can confirm that they will change the results). And I didn't forget to solve after changing the constraint list.
– V. Brunelle
Nov 13 '18 at 19:51
I can't really prove you if it will update, but you can try something like: Assume your objective to minimize is x, and you have a constraint, which says x>=10, and if you add x<=11 in your constraint list, and if you resolve that model, u should get in-feasibility error from your solver. So that you can understand it adds the constraint.
– oakca
Nov 14 '18 at 14:57
you might find an interesting answer to my question on the Pyomo forum here: groups.google.com/forum/#!topic/pyomo-forum/TI0bWesN62o Thanks for the time and help!
– V. Brunelle
Nov 14 '18 at 19:33
add a comment |
Can you confirm/prove/show me the docs that the method.add(
from a constraint list will update the model that was previously uploaded only once in the persistent solver instance? It is very important since solving with those constraints gives the same result as solving without these (and I can confirm that they will change the results). And I didn't forget to solve after changing the constraint list.
– V. Brunelle
Nov 13 '18 at 19:51
I can't really prove you if it will update, but you can try something like: Assume your objective to minimize is x, and you have a constraint, which says x>=10, and if you add x<=11 in your constraint list, and if you resolve that model, u should get in-feasibility error from your solver. So that you can understand it adds the constraint.
– oakca
Nov 14 '18 at 14:57
you might find an interesting answer to my question on the Pyomo forum here: groups.google.com/forum/#!topic/pyomo-forum/TI0bWesN62o Thanks for the time and help!
– V. Brunelle
Nov 14 '18 at 19:33
Can you confirm/prove/show me the docs that the method
.add(
from a constraint list will update the model that was previously uploaded only once in the persistent solver instance? It is very important since solving with those constraints gives the same result as solving without these (and I can confirm that they will change the results). And I didn't forget to solve after changing the constraint list.– V. Brunelle
Nov 13 '18 at 19:51
Can you confirm/prove/show me the docs that the method
.add(
from a constraint list will update the model that was previously uploaded only once in the persistent solver instance? It is very important since solving with those constraints gives the same result as solving without these (and I can confirm that they will change the results). And I didn't forget to solve after changing the constraint list.– V. Brunelle
Nov 13 '18 at 19:51
I can't really prove you if it will update, but you can try something like: Assume your objective to minimize is x, and you have a constraint, which says x>=10, and if you add x<=11 in your constraint list, and if you resolve that model, u should get in-feasibility error from your solver. So that you can understand it adds the constraint.
– oakca
Nov 14 '18 at 14:57
I can't really prove you if it will update, but you can try something like: Assume your objective to minimize is x, and you have a constraint, which says x>=10, and if you add x<=11 in your constraint list, and if you resolve that model, u should get in-feasibility error from your solver. So that you can understand it adds the constraint.
– oakca
Nov 14 '18 at 14:57
you might find an interesting answer to my question on the Pyomo forum here: groups.google.com/forum/#!topic/pyomo-forum/TI0bWesN62o Thanks for the time and help!
– V. Brunelle
Nov 14 '18 at 19:33
you might find an interesting answer to my question on the Pyomo forum here: groups.google.com/forum/#!topic/pyomo-forum/TI0bWesN62o Thanks for the time and help!
– V. Brunelle
Nov 14 '18 at 19:33
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53269913%2fhandle-constraintlist-with-persistent-solver%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown