Constraint Satisfaction taking advantage of internal structure of states when paths don’t matter
D Goforth - COSC 4117, fall 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 Example problem – timetable of university (1) state - collection of schedule objects schedule professor(~10 2 ) (~350 at LU) course (~10 3 ) time slot (~10) (16 at LU) location (~10 2 ) constraints objective function
D Goforth - COSC 4117, fall 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 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 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 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 CSP – problem definition state representation (R&N) state variables X 1, X 2, …, X n X i from domain D i constraints C 1, C 2, …, C m Cj are functions of Xi (unary, binary, … fns) solution – assignment of values v i to all X i so all constraint functions C j are satisfied objective function – optimized function of X i over solution set
D Goforth - COSC 4117, fall Example problem – timetable of university (4) variables: array of assignments of courses (c k ) to locations (loc i )and time (t j ) slots c k :prof,enroll,prog loc i : capacity t j : time, day A[loc,t] = c k constraints: loc.capacity >= c.enroll (unary) if (loc i1 != loc i2 ) A[loc i1,t j ].prof != A[loc i2,t j ].prof
D Goforth - COSC 4117, fall Modelling a state as constraint graph variables are nodes loc 1: 25loc 2: 100 t 1 t 2 t 3 c 1:Ann20 c 2:Ben45 c 3:Cec 15 c 4:Ben80 c 5:Ann90
D Goforth - COSC 4117, fall Modelling a state as constraint graph unary constraints reduce domains loc 1: 25loc 2: 100 t 1 t 2 t 3 c 1:Ann20 c 2:Ben45 c 3:Cec 15 c 4:Ben80 c 5:Ann90 for A(loc 1, t) {c 1,c 3 } for A(loc 2, t) {c 1,c 2,c 3,c 4,c 5 }
D Goforth - COSC 4117, fall Modelling a state as constraint graph binary constraints are edges loc 1: 25loc 2: 100 t 1 t 2 t 3 c 1:Ann20 c 2:Ben45 c 3:Cec 15 c 4:Ben80 c 5:Ann90 for A(loc 1, t) {c 1,c 3 } for A(loc 2, t) {c 1,c 2,c 3,c 4,c 5 } A[loc 1,t j ].prof != A[loc 2,t j ].prof
D Goforth - COSC 4117, fall Modelling a state as constraint graph multiple constraints are ‘hubs’ loc 1: 25loc 2: 100 t 1 t 2 t 3 c 1:Ann20 c 2:Ben45 c 3:Cec 15 c 4:Ben80 c 5:Ann90 for A(loc 1, t) {c 1,c 3 } for A(loc 2, t) {c 1,c 2,c 3,c 4,c 5 } each course in one slot only
D Goforth - COSC 4117, fall Variable domains discrete finite discrete infinite continuous Domains may be distinct or shared among variables (typical)
D Goforth - COSC 4117, fall Constraints enumerations of possible combinations functions of variables linear, non-linear, … unary, binary,…
D Goforth - COSC 4117, fall 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 Solution by incremental formulation advantage depth of search is limited to number of variables in state depth limited dfs is natural algorithm ‘backtracking search’
Backtracking search loc 1: 25 loc 2: 100 c 1:Ann20 c 2:Ben45 c 3:Cec 15 c 4:Ben80 c 5:Ann90 c 5c 1c 5 c 1 c 5
D Goforth - COSC 4117, fall 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 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 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 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 Efficient Backtracking search (5) k-consistency: extending arc- consistency forward checking remove variables arc consistency
D Goforth - COSC 4117, fall Norvig and Russell example chapter04b.ps
D Goforth - COSC 4117, fall DFS ‘chronological’ backtracking when search fails X6 (no value can be set for variable) back up one level, try again v 5 v 5 useless IF no constraint between X 5, X 6 X1 X2 X3 X4 X5 X6
D Goforth - COSC 4117, fall 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 Solution by local search start state has values for every variable state variables X 1 =v 1, X 2 =v 2, …, X n =v n constraints C 1, C 2, …, C m some satisfied, some violated objective function not optimized successor function changes one or more variables – evaluate to minimize conflicts
D Goforth - COSC 4117, fall 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 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 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 Examples crossword puzzle construction p.158 #5.4 cryptarithmetic puzzle – section 5.2 other example Sudoku puzzle
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 y y x|A B C D E F G H I c B3