1 / 32

Constraint Satisfaction

Constraint Satisfaction. taking advantage of internal structure of states when paths don’t matter. Constraint satisfaction problems (CSPs). no prescribed start state path does not matter acceptable states must satisfy constraints functions of state variables

stacia
Download Presentation

Constraint Satisfaction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Constraint Satisfaction taking advantage of internal structure of states when paths don’t matter

  2. Constraint satisfaction problems (CSPs) • no prescribed start state • path does not matter • acceptable states must satisfy constraints • functions of state variables • among acceptable states, goal states will optimize an objective function D Goforth - COSC 4117, fall 2003

  3. Example problem – timetable of university (1) • state - collection of schedule objects • schedule • professor(~102) (~350 at LU) • course (~103) • time slot (~10) (16 at LU) • location (~102) • constraints • objective function D Goforth - COSC 4117, fall 2003

  4. Example problem – timetable of university (2) • constraints • professors assigned to courses • one course per location per time slot • location capacity >= course (projected) enrollment • professors assigned only once per time slot • rooms assigned only once per time slot • courses in program in different time slots D Goforth - COSC 4117, fall 2003

  5. Example problem – timetable of university (3) • objective function • minimize total course enrollment in early morning time slots • distribute program courses across days • concentrate professor assignments on same day • accommodate special requests D Goforth - COSC 4117, fall 2003

  6. Solving CSPs • analysis of problem state structure is critical • two basic approaches: • start state is null: assign state variables one at a time and backtrack if constraint is violated • assign variables ‘randomly/intelligently’ to make a start state and use greedy search by changing variable assignments D Goforth - COSC 4117, fall 2003

  7. Example problem – timetable of university (4) • analyzing the problem • e.g. fix time slots for all weekly sessions of a course (tutorials?) • problem solving approaches • allocate courses to rooms and times one after the other • assign all courses then start moving those involved in constraint violations D Goforth - COSC 4117, fall 2003

  8. CSP – problem definition • state representation (R&N) • state variables X1, X2, …, Xn • Xi from domain Di • constraints C1, C2, …, Cm • Cj are functions of Xi (unary, binary, … fns) • solution – assignment of values vi to all Xi so all constraint functions Cj are satisfied • objective function – optimized function of Xi over solution set D Goforth - COSC 4117, fall 2003

  9. Example problem – timetable of university (4) • variables: array of assignments of courses (ck) to locations (loci)and time (tj) slots • ck:prof,enroll,prog • loci: capacity • tj: time, day • A[loc,t] = ck • constraints: • loc.capacity >= c.enroll (unary) • if (loci1 != loci2) A[loci1,tj].prof != A[loci2,tj].prof D Goforth - COSC 4117, fall 2003

  10. Modelling a state as constraint graph • variables are nodes loc 1: 25 loc 2: 100 c 1: Ann 20 c 2: Ben 45 c 3: Cec 15 c 4: Ben 80 c 5: Ann 90 t 1 t 2 t 3 D Goforth - COSC 4117, fall 2003

  11. Modelling a state as constraint graph • unary constraints reduce domains for A(loc1, t) {c1,c3} for A(loc2, t) {c1,c2,c3,c4,c5} loc 1: 25 loc 2: 100 c 1: Ann 20 c 2: Ben 45 c 3: Cec 15 c 4: Ben 80 c 5: Ann 90 t 1 t 2 t 3 D Goforth - COSC 4117, fall 2003

  12. Modelling a state as constraint graph • binary constraints are edges for A(loc1, t) {c1,c3} for A(loc2, t) {c1,c2,c3,c4,c5} loc 1: 25 loc 2: 100 c 1: Ann 20 c 2: Ben 45 c 3: Cec 15 c 4: Ben 80 c 5: Ann 90 t 1 t 2 A[loc1,tj].prof != A[loc2,tj].prof t 3 D Goforth - COSC 4117, fall 2003

  13. Modelling a state as constraint graph • multiple constraints are ‘hubs’ for A(loc1, t) {c1,c3} for A(loc2, t) {c1,c2,c3,c4,c5} loc 1: 25 loc 2: 100 c 1: Ann 20 c 2: Ben 45 c 3: Cec 15 c 4: Ben 80 c 5: Ann 90 t 1 t 2 each course in one slot only t 3 D Goforth - COSC 4117, fall 2003

  14. Variable domains • discrete finite • discrete infinite • continuous Domains may be distinct or shared among variables (typical) D Goforth - COSC 4117, fall 2003

  15. Constraints • enumerations of possible combinations • functions of variables • linear, non-linear, … • unary, binary,… D Goforth - COSC 4117, fall 2003

  16. Solution by incremental formulation • initial state – no variable assigned • successor function for transition: • pick a variable and set a value that does not conflict with previous assignments by applying constraint functions • goal – all variables assigned D Goforth - COSC 4117, fall 2003

  17. Solution by incremental formulation • advantage • depth of search is limited to number of variables in state • depth limited dfs is natural algorithm • ‘backtracking search’ D Goforth - COSC 4117, fall 2003

  18. c 1 c 5 c 5 c 5 c 5 c 5 c 1 c 5 c 1: Ann 20 c 2: Ben 45 c 3: Cec 15 c 4: Ben 80 c 5: Ann 90 Backtracking search loc 1: 25 loc 2: 100

  19. Efficient Backtracking search (1) • Forward checking - Propagate constraints • when variable is assigned, use constraints to reduce value sets of remaining variables • e.g. when course is assigned: • remove course from domain of all remaining variables • remove courses with same prof from allocations in same time slot D Goforth - COSC 4117, fall 2003

  20. Efficient Backtracking search (2) • Variable ordering – which variable to assign a value next? • MRV heuristic – pick most constrained variable (minimum remaining values) • e.g. – book small room first • degree heuristic – pick variable involved in most constraints (propagates and prunes most) D Goforth - COSC 4117, fall 2003

  21. Efficient Backtracking search (3) • Value ordering: once variable is selected, which value to try first? • least constraining value heuristic – pick value that reduces value sets of remaining variables the least • e.g. when assigning a course: • pick location with smallest capacity that will accommodate the course (risk?) D Goforth - COSC 4117, fall 2003

  22. Efficient Backtracking search (4) • Arc consistency: stronger constraint propagation • check for consistency between variables after value is set forward checking remove variables ? arc consistency D Goforth - COSC 4117, fall 2003

  23. Efficient Backtracking search (5) • k-consistency: extending arc-consistency forward checking remove variables arc consistency D Goforth - COSC 4117, fall 2003

  24. Norvig and Russell example chapter04b.ps D Goforth - COSC 4117, fall 2003

  25. DFS ‘chronological’ backtracking • when search fails X6 (no value can be set for variable) • back up one level, try again v5v5 • useless IF no constraint between X5, X6 X1 X2 X3 X4 X5 X6 D Goforth - COSC 4117, fall 2003

  26. DFS backjumping • when search fails X6 (no value can be set for variable) • look at conflict set of X6 {X3, X1} • jump back to change v3 v3 X1 X2 X3 X4 X5 X6 D Goforth - COSC 4117, fall 2003

  27. Solution by local search • start state has values for every variable • state variables X1=v1, X2=v2, …, Xn=vn • constraints C1, C2, …, Cm • some satisfied, some violated • objective function not optimized • successor function changes one or more variables – evaluate to minimize conflicts D Goforth - COSC 4117, fall 2003

  28. Solution by local search • timetable example: • start state – assign all courses to room/time slot • change assignments to reduce conflicts D Goforth - COSC 4117, fall 2003

  29. advantages of local search • solves some problems very fast • flexible in online situations – revised conditions can be re-solved with minimal changes • e.g. course enrollment projections turn out to be wrong – conflicts with room sizes • takes advantage of any known partial solutions installed in start state D Goforth - COSC 4117, fall 2003

  30. Constraint graph structure • independent variables (unary constraints only) easy but rare • tree graphs – process variables in top-down order from any node as root • general graphs – may be reducible (by removing and assigning some nodes) to trees • general graphs – may be reducible by clustering into subgraphs D Goforth - COSC 4117, fall 2003

  31. Examples • crossword puzzle construction • p.158 #5.4 • cryptarithmetic puzzle – section 5.2 • other example • Sudoku puzzle D Goforth - COSC 4117, fall 2003

  32. cB3 1 2 3 4 5 6 7 8 9 y 1 2 3 4 5 6 7 8 9 x|A B C D E F G H I Sudoku constraints From rules Constraints on all cells: For rows, columns, squares Every integer occurs No integer is repeated From data (particular game) Constraints on some cells Specific value Underconstrained – many solutions Overconstrained – no solutions

More Related