Download presentation
Presentation is loading. Please wait.
Published byAlaina Parker Modified over 8 years ago
1
Constraint Satisfaction CPSC 386 Artificial Intelligence Ellen Walker Hiram College
2
Constraint Satisfaction Problem Variables: X1, X2, … XN Constraints: C1, C2, … CN –Often mathematical e.g. X1+X2=0 Domains: D1, D2, … DN (possible values for variables) A solution assigns values to variable (X1=V1, X2=V2 etc.) so all constraints are satisfied A partial solution (or consistent assignment) doesn’t violate any constraints, but may leave some variables unassigned If there are multiple solutions, choose the one that maximizes an objective function (e.g. contiinuous problems)
3
Domain Types Finite domain (fixed number of variables, possible assignments) –Depth is #variables, breadth is #assignments/variable Discrete variables with infinite domains (e.g. integers, strings) –Cannot search by enumeration, need a language to represent constraints Continuous variables (e.g. real numbers) –Linear programming and other continuous optimization techniques
4
Example Problems Map Coloring (see text) Course / room scheduling –Each course has a room –Each room has no more than one course at a given time –Additional constraints (e.g. size, projector) Cryptarithmetic (see text) Line labeling Sudoku, Kakuro, KenKen, etc.
5
A Cryptarithmetic Problem SEND + MORE = MONEY Constraints –S≠E≠N≠D≠M≠O≠R≠Y (rules) –M = 1(It is a carry out of the high-order digit) –D+E = Y or D+E=10+Y –N+R+ (Y-(D+E))/10 = E (or 10+E) (etc) Solution –One technique: trial and error (with backtracking…) –Set M=1, that constrains S to be 8 or 9 and 0 can’t be 1, so it must be 0…
6
Consistency Node Consistency –Every value in the variable’s domain meets all unary constraints Arc Consistency –Every value in the variable’s domain meets all binary constraints (with at least one value in the relevant neighbor) If not consistent, remove value(s) from domain(s) until it is. – Book calls this “applying {Node, Arc} consistency
7
Arc Consistency Algorithm AC-3 Initialize a queue (really a set) of all arcs (pairs of constrained nodes) in the problem While the queue isn’t empty: –Remove an arc from the queue –Remove values that do not satisfy the constraint –If domain is empty return false –If domain changed, then add pairs of this node and all neighbors (except the one just checked) to the queue Return true (domains reduced as much as possible)
8
Arc Consistency Isn’t Enough Consider 2-coloring problem –Color Texas Flag with 3 colors, no two that touch and are the same. –Arc consistency does not reveal the problem –Need Path Consistency: for every pair of consistent elements, there is a third element so that first and third are consistent, and second and third are also consistent. (I.e. there is a path of consistency across two constraint pairs)
9
Line Labeling Label each line in the picture (left) Constraints based on vertices (“L” and “arrow” vertices shown) Both ends of the segment must have the same label! >><<<+–>>–+<
10
Constraint Problem as Search Formulation –Initial state: no assignments –Successor function: assign a value to an unassigned variable without violating constraints –Goal test: all variables are assigned –Path cost: constant for each step Order of assignments doesn’t matter Known solution depth (# of variables) Appropriate search is depth-limited DFS
11
Backtracking Search for CSP’s Pick an unassigned variable For each possible value that meets constraints Assign the value If all variables are assigned, return the solution Else Recursively solve the rest of the problem If the recursion succeeded, return the solution Return failure
12
Searching More Efficiently Choose the most constrained variable (fewest legal values) to assign next –# of iterations of loop is minimized –“MRV” Minimum Remaining Values heuristic In case of tie, choose the variable that is involved in the most constraints (highest degree) Once a variable is chosen, choose the least constraining value, i.e. rule out the fewest future choices
13
Constraint Propagation Forward checking –Whenever a variable is assigned, delete inconsistent values from other domains –Works well with MRV heuristic Maintaining Arc Consistency (MAC) –Consider results of constraints between variables affected by forward checking –Needs to be recursively applied, because removal could make a future arc inconsistent; after each change use AC3 starting with only the neighbors of changed nodes. –Tradeoff between consistency checking (takes time) and overall search time, but polynomial time is likely impossible
14
Chronological vs. Intelligent Backtracking Chronological Backtracking –Undoes most recent decision Intelligent Backtracking –Undoes the decision that caused the problem in the first place! –Set of variables that caused the failure is “conflict set” –Backjumping: undo most recent variable in conflict set (redundant with forward-checking; see text)
15
Local Search for CSP Hill Climbing with min conflicts as heuristic Every state is a complete assignment, count how many variables are conflicted (violate constraints) At each step: choose a conflicted variable at random, change its assignment to the value that causes the minimum number of conflicts Surprisingly effective for many CSP’s e.g. N-queens problem! Does depend (like all hill climbing) on initial state though.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.