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

Decision Procedures for Linear Arithmetic

  • Upload
    kimi

  • View
    37

  • Download
    0

Embed Size (px)

DESCRIPTION

Decision Procedures for Linear Arithmetic. Presented By Omer Katz 01/04/14. Based on slides by Ofer Strichman. Agenda. DPLL-T (a very short reminder) What is Linear Arithmetic and why is it needed Decision procedures for Decision procedures for A few preprocessing improvement steps - PowerPoint PPT Presentation

Citation preview

Page 1: Decision  Procedures for Linear Arithmetic

1

Decision Procedures for Linear Arithmetic

Presented By Omer Katz01/04/14

Based on slides by Ofer Strichman

Page 2: Decision  Procedures for Linear Arithmetic

3

Agenda

DPLL-T (a very short reminder) What is Linear Arithmetic and why is it needed Decision procedures for Decision procedures for A few preprocessing improvement steps

Given enough time: Difference logic Delayed Theory Combination

Improvement on Nelson-Oppen Not related to Linear Arithmetic

Page 3: Decision  Procedures for Linear Arithmetic

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

Page 4: Decision  Procedures for Linear Arithmetic

5

Reminder: DPLL-T

Page 5: Decision  Procedures for Linear Arithmetic

6

Linear Arithmetic

Theory grammar:

Can be defined over Rational () or Integers ()

Example:

Page 6: Decision  Procedures for Linear Arithmetic

7

Why is it needed?

Given the following C code:

The following assembly can be generated:

Page 7: Decision  Procedures for Linear Arithmetic

8

Why is it needed?

A possible optimization: Read the value of a[j] only once

Need to verify that loop won’t change a[j] Can be encoded as Linear Arithmetic problem

If no solution is found, optimization is safe

Page 8: Decision  Procedures for Linear Arithmetic

9

Decision Procedures for

Gaussian’s elimination Fourier-Motzkin Simplex

Page 9: Decision  Procedures for Linear Arithmetic

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

Page 10: Decision  Procedures for Linear Arithmetic

11

Gaussian’s elimination

Manipulate A|b to an upper-triangular form

Then, solve backwards from the k’s row according to:

Page 11: Decision  Procedures for Linear Arithmetic

12

Gaussian elimination - example

And now… x3 = -1, x2 = 3, x1 = 1 problem solved.

Page 12: Decision  Procedures for Linear Arithmetic

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

Page 13: Decision  Procedures for Linear Arithmetic

14

Fourier-Motzkin Elimination

nnmnm

n

b

bb

x

xx

aa

aaaaa

::

::

......:::::

....

2

1

2

1

1

2221

11211

bIA A system of conjoined linear inequalities

m constraints

n variables

Page 14: Decision  Procedures for Linear Arithmetic

15

Fourier-Motzkin Elimination

1. When eliminating xn, partition the constraints according to the coefficient ain: ain > 0: upper bound ain < 0: lower bound

assume ai,n >0

Page 15: Decision  Procedures for Linear Arithmetic

16

Fourier-Motzkin Elimination

Example:(1) x1 – x2 ≤ 0(2) x1 – x3 ≤ 0(3) -x1 + x2 + 2x3 ≤ 0(4) -x3 ≤ -1

Assume we eliminate x1.Upper bound

Upper bound

Lower bound

Category?

Page 16: Decision  Procedures for Linear Arithmetic

17

Fourier-Motzkin Elimination

2. For each pair of a lower bound aln<0 andupper bound aun>0, we have

3. For each such pair, add a constraint

Page 17: Decision  Procedures for Linear Arithmetic

18

Fourier-Motzkin Elimination

Example:(1) x1 – x2 ≤ 0(2) x1 – x3 ≤ 0(3) -x1 + x2 + 2x3 ≤ 0(4) -x3 ≤ -1

(5) 2x3 ≤ 0 (from 1 and 3)(6) x2 + x3 ≤ 0 (from 2 and 3)

We eliminate x1.

Page 18: Decision  Procedures for Linear Arithmetic

19

Fourier-Motzkin Elimination

Example:(1) x1 – x2 ≤ 0(2) x1 – x3 ≤ 0(3) -x1 + x2 + 2x3 ≤ 0(4) -x3 ≤ -1

(5) 2x3 ≤ 0 (from 1 and 3)(6) x2 + x3 ≤ 0 (from 2 and 3)

(7) 0 ≤ -1 (from 4 and 5)Contradiction (the system is unsatisfiable)!

We eliminate x3.

Page 19: Decision  Procedures for Linear Arithmetic

20

Complexity of Fourier-Motzkin

Worst-case complexity: m2n

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

Page 20: Decision  Procedures for Linear Arithmetic

21

Simplex

Simplex was originally designed for solving optimization problems: Given coefficient matrix and bound vector find a

satisfying assignment that maximizes a goal function described by

Also known as Linear Programming

We are only interested in the feasibility problem If problem is feasible than it is satisfiable

Page 21: Decision  Procedures for Linear Arithmetic

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.

Page 22: Decision  Procedures for Linear Arithmetic

23

Converting to General Form

Replace (where )

with

and

s1,..., sm are called the additional variables.

Page 23: Decision  Procedures for Linear Arithmetic

24

Example 1

Convert

to:

Page 24: Decision  Procedures for Linear Arithmetic

25

Example 2

Convert

to:

Page 25: Decision  Procedures for Linear Arithmetic

26

Same problem, geometrically

Page 26: Decision  Procedures for Linear Arithmetic

27

Matrix form

x y s1 s2 s3

Due to the additional variables: now A is an m x (n + m) matrix.

Page 27: Decision  Procedures for Linear Arithmetic

28

The tableau

The diagonal part is inherent to the general form

Marked section will always be there

We can instead write:

x y s1 s2 s3

x ys1s2s3

Page 28: Decision  Procedures for Linear Arithmetic

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.

x ys1s2s3

Page 29: Decision  Procedures for Linear Arithmetic

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

Page 30: Decision  Procedures for Linear Arithmetic

31

The general simplex algorithm

Simplex maintains and updates: The tableau, an assignment to all variables The bounds

Two invariants:

All nonbasic variables satisfy their bounds

Page 31: Decision  Procedures for Linear Arithmetic

32

Invariants

Initially, B = additional variables N = problem variables (xi) = 0 for i {1,...,n+m}

Trivial to see that initial state satisfies invariants

Page 32: Decision  Procedures for Linear Arithmetic

33

The simplex algorithm

The initial assignment satisfies If the bounds of all basic variables are satisfied by ,

return `Satisfiable’

Otherwise... choose a variable and pivot Pivoting is the basic step of the algorithm

Page 33: Decision  Procedures for Linear Arithmetic

34

Pivoting

Find a basic variable xi that violates its bounds. Suppose that (xi) < li We need to fix the value of xi

Find a nonbasic variable xj such that aij > 0 and (xj) < uj, or aij < 0 and (xj) > lj

Such a variable xj is called suitable. If there is no suitable variable – return ‘Unsatisfiable’

Page 34: Decision  Procedures for Linear Arithmetic

35

Pivoting xi with xj

Solve equation i for xj:

From:

To:

Swap xi and xj, and update the i-th row accordingly.

From

To:

ai1 ... aij ... ain

-ai1

aij

... 1 aij

... -ain

aij

Page 35: Decision  Procedures for Linear Arithmetic

36

Pivoting xi with xj

Update all other rows: Replace xj with its equivalent obtained from row i:

Page 36: Decision  Procedures for Linear Arithmetic

37

Pivoting

Update as follows: Increase (xj) by

Now xj is a basic variable: it can violate its bounds.

Update (xi) to li

Update for all other basic (dependent) variables.

Page 37: Decision  Procedures for Linear Arithmetic

38

Example

Recall the tableau and constraints in our example:

Initially assigns 0 to all variables Bounds of s1 and s3 are violated

Page 38: Decision  Procedures for Linear Arithmetic

39

Example

Recall the tableau and constraints in our example:

We will pivot on s1

x is a suitable nonbasic variable for pivoting It has no upper bound

So now we pivot s1 with x

Page 39: Decision  Procedures for Linear Arithmetic

40

Example

Recall the tableau and constraints in our example:

Solve 1st row for x: Replace x with s1 in other rows:

Page 40: Decision  Procedures for Linear Arithmetic

41

Example

The new state:

Solve 1st row for x: Replace x with s1 in other rows:

Page 41: Decision  Procedures for Linear Arithmetic

42

Example

The new state:

We should increase x by Hence, (x) = 0 + 2 = 2 Now s1 is equal to its lower bound: (s1) = 2 Update all the others

Page 42: Decision  Procedures for Linear Arithmetic

43

Example

The new state:

Now s3 violates its lower bound y is a suitable nonbasic variable for pivoting

Page 43: Decision  Procedures for Linear Arithmetic

44

Example

The new state:

We should increase y by

Page 44: Decision  Procedures for Linear Arithmetic

45

Example

The final state:

All constraints are now satisfied

Page 45: Decision  Procedures for Linear Arithmetic

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).

Page 46: Decision  Procedures for Linear Arithmetic

47

A few observations

Can it be that we pivot(xi,xj) and then pivot(xj,xi) and enter a (local) cycle ? No.

Is termination guaranteed ? No. Perhaps there are bigger cycles.

Page 47: Decision  Procedures for Linear Arithmetic

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

Page 48: Decision  Procedures for Linear Arithmetic

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

Page 49: Decision  Procedures for Linear Arithmetic

50

Decision Procedures for

Decision problem for is NP-hard Unlike

Branch & Bound Cuts

Omega test Based on Fourier-Motzkin elimination Will not be discussed today

Page 50: Decision  Procedures for Linear Arithmetic

51

Decision Procedures for

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

Page 51: Decision  Procedures for Linear Arithmetic

52

x1

x2

Non-Integral Solution

Is there a difference?

52

Previous methods found non-integral solutions

Rounding will not suffice

Page 52: Decision  Procedures for Linear Arithmetic

53

Is there a difference?

Previous methods found non-integral solutions

Rounding will not suffice No guarantee that integral

solution exists

53

x1

x2

Page 53: Decision  Procedures for Linear Arithmetic

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

x1=0

x2=0 x2=2x2=1

x1=1 x1=2

x2=0 x2=2x2=1x2=0 x2=2x2=1

Page 54: Decision  Procedures for Linear Arithmetic

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

Page 55: Decision  Procedures for Linear Arithmetic

56

x2≤1

Splitting on non-integral solutions.

x1

x2

x1

x2

Solve Relaxation to get Non-Integral solutions If relaxation is infeasible, prune branch

Create two sub-branches by adding constraints

x2≥2

Non-integral solution

Page 56: Decision  Procedures for Linear Arithmetic

57

Example

Suppose our system A has variables x1… x4, and that the solver returned a solution (1, 0.7, 2.5, 3).

Choose one of x2, x3. Suppose we choose x2. Solve two new problems:

A1 = A {x2 0} A2 = A {x2 1}

Clearly A1 or A2 are satisfiable iff A is.

Page 57: Decision  Procedures for Linear Arithmetic

58

The branch and bound tree

A

A2 A1

A12 A11

(1,0 .7,2.5,3)

(1,-1.5,1.5,4.1)

x2 · 0 x2 ¸ 1

x3 ¸ 1

(1,3,0.5,2)

(1,3,0.5,2)

x3 · 0

(1,3,4,1) x

Each leaf is a feasible solution.

Pruned due to infeasibility

Page 58: Decision  Procedures for Linear Arithmetic

59

Termination

x

y

Does B & B guaranteed to terminate ? No.

For example: Consider a constraint like This constraint won’t terminate

Page 59: Decision  Procedures for Linear Arithmetic

60

Termination

Does B & B guaranteed to terminate ? No.

For example: Consider a constraint like This constraint won’t terminate

It is always possible to find tighter bounds on variable values Will not be discussed

Page 60: Decision  Procedures for Linear Arithmetic

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

x1

x2

Added Cut

Page 61: Decision  Procedures for Linear Arithmetic

63

Cutting Planes

Cutting planes might never find a solution Will get exponentially closer to a solution

Usually applied in conjunction with Branch & Bound

x1

x2

Added Cut

Page 62: Decision  Procedures for Linear Arithmetic

64

Cutting planes

Adding valid inequalities

Examples: From 2x 11

we can conclude x 5 What can be learned from the bounds , the constraint and

the assignment ?

Page 63: Decision  Procedures for Linear Arithmetic

65

Cutting planes

Examples: What can be learned from the bounds , the constraint and

the assignment ?

We know that the following currently holds:

We need to make both sides of the equation integers

Page 64: Decision  Procedures for Linear Arithmetic

66

Cutting planes

Examples: We need to make both sides of the equation integers

1, 0.5 are lower bounds therefore right side of equation is positive

Therefore:

In case of upper bounds replace “” with “”

New constraint eliminates current assignment

Page 65: Decision  Procedures for Linear Arithmetic

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 formand assignment

Split nonbasic variables into 2 groups:

Page 66: Decision  Procedures for Linear Arithmetic

68

Gomory cuts

Substract bounds from constraint

And make left side integer

Page 67: Decision  Procedures for Linear Arithmetic

69

Gomory cuts

Further split J and K:

Page 68: Decision  Procedures for Linear Arithmetic

70

Gomory cuts

If right side is positive:

Page 69: Decision  Procedures for Linear Arithmetic

71

Gomory cuts

If right side is negative:

Page 70: Decision  Procedures for Linear Arithmetic

72

New constraint:

Gomory cuts

Could probably be 2

Page 71: Decision  Procedures for Linear Arithmetic

73

Preprocessing

Constraints can be removed Example:

x1 + x2 2, x1 1, x2 1 First constraint is redundant.

In general, for a set:

is redundant if

Page 72: Decision  Procedures for Linear Arithmetic

74

Preprocessing

Bounds can be tightened Example:

2x1 + x2 2, x2 4, x1 3 From 1st and 2nd constraints: x1 -1

In general, if a0 > 0

And, if a0 < 0

Page 73: Decision  Procedures for Linear Arithmetic

75

Preprocessing (Only for integers)

Convert strict inequalities to non-strict inequalities Example:

Given inequality

Rewrite as Or

Page 74: Decision  Procedures for Linear Arithmetic

77

Questions?