Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Introduction to Artificial Intelligence Lecture 5: Constraint Satisfaction Problems Ramin Halavati In which we see how treating.

Similar presentations


Presentation on theme: "An Introduction to Artificial Intelligence Lecture 5: Constraint Satisfaction Problems Ramin Halavati In which we see how treating."— Presentation transcript:

1 An Introduction to Artificial Intelligence Lecture 5: Constraint Satisfaction Problems Ramin Halavati (halavati@ce.sharif.edu) In which we see how treating states as more than just black boxes leads to the invention of a range of powerful new search methods and a deeper understanding of problem structure and complexity.

2 Overview States/Goal(s) –Black Box vs. Structured –General Purpose Heuristics

3 What is Constraint Satisfaction? A set of variables: X 1,X 2,…,X n. A set of constraints: C 1,C 2,…,C m. Each variable, a domain: D 1,D 2,…,D n. State: An assignment of values to X i s. Consistent: Obeying all constraints. Complete: All variables having values. Solution: A complete, consistent state. Objective Function: Extra!

4 Real World Samples of CSP Assignment problems –e.g., who teaches what class Timetabling problems –e.g., which class is offered when and where? Transportation scheduling Factory scheduling

5 CSP, Sample To assign one of {red, green, blue} to each of 7 variables: WA, BT, SA, Q, NSW, V, T. Constraints: –WA ≠ NT,WA ≠ SA, NT ≠ Q, SA ≠ Q, … Solution: –{WA = red, NT = green, Q = red, NSW = green, …

6 Formulation Initial State: { } Successor Function: Value assignment to one variable with no conflict. Goal Test: Consistent, Complete, assignment. Path Cost: 1 for each step.

7 Constraint Types Constraint Types: –Unary / Binary / More… Auxiliary Variables Variables: F T U W, R O X 1 X 2 X 3 Constraints: All Different (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 TWO +TWO FOUR TWO +TWO FOUR

8 Constraint Graph

9 Recursive Back Track Algorithm Recursive Back Track( assignment, CSP ) If assignment is complete, return assignment. Var  Select an unassigned variable. For each Value in Domain (Var), if Consistent( assignment + Var  Value ) Then result  RBT (assignment + Var  Value ) if ( result ≠ failure ) return result. Return failure.

10 Major Questions… 1.Which variable to assign. 2.What to assign. 3.How to prevent further repetitions of a failure.

11 Minimum Remaining Values (MRV) To choose one which is most likely to fail Immediate recognition of failure

12 Benchmark ProblemBacktrackingBacktracking + MRV USA 4-Coloring > 1000 K N-Queens (2-50)> 40000 K13500 K Zebra3859 K1 K

13 Most Constraining Variable (MCS) To choose one who interferes the others most! Major reduction in branching factor. 5 5 3 3 3 3 3 3 2 2 2 2 0 0

14 Least Constraining Value (LCS) To choose a value which puts minimum constraint on other variables. To leave maximum flexibility.

15 Forward Checking Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values

16 Benchmark ProblemBT BT + MRV Forward Checking FC + MRV USA > 1 M 2 K60 N-Queens> 40 M13.5 K>40 M817 K Zebra3859 K1 K35 K500

17 Constraint Propagation How to find fast that implications of one variable on other variables.

18 Arc Consistency A  B is consistent if for each remaining value in domain ofA, there may be a consistent value in domain of B. –Consistent: SA  NSW, NSW  V,… –Not C.: NSW  SA, NT  SA,…

19 Arc Consistency Checking Algorithm (AC-3!) AC3( csp ) Fill queue with all available arcs of csp. While queue not empty, (X i,X j )  RemoveHead( queue ) If RemoveInconsistentValues(X i,X j ) Then for each X k in Neighbor (X i ) do Add (X k,X i ) to queue. Remove Inconsistent Values (X i,X j ) removed  false. For each x in Domain (X i ) if no allowed value in Domain (X j ) after assignment of x to X i, delete x from Domain (X i ); removed  true. Return removed.

20 Special Constraints… All Different –Sort remaining variables based on their number of choices… Resource Constraints –Checking the sums, … Flight271  [0,165], Flight272  [0,385] Flight271+Flight272 = 420  Flight271  [35,165], Flight272  [255,385] Bounds Propagation

21 Intelligent Backtracking 1.Q  Red 2.NSW  Green 3.V  Blue 4.T  Red 5.SA  ? Chronological Backtracking 11 22 33 44 ??

22 Back Jumping 1.Q  Red 2.NSW  Green 3.V  Blue 4.T  Red 5.SA  ? Conflict Set: {Q, V, NSW} NOTE: Back Jumping doesn’t help Forward Checking. 11 22 33 44 ??

23 Local Search for Constraint Satisfaction Problems Min Conflict Algorithm –Create a random complete state. –For a fixed number of times If current state is consistent, return. Choose a random variable v, and change assignment of v to a value that causes minimum conflict. Scheduling Hubble’s weekly observation: –From 3 weeks to 10 minutes! Extra advantage: Online Updating

24 Benchmark ProblemBT BT + MRV Forward Checking FC + MRV Min Conflicts USA > 1 M 2 K6064 N-Queens> 40 M13.5 K>40 M817 K4 K Zebra3859 K1 K35 K5002 K

25 Heuristics based on Structure Sub Problems –Finding Connected Components Constraint Trees A A B B C C D D E E F F

26 Heuristics based on Structure Constraint Trees: –Order nodes. –From last to first, remove all values from domain of parent which may violate arc-consistency. –From first to last, assign a remaining value. A A B B C C D D E E F F A A B B C C D D E E F F 1 1 3 3 2 2 5 5 4 4 6 6

27 How to convert Constraint Graph to Constraint Tree Cut-Set Conditioning –To select a set of nodes that subtracting them results in a tree. –To check the rest for all valid assignments of this set.

28 How to convert Constraint Graph to Constraint Tree Tree Decomposition

29 Include all variables Each constraint must be in at least one sub problem. If a variable is in two sub-probs, it must be in all sub- probs along the path.

30 Summery…


Download ppt "An Introduction to Artificial Intelligence Lecture 5: Constraint Satisfaction Problems Ramin Halavati In which we see how treating."

Similar presentations


Ads by Google