-
-
Notifications
You must be signed in to change notification settings - Fork 398
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
[RFC] Another iteration on JuMPDicts #241
Conversation
Conflicts: src/JuMPDict.jl
Conflicts: src/JuMPDict.jl
Conflicts: src/JuMP.jl src/JuMPDict.jl src/macros.jl
This is a reasonably syntax for conditionals. Why support multiple conditions instead of using |
I think it's a bit nicer, if only because it makes printing look nicer. I don't see a compelling reason why we should limit it to a single conditional. |
If it's just for our convenience I think it makes more sense to avoid introducing an additional non-Julian syntax and just try to print the |
The real motivation is that I think I prefer the syntax @defVar(m, x[i,j]; i=1:n, j=1:n, j>=i) which I think is less cluttered and closer to the standard mathematical notation. This is a bit more complex to parse though, so I held off on it for now. |
The tests are now passing on this branch. This is currently a breaking change, as behavior like |
The Another issue with this syntax is that the conditions might end up far away from indexing, e.g.,:
This isn't ideal. The original proposal is better in this respect with |
More explicitly, a design principle for JuMP's syntax should be to minimize the potential instances of someone thinking, "wait, what does that mean?" when seeing it for the first time. Using commas to separate conditions falls into that category for me. @IainNZ? |
Personally I find specifying the index sets inside square brackets a little unnatural, especially when there are dependencies between indices. For example, I think this @defVar(m, x[i,j] >= c[i]; i=1:n, j=i:n) is more clear than @defVar(m, x[i=1:n,j=1:n;i<=j] >= c[i]) or @defVar(m, x[i=1:n,i:n] >= c[i]) I think this syntax is a little closer to what you would write mathematically. |
Reading:
it's not clear to me whether |
By reading the rest of the model, though I'll admit it's visually ambiguous in the sense that you can't disambiguate by just reading that line. That hasn't stopped this from being the predominate way of writing mathematical models in the literature, perhaps because it's actually somewhat of a corner case (one-sided bound, bound value taken from an array, same index sets for both). |
I think I still like indexing inside the variable, although it can look pretty nice next to it. I think the commas to separate conditions is too ambiguous though, I think the && is super clear and we shouldn't lose that. Do we have/have we seen real uses of complicated variables definitions that we could check out? |
It's not just variable definitions, this also affects |
There's also the option of allowing both syntaxes. Not sure if that would just make things more confusing, though. |
What do you guys think about trying this syntax on for size? If we eventually get language support for |
There's been a few proposals here, I'd be fine with
removing the commas to separate conditions. A complete revamp of the syntax is a bit out of scope of this PR. |
That sounds good to me. |
I branched this off of #192 to try to add conditionals to indexing JuMPDicts. Here's a small example: