Presentation is loading. Please wait.

Presentation is loading. Please wait.

Artificial Intelligence Constraint satisfaction problems Fall 2008 professor: Luigi Ceccaroni.

Similar presentations


Presentation on theme: "Artificial Intelligence Constraint satisfaction problems Fall 2008 professor: Luigi Ceccaroni."— Presentation transcript:

1 Artificial Intelligence Constraint satisfaction problems Fall 2008 professor: Luigi Ceccaroni

2 Problem characterization A constraint satisfaction problem (or CSP) is a special kind of problem that satisfies some additional structural properties beyond the basic requirements for problems in general. In a CSP, the states are defined by the values of a set of variables and the goal test specifies a set of constraints that the values have to obey.

3 Problem characterization State components: –Variables –Domains (possible values for the variables) –(Binary) constraints between variables Goal: to find a state (a complete assignment of values to variables), which satisfies the constraints Examples: –map coloring –crossword puzzles –n-queens –resource assignment/distribution/location

4 Representation State = constraint graph –variables (n) = node tags –domains = node content –constraints = directed and tagged arcs between nodes Example: map coloring C1 C2C4 C3 C1 C2 C3 C4     blue, red, greenblue, green blue blue, red initial state

5 Representation In the search tree, a variable is assigned at each level. Solutions have to be complete assignment, therefore they appear at depth n, the number of variable and maximum depth of the tree. Depth-first search algorithms are popular in CSPs. The simplest class of CSP (map coloring, n- queens) are characterized by: –discrete variables –finite domains

6 Finite domains If the maximum size of the domain of any variable is d, then the number of possible complete assignments is O(d n ), exponential in the number of variables. CSPs with finite domain include Boolean CSPs, whose variables can only be true or false. In most practical applications, CSP algorithms can solve problems with domains orders of magnitude larger than the ones solvable by uninformed search algorithms.

7 Infinite domains With infinite domains (e.g., integers and strings), to describe constraints enumerating all legal combinations of values is not possible. A constraint language has to be used, for example: –job-start 1 + 5 ≤ job-start 3 There exist algorithms for linear constraints over integer variables. No algorithm exists for general non-linear constraints over integer variables. In cases, infinite-domain problems can be reduced to a finite domain, just restricting the values of all variables (e.g., setting limits to the dates in which jobs can start).

8 Search-based algorithms Incremental formulation: –Initial state: empty assignment { }, with all unassigned variables –Successor function: assignment of a value to any variable not yet assigned, provided it does not conflict with assigned variables –Goal test: check if the current assignment is complete –Path cost: a constant cost (e.g., 1) for every step Complete formulation: –Each state is a complete assignment, which satisfies or not the constraints. –Local-search methods work well in this case. Constraint propagation: –Before the search –During the search

9 Constraints The simplest type is the unary constraint, which constraints the values of just one variable. A binary constraint relates two variables. Higher-order constraints involve three or more variables. Cryptarithmetic puzzles are an example:

10 Cryptarithmetic puzzles Variables: F, T, U, W, R, O, X 1, X 2, X 3 Domains: {0,1,2,3,4,5,6,7,8,9} Constraints: –Alldiff (F,T,U,W,R,O) –O + O = R + 10 · X 1 –X 1 + W + W = U + 10 · X 2 –X 2 + T + T = O + 10 · X 3 –X 3 = F, T ≠ 0, F ≠ 0

11 Depth-first search with backtracking Standard depth-first search on a CSP wastes time searching when constraints have already been violated. Because of the way that the operators have been defined, an operator can never redeem a constraint that has already been violated. A first improvement is: –To test constraints after each variable assignment –If all possible values violate some constraint, then the algorithm backtracks to the last valid assignment Variables are classified as: past, current, future.

12 Backtracking search algorithm

13 1.Set each variable as undefined. Empty stack. All variables are future variables. 2.Select a future variable as current variable. If it exists, delete it from FUTURE and stack it (top = current variable), if not, the assignment is a solution. 3.Select an unused value for the current variable. If it exists, mark the value as used, if not, set current variable as undefined, mark all its values as unused, unstack the variable and add it to FUTURE, if stack is empty, there is no solution, if not, go to 3. 4.Test constraints between past variables and the current one. If they are satisfied, go to 2, if not, go to 3. (It is possible to use heuristics to select variables (2.) and values (3.).

14 Backtracking search algorithm

15 Example: 4-queens Place 4 queens, one per row, so that they do not attack each others –Variables: R 1 … R 4 (queens) –Domains: [1 … 4] for each R i (columns) –Constraints: R i does not attack R j not attacking RiRi RjRj [1.. 4]

16 R1=1 R2=1 NO R2=2 NO R2=3 R3=1 NO R3=2 NO R3=3 NO R3=4 NO R2=4 R3=1 NO R3=2 R4=1 NO R4=2 NO R4=3 NO R4=4 NO R1=2 R2=1 NO R2=2 NO R2=3 NO R2=4 R3=1 R4=1 NO R4=2 NO R4=3 Backtracking R2 Backtracking R3, R2, R1

17 Propagating information through constraints So far the algorithm considers the constraints on a variable only at the time that the variable is chosen (e.g., by Select- Unassigned-Variable). By looking at some of the constraints earlier in the search, or even before the search has started, the search space can be drastically reduced.

18 Forward checking A way to make better use of constraints during search. Whenever a variable X is assigned: –the forward checking process looks at each unassigned variable Y that is connected to X by a constraint and –deletes from Y’s domain any value that is inconsistent with the value chosen for X.

19 Forward checking algorithm

20 Forward checking: example

21

22

23 Idea: –Keep track of remaining legal values for unassigned variables –Terminate search when any variable has no legal values

24 Forward checking: example Idea: –Keep track of remaining legal values for unassigned variables –Terminate search when any variable has no legal values

25 Forward checking: example Idea: –Keep track of remaining legal values for unassigned variables –Terminate search when any variable has no legal values

26 Forward checking: example Idea: –Keep track of remaining legal values for unassigned variables –Terminate search when any variable has no legal values

27 R1=1? propagation: R2=3,4; R3=2,4; R4=2,3  R1=1 R2=3? propagation : R3=  R2=4? propagation : R3=2; R4=3  R2=4 R3=2? propagation : R4=  No other value for R3. Backtracking to R2 No other value for R2. Backtracking to R1 R1=2? propagation : R2=4; R3=1,3; R4=1,3,4  R1=2 R2=4? propagation : R3=1; R4=1,3  R2=4 R3=1? propagation : R4=3  R3=1 R4=3? No propagations  R4=3 Forward checking: 4-queens example

28 Constraint propagation Forward checking propagates information from assigned to unassigned variables, but doesn't provide early detection for all failures: NT and SA cannot both be blue! Constraint propagation repeatedly enforces constraints locally

29 Constraint propagation Forward checking does not detect the “blue” inconsistency, because it does not look far enough ahead. Constraint propagation is the general term for propagating the implications of a constraint on one variable onto other variables. The idea of arc consistency provides a fast method of constraint propagation that is substantially stronger than forward checking.

30 Arc consistency Simplest form of propagation makes each arc consistent X  Y is consistent iff for every value x of X there is some allowed y

31 Arc consistency Simplest form of propagation makes each arc consistent X  Y is consistent iff for every value x of X there is some allowed y

32 Arc consistency Simplest form of propagation makes each arc consistent X  Y is consistent iff for every value x of X there is some allowed y If X loses a value, neighbors of X need to be rechecked.

33 Arc consistency Simplest form of propagation makes each arc consistent X  Y is consistent iff for every value x of X there is some allowed y If X loses a value, neighbors of X need to be rechecked Arc consistency detects failure earlier than forward checking Can be run as a preprocess or after each assignment

34 Algorithm for arc consistency

35 Algorithm for arc consistency: AC-3 It uses a queue to keep track of the arcs that need to be checked for inconsistency. Each arc (X i, X j ) in turn is removed from the agenda and checked. If any values need to be deleted from the domain of X i, then every arc (X k, X j ) pointing to X i must be reinserted on the queue for checking.

36 (C1,C2): eliminate AZUL (C2,C1): ok (C2,C3): ok (C3,C2): eliminate AZUL (C2,C4): ok (C4,C2): eliminate AZUL (C3,C4): eliminate VERDE add (C2,C3) (C4,C3): ok (C2,C3): ok C1 C2 C3 C4     AZUL, ROJO, VERDEAZUL, VERDE AZUL AZUL, ROJO Initial list: (C1,C2), (C2,C1), (C2,C3), (C3,C2), (C2,C4), (C4,C2), (C3,C4), (C4,C3) Algorithm for arc consistency: AC-3


Download ppt "Artificial Intelligence Constraint satisfaction problems Fall 2008 professor: Luigi Ceccaroni."

Similar presentations


Ads by Google