-
Notifications
You must be signed in to change notification settings - Fork 505
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
Adds support for the validation of IndexedSets using the index #3304
Conversation
Valsetindexprior
I reverted the changes introduced by black. It should work as intended now. |
@@ -4319,15 +4319,15 @@ def _lt_3(model, i): | |||
|
|||
m = ConcreteModel() | |||
|
|||
def _validate(model, i, j): | |||
def _validate_I(model, i, j): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I envision that future developers looking at this code will wonder, "What is I
?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my mind, it is a simple set that we validate through the normal rule (no index).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is, a non-indexed set.
@@ -4347,7 +4347,10 @@ def _validate(model, i, j): | |||
|
|||
# Note: one of these indices will trigger the exception in the | |||
# validot when it is called for the index. | |||
m.J = Set([(0, 0), (2, 2)], validate=_validate) | |||
def _validate_J(model, i, j, index): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I envision that future developers looking at this code will wonder, "What is J
?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my mind, it is just an indexed set that we validate through this new rule.
This is pretty close. I really only have two concerns with it:
I am happy to work on a patch for this, but it will take me a little while to get to it. |
As you say, the book is vague about this and it led me to think Sets behaved exactly like Parameters. Once I realised that they did not, I raised this issue. Only recently did I find the time to come up with a solution. Therefore, the On the subject of backwards compatibility, the adjustments needed are minimal and by design: all that is needed is to add the index to the arguments (it is always the last argument) and ignore it, which is what I did in some of the tests. Issuing a deprecation warning seems reasonable. |
This PR has been superseded by #3338 (that PR includes all commits here plus the rework of the Initializer and restoration of backwards compatibility [with deprecation warnings]). I am closing this PR to ease some of the burden on the CI system. |
Fixes #2655.
Summary/Motivation:
Set members could not be validated using the index in indexed sets. This PR adds that option to allow for more complex validation rules.
Changes proposed in this PR:
Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: