constr traint t sati tisfacti tion problems
play

Constr traint t Sati tisfacti tion Problems CSPs & Backtr - PowerPoint PPT Presentation

EEC EECS 3401: Intr tro to to AI & LP Constr traint t Sati tisfacti tion Problems CSPs & Backtr tracking Search The search algorithms we discussed so far had Readings: R & N Chapter 6. no knowledge of the states


  1. EEC EECS 3401: Intr tro to to AI & LP 
 Constr traint t Sati tisfacti tion Problems CSPs & Backtr tracking Search ● The search algorithms we discussed so far had ● Readings: R & N Chapter 6. no knowledge of the states representation (black box). So, we could not take advantage of domain-specific information. ● CSP are a special class of search problems with a uniform and simple state representation. ● This allows to design more efficient algorithms. 1 1 2 2 EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance Constr traint t Sati tisfacti tion Problems Constr traint t Sati tisfacti tion Problems ● Sudoku: ● Many problems can be represented as a search for a vector of feature values. ■ 81 variables, the value in each cell. ■ Values: a fixed value for those cells that are already ■ k-features: variables. filled in, the values {1-9} for those cells that are ■ Each feature has a value. Domain of values for the empty. variables. ■ Solution: a value for each cell satisfying the ■ e.g., height = {short, average, tall}, weight = {light, constraints: average, heavy}. ● no cell in the same column can have the same value. ● In these problems the problem is to search for ● no cell in the same row can have the same value. a set of values for the features (variables) so ● no cell in the same sub-square can have the same that the values satisfy some conditions value. (constraints). 3 3 4 4 EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance 1

  2. Constr traint t Sati tisfacti tion Problems Constr traint t Sati tisfacti tion Problems ● Scheduling ● Variables: ■ Want to schedule a time and a space for each final ■ T1, …, Tm: Ti is a variable representing the exam so that scheduled time for the i-th final. ● No student is scheduled to take more than one final ● Assume domains are fixed to {MonAm, MonPm, …, at the same time. FriAm, FriPm}. ● The space allocated has to be available at the time ■ S1, …, Sm: Si is the space variable for the i-th final. set. ● Domain of Si are all rooms big enough to hold the ● The space has to be large enough to accommodate i-th final. all of the students taking the exam. 5 5 6 6 EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance Constr traint t Sati tisfacti tion Problems Constr traint t Sati tisfacti tion Problems (CSP) ● Want to find an assignment of values to each ● More formally. variable (times, rooms for each final), subject ● A CSP consists of to the constraints: ■ a set of variables V1, …, Vn ■ For all pairs of finals i, j such that there is a student ■ for each variable a domain of possible values taking both: Dom[Vi]. ● Ti ≠ Tj ■ A set of constraints C1,…, Cm. ■ For all pairs of finals i, j ● Ti ≠ Tj or Si ≠ Sj ■ either i and j are not scheduled at the same time, or if they are they are not in the same space. 7 7 8 8 EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance 2

  3. Constr traint t Sati tisfacti tion Problems Constr traint t Sati tisfacti tion Problems ● Each variable be assigned any value from its ● A solution to a CSP is domain. ■ an assignment of a value to all of the variables such ● Vi = d where d ∈ Dom[Vi] that ● Each constraint C has ● every constraint is satisfied. ■ A set of variables it is over, called its scope: e.g., C(V1,V2,V4). ■ Is a boolean function that maps assignments to these variables to true/false. ● e.g. C(V1=a,V2=b,V4=c) = True ● this set of assignments satisfies the constraint. ● e.g. C(V1=b,V2=c,V4=c) = False ● this set of assignments falsifies the constraint. 9 9 10 10 EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance Constr traint t Sati tisfacti tion Problems Constr traint t Sati tisfacti tion Problems ● Sudoku: ● Sudoku: ■ V 11 , V 12 , …, V 21 , V 22 , …, V 91 , …, V 99 ■ Each of these constraints is over 9 variables, and they ● Dom[V ij ] = {1-9} for empty cells are all the same constraint: ● Dom[V ij ] = {k} a fixed value k for filled cells. ■ Row constraints: ● Any assignment to these 9 variables such that each ● CR1(V 11 , V 12 , V 13 , …, V 19 ) variable has a unique value satisfies the constraint. ● CR2(V 21 , V 22 , V 23 , …, V 29 ) ● Any assignment where two or more variables have ● ...., CR9(V 91 , V 92 , …, V 99 ) ■ Column Constraints: the same value falsifies the constraint. ● CC1(V 11 , V 21 , V 31 , …, V 91 ) ■ Such constraints are often called ALL-DIFF ● CC2(V 21 , V 22 , V 13 , …, V 92 ) constraints. ● ...., CC9(V 19 , V 29 , …, V 99 ) ■ Sub-Square Constraints: ● CSS1(V 11 , V 12 , V 13 , V 21 , V 22 , V 23 , V 31 , V 32 , V 33 ) ● CSS1(V 14 , V 15 , V 16 ,…, V 34 , V 35 , V 36 ) 11 11 12 12 EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance 3

  4. Constr traint t Sati tisfacti tion Problems Constr traint t Sati tisfacti tion Problems ● Sudoku: ● Exam Scheduling ■ Thus Sudoku has 3x9 ALL-Diff constraints, one over ■ constraints: each set of variables in the same row, one over each ■ For all pairs of finals i, j such that there is a student set of variables in the same column, and one over taking both: each set of variables in the same sub-square. ● NEQ(Ti,Tj) ■ For all pairs of finals i, j ■ Note also that an ALL-Diff constraint over k variables ● C(Ti,Tj,Si,Sj) can be equivalently represented by k choose 2 not- ■ This constraint is satisfied equal constraints over each pair of these variables. ● by any set of assignments in which Ti ≠ Tj. ● e.g. CSS1(V 11 , V 12 , V 13 , V 21 , V 22 , V 23 , V 31 , V 32 , V 33 ) = ● any set of assignments in which Si ≠ Sj. NEQ(V 11 ,V 12 ), NEQ(V 11 ,V 13 ), NEQ(V 11 ,V 21 ) …, NEQ(V 32 ,V 33 ) ■ Falsified by any set of assignments in which Ti=Tj as well as Si=Sj. ■ NEQ is a not-equal constraint. 13 13 14 14 EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance Solvi So ving ng CSPs CSPs Backtr tracking Search ● These ideas lead to the backtracking search algorithm ● CSPs can be solved by a specialized version of depth first search. Algorithm BT (Backtracking) BT(Level) If all variables assigned ● Key intuitions: PRINT Value of each Variable RETURN or EXIT (RETURN for more solutions) ■ We can build up to a solution by searching through (EXIT for only one solution) V := PickUnassignedVariable() the space of partial assignments. Variable[Level] := V ■ Order in which we assign the variables does not Assigned[V] := TRUE for d := each member of Domain(V) matter---eventually they all have to be assigned. Value[V] := d OK := TRUE ■ If during the process of building up a solution we for each constraint C such that V is a variable of C falsify a constraint, we can immediately reject all and all other variables of C are assigned. possible ways of extending the current partial if C is not not satisfied by the current set of assignments OK := FALSE assignment. if(OK) BT(Level+1) return 15 15 16 16 EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance 4

  5. Solvi So ving ng CSPs CSPs Backtr tracking Search ● The algorithm searches a tree of partial assignments. ● Heuristics are used to determine which variable to assign next “ PickUnassignedVariable ” . Children of a node are The root has the empty set all possible values of of assignments ● The choice can vary from branch to branch, some (any) unassigned Root {} variable e.g., ■ under the assignment V1=a we might choose to assign V4 next, while under V1=b we might choose Vi=a Vi=b Vi=c to assign V5 next. ● This “ dynamically ” chosen variable ordering has a tremendous impact on performance. Search stops Vj=1 Vj=2 descending if the assignments on path to the node Subtree violate a constraint 17 17 18 18 EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance Ex Example. Example. Ex ● N-Queens. Place N Queens on an N X N chess board so ● 4X4 Queens that no Queen can attack any other Queen. ■ Variables, one per row. ● Value of Vi is the column the Queen in row i is place. ■ Constrants. ● Vi ≠ Vj for all i ≠ j (can put two Queens in same column) ● |Vi-Vj| ≠ i-j (Diagonal constraint) ■ (i.e., the difference in the values assigned to Vi and Vj can ’ t be equal to the difference between i and j. 19 19 20 20 EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance EECS 3401 Winter 2017 Fahiem Bacchus & Yves Lesperance 5

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend