S 1571 Introduction to I Lecture 8 onstraint satisfaction search. ombinatorial optimization search. Milos Hauskrecht milos@cs.pitt.edu 539 Sennott Square onstraint satisfaction problem (SP) Objective: ind a configuration satisfying goal conditions onstraint satisfaction problem (SP) is a configuration search problem where: state is defined by a set of variables and their values Goal condition is represented by a set constraints on possible variable values 1
SP example: N-queens Goal: n queens placed in non-attacking positions on the board ariables: Represent queens, one for each column: 1,, 3, alues: Row placement of each queen on the board {1,, 3, } 1, onstraints: i j i j i j wo queens not in the same row wo queens not on the same diagonal olor a map using k different colors such that no adjacent countries have the same color ariables: Represent countries,,, D, alues: K -different colors {Red, lue, Green,..} onstraints:,,, etc n example of a problem with binary constraints
Solving a SP through standard search Maximum depth of the tree: Number of variables in the SP Depth of the solution: Number of variables in the SP ranching factor: if we fix the order of variable assignments the branch factor depends on the number of their values Unassigned:,, ssigned: 1 3, Unassigned:, 3, ssigned: 1 1 Unassigned:, 3, ssigned: 1 Unassigned: ssigned:, 3, 1 Solving a SP through standard search What search algorithm to use: Depth first search!!! Since we know the depth of the solution We do not have to keep large number of nodes in queues Unassigned:,, ssigned: 1 3, Unassigned:, 3, ssigned: 1 1 Unassigned:, 3, ssigned: 1 Unassigned:, 3 ssigned:, 1 3
onstraint consistency uestion: When to check the constraints defining the goal condition? he violation of constraints can be checked: at the end (for the leaf nodes) for each node of the search tree during its generation or before its expansion hecking the constraints for intermediate nodes: More efficient: cuts branches of the search tree early onstraint consistency hecking the constraints for intermediate nodes: More efficient: cuts branches of the search tree early Unassigned:,, ssigned: 1 3, Unassigned:, 3, ssigned: 1 1 Unassigned:, 3, ssigned: 1 Unassigned:, 3 ssigned:, 1
onstraint consistency hecking the constraints for intermediate nodes: More efficient: cuts branches of the search tree early Unassigned:,, ssigned: 1 3, Unassigned:, 3, ssigned: 1 1 Unassigned:, 3, ssigned: 1 Unassigned: ssigned:, 3, 1 onstraint consistency nother way to cut the search space and tree exploration urrent variable assignments together with constraints restrict remaining legal values of unassigned variables he remaining legal and illegal values of variables may be inferred (effect of constraints propagates) Unassigned: 1,, 3, ssigned: Unassigned:, 3, ssigned: 1 1 Unassigned:, 3, ssigned: 1 Unassigned: ssigned:, 3, 1 We know that 1 5
onstraint consistency nother way to cut the search space and tree exploration urrent variable assignments together with constraints restrict remaining legal values of unassigned variables he remaining legal and illegal values of variables may be inferred (effect of constraints propagates) Unassigned: 1,, 3, ssigned: Unassigned:, 3, ssigned: 1 1 Unassigned:, 3, ssigned: 1 hen node representing Unassigned:, 1, 3 is not ssigned: even generated 1, We know that 1 onstraint propagation state (more broadly) is defined: by a set of assigned variables, their values and a list of legal and illegal assignments for unassigned variables Legal and illegal assignments can be represented: equations (value assignments) and disequations (list of invalid assignments) Red, lue Red onstraints + assignments can entail new equations and disequations Red Red onstraint propagation: the process of inferring of new equations and disequations from existing equations and disequations 6
onstraint propagation ssign =Red =Red D Red lue Green - ssignments (equations) - Invalid assignments (disequations) onstraint propagation ssign =Red Red lue Green D = =Red x - ssignments (equations) - Invalid assignments (disequations) 7
onstraint propagation ssign =lue Red lue Green D =lue =Red x onstraint propagation ssign =lue Red lue Green =? =lue =Red x x D 8
onstraint propagation ssign =Green Red lue Green =Green =lue =Red x x D onstraint propagation hree techniques for propagating the effects of past assignments and constraints: Node propagation rc consistency orward checking Difference: ompleteness of inferences ime complexity of inferences. 9
onstraint propagation 1. Node consistency. Infers: equations (valid assignments) or disequations (invalid assignments) for an individual variable by applying a unary constraint. rc consistency. Infers: disequations from the set of equations and disequations defining the partial assignment, and a constraint equations through the exhaustion of alternatives 3. orward checking. Infers: disequations from a set of equations defining the partial assignment, and a constraint quations through the exhaustion of alternatives Restricted forward checking: uses only active constraints (active constraint only one variable unassigned in the constraint) xample of ustralia territories Note: problem with binary constraints 10
xample: node consistency ssume a constraint: Green vars inferred??????? xample: node consistency ssume a constraint: Green Infer: invalid assignments from Green constraint vars inferred R R G R G R G R G R G R G 11
xample: forward checking Set: =Red vars =Red R?????? xample: forward checking Infer: invalid assignments from =Red + constraints vars =Red R G R G R G R G G R G 1
xample: forward checking Set: =Green vars =Red R G R G R G R G G R G =Green R? G???? xample: forward checking Infer: invalid assignments from =Green + constraints vars =Red R G R G R G R G G R G =Green R G R R G R G 13
xample: forward checking Infer: = xhaustions of alternatives vars =Red R G R G R G R G G R G =Green R G R R G R G Infer R G???? xample: forward checking Infer: invalid assignments from = vars =Red R G R G R G R G G R G =Green R G R R G R G Infer R G R R G! R G 1
xample: arc consistency Set: =Red Set: =Green vars =Red R G R G R G R G G R G =Green R G R R G R G xample: arc consistency {} Infer: invalid assignments from valid and invalid assignments vars =Red R G R G R G R G G R G =Green R G R R G R G {R,} 15
xample: arc consistency {} Infer: invalid assignments from valid and invalid assignments vars =Red R G R G R G R G G R G =Green R G R R G R G {R,} = =R onsistent assignment xample: arc consistency {} Infer: invalid assignments from valid and invalid assignments vars =Red R G R G R G R G G R G =Green R G R R G R G {R,} =R = onsistent assignment 16
xample: arc consistency {} Infer: invalid assignments from valid and invalid assignments vars =Red R G R G R G R G G R G =Green R G R R G R G {R,} = =! Inconsistent assignment xample: arc consistency {} Infer: invalid assignments from valid and invalid assignments vars =Red R G R G R G R G G R G =Green R G R R G R G R {R,} = =! Inconsistent assignment 17
Heuristics for SPs SP searches the space in the depth-first manner. ut we still can choose: Which variable to assign next? Which value to choose first? Heuristics Most constrained variable Which variable is likely to become a bottleneck? Least constraining value Which value gives us more flexibility later? xamples: map coloring Heuristics for SP Heuristics Most constrained variable ountry is the most constrained one (cannot use Red, Green) Least constraining value ssume we have chosen variable Red is the least constraining valid color for the future 18
inding optimal configurations Search for the optimal configuration onstrain satisfaction problem: Objective: find a configuration that satisfies all constraints Optimal configuration problem: Objective: find the best configuration he quality of a configuration: is defined by some quality measure that reflects our preference towards each configuration (or state) Our goal: optimize the configuration according to the quality measure also referred to as objective function 19
Search for the optimal configuration Optimal configuration search: onfigurations are described in terms of variables and their values ach configuration has a quality measure Goal: find the configuration with the best value If the space of configurations we search among is Discrete or finite then it is a combinatorial optimization problem ontinuous then it is a parametric optimization problem xample: raveling salesman problem Problem: graph with distances tour a path that visits every city once and returns to the start e.g. D D Goal: find the shortest tour 0
xample: N queens SP problem Is it possible to formulate the problem as an optimal configuration search problem? xample: N queens SP problem Is it possible to formulate the problem as an optimal configuration search problem? Yes. he quality of a configuration in a SP can be measured by the number of violated constraints Solving: minimize the number of constraint violations # of violations =3 # of violations =1 # of violations =0 1
Iterative optimization methods Searching systematically for the best configuration with the DS may not be the best solution Worst case running time: xponential in the number of variables Solutions to large optimal configuration problems are often found using iterative optimization methods Methods: Hill climbing Simulated nnealing Genetic algorithms Properties: Iterative optimization methods Search the space of complete configurations ake advantage of local moves Operators make local changes to complete configurations Keep track of just one state (the current state) no memory of past states!!! No search tree is necessary!!!
xample: N-queens Local operators for generating the next state: Select a variable (a queen) Reallocate its position xample: raveling salesman problem Local operator for generating the next state: divide the existing tour into two parts, reconnect the two parts in the opposite order xample: D D 3
xample: raveling salesman problem Local operator for generating the next state: divide the existing tour into two parts, reconnect the two parts in the opposite order xample: D D Part 1 D Part D xample: raveling salesman problem Local operator: generates the next configuration (state) by rearranging the existing tour D D D D D
Searching the configuration space Search algorithms keep only one configuration (the current configuration) D D Problem: How to decide about which operator to apply?? D Search algorithms Strategies to choose the configuration (state) to be visited next: Hill climbing Simulated annealing Later: xtensions to multiple current states: Genetic algorithms Note: Maximization is inverse of the minimization min f ( X ) max f ( X ) 5