1 Chapter 3: Finite Constraint Domains Where we meet the simplest and yet most difficult constraints, and some clever and not so clever ways to solve them.

Slides:



Advertisements
Similar presentations
Constraint Satisfaction Problems
Advertisements

Constraint Satisfaction Problems Russell and Norvig: Chapter
Lecture 11 Last Time: Local Search, Constraint Satisfaction Problems Today: More on CSPs.
1 Constraint Satisfaction Problems A Quick Overview (based on AIMA book slides)
1 Finite Constraint Domains. 2 u Constraint satisfaction problems (CSP) u A backtracking solver u Node and arc consistency u Bounds consistency u Generalized.
ICS-271:Notes 5: 1 Lecture 5: Constraint Satisfaction Problems ICS 271 Fall 2008.
1 Chapter 8: Modelling with Finite Domain Constraints Where we examine how modelling and controlling search interact with finite domain constraints.
Artificial Intelligence Constraint satisfaction problems Fall 2008 professor: Luigi Ceccaroni.
1 Chapter 2: Simplification, Optimization and Implication Where we learn more fun things we can do with constraints.
Constraint Satisfaction problems (CSP)
4 Feb 2004CS Constraint Satisfaction1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3.
Artificial Intelligence Constraint satisfaction Chapter 5, AIMA.
Constraint Satisfaction Problems
Constraint Satisfaction
CSE461: Constraint Programming & Modelling --Constraint Satisfaction Problems-- u Constraint satisfaction problems (CSPs) u A backtracking solver u Node.
Constraint Satisfaction Problems Russell and Norvig: Chapter 3, Section 3.7 Chapter 4, Pages Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm.
Ch 13 – Backtracking + Branch-and-Bound
Constraint Satisfaction Problem Solving Chapter 5.
Chapter 5 Outline Formal definition of CSP CSP Examples
Daniel Kroening and Ofer Strichman Decision Procedures An Algorithmic Point of View Deciding ILPs with Branch & Bound ILP References: ‘Integer Programming’
Constraint Satisfaction Problems
Constraint Satisfaction Problems
1 Constraint Programming: An Introduction Adapted by Cristian OLIVA from Peter Stuckey (1998) Ho Chi Minh City.
1 Constraint Satisfaction Problems Slides by Prof WELLING.
Decision Procedures An Algorithmic Point of View
CP Summer School Modelling for Constraint Programming Barbara Smith 1.Definitions, Viewpoints, Constraints 2.Implied Constraints, Optimization,
Topic III The Simplex Method Setting up the Method Tabular Form Chapter(s): 4.
Constraint Satisfaction Problems (CSPs) CPSC 322 – CSP 1 Poole & Mackworth textbook: Sections § Lecturer: Alan Mackworth September 28, 2012.
Constraint Satisfaction Problems Chapter 6. Review Agent, Environment, State Agent as search problem Uninformed search strategies Informed (heuristic.
Chapter 5 Section 1 – 3 1.  Constraint Satisfaction Problems (CSP)  Backtracking search for CSPs  Local search for CSPs 2.
Constraint Satisfaction CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Hande ÇAKIN IES 503 TERM PROJECT CONSTRAINT SATISFACTION PROBLEMS.
Artificial Intelligence CS482, CS682, MW 1 – 2:15, SEM 201, MS 227 Prerequisites: 302, 365 Instructor: Sushil Louis,
Chapter 5: Constraint Satisfaction ICS 171 Fall 2006.
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Fall 2006 Jim Martin.
CSC 8520 Spring Paula Matuszek CS 8520: Artificial Intelligence Search 3: Constraint Satisfaction Problems Paula Matuszek Spring, 2013.
Chapter 5 Constraint Satisfaction Problems
An Introduction to Artificial Intelligence Lecture 5: Constraint Satisfaction Problems Ramin Halavati In which we see how treating.
1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3 Grand Challenge:
CHAPTER 5 SECTION 1 – 3 4 Feb 2004 CS Constraint Satisfaction 1 Constraint Satisfaction Problems.
1. 2 Outline of Ch 4 Best-first search Greedy best-first search A * search Heuristics Functions Local search algorithms Hill-climbing search Simulated.
Chapter 13 Backtracking Introduction The 3-coloring problem
Chapter 5 Team Teaching AI (created by Dewi Liliana) PTIIK Constraint Satisfaction Problems.
EXAMPLE: MAP COLORING. Example: Map coloring Variables — WA, NT, Q, NSW, V, SA, T Domains — D i ={red,green,blue} Constraints — adjacent regions must.
Constraint Propagation Artificial Intelligence CMSC January 22, 2002.
1 Constraint Satisfaction Problems (CSP). Announcements Second Test Wednesday, April 27.
Constraint Satisfaction Problems
CS 561, Session 8 1 This time: constraint satisfaction - Constraint Satisfaction Problems (CSP) - Backtracking search for CSPs - Local search for CSPs.
Finite Domain Propagation
Optimization Problems
CSC Modeling with FD Constraints
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Finite Constraint Domains
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Constraint Satisfaction Problems Lecture # 14, 15 & 16
Chapter 3: Finite Constraint Domains
CS 188: Artificial Intelligence
Chapter 3: Finite Constraint Domains
Constraint Satisfaction Problems
Artificial Intelligence
Constraints and Search
Chapter 3: Finite Constraint Domains
Constraint satisfaction problems
Constraint Satisfaction Problems. A Quick Overview
Flow Feasibility Problems
CS 8520: Artificial Intelligence
Constraint Satisfaction Problems
Constraint satisfaction problems
Constraint Satisfaction Problems (CSP)
Presentation transcript:

1 Chapter 3: Finite Constraint Domains Where we meet the simplest and yet most difficult constraints, and some clever and not so clever ways to solve them

2 Finite Constraint Domains u Constraint satisfaction problems u A backtracking solver u Node and arc consistency u Bounds consistency u Generalized consistency u Optimization for arithmetic csps

3 Finite Constraint Domains u An important class of constraint domains u Use to model constraint problems involving choice: e.G. Scheduling, routing and timetabling u The greatest industrial impact of constraint programming has been on these problems

4 Constraint Satisfaction Problems u A constraint satisfaction problem (CSP) consists of: u A constraint C over variables x1,..., Xn u A domain D which maps each variable xi to a set of possible values d(xi) u It is understood as the constraint

5 Map Colouring A classic CSP is the problem of coloring a map so that no adjacent regions have the same color Can the map of Australia be colored with 3 colors ?

6 4-queens Place 4 queens on a 4 x 4 chessboard so that none can take another. Q1Q2Q3Q Four variables Q1, Q2, Q3, Q4 representing the row of the queen in each column. Domain of each variable is {1,2,3,4} One solution! -->

7 4-queens The constraints: Not on the same row Not diagonally up Not diagonally down

8 Smugglers Knapsack Smuggler with knapsack with capacity 9, who needs to choose items to smuggle to make profit at least 30 What should be the domains of the variables?

9 Simple Backtracking Solver u The simplest way to solve csps is to enumerate the possible solutions u The backtracking solver: u Enumerates values for one variable at a time u Checks that no prim. Constraint is false at each stage u Assume satisfiable(c) returns false when primitive constraint c with no variables is unsatisfiable

10 Partial Satisfiable u Check whether a constraint is unsatisfiable because of a prim. Constraint with no vars u Partial_satisfiable u Partial_satisfiable(c) u For each primitive constraint c in C u If vars(c) is empty u If satisfiable(c) = false return false u Return true

11 Backtrack Solve u Back_solve u Back_solve(c,d) partial_satisfiable u If vars(c) is empty return partial_satisfiable(c) u Choose x in vars(c) u For each value d in d(x) u Let C1 be C with x replaced by d partial_satisfiable( u If partial_satisfiable(c1) then back_solve u If back_solve(c1,d) then return true u Return false

12 Backtracking Solve Choose var X domain {1,2} Choose var Y domain {1,2} partial_satisfiable partial_satisfiable false Choose var Z domain {1,2} No variables, and false Variable X domain {1,2} Choose var Y domain {1,2}

13 Node and Arc Consistency u Basic idea: find an equivalent CSP to the original one with smaller domains of vars u Key: examine 1 prim.Constraint c at a time u Node consistency: (vars(c)={x}) remove any values from domain of x that falsify c u Arc consistency: (vars(c)={x,y}) remove any values from d(x) for which there is no value in d(y) that satisfies c and vice versa

14 Node Consistency u Primitive constraint c is node consistent with domain D if |vars(c)| !=1 or u If vars(c) = {x} then for each d in d(x) u X assigned d is a solution of c u A CSP is node consistent if each prim. Constraint in it is node consistent

15 Node Consistency Examples Example CSP is not node consistent (see Z) This CSP is node consistent The map coloring and 4-queens CSPs are node consistent. Why?

16 Achieving Node Consistency u Node_consistent u Node_consistent(c,d) u For each prim. Constraint c in C node_consistent_primitive u D := node_consistent_primitive(c, D) u Return D u Node_consistent_primitive u Node_consistent_primitive(c, D) u If |vars(c)| =1 then u Let {x} = vars(c) u Return D

17 Arc Consistency u A primitive constraint c is arc consistent with domain D if |vars{c}| != 2 or u Vars(c) = {x,y} and for each d in d(x) there exists e in d(y) such that u And similarly for y u A CSP is arc consistent if each prim. Constraint in it is arc consistent

18 Arc Consistency Examples This CSP is node consistent but not arc consistent For example the value 4 for X and X < Y. The following equivalent CSP is arc consistent The map coloring and 4-queens CSPs are also arc consistent.

19 Achieving Arc Consistency u Arc_consistent_primitive u Arc_consistent_primitive(c, D) u If |vars(c)| = 2 then u Return D u Removes values which are not arc consistent with c

20 Achieving Arc Consistency u Arc_consistent u Arc_consistent(c,d) u Repeat u W := d u For each prim. Constraint c in C arc_consistent_primitive u D := arc_consistent_primitive(c,d) u Until W = D u Return D u A very naive version (there are much better)

21 Using Node and Arc Cons. u We can build constraint solvers using the consistency methods u Two important kinds of domain u False domain: some variable has empty domain u Valuation domain: each variable has a singleton domain u Extend satisfiable to CSP with val. Domain

22 Node and Arc Cons. Solver node_consistent u D := node_consistent(C,D) arc_consistent u D := arc_consistent(C,D) u if D is a false domain u return false u if D is a valuation domain u return satisfiable(C,D) u return unknown

23 Node and Arc Solver Example Colouring Australia: with constraints WA NT SA Q NSW V T Node consistency

24 Node and Arc Solver Example Colouring Australia: with constraints WA NT SA Q NSW V T Arc consistency

25 Node and Arc Solver Example Colouring Australia: with constraints WA NT SA Q NSW V T Arc consistency

26 Node and Arc Solver Example Colouring Australia: with constraints WA NT SA Q NSW V T Arc consistency Answer: unknown

27 Backtracking Cons. Solver u We can combine consistency with the backtracking solver u Apply node and arc consistency before starting the backtracking solver and after each variable is given a value

28 Back. Cons Solver Example There is no possible value for variable Q3! Q1Q2Q3Q No value can be assigned to Q3 in this case! Therefore, we need to choose another value for Q2.

29 Back. Cons Solver Example Q1Q2Q3Q We cannot find any possible value for Q4 in this case! Backtracking… Find another value for Q3? No! backtracking, Find another value of Q2? No! backtracking, Find another value of Q1? Yes, Q1 = 2

30 Back. Cons Solver Example Q1Q2Q3Q

31 Back. Cons Solver Example Q1Q2Q3Q

32 Node and Arc Solver Example Colouring Australia: with constraints WA NT SA Q NSW V T Backtracking enumeration Select a variable with domain of more than 1, T Add constraintApply consistency Answer: true

33 Bounds Consistency u What about prim. constraints with more than 2 variables? u hyper-arc consistency: extending arc consistency to arbitrary number of variables u Unfortunately determining hyper-arc consistency is NP-hard (so its probably exponential) u What is the solution?

34 Bounds Consistency u arithmetic CSP: constraints are integer u range: [l..u] represents the set of integers {l, l+1,..., u} u idea use real number consistency and only examine the endpoints (upper and lower bounds) of the domain of each variable u Define min(D,x) as minimum element in domain of x, similarly for max(D,x)

35 Bounds Consistency u A prim. constraint c is bounds consistent with domain D if for each var x in vars(c) u exist real numbers d1,..., dk for remaining vars x1,..., xk such that u is a solution of c u and similarly for u An arithmetic CSP is bounds consistent if all its primitive constraints are

36 Bounds Consistency Examples Not bounds consistent, consider Z=2, then X-3Y=10 But the domain below is bounds consistent Compare with the hyper-arc consistent domain

37 Achieving Bounds Consistency u Given a current domain D we wish to modify the endpoints of domains so the result is bounds consistent u propagation rules do this

38 Achieving Bounds Consistency Consider the primitive constraint X = Y + Z which is equivalent to the three forms Reasoning about minimum and maximum values: Propagation rules for the constraint X = Y + Z

39 Achieving Bounds Consistency The propagation rules determine that: Hence the domains can be reduced to

40 More propagation rules Given initial domain: We determine that new domain:

41 Disequations Disequations give weak propagation rules, only when one side takes a fixed value that equals the minimum or maximum of the other is there propagation

42 Multiplication If all variables are positive its simple enough But what if variables can be 0 or negative? Example: becomes:

43 Multiplication Calculate X bounds by examining extreme values Similarly for upper bound on X using maximum BUT this does not work for Y and Z? As long as min(D,Z) 0 there is no bounds restriction on Y Recall we are using real numbers (e.g. 4/d)

44 Multiplication We can wait until the range of Z is non-negative or non-positive and then use rules like division by 0:

45 Bounds Consistency Algm u Repeatedly apply the propagation rules for each primitive constraint until there is no change in the domain u We do not need to examine a primitive constraint until the domains of the variables involve are modified

46 Bounds Consistency Example Smugglers knapsack problem (no whiskey available) Continuing there is no further change Note how we had to reexamine the profit constraint

47 Bounds consistency solver bounds_consistent u D := bounds_consistent(C,D) u if D is a false domain u return false u if D is a valuation domain u return satisfiable(C,D) u return unknown

48 Back. Bounds Cons. Solver u Apply bounds consistency before starting the backtracking solver and after each variable is given a value

49 Back. Bounds Solver Example Smugglers knapsack problem (whiskey available) Current domain: Initial bounds consistency W = 0 P = 1 (0,1,3) Solution Found: return true

50 Back. Bounds Solver Example Smugglers knapsack problem (whiskey available) Current domain: Initial bounds consistencyBacktrack P = 2 false Backtrack P = 3 W = 0 P = 1 (0,1,3) (0,3,0) W = 1 (1,1,1) W = 2 (2,0,0) No more solutions

51 Generalized Consistency u Can use any consistency method with any other communicating through the domain, u node consistency : prim constraints with 1 var u arc consistency: prim constraints with 2 vars u bounds consistency: other prim. constraints u Sometimes we can get more information by using complex constraints and special consistency methods

52 Alldifferent u alldifferent({V1,...,Vn}) holds when each variable V1,..,Vn takes a different value u alldifferent({X, Y, Z}) is equivalent to u Arc consistent with domain u BUT there is no solution! specialized consistency for alldifferent can find it

53 Alldifferent Consistency u let c be of the form alldifferent(V) u while exists v in V where D(v) = {d} u V := V - {v} u for each v’ in V u D(v’) := D(v’) - {d} u DV := union of all D(v) for v in V u if |DV| < |V| then return false domain u return D

54 Alldifferent Examples DV = {1,2}, V={X,Y,Z} hence detect unsatisfiability DV = {1,2,3,4,5}, V={X,Y,Z,T} don’t detect unsat. Maximal matching based consistency could

55 Other Complex Constraints u schedule n tasks with start times Si and durations Di needing resources Ri where L resources are available at each moment u array access if I = i, then X = Vi and if X != Vi then I != i

56 Optimization for CSPs u Because domains are finite can use a solver to build a straightforward optimizer u retry_int_opt u retry_int_opt(C, D, f, best) int_solv u D2 := int_solv(C,D) u if D2 is a false domain then return best u let sol be the solution corresponding to D2 retry_int_opt u return retry_int_opt(C /\ f < sol(f), D, f, sol)

57 Retry Optimization Example Smugglers knapsack problem (optimize profit) First solution found: Corresponding solution Next solution found:No next solution! Return best solution

58 Backtracking Optimization u Since the solver may use backtrack search anyway combine it with the optimization u At each step in backtracking search, if best is the best solution so far add the constraint f < best(f)

59 Back. Optimization Example Smugglers knapsack problem (whiskey available) Current domain: Initial bounds consistency W = 0 P = 1 (0,1,3) Solution Found: add constraint Smugglers knapsack problem (whiskey available)

60 Back. Optimization Example Initial bounds consistency P = 2 false P = 3 false W = 1 (1,1,1) Modify constraint W = 0 P = 1 (0,1,3) Smugglers knapsack problem (whiskey available) W = 2 false Return last sol (1,1,1)

61 Branch and Bound Opt. u The previous methods,unlike simplex don't use the objective function to direct search u branch and bound optimization for (C,f) u use simplex to find a real optimal, u if solution is integer stop u otherwise choose a var x with non-integer opt value d and examine the problems u use the current best solution to constrain prob.

62 Branch and Bound Example Smugglers knapsack problem Solution (2,0,0) = 30 false Solution (1,1,1) = 32 Worse than best sol false

63 Finite Constraint Domains Summary u CSPs form an important class of problems u Solving of CSPs is essentially based on backtracking search u Reduce the search using consistency methods u node, arc, bound, generalized u Optimization is based on repeated solving or using a real optimizer to guide the search