0

Dears,
I have a model with two boolean decision variable, avere only one can be equal ti 1.

Is it the solver faster if I use AddAllDifferent or It i use a simple constraint (ADD) x+y=1?

1 Answers1

1

In this case, i would drop both ideas and stick to boolean-clauses:

x.Not() OR y.Not()
AND
x OR y

or if ortools supports it:

x XOR y

(= pseudocode -> not necessarily any sane syntax)

This is as simple as it gets and can be very efficiently reasoned about by unit-propagation. Furthermore, 2-SAT things might be at work internally (implication-graph and so on).

No need to reason about integer-arithmetic (including potential channeling of bool/int) or global-constraints.

The above is something which is sometimes even used in SAT when decomposing all-different by prohibit all possible pairs.

(ortools might be clever to analyze your approaches to get to the same boiled-down formulation; but maybe not -> why not help if it's so simple)

sascha
  • 32,238
  • 6
  • 68
  • 110
  • My advice is that if you think of using an all-different, you should use Boolean variables instead. – Laurent Perron Mar 24 '20 at 08:48
  • thanks it is very interesting...and what if I have more than 2 boolean decision variables where only one MUST be true? I resolved with x+y+z=1. Is there a more efficent way? – stefano guerrieri Mar 24 '20 at 08:49
  • Hi Laurent, yes X and Y are boolean in my model – stefano guerrieri Mar 24 '20 at 08:50
  • The more general case is hard to predict. If `n` is in `~1000`, the linear-arithmetic based approach will probably dominate (but in this case one probably might think about the boolean-domain + decomposed alldiff VS. non-boolean domain + custimized alldiff; e.g. a CP-focused approach for sudokus will probably reason about 1-9-int-domains;not bools).If `n` is `~10`, the binary-decomposition will maybe be competitive or better? Even for experts (i would not call me one), some of those modelling-questions are hard to predict and empirical analysis is often just more economical -> *easy to try*. – sascha Mar 24 '20 at 11:26