Save end_is_none flag in Cumulative and NoOverlap#830
Conversation
|
It doesn't feel the right way, but haven't further looked into it. |
|
Now that I think about it, probably the right way of doing this, is to let the expressions decide which arguments should recusively be transformed. |
|
Since doing the type hinting, I'm starting to be convinced that the Expression object should be a simple container and args can contain anything... so then also the transformation functions should be able to either copy or skip things that are not subexpressions... You now do this for 'None'... it adds an additional test to the already often called/slowing down is flat var; I've pushed it up one level. I'm OK with this fix. But more generally, in DirectConstraint I added something like that, a 'self.novar' which is a list of indices at which there are guaranteed not to be any subexpressions/variables. This could be extended to all expressions... then expression (including DirectConstraint) can indeed have Expression.args be a Tuple[Any, ...]? |
|
so no, after more playing with Typing, the realisation is now:
then transformations remain untouched as intended, and you don need |
|
Updated this PR to indeed have a Keeping it as draft for now, as there will some merge issues with #676, so leaving it unmerged until that one is in master. TODO:
|
None valueend_is_none flag in Cumulative and NoOverlap
tias
left a comment
There was a problem hiding this comment.
great, and we should do that indeed.
I just had one simplication realisation: we don't need the flag, we can just check len(args)... this would be simpler/cleaner I think...
Would you be OK changing it to that, or do you prefer it this way?
(also smth ortools specific)
| assert isinstance(cpm_expr, Cumulative) # ensure hasattr end_is_none | ||
| if cpm_expr.end_is_none: | ||
| start, dur, demand, cap = cpm_expr.args | ||
| end = [intvar(*get_bounds(s+d)) for s,d in zip(start, dur)] |
There was a problem hiding this comment.
ortools also has an new_fixed_size_interval_var()
I'm a bit confused, I can't find the docs I'm used to... the docs I do find are all messy, and they use underscore based names; while we use CamelBack names? e.g. NewIntervalVar() vs new_interval_var()?
https://or-tools.github.io/docs/pdoc/ortools/sat/python/cp_model.html
so, my original point is: this should just be about first creating the right kind of interval var, then posting the constraint. In case end_is_none and demand is constant, the better thing to do is to create a new_fixed_size_interval_var() rather then a new_interval_var()
There was a problem hiding this comment.
Yes, OR-Tools refactored their API to snake_case, acually not sure how long the camelCase is still supported. We should find out which version introduced the snake case, update our API and bump the min requirements. I think I read somewhere there should be a sed file to automatically replace all occurences.
For the issue here: I'll use the fixed intervals indeed if duration is constant.
Fixes #828; not sure if this is the best way to do it, but seems like the most obvious for now.