Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Decision Procedures for Linear Arithmetic Presented By Omer Katz 01/04/14 Based on slides by Ofer Strichman.

Similar presentations


Presentation on theme: "1 Decision Procedures for Linear Arithmetic Presented By Omer Katz 01/04/14 Based on slides by Ofer Strichman."— Presentation transcript:

1 1 Decision Procedures for Linear Arithmetic Presented By Omer Katz 01/04/14 Based on slides by Ofer Strichman

2 2 Disclaimer

3 3 Agenda

4 4 Reminder: DPLL-T Our goal is to solve SMT problems with formulas from a theory T DPLL-T is the most common approach  Based on the DPLL algorithm for SAT problems  Combines a decision procedure for the theory T

5 5 Reminder: DPLL-T

6 6 Linear Arithmetic

7 Why is it needed? Given the following C code: The following assembly can be generated: 7

8 Why is it needed? 8

9 9 Gaussian’s elimination Fourier-Motzkin Simplex

10 10 Gaussian’s elimination A simple method for solving a set of equalities  Less suitable for inequalities Given a linear system Ax = b A x = b

11 11 Gaussian’s elimination Manipulate A|b to an upper-triangular form Then, solve backwards from the k ’s row according to:

12 12 Gaussian elimination - example And now… x 3 = -1, x 2 = 3, x 1 = 1 problem solved.

13 13 Fourier-Motzkin Elimination Earliest method for solving linear inequalities Given linear non-strict inequalities:  Pick a variable and eliminate it  Continue until all variables but one are eliminated If problem included equalities, eliminate by assignment

14 14 Fourier-Motzkin Elimination A system of conjoined linear inequalities m constraints n variables

15 15 Fourier-Motzkin Elimination 1.When eliminating x n, partition the constraints according to the coefficient a in :  a in > 0: upper bound  a in < 0: lower bound assume a i, n >0

16 16 Fourier-Motzkin Elimination Example: (1) x 1 – x 2 ≤ 0 (2) x 1 – x 3 ≤ 0 (3) -x 1 + x 2 + 2x 3 ≤ 0 (4) -x 3 ≤ -1 Assume we eliminate x 1. Upper bound Lower bound Category?

17 17 Fourier-Motzkin Elimination 2.For each pair of a lower bound a ln 0, we have 3.For each such pair, add a constraint

18 18 Fourier-Motzkin Elimination Example: (1) x 1 – x 2 ≤ 0 (2) x 1 – x 3 ≤ 0 (3) -x 1 + x 2 + 2x 3 ≤ 0 (4) -x 3 ≤ -1 (5) 2x 3 ≤ 0 (from 1 and 3) (6) x 2 + x 3 ≤ 0 (from 2 and 3) We eliminate x 1.

19 19 Fourier-Motzkin Elimination Example: (1) x 1 – x 2 ≤ 0 (2) x 1 – x 3 ≤ 0 (3) -x 1 + x 2 + 2x 3 ≤ 0 (4) -x 3 ≤ -1 (5) 2x 3 ≤ 0 (from 1 and 3) (6) x 2 + x 3 ≤ 0 (from 2 and 3) (7) 0 ≤ -1 (from 4 and 5) Contradiction (the system is unsatisfiable)! We eliminate x 3.

20 20 Complexity of Fourier-Motzkin Worst-case complexity: m 2 n Popular in compilers  Because of simplicity Popular when the problems are small – then it can be the fastest.  Not suitable for large problems Need another solution for big problems

21 21 Simplex

22 22 General form Given same input as Fourier-Motzkin, convert input to general form General form: A combination of:  Linear equalities of the form  Lower and upper bounds on variables.

23 23 Converting to General Form Replace (where ) with and s 1,..., s m are called the additional variables.

24 24 Example 1 Convert to:

25 25 Example 2 Convert to:

26 26 Same problem, geometrically

27 27 Matrix form xys1s2s3xys1s2s3 Due to the additional variables:  now A is an m x ( n + m ) matrix.

28 28 The tableau The diagonal part is inherent to the general form  Marked section will always be there We can instead write: xys1s2s3xys1s2s3 xyxy s1s2s3s1s2s3

29 29 The tableau The tableau changes throughout the algorithm, but maintains its m x n structure Distinguish between basic and nonbasic variables Initially, basic variables = the additional variables. xyxy s1s2s3s1s2s3

30 30 The tableau Denote by  B – Basic variables  N – Nonbasic variables The tableau is simply a rewrite of the system: The basic variables are also called the dependent variables.  Their value is determined by the values of the other variables

31 31 The general simplex algorithm

32 32 Invariants

33 33 The simplex algorithm

34 34 Pivoting

35 35 Pivoting x i with x j Solve equation i for x j : From: To: Swap x i and x j, and update the i -th row accordingly. From To: a i1... a ij... a in - a i1 a ij... 1 a ij...- a in a ij

36 36 Pivoting x i with x j Update all other rows:  Replace x j with its equivalent obtained from row i :

37 37 Pivoting

38 38 Example Recall the tableau and constraints in our example: Initially  assigns 0 to all variables Bounds of s 1 and s 3 are violated

39 39 Example Recall the tableau and constraints in our example: We will pivot on s 1 x is a suitable nonbasic variable for pivoting  It has no upper bound So now we pivot s 1 with x

40 40 Example Recall the tableau and constraints in our example: Solve 1 st row for x : Replace x with s 1 in other rows:

41 41 Example The new state: Solve 1 st row for x : Replace x with s 1 in other rows:

42 42 Example The new state: We should increase x by  Hence,  ( x ) = 0 + 2 = 2  Now s 1 is equal to its lower bound:  ( s 1 ) = 2  Update all the others

43 43 Example The new state: Now s 3 violates its lower bound y is a suitable nonbasic variable for pivoting

44 44 Example The new state: We should increase y by

45 45 Example The final state: All constraints are now satisfied

46 46 A few observations The additional variables:  Only additional variables have bounds.  These bounds are permanent.  Additional variables exit the base only on extreme points (their lower or upper bounds).  When entering the base, they shift towards the other bound and possibly cross it (violate it).

47 47 A few observations Can it be that we pivot( x i, x j ) and then pivot( x j, x i ) and enter a (local) cycle ?  No. Is termination guaranteed ?  No.  Perhaps there are bigger cycles.

48 48 A few observations In order to avoid circles, we use Bland’s rule:  determine a total order on the variables.  Choose the first basic variable that violates its bounds, and first nonbasic suitable variable for pivoting.  It can be proven that this guarantees that no base is repeated, which implies termination. We won’t prove this

49 49 A few observations Simplex is exponential in the worst case However, considered very efficient on most real practical problems  Need for exponential number of steps is rare

50 50

51 51 Both Branch & Bound and Cuts rely on a solver to provide a (possibly non-integer) solution  For example: Simplex All variables in the final solution must be integers  In the case of simplex, this does not includes the additional variables The additional variables do not have to be a part of the outputted solution

52 x1x1 x2x2 Non-Integral Solution 52 Is there a difference? 52 Previous methods found non-integral solutions Rounding will not suffice

53 53 Is there a difference? Previous methods found non-integral solutions Rounding will not suffice No guarantee that integral solution exists 53 x1x1 x2x2

54 54 Assume that all variables are finite. Enumerate all solutions with a tree Guaranteed to find a feasible solution if it exists But, exponential growth in the size of the tree / computation time A naïve solution x 1 =0 x 2 =0x 2 =2x 2 =1 x 1 =1 x 1 =2 x 2 =0x 2 =2x 2 =1x 2 =0x 2 =2x 2 =1

55 55 Branch and Bound The main idea:  Solve the ‘relaxed’ problem, i.e. no integrality constraints.  If the relaxed problem is infeasible – backtrack (there is no integer solution in this branch)  If the solution is integral – terminate (‘feasible’).  Otherwise split on a variable for which the assignment is non-integral, and repeat for each case. Branch & Bound is guaranteed to find an integer solution if one exists Branch & Bound can extended to handle the case where some of the variables are integers and some remain rational

56 56 x 2 ≤1 Splitting on non-integral solutions. x1x1 x2x2 x1x1 x2x2 Solve Relaxation to get Non-Integral solutions  If relaxation is infeasible, prune branch Create two sub-branches by adding constraints x2≥2x2≥2 Non-integral solution

57 57 Example

58 58 The branch and bound tree A A2A2 A1A1 A 12 A 11 (1,0.7,2.5,3) (1,-1.5,1.5,4.1) x 2 · 0 x 2 ¸ 1 x 3 ¸ 1 (1,3,0.5,2) x 3 · 0 (1,3,4,1) x Each leaf is a feasible solution. Pruned due to infeasibility

59 59 Termination x y

60 60 Termination

61 61 Bounds

62 62 Improvement - Cutting Planes Eliminate non-integer solutions by adding constraints (i.e. improve tightness of relaxation). All feasible integer solutions remain feasible Last non-integer solution is not feasible x1x1 x2x2 Added Cut

63 63 Cutting Planes Cutting planes might never find a solution  Will get exponentially closer to a solution Usually applied in conjunction with Branch & Bound x1x1 x2x2 Added Cut

64 64 Cutting planes

65 65 Cutting planes

66 66 Cutting planes

67 67 Gomory cuts If basic variable as non-integer value and all nonbasic variables are at bounds => we can apply cut Given constraint of the form and assignment Split nonbasic variables into 2 groups:

68 68 Gomory cuts Substract bounds from constraint And make left side integer

69 69 Gomory cuts Further split J and K:

70 70 Gomory cuts If right side is positive:

71 71 Gomory cuts If right side is negative:

72 New constraint: 72 Gomory cuts Could probably be 2

73 73 Preprocessing

74 74 Preprocessing

75 75 Preprocessing (Only for integers)

76 76 Preprocessing (Only for integers) Convert rational coefficients to integer coefficients  multiply all coefficients with their lowest common multiple of the coefficients This will result in a all integer coefficient tableau and will promise that in a satisfying solution the additional variables will also be integers Usually not required and strictly optional  Previous preprocessing steps should be performed in order to improve algorithm performance (reduce run time, etc…)

77 Questions? 77

78 Difference Logic 78

79 79 Difference Logic

80 80 Difference Logic

81 81 Decision procedure for Difference Logic

82 Delayed Theory Combination 82

83 83 Delayed Theory Combination Delayed Theory Combination is an improvement on the Nelson-Oppen combination schema

84 84 Why do we need it?

85 85 Why do we need it? Nelson-Oppen  Combine 2 theories by exchanging interface variable equalities Problem:  requires equality deduction complete solver Solution:  can use non- deterministic version

86 86 Why do we need it? Non-Deterministic Nelson-Oppen  Equalities of interface variables creates equivalence classes  Instead of deducting equivalences, guess them Presented last week as “abstract version” Problem:  expensive to guess all classes Solution:  incremental guessing

87 87 Why do we need it? Incremental Non-Deterministic Nelson-Oppen  Don’t guess complete equivalence classes  At each step guess equivalence between 2 variables  Prune branch is are unsatisfiable Problem:  still requires a separate solver for each combination of theories Also a problem in other variants of Nelson-Oppen Solution:  Delayed Theory Combination

88 88 Delayed Theory Combination Don’t combine theories in theory solver Combine in SAT level by requiring consistency on interface variables For each pair of interface variables, add boolean variable to indicate they are equal Allow SAT solver to enumerate assignments to interface variable equivalence  These variables are assigned last

89 89 Delayed Theory Combination

90 90 Delayed Theory Combination Advantages:  Theory solvers can be developed separately  Easier to add theories to combination  Reasoning over interface variable equivalence is left to SAT solver Can use better heuristics to choose assignment  Equivalence of interface variable can be an integral part of conflict clauses

91 91 Delayed Theory Combination


Download ppt "1 Decision Procedures for Linear Arithmetic Presented By Omer Katz 01/04/14 Based on slides by Ofer Strichman."

Similar presentations


Ads by Google