Adds support for the validation of IndexedSets using the index#3304
Adds support for the validation of IndexedSets using the index#3304pmlpm1986 wants to merge 20 commits intoPyomo:mainfrom
Conversation
Valsetindexprior
|
I reverted the changes introduced by black. It should work as intended now. |
| m = ConcreteModel() | ||
|
|
||
| def _validate(model, i, j): | ||
| def _validate_I(model, i, j): |
There was a problem hiding this comment.
I envision that future developers looking at this code will wonder, "What is I?"
There was a problem hiding this comment.
In my mind, it is a simple set that we validate through the normal rule (no index).
There was a problem hiding this comment.
That is, a non-indexed set.
| # 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.
I envision that future developers looking at this code will wonder, "What is J?"
There was a problem hiding this comment.
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: