pysat icon indicating copy to clipboard operation
pysat copied to clipboard

Support for lexicographic constraints

Open algebravic opened this issue 1 year ago • 3 comments

It would be nice if you had support for lexicographic comparison between two lists of literals, somewhat analogous to the support that you have for cardinality constraints.

algebravic avatar Apr 27 '23 22:04 algebravic

@algebravic, could you please explain what kind of constraint you need here?

alexeyignatiev avatar Apr 28 '23 07:04 alexeyignatiev

If a and b are two lists (for now of equal length) of boolean variables, and a <=lex b if and only if the following: either a[0] < b[0] or ((a[0] == b[0]) and a[1:] <= lex b[1:]. Here's a survey of possible implementations: https://digitalcommons.iwu.edu/cgi/viewcontent.cgi?article=1022&context=cs_honproj

This has even more details: https://www.cs.york.ac.uk/aig/constraints/SMT/ElgabouThesis.pdf

They are used all the time in symmetry breaking: https://eprints.soton.ac.uk/263661/1/jpms-sat07.pdf

algebravic avatar Apr 28 '23 16:04 algebravic

OK, I see what you mean now. It would be indeed nice to have a separate module providing CNF encodings for a list of typical constraints, including this one and some others, e.g. alldifferent.

alexeyignatiev avatar Apr 29 '23 00:04 alexeyignatiev