At most k of the boolean args are true.
(args: Sequence[BoolRef], k: int)
| 2095 | |
| 2096 | |
| 2097 | def AtMost(args: Sequence[BoolRef], k: int) -> BoolRef: |
| 2098 | """At most k of the boolean args are true.""" |
| 2099 | exprs = list(args) |
| 2100 | if not exprs: |
| 2101 | return BoolVal(True) |
| 2102 | int_args = [_bool_to_int(b) for b in exprs] |
| 2103 | total = Sum(*int_args) |
| 2104 | return total <= k |
| 2105 | |
| 2106 | |
| 2107 | def AtLeast(args: Sequence[BoolRef], k: int) -> BoolRef: |