encodings into sat
play

Encodings into SAT Combinatorial Problem Solving (CPS) Enric Rodr - PowerPoint PPT Presentation

Encodings into SAT Combinatorial Problem Solving (CPS) Enric Rodr guez-Carbonell May 29, 2020 What is an encoding? Language of SAT solvers: CNF propositional formulas To solve combinatorial problems with SAT solvers,


  1. Encodings into SAT Combinatorial Problem Solving (CPS) Enric Rodr´ ıguez-Carbonell May 29, 2020

  2. What is an encoding? Language of SAT solvers: CNF propositional formulas ■ To solve combinatorial problems with SAT solvers, ■ constraints have to be represented in this language An encoding of a constraint C into SAT is ■ a CNF F that expresses C , so that there is a bijection solutions to C ⇐ ⇒ models of F 2 / 23

  3. Examples: AMO constraints An AMO constraint is of the form x 0 + . . . + x n − 1 ≤ 1 ■ where each x i is 0-1 (At Most One of the variables can be true) Quadratic encoding. ■ Variables: the same x 0 , . . . , x n − 1 ◆ Clauses: for 0 ≤ i < j < n , x i ∨ x j ◆ � n = O ( n 2 ) clauses � Requires ◆ 2 Other encodings try to use fewer clauses, ■ at the cost of introducing new variables 3 / 23

  4. Examples: AMO constraints Logarithmic encoding. Let m = ⌈ log 2 n ⌉ . Then: ■ Variables: the x i and new variables y 0 , y 1 , . . . , y m − 1 ◆ Clauses: for 0 ≤ i < n , 0 ≤ j < m ◆ x i ∨ y j if the j -th digit in binary of i is 1 ■ x i ∨ y j otherwise ■ Requires O (log n ) new variables, O ( n log n ) clauses ◆ Heule encoding. ■ If n ≤ 3 , the encoding is the quadratic encoding. ◆ If n ≥ 4 , introduce an auxiliary variable y and encode (recursively) ◆ x 0 + x 1 + y ≤ 1 and x 2 + · · · + x n − 1 + y ≤ 1 . Requires O ( n ) new variables, O ( n ) clauses ◆ Other encodings exist (see next) ■ 4 / 23

  5. Consistency and Arc-Consistency Let us consider an encoding of a constraint C such that ■ there is a correspondence between maps of the variables of C to their domains, and partial assignments of the boolean variables of the encoding The encoding is consistent if ■ whenever M is not compatible with any solution to C , unit propagation on the boolean assignment of M leads to a conflict The encoding is arc-consistent if ■ it is consistent, and ◆ unit propagation discards arc-inconsistent values ◆ (i.e., values without a support) These are good properties for encodings: ■ SAT solvers are very good at unit propagation! 5 / 23

  6. Consistency and Arc-Consistency In the case of an AMO constraint x 0 + . . . + x n − 1 ≤ 1 : ■ Consistency ≡ if there are two true vars x i in M or more, ■ then unit propagation should give a conflict Arc-consistency ≡ Consistency + if there is one true var x i in M , ■ then unit propagation should set all others x j to false The quadratic, logarithmic and Heule encodings ■ are all arc-consistent 6 / 23

  7. Cardinality Constraints A cardinality constraint is of the form x 1 + . . . + x n ⊲ ⊳ k ■ where each x i is 0-1 and ⊲ ⊳ ∈ {≤ , <, ≥ , >, = } AMO are a particular case of card. constraints where k = 1 and ⊲ ⊳ is ≤ ■ Without loss of generality we may assume ⊲ ⊳ is < , i.e., ■ x 1 + . . . + x n < k Naive encoding. ■ Variables: the same x 1 , . . . , x n ◆ Clauses: for all 1 ≤ i 1 < i 2 < . . . < i k ≤ n , ◆ x i 1 ∨ x i 2 ∨ . . . ∨ x i k � n � This is clauses! ◆ k 7 / 23

  8. Adders Again, other encodings try to use fewer clauses, ■ at the cost of introducing new variables Adder encoding. ■ Build an adder circuit by using bit-adders as building blocks: x s Full Adder y c z ↔ XOR( x, y, z ) s ↔ ( x ∧ y ) ∨ ( x ∧ z ) ∨ ( y ∧ z ) c where XOR( x, y, z ) is short for ( x ∧ y ∧ z ) ∨ ( x ∧ y ∧ z ) ∨ ( x ∧ y ∧ z ) ∨ ( x ∧ y ∧ z ) 8 / 23

  9. Adders Encodings of this kind are not arc-consistent. ■ Consider x + y + z ≤ 0 . ■ Then unit propagation should propagate x, y, z . Let us encode the constraint with a full adder ■ The encoding is the Tseitin transformation of s, c and ■ ↔ XOR( x, y, z ) s ↔ ( x ∧ y ) ∨ ( x ∧ z ) ∨ ( y ∧ z ) c Note that ■ → ( x ∨ y ∨ z ) ∧ ( x ∨ y ∨ z ) ∧ ( x ∨ y ∨ z ) ∧ ( x ∨ y ∨ z ) s → ( x ∨ y ) ∧ ( x ∨ z ) ∧ ( y ∨ z ) c Unit propagation cannot propagate anything! ■ 9 / 23

  10. Sorting Networks Sorting Network encoding. ■ Pass x 1 , . . . , x n as inputs to a circuit that sorts (say, decreasingly) n bits. Let y 1 , . . . , y n be the outputs of this circuit. Then if the constraint to be encoded is � n i =1 x i ≥ k , then add clause y k ◆ � n i =1 x i ≤ k , then add clause y k +1 ◆ � n i =1 x i = k , then add clauses y k , y k +1 ◆ 10 / 23

  11. Sorting Networks How to build such a sorting circuit? ■ A possibility is to implement mergesort ■ In what follows: so-called odd-even sorting networks ■ The basic block of odd-even sorting networks are 2-comparators ■ 11 / 23

  12. 2-comparators A 2-comparator is a sorting network of size 2: ■ it has 2 input variables ( x 1 and x 2 ) ◆ it has 2 output variables ( y 1 and y 2 ) ◆ y 1 is true if and only if at least one of the input variables is true ◆ (i.e., it is the maximum or disjunction) y 2 is true if and only if both two input variables are true ◆ (i.e., it is the minimum or conjunction) 12 / 23

  13. 2-comparators Clauses: ■ ← ← x 1 ∨ x 2 ← x 1 y 2 , x 2 y 2 , y 1 , → → x 1 ∧ x 2 → x 1 y 1 , x 2 y 1 , y 2 Graphical representation: ■ y 1 x 1 y 2 x 2 Some simplifications are possible: ■ For ≥ constraints: top three clauses suffice ◆ For ≤ constraints: bottom three clauses suffice ◆ For = constraints: all clauses needed ◆ 13 / 23

  14. 2-comparators Clauses: ■ ← ← x 1 ∨ x 2 ← x 1 y 2 , x 2 y 2 , y 1 , ← ← x 1 ∨ x 2 ← x 1 y 1 , x 2 y 1 , y 2 Graphical representation: ■ y 1 x 1 y 2 x 2 Some simplifications are possible: ■ For ≥ constraints: top three clauses suffice ◆ For ≤ constraints: bottom three clauses suffice ◆ For = constraints: all clauses needed ◆ 13 / 23

  15. Merge Networks From now on we assume that n is a power of two ■ (if not, pad with variables set to false) A merge network takes as input two ordered sets of variables of size n and ■ produces an ordered output of size 2 n . Let ( x 1 , . . . , x n ) and ( x ′ 1 , . . . , x ′ n ) be the inputs. ■ We recursively define a merge network as follows: If n = 1 , a merge network is a 2-comparator: ■ Merge( x 1 ; x ′ 1 ) := 2-Comp( x 1 , x ′ 1 ) . 14 / 23

  16. Merge Networks For n > 1 : Let us define ■ ( z 1 , z 3 , . . . , z 2 n − 1 ) = Merge( x 1 , x 3 , . . . , x n − 1 ; x ′ 1 , x ′ 3 , . . . x ′ n − 1 ) , ( z 2 , z 4 , . . . , z 2 n ) = Merge( x 2 , x 4 , . . . , x n ; x ′ 2 , x ′ 4 , . . . , x ′ n ) , ( y 2 , y 3 ) = 2-Comp( z 2 , z 3 ) , ( y 4 , y 5 ) = 2-Comp( z 4 , z 5 ) , . . . ( y 2 n − 2 , y 2 n − 1 ) = 2-Comp( z 2 n − 2 , z 2 n − 1 ) Then, Merge( x 1 , x 2 , . . . , x n ; x ′ 1 , x ′ 2 , . . . , x ′ n ) := ( z 1 , y 2 , y 3 , . . . , y 2 n − 1 , z 2 n ) 15 / 23

  17. Merge Networks z 1 x 1 z 1 z 2 x 2 y 2 z 3 x 3 y 3 z 4 x 4 y 4 Merge n =2 Merge n =2 y 5 x ′ z 5 1 y 6 x ′ z 6 2 y 7 x ′ z 7 3 z 8 x ′ z 8 4 16 / 23

  18. Merge Networks Sketch of the proof of correctness of Merge : By IH: { x 1 , x 3 , . . . , x n − 1 , x ′ 1 , x ′ 3 , . . . , x ′ n − 1 } = { z 1 , z 3 , . . . , z 2 n − 1 } x ′ 2 , x ′ 4 , . . . , x ′ By IH: { x 2 , x 4 , . . . , x n , n } = { z 2 , z 4 , . . . , z 2 n } x ′ 1 , x ′ 2 , . . . , x ′ Hence { x 1 , x 2 , . . . , x n , n } = { z 1 , z 2 , . . . , z 2 n } And ( y 2 , y 3 ) = 2-Comp( z 2 , z 3 ) implies { y 2 , y 3 } = { z 2 , z 3 } ( y 4 , y 5 ) = 2-Comp( z 4 , z 5 ) implies { y 4 , y 5 } = { z 4 , z 5 } . . . ( y 2 n − 2 , y 2 n − 1 ) = 2-Comp( z 2 n − 2 , z 2 n − 1 ) implies { y 2 n − 2 , y 2 n − 1 } = { z 2 n − 2 , z 2 n − 1 } So { x 1 , x 2 , . . . , x n , x ′ 1 , x ′ 2 , . . . , x ′ n } = { z 1 , y 2 , y 3 , . . . , y 2 n − 2 , y 2 n − 1 , z 2 n } 17 / 23

  19. Merge Networks Let us prove outputs are sorted decreasingly. For 1 ≤ i < n − 1 let us see: z 2 i ≥ z 2( i +1)+1 : ■ Let us see z 2( i +1)+1 = 1 implies z 2 i = 1 If z 2( i +1)+1 = z 2 i +3 = z 2( i +2) − 1 = 1 there are i + 2 1’s in odd x, x ′ Let p be the number of 1’s in odd x Let q the number of 1’s in odd x ′ Then p + q = i + 2 As x, x ′ is ordered decreasingly, there are p − 1 1’s in even x , q − 1 1’s in even x ′ So altogether there are ( p − 1) + ( q − 1) = p + q − 2 = i 1’s in even x, x ′ Hence z 2 i = 1 18 / 23

  20. Merge Networks Let us prove outputs are sorted decreasingly. For 1 ≤ i < n − 1 let us see: z 2 i ≥ z 2( i +1)+1 : proved ■ 18 / 23

  21. Merge Networks Let us prove outputs are sorted decreasingly. For 1 ≤ i < n − 1 let us see: z 2 i ≥ z 2( i +1)+1 : proved ■ z 2 i ≥ z 2( i +1) : by IH ■ 18 / 23

  22. Merge Networks Let us prove outputs are sorted decreasingly. For 1 ≤ i < n − 1 let us see: z 2 i ≥ z 2( i +1)+1 : proved ■ z 2 i ≥ z 2( i +1) : by IH ■ z 2 i +1 ≥ z 2( i +1)+1 : by IH ■ 18 / 23

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend