Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 5: Constraint Satisfaction

Similar presentations


Presentation on theme: "Lecture 5: Constraint Satisfaction"— Presentation transcript:

1 Lecture 5: Constraint Satisfaction
Definition and examples Properties of CSP problems Heuristics arc-consistency checking heuristic repair most-constrained first Heshaam Faili University of Tehran

2 Constraint Satisfaction Problems
Many problems can be formulated as finding a solution, possibly optimal, that satisfies a set of constraints. built a time table for the next semester with the minimum number of conflicts schedule air crew assignments so that pilots don’t fly too many hours, have evenly-spaced breaks, … find a 0/1 assignment to a propositional formula 8-queen problem, crypto arithmetic

3 CSP as a search problem (1)
State: a set of variables x1, x2, …,xn variable domains D1, D2 …Dn state vector (x1, x2, x3, … xn) with instantiated and uninstantiated variables Rule: constraints relating the variables xi  xj,  xi = 1, min f(x1, x2, …,xn) Start state: vector of uninstantiated variables Goal state: instantiated vector that satisfies all the constraints

4 Examples of CSP formulation
Cryptoarithmetic problem F O R T Y T E N S I X T Y Solution F=2, O=9 R=7, T=8 Y=6, E=5 N=0, I=1, X=4 8-queens problem Time-table schedule Mon Tue Wed Thu Fri 8 9 10 11

5 CSP and Constraint Graph

6 CSP as a search problem (2)
Simplest form: discrete and finite domain For n variables and domain size d the possible assignments are O(dn) Boolean CSP: domains are boolean, like 3SAT , special case of NP-complete Infinite domain: no exact solution can be found Linear constraints Non-linear constraints Continuous domains: The best-known category is linear programming Constraints are linear inequalities forming a convex region Constraints: Unary: involve only one variable: can be eliminated by remove any value violate the constraint from the domain of that variable Binary: involves two variables (like 8-queen) Higher-order : like crypt arithmetic

7 Higher-order Constraints
Can be represented by a constraints hyper-graph prove, every higher-order, finite-domain constraint can be reduced to a set of binary constraints if enough auxiliary variables are introduced.

8 Backtracking in CSP For n variables with d value in each domain
Branching factor for level 1 is nd, level 2 is (n-1)d, level 3 is (n-2)d, … Tree has n!dn leaves while there are only dn possible assignments Commutativity: if the order of application of any given set of actions has no effect on the outcome. CSPs are commutative all CSP search algorithms generate successors by considering possible assignments for only a single variable at each node in the search tree In root node of Australia region coloring: we choice between SA = red, SA = green, and SA = blue, and we never choose between SA = red and WA = blue. The number of leaves are dn

9 CSP as a search problem Search strategy Size of search tree: bd
1. pick an uninstantiated variable, pick a value from its domain, check if all constraints are satisfied 2. if constraints are satisfied, continue search recursively 3. else, backtrack: go back to previous decision and make another choice Size of search tree: bd d = n, number of variables b = max Di when only one variable at a time is

10 Backtracking Search

11 CSP search example

12 CSP search example C1 C2 C3 S E N D + M O R E M O N E Y S 3 2 D
S E N D M O R E M O N E Y + M = 1 O = 0 O = 2 O = 3 N = 2 S 3 2 D 1 0 R 3 Y E = 3 Conflict!

13 CSP problem characteristics (1)
Special case of a search problem Domains can be discrete or continuous The order in which the constraints are satisfied does not matter. The order in which variables and their values are picked makes a big difference!

14 CSP problem characteristics (2)
The goal test is decomposed into a set of constraints on variables, rather than a single black box When sets of variables are independent (no constraints between them) the problem is decomposable and sub-problems can be solved independently. A each step we must check for consistency. We need constraint propagation methods!

15 CSP problem characteristics (3)
Answering the following questions are important key: Which variable should be assigned next, and in what order should its values be tried? What are the implications of the current variable assignments for the other unassigned variables? When a path fails—that is, a state is reached in which a variable has no legal values— can the search avoid repeating this failure in subsequent paths?

16 Comparison of various CSP algorithms

17 Variable and value ordering
Pick values for the minimum remaining values (MRV) or most constrained variables or first fail principle choosing the variable with the fewest "legal" value those with smaller domains and which appear in more constraints. The rationale: those leave fewer choices and focus the search Improve the search from 3 til 3000 times better than simple

18 Variable and value ordering
MRV doesn’t help in choosing the first variable Degree heuristic: attempts to reduce the BF in feature by selecting the variables that is involved in the largest number of constraints on other unassigned variables SA on region coloring example

19 Value ordering least-constraining-value: prefers the value that rules out the fewest choices for the neighboring variables in the constraint In the previous coloring problem: WA = red and NT = green, Q is better to assign red that blue if we are trying to find all the solutions to a problem, not just the first one, then the ordering does not matter because we have to consider every value anyway.

20 Propagating information through constraints (1)
Forward checking: delete values from domains as the assignments are made When a domain becomes empty, abort. Often more efficient than backtracking

21 Forward checking example

22 Propagating information through constraints (2)
Forward Checking: doesn't detect all of inconsistencies. WA = red, Q=green => NT = SA = blue (this inconsistency doesn’t detected) Arc-consistency: a state is arc-consistent if every variable has a value in its domain that is consistent with each of the constraints of that variable. This is a form of constraint propagation. Arc-consistency provides a fast method of constraint propagation that is substantially stronger than forward checking. arc-consistency is directed arc in constraint graph (SA, NSW) is consistent while (NSW,SA) is not consistent Complexity: O(n2d3) for binary CSP Binary CSP has at most O(n2) arcs Each arc (Xi,Xk) can be inserted on the agenda only d times: Xi has at most d values to delete Checking consistency of an arc can be done in O(d2)

23 AC-3 can not find harder the inconsistency (WA=red, NSW=red)
Arc-Consistency AC-3 can not find harder the inconsistency (WA=red, NSW=red) Need more concepts

24 CSP terminology Label <xi, a> Compound Label { <xi, a> }
K-Constraint Modeling 8-Queen problem: Q1,Q2, …,Q8 in [a,b,…,h] Qx  Qy , |Qx-Qy|  |x-y|

25 A {red, green} B{red} C{red} Important Concepts K-Satisfiable
K-Consistency K=1: node consistency K>1: for each K-1 satisfiable variable set can add the Kth variable with consistent value and no change in the previous K-1 variable values K-strongly consistent A {red, green} B{red} C{red} 3-Consistent But not 2-Consistent

26 Handling special constraints
some problem-specific constraints are used much in different problems AllDiff constraints says that all variables should be different If n variables with m values and n>m, the constraints should not be satisfied Use the following idea to develop a method: First, remove any variable in the constraint that has a singleton domain, and delete that variable's value from the domains of the remaining variables. Repeat as long as there are singleton variables. If at any point an empty domain is produced or there are more variables than domain values left, then an inconsistency has been detected. By using the above method, the inconsistency (WA=red, NSW=red) can be detected.

27 Handling special constraints
Resource constraints: the most important higher-order constraints Atmost constraints:(A0, PA1, PA2, PA3, PA4). Checking the sum of minimum values of current domains (in each step of procedure) For example, let's suppose there are two flights, 271 and 272, for which the planes have capacities 165 and 385, respectively. The initial domains for the numbers of passengers on each flight are then Flight271  [0,165] and Flight272  [0, 385] Now suppose we have the additional constraint that the two flights together must carry 420 people: Flight271 + Flight272  [420,420]. Propagating bounds constraints, we reduce the domains to Flight271  [35,165] and Flight272  [255, 385]

28 CSP heuristics: example
C1 C2 C3 C4 S E N D M O R E M O N E Y + C1 = 1 C2 + S + 1 = O M = 1 C2 + S + 1 = 1 C3 + E + 0 = N C4 + N + R = E O = 0 O = 2 O = 3 N = 2 Conflict is detected as soon as the assignement is made E = 3

29 Graph of variables dependencies
Y Constraints X + Y = Z X - Z < 7 Y = Z X - W = 3 U - V = 0 Domains DX = {0, 1, 2} DY = {0, … 10} …. W X Z U V

30 Intelligent backtracking: looking backward
chronological backtracking: Simple BT More intelligent: use conflict set Backjumping method: backtrack to the most recent variable in conflict set

31 Min-conflict strategy on 8-queens

32 Important concept (constraint graph)
Graph Order Node width Graph Order width Graph Width Value ordering for CSP search in the minimum Graph order width If the level of strong consistency is greater than the width of constraint graph, the search for solution tuple is backtrack free

33 Search Strategies (Haralick & Elliot 1980)
Standard Backtracking Fully Looking Forward Partial Looking Ahead Forward Checking Backchecking BackMarking

34 CSP problems at large An area of great economic importance
scheduling, production, etc. Closely related to optimization problems integer programming multiobjective optimization Large body of literature in different areas: AI, CS, Operations Research, Mathematics, …

35 ?


Download ppt "Lecture 5: Constraint Satisfaction"

Similar presentations


Ads by Google