Add expression objects, convertible to LinearConstraints#9
Add expression objects, convertible to LinearConstraints#9funkey merged 17 commits intofunkelab:masterfrom
Conversation
| return constraint | ||
|
|
||
|
|
||
| def _get_coefficients( |
There was a problem hiding this comment.
would appreciate a careful look at this function... which is responsible for reducing an expression to coefficients (even if a term appears multiple times or is nested inside parentheses)
| e = expr.right | ||
| v = expr.left.value | ||
| else: | ||
| # XXX: will we ever need multiplication by a variable? |
There was a problem hiding this comment.
yeah, I thought so. that raises another question: should the Expression.constraint() method be renamed to linear_constraint()? or should it simply be smart and return the right type of constraint given the expression? (i.e. autodetect whether it's a quadratic expression)
There was a problem hiding this comment.
also, do you want that done in this PR? or should I switch it to a NotImplementedError for now and follow up in another PR?
There was a problem hiding this comment.
NotImplementedError is totally fine for now.
There was a problem hiding this comment.
I'd keep the constraint() instead of linear_constraint(). Future versions might return either, no need for the user to specify it.
funkey
left a comment
There was a problem hiding this comment.
Wonderful, I like it very much!
Only problem I have with it is that I want more of it now :)
Those are the things we could build on top of the expressions:
- conversion of expressions into objectives
- support for quadratic objectives (and maybe at some point quadratic constraints, which are not part of the C++ wrapper, yet)
- definitions of ranges (
0 <= x <= 10could be allowed) - support for boolean expressions (
x > 0 and y == 1 = z)
...but this is out of scope for this PR I'd say.
| return constraint | ||
|
|
||
|
|
||
| def _get_coefficients( |
this is now ready @funkey
see funkelab/motile#30 for an example of how this could be used in motile