Skip to content

Commit

Permalink
no distributivity in flatten_model.py (#426)
Browse files Browse the repository at this point in the history
* no distributivity in flatten_model.py
  • Loading branch information
Wout4 authored Oct 19, 2023
1 parent 2c380db commit 0efb8df
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions cpmpy/transformations/flatten_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,9 @@ def flatten_constraint(expr):
# there could be nested implications
newlist.extend(flatten_constraint(Operator('or', newargs)))
continue
else:
# check if disjunction contains conjunctions, and if so split out
newexprs = None
for i,a in enumerate(expr.args):
if isinstance(a, Operator) and a.name == 'and':
# can avoid aux var creation by splitting over the and
newexprs = [Operator("or", expr.args[:i]+[e]+expr.args[i+1:]) for e in a.args]
break
if newexprs is not None:
newlist.extend(flatten_constraint(newexprs))
continue

# conjunctions in disjunctions could be split out by applying distributivity,
# but this would explode the number of constraints in favour of having less auxiliary variables.
# Testing has proven that this is not worth it.
elif expr.name == '->':
# some rewrite rules that avoid creating auxiliary variables
# 1) if rhs is 'and', split into individual implications a0->and([a11..a1n]) :: a0->a11,...,a0->a1n
Expand Down

0 comments on commit 0efb8df

Please sign in to comment.