artificial intelligence and lisp #11 satisfiability solvers (sat techniques) constraint propagation

35
Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Post on 22-Dec-2015

231 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Artificial Intelligence and Lisp #11

Satisfiability Solvers (SAT Techniques)

Constraint Propagation

Page 2: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Lab statistics 2009-11-09

Registration: 50 students

Number of: lab2a lab2b lab3a lab3b lab4a ---------------------------------Reg. Downloads 46 42 23 16Orphan downloads 3 2 1 0Lab completed 39 16 13 8Incomplete upload 1 3 0 1

Page 3: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Remember from lecture #9: Details of proof[a? [b? [c? red green] [c? blue white]] [b? [c? white red] [c? blue green]]]

white-a v -b v -c v red | -red-a v -b v c v green | -a v -b v -c-a v b v -c v blue | a v -b v c-a v b v c v white | -greena v -b v -c v white | -a v -b v ca v -b v c v red | a v b v ca v b v -c v blue | -bluea v b v c v green | -a v b v -c-white v -red | a v b v -c-white v -green | -b v c -white v -blue (and more...) | b v -c | (-b v c) & (b v -c) | (b -> c) & (c -> b) | b <-> c

Page 4: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Propositional vs Predicative Representation

• Propositional: each literal is a proposition symbol or its negation. Simple resolution operator.

• Predicative: literals are formed using a predicate symbol and its arguments, which may be formed using function symbols, variables, and constant symbols. Resolution is generalized to include unification (substitution of subexpressions for variables)

• Predicative representation is often necessary (rabbit offspring example!)

Page 5: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Propositional vs Predicative Representation

• Propositional: each literal is a proposition symbol or its negation. Simple resolution operator.

• Predicative: literals are formed using a predicate symbol and its arguments, which may be formed using function symbols, variables, and constant symbols. Resolution is generalized to include unification (substitution of subexpressions for variables)

• Predicative representation is often necessary (rabbit offspring example!)

• Idea in SAT solvers: work with very large numbers of propositional clauses (even millions). Use computational brute force with very efficient algorithms.

Page 6: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Boolean Satisfiability Problem (SAT)

• Given: a set of propositional clauses

• Question: does there exist an assignment of truthvalues to the proposition symbols whereby all the clauses are true?

• In other words, does there exist an assignment whereby at least one of the literals in each clause is true?

• Two main methods: (1) The DPLL Procedure: search the space of truthvalue assignments in a systematic, depth-first way

• (2) Stochastic Local Search: Pick one assignment randomly, then change the value of one proposition symbol at a time

Page 7: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

A Very Simple Example

a, -b, ca, b, d-aa, -ca, -d

a, c, dc, da, ddaFalse

Consider each clause as a set of literals, and the empty set as False

Page 8: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Completeness theorem

• If there does not exist an assignment of truth values whereby all given clauses are made true, then the resolution operator can produce the empty clause

• If there exists an assignment of truth values whereby all given clauses are made true, then the resolution operator can not produce the empty clause

• Proof for the second part: Consider a case where there is such an assignment, and assume that there is a resolution sequence leading to False. One can easily see that if two clauses are true with a given assignment, then any clause that is obtained by resolving them is also true with that assignment. By induction, this holds for all clauses in the resolution sequence. However, the last step before arriving to False must resolve two unit clauses e.g. a and -a. This is impossible.

Page 9: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Proving that A |- c

• Suppose that A is a set of clauses and c is a clause

• Obtain A' by adding the negation of c to A

• Try to prove that A' leads to False. If you succeed then you have also proved that A leads to c

• One way of proving that A leads to False is to show that there does not exist any assignment of truth values whereby all clauses in A' are true

• Proving that such an assignment does not exist can be done by making an exhaustive search for it; if the exhaustive search fails then the assignment does not exist.

Page 10: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Example

• Given: a v b, a → c, c → d, b → e

• Try to prove: d v e

• Rewrite as: {a, b}, {-a, c}, {-c, d}, {-b, e}, {-d}, {-e}

• Resolution obtains: {c, b}, {d, b}, {d, e}, {e}, {}

• Another way of doing the resolutions: {-c}, {-a}, {b}, {e}, {}; this does resolutions using a unit preference strategy

• In the first resolution sequence we obtained the desired conclusion just before we obtained False i.e. {}

• In the second resolution sequence we did not have the desired conclusion as an intermediate result.

Page 11: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Summing up so far

• In order to prove A |- c, form A' by adding the negation of c to A, and prove that A' leads to a contradiction (False, empty clause)

• A' leads to a contradiction if and only if there does not exist any assignment of truth values to proposition symbols whereby all clauses in A' are true

• SAT is a method for determining exactly that

• Notice that it may not be necessary to know the exact assignment, just to know whether it exists!

Page 12: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

The DPLL Procedure

• DPLL = Davis-Putnam-Logemann-Loveland, after the inventors of the basic procedure (long ago)

• The procedure obtains its strengths by the various “plug-in” methods that have been developed for it

• Basic algorithm for a given set A of clauses:

• Pick one of the prop symbols, e.g. p, and construct one modification of A for each of the two truth-values. Obtain A[p] by removing all clauses containing p and by removing -p in all clauses where they occur. Similarly for A[-p].

• Repeat the same operation with another prop symbol, obtaining e.g. A[p,-q], and proceed recursively obtaining a search tree.

• If a branch obtains a descendant of A containing both {a} and {-a} for some literal a, then close that branch, i.e. do not expand the tree further from that point. This is called a conflict.

• If you can find a branch where all the prop symbols have a value, then you have found an assignment. If all branches become closed then no assignment can exist whereby all clauses are true.

Page 13: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Implementation considerations for DPLL• Do a (modified) depth-first search, not a breadth-first search

of the tree of possible assignments

• Implement iteratively rather than using recursion

• Literals in unit clauses are immediately set to true (as a preprocessing step and during the computation), except if you have a conflict (in which case close that branch)

• Proposition symbols that only occur positively in all the given clauses are immediately set to true and those clauses are removed. Conversely for those prop symbols that only occur negatively

• Decision strategies must be used; a large number of these have been developed. A decision strategy gives rules for which proposition symbol to consider next, and which value to choose for it

Page 14: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Example, revisited

• Given: a v b, a → c, c → d, b → e

• Try to prove: d v e

• Rewrite as: {a, b}, {-a, c}, {-c, d}, {-b, e}, {-d}, {-e}

• Select d and e false since they occur in unit clauses, obtaining {a, b}, {-a, c}, {-c}, {-b}

• Select c and b false for the same reason, obtaining {a}, {-a} which is a conflict

• The current branch must be closed, but it is the only one, so no assignment can be found

• Important: the actual implementation does not rewrite the set of clauses, it just keeps track of the current, partial assignment of truth-values to proposition symbols

Page 15: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Examples of Decision Strategies

• Maximum Occurrence in clauses of Minimum Size (MOMS) as a goodness measure for selecting prop symbol

• Dynamic Largest Individual Sum (DLIS): choose the literal occurring the most frequently in the clauses at hand

• Variable State Independent Decaying Sum (VSIDS): keep track of the 'weight' of each literal, allow it to 'decay' i.e. it is gradually reduced over time, but if a literal is used for closing a branch then it is 'boosted' (its value is increased) for use elsewhere in the search tree

• There are also several other decision strategies.

Page 16: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

The Watched Literals Scheme

• The purpose of this scheme is to reduce the amount of bookkeeping for truth-value assignments after backup in an iterative implementation of DPLL. It is used in most contemporary SAT systems.

• Maintain two literals in each clause, called its watched literals. These must be unassigned or true in the current assignment

• Maintenance when a literal a is set to False: (1) In every clause that has a as a watched literal, find another one to watch

• (2) In every clause containing -a, make that one of its two watched literals, replacing one of the present ones

• Corresponding operation when a is set to True i.e. -a to False

• Then, as long as you descend recursively into the tree, to check whether a clause is satisfied you merely check its two watched literals

• Also, when you backtrack, it is not necessary to update the watched literals; they will self-adjust after a while. Until then the computation is less efficient, but the overall efficiency is much improved.

Page 17: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Clause learning and Randomized Restart

• Modify the basic algorithm as follows. When you arrive to a conflict then analyze the situation and identify what clauses contributed to the conflict. Extract one or more additional “learned” clauses that are added to the given ones. Also, identify the level in the search tree that one has to return to. Proceed from there.

• Randomized restart: restart the search process from the root of the search tree, but retain the learned clauses.

• The purpose of these techniques is to let the process “learn” more direct ways of arriving to the desired result in the sense of the closing of a branch in the search tree

Page 18: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Backtrack Strategies

• Conflict-directed backjumping, Fast backjumping: Suppose at one point in the tree you have assigned True to a prop symbol a, and further down in the tree you have a particular locality condition (details omitted). These strategies allow you to close the entire subtree under a = True and to switch to the assignment a = False (or to backup further if that assignment has also been closed.

• Randomized restart can be thought of as kind of backtrack strategy.

Page 19: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

State of the Art for SAT Solvers

• SAT solvers have been strikingly successful, both within Artificial Intelligence and in other areas

• In principle, they provide an “engine” for combinatorial reasoning and search which is able to handle very large sets of clauses

• A theorem-proving program that draws conclusions using e.g. the resolution operator is another example of such an “engine” or “platform”

• A SAT solver uses a more primitive representation, but it has the advantage of a number of very efficient implementation techniques

Page 20: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

From predicative to propositional representation

• Predicative: use predicates, functions, constants, variables, quantifiers

• Propositional: none of those, just 'atomic' proposition symbols

• Conversion of a predicative formulation to a propositional one, at the expense of large increase in size:

• For every predicate and every combination of constant-symbol arguments, introduce a proposition symbol

• For every predicate with variables in some of the arguments, generate all possible instances

• For every function, do the same with its arguments and introduce new constant symbols

Page 21: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Example of Propositional Conversion

• Given: P(a,b), -P(a,c), P(c,c)

• Construct proposition symbols Paa, Pab, Pac, Pba,...

• Add also P(f(a),c) as given

• Add constant symbols Fa, Fb, Fc and proposition symbols PFaa, PFab, ... obtaining altogether 36 prop symbols

• In the general case we must also add constant symbols FFa, FFb, and FFFa, etc. which means we obtain an infinite set of proposition symbols, which means it is not amenable to SAT

• Type restrictions may prevent recursive use of functions, for example in (the-bodypart Groucho lefthand)

Page 22: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Requirements for Propositional Conversion

• Finite number of 'objects' in the domain

• Individual names for all the objects

• No function symbols, or restrictions on their use so that arbitrarily large terms can not be formed

• The application of a function on arguments shall result in a new 'object'. No rules such as

• father(Groucho) = father(Bronx)

• (or at least, the existence of such rules make things much more difficult)

Page 23: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Statistical Local Search Techniques

• Approach: pick one assignment randomly, then change the value of one proposition symbol at a time

• A number of techniques of this kind exist. We only consider one, called GSAT (G for Greedy)

• Basic idea in GSAT: Start with an randomly chosen assignment. Calculate, for each proposition symbol, the increase or decrease in the number of clauses that become true if the value of that prop symbol is reversed. Pick the one that gives the best increase.

• Repeat this process until a satisfying assignment has been found or a maximum number (max-flips) has been reached

• If max-flips has been reached, then try another randomly chosen assignment. Repeat until success or until a maximum number (max-tries) has been reached.

Page 24: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

What Happens in Practice with GSAT

• When it was new, it outperformed even the best backtracking algorithms on several types of test problems

• The process does not very often get stuck in local minima

• Very often, it gets to a 'plateau' of assignments of roughly equal value, moves around there, and then moves to a lower 'plateau'

• Such a plateau often seems to have fairly well-defined 'exits' to lower plateaus, and the problem for the search is to find those. Otherwise the search may spend quite long time within one plateau

• One method for this is to let a certain, random proportion of moves go upward when the search finds itself in a plateau. This was first proposed by the Walksat strategy.

Page 25: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Phase Transition in Random k-SAT

• In order to study the computational properties of statistical SAT techniques, it is common to focus on e.g. 3-SAT problems where all clauses contain exactly 3 literals. Randomized sets of clauses are generated for experiments.

• Each 3-SAT problem is characterized by the number of clauses and the number of prop symbols. Consider the ratio between these.

• Now, in each problem, identify the computation time during the random search, and the outcome (satisfiable or not).

• Observation 1: The computation time has a distinct maximum at a ratio around 4.26. This maximum becomes more sharp when the size of the problem increases.

• Observation 2: The same value is the point of switch from mostly satisfiable to mostly unsatisfiable, and this also becomes more distinct for larger problems.

Page 26: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Phase Transition Problems in General

• The observation of phase transition behavior in 3-SAT has counterparts for several other kinds of random-search techniques

• On the mathematical level, this is related to the process of annealing in material science; the search can be viewed as “simulated annealing”

• There is interesting research on using this in the context of entirely new types of computing hardware

Page 27: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Next Topic: Constraint Programming

Example: SEND + MORE MONEYExpressed in logic programming:

sendmore(Digits) :- Digits = [S,E,N,D,M,O,R,Y], % Create variables Digits :: [0..9], % Associate domains S #\= 0, % Constraint M #\= 0, alldifferent(Digits), % all the elements % must take different values % Additional constraint: 1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E #= 10000*M + 1000*O + 100*N + 10*E + Y, .... (start the search)

Page 28: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Constraint Programming

• In general, a constraint programming problem specifies:

• A set of “variables”

• A domain of possible values for each variable

• A set of constraints (“relations”) on these variables

• An assignment of values to the variables that satisfies the restrictions is a solution to the constraint programming problem

• Constraint programming is a programming technique where a programming language contains a facility for stating and solving constraint programming problems

• Logic programming was the original host language for constraint programming. In this case we talk of constraint logic programming.

Page 29: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Constraint Programming, SAT, host languages

• SAT is a constraint problem

• SAT solvers are not typical examples of constraint programming, since they are not tied to a host programming language

• A tight integration of constraint programming in its host language requires it to use as much as possible the data structures, declarations, and operators on data that are provided by the host language

• Therefore, constraint programming is the most easily hosted by languages with an interpretive character, e.g. functional programming languages (including Lisp and Scheme) and even Java, besides logic programming languages.

• However, Constraint programming packages exist even for C++. (See Wikipedia article on Constraint Programming).

Page 30: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Constraint Programming and SAT Solvers

• In spite of that difference, Constraint Programming is related to SAT solvers in the sense that many of the efficiency improving techniques of SAT solvers have counterparts in constraint programming:

• Both systematic search and local random search are used for constraint programming

• Backjumping and random restart techniques are used in constraint programming as well

• A local inconsistency in a CP problem is an assignment of values to some of the variables that does not violate any of the constraints, but which can not be extended with an assignment to one more variable, so it can not be part of a solution – it requires backup in the case of depth-first search. This corresponds to a conflict in a SAT solver.

Page 31: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Arc consistency

• Arc consistency is an important kind of local consistency

• Given a constraint, a value for a variable in the constraint has support there iff there exist values for the other variables in the constraint such that the constraint is satisfied.

• Example: the value 0 for the variable x does not have support in the constraint x * y = 100, but the value 5 for the variable x does have support

• A constraint is arc consistent if every value in the domain of every variable in the constraint has support

• The pruning operation removes unsupported values from the domains of variables. Each constraint can be made arc consistent in this way.

Page 32: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Systematic Search + Pruning

• A very common framework in constraint programming is to do a systematic search for variable assignments, but with additional operations in each step of the search

• Pruning is one such operation that can be interleaved with the search. There are different varieties of pruning

• More generally, search is interleaved with constraint propagation, i.e. using some of the constraints for modifying the assignment at hand

• There is a tradeoff between how much time to spend on pruning or other constraint propagation, and how much to spend on just proceeding with the search.

Page 33: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Global constraints

• A “global constraint” (better called a generic constraint) is a constraint affects all, or many of the variables, and that can be used in many applications

• Constraint programming packages typically provide support for a number of global constraints

• The alldifferent constraint (all variables, or a given set of variables must have different values) is a widely used global constraint

• The global cardinality constraint (gcc) is a generalization which provides a lower and an upper bound on the number of variables having the same value

Page 34: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Distributed Constraint Programming

• Problem: given a set of communicating agents each of which has its own set of constraints for the same (or overlapping) sets of variables, find an assignment of values to the variables that satisfies all the constraints in all the agents.

Page 35: Artificial Intelligence and Lisp #11 Satisfiability Solvers (SAT Techniques) Constraint Propagation

Conclusion

• SAT solvers, constraint programming packages, and resolution theorem-proving programs all provide “engines” or “platforms” for combinatorial reasoning and search which can be used in various applications, both for specific applications and as parts of larger systems, and both within AI and outside

• The concept of an “engine” or “platform” is an important one. A relational database system is an example of a “platform” in mainstream computing

• In Artificial Intelligence there is also a number of examples of more specialized “engines”, for example for action planning (remember partial-order planning!), and for diagnostic reasoning (covered in a later course).