Constraint Satisfaction Problems

Similar documents
Constraint Satisfaction Problems

Constraint Satisfaction

Constraint Satisfaction Problems

Constraint Satisfaction Problems

Example: Map-Coloring. Constraint Satisfaction Problems Western Australia. Example: Map-Coloring contd. Outline. Constraint graph

Constraint Satisfaction Problems. Chapter 6

Australia Western Australia Western Territory Northern Territory Northern Australia South Australia South Tasmania Queensland Tasmania Victoria

Lecture 6: Constraint Satisfaction Problems (CSPs)

Constraint Satisfaction. AI Slides (5e) c Lin

Chapter 6 Constraint Satisfaction Problems

Constraint Satisfaction Problems. A Quick Overview (based on AIMA book slides)

Constraint Satisfaction Problems (CSPs)

CSE 473: Artificial Intelligence

Artificial Intelligence

Constraint Satisfaction Problems

CS 188: Artificial Intelligence Fall 2008

Announcements. CS 188: Artificial Intelligence Fall Large Scale: Problems with A* What is Search For? Example: N-Queens

10/11/2017. Constraint Satisfaction Problems II. Review: CSP Representations. Heuristic 1: Most constrained variable

What is Search For? CSE 473: Artificial Intelligence. Example: N-Queens. Example: N-Queens. Example: Map-Coloring 4/7/17

CS 188: Artificial Intelligence Fall 2011

Constraint Satisfaction Problems

Outline. Best-first search

CS 188: Artificial Intelligence. Recap: Search

Week 8: Constraint Satisfaction Problems

Reading: Chapter 6 (3 rd ed.); Chapter 5 (2 nd ed.) For next week: Thursday: Chapter 8

Iterative improvement algorithms. Today. Example: Travelling Salesperson Problem. Example: n-queens

CS 188: Artificial Intelligence Spring Announcements

Announcements. CS 188: Artificial Intelligence Spring Today. A* Review. Consistency. A* Graph Search Gone Wrong

Space of Search Strategies. CSE 573: Artificial Intelligence. Constraint Satisfaction. Recap: Search Problem. Example: Map-Coloring 11/30/2012

Announcements. Reminder: CSPs. Today. Example: N-Queens. Example: Map-Coloring. Introduction to Artificial Intelligence

Constraint Satisfaction Problems Part 2

Foundations of Artificial Intelligence

Recap: Search Problem. CSE 473: Artificial Intelligence. Space of Search Strategies. Constraint Satisfaction. Example: N-Queens 4/9/2012

CS 4100 // artificial intelligence

CS W4701 Artificial Intelligence

CS 771 Artificial Intelligence. Constraint Satisfaction Problem

Lars Schmidt-Thieme, Information Systems and Machine Learning Lab (ISMLL), University of Hildesheim, Germany, Course on Artificial Intelligence,

Artificial Intelligence Constraint Satisfaction Problems

CS 188: Artificial Intelligence Spring Announcements

Announcements. CS 188: Artificial Intelligence Fall Reminder: CSPs. Today. Example: 3-SAT. Example: Boolean Satisfiability.

CS 188: Artificial Intelligence Fall 2008

Constraint Satisfaction Problems

CS 188: Artificial Intelligence Fall 2011

Material. Thought Question. Outline For Today. Example: Map-Coloring EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS

ARTIFICIAL INTELLIGENCE (CS 370D)

Announcements. CS 188: Artificial Intelligence Fall 2010

Constraint Satisfaction Problems

CS 188: Artificial Intelligence

What is Search For? CS 188: Artificial Intelligence. Example: Map Coloring. Example: N-Queens. Example: N-Queens. Constraint Satisfaction Problems

Constraints. CSC 411: AI Fall NC State University 1 / 53. Constraints

What is Search For? CS 188: Artificial Intelligence. Constraint Satisfaction Problems

CS 343: Artificial Intelligence

CS 188: Artificial Intelligence

Announcements. Homework 1: Search. Project 1: Search. Midterm date and time has been set:

DIT411/TIN175, Artificial Intelligence. Peter Ljunglöf. 30 January, 2018

CS 188: Artificial Intelligence. What is Search For? Constraint Satisfaction Problems. Constraint Satisfaction Problems

Constraint Satisfaction Problems Chapter 3, Section 7 and Chapter 4, Section 4.4 AIMA Slides cstuart Russell and Peter Norvig, 1998 Chapter 3, Section

Outline. Best-first search

Announcements. Homework 4. Project 3. Due tonight at 11:59pm. Due 3/8 at 4:00pm

Spezielle Themen der Künstlichen Intelligenz

Announcements. CS 188: Artificial Intelligence Spring Production Scheduling. Today. Backtracking Search Review. Production Scheduling

Constraint Satisfaction Problems. Chapter 6

Constraint Satisfaction Problems

Today. CS 188: Artificial Intelligence Fall Example: Boolean Satisfiability. Reminder: CSPs. Example: 3-SAT. CSPs: Queries.

Solving Problems by Searching: Constraint Satisfaction Problems

CONSTRAINT SATISFACTION

Announcements. CS 188: Artificial Intelligence Spring Today. Example: Map-Coloring. Example: Cryptarithmetic.

Artificial Intelligence, CS, Nanjing University Spring, 2018, Yang Yu. Lecture 5: Search 4.

CS 188: Artificial Intelligence Spring Today

CS 188: Artificial Intelligence

Lecture 18. Questions? Monday, February 20 CS 430 Artificial Intelligence - Lecture 18 1

Constraint Satisfaction Problems. slides from: Padhraic Smyth, Bryan Low, S. Russell and P. Norvig, Jean-Claude Latombe

Moving to a different formalism... SEND + MORE MONEY

Map Colouring. Constraint Satisfaction. Map Colouring. Constraint Satisfaction

K-Consistency. CS 188: Artificial Intelligence. K-Consistency. Strong K-Consistency. Constraint Satisfaction Problems II

Constraint Satisfaction Problems

Constraint satisfaction problems. CS171, Winter 2018 Introduction to Artificial Intelligence Prof. Richard Lathrop

CONSTRAINT SATISFACTION

Artificial Intelligence

Artificial Intelligence

Constraint Satisfaction Problems (CSPs) Introduction and Backtracking Search

Constraint Satisfaction Problems

DIT411/TIN175, Artificial Intelligence. Peter Ljunglöf. 6 February, 2018

Constraint Satisfaction Problems

Constraint Satisfaction Problems

Introduction. 2D1380 Constraint Satisfaction Problems. Outline. Outline. Earlier lectures have considered search The goal is a final state

Discussion Section Week 1

AI Fundamentals: Constraints Satisfaction Problems. Maria Simi

Games and Adversarial Search II Alpha-Beta Pruning (AIMA 5.3)

CONSTRAINT SATISFACTION

What is Search For? CS 188: Ar)ficial Intelligence. Constraint Sa)sfac)on Problems Sep 14, 2015

Constraint Satisfaction. CS 486/686: Introduction to Artificial Intelligence

CSE 573: Artificial Intelligence

Example: Map coloring

CS 188: Artificial Intelligence. Recap Search I

Constraint Satisfaction Problems

CMU-Q Lecture 7: Searching in solution space Constraint Satisfaction Problems (CSPs) Teacher: Gianni A. Di Caro

CS 4100/5100: Foundations of AI

Review I" CMPSCI 383 December 6, 2011!

Artificial Intelligence. Some Problems. 15-Puzzle. Search and Constraint Satisfaction. 8/15-Puzzle n-queens Puzzle

Transcription:

Revised by Hankui Zhuo, March 14, 2018 Constraint Satisfaction Problems Chapter 5 Chapter 5 1

Outline CSP examples Backtracking search for CSPs Problem structure and problem decomposition Local search for CSPs Chapter 5 2

Constraint satisfaction problems (CSPs) Standard search problem: state is a black box any old data structure that supports goal test, eval, successor CSP: state is defined by variables X i with values from domain D i goal test is a set of constraints specifying allowable combinations of values for subsets of variables Simple example of a formal representation language Allows useful general-purpose algorithms with more power than standard search algorithms Chapter 5 3

Example: Map-Coloring Western Australia Northern Territory South Australia Queensland New South Wales Victoria Tasmania Variables WA, NT, Q, NSW, V, SA, T Domains D i = {red, green, blue} Constraints: adjacent regions must have different colors e.g., WA NT (if the language allows this), or (WA,NT) {(red, green), (red, blue), (green, red), (green, blue),...} Chapter 5 4

Example: Map-Coloring contd. Western Australia Northern Territory South Australia Queensland New South Wales Victoria Tasmania Solutions are assignments satisfying all constraints, e.g., {WA= red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = green} Chapter 5 5

Constraint graph Binary CSP: each constraint relates at most two variables Constraint graph: nodes are variables, arcs show constraints WA NT Q SA NSW V Victoria T General-purpose CSP algorithms use the graph structure to speed up search. E.g., Tasmania is an independent subproblem! Chapter 5 6

Varieties of constraints Unary constraints involve a single variable, e.g., SA green Binary constraints involve pairs of variables, e.g., SA WA Higher-order constraints involve 3 or more variables, e.g., cryptarithmetic column constraints Preferences (soft constraints), e.g., red is better than green often representable by a cost for each variable assignment constrained optimization problems Chapter 5 7

Example: Cryptarithmetic T W O + T W O F O U R F T U W R O X 3 X 2 X 1 Variables: FTUWROX 1 X 2 X 3 Domains: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Constraints alldiff(f, T, U, W, R, O) O + O = R +10 X 1,etc. Chapter 5 8

Assignment problems e.g., who teaches what class Real-world CSPs Timetabling problems e.g., which class is offered when and where? Hardware configuration Spreadsheets Transportation scheduling Factory scheduling Floorplanning Notice that many real-world problems involve real-valued variables Chapter 5 9

Standard search formulation (incremental) Let s start with the straightforward, dumb approach, then fix it States are defined by the values assigned so far Initial state: the empty assignment, {} Successor function: assign a value to an unassigned variable that does not conflict with current assignment. fail if no legal assignments (not fixable!) Goal test: the current assignment is complete 1) This is the same for all CSPs! 2) Every solution appears at depth n with n variables use depth-first search 3) Path is irrelevant, so can also use complete-state formulation 4) b =(n l)d at depth l, hence n!d n leaves!!!! Chapter 5 10

Backtracking search Variable assignments are commutative (the order makes no difference), i.e., [WA= red then NT = green] sameas [NT = green then WA= red] Only need to consider assignments to a single variable at each node b = d and there are d n leaves Depth-first search for CSPs with single-variable assignments is called backtracking search Backtracking search is the basic uninformed algorithm for CSPs Can solve n-queens for n 25 Chapter 5 11

Backtracking search function Backtracking-Search(csp) returns solution/failure return Recursive-Backtracking({}, csp) function Recursive-Backtracking(assignment, csp) returns soln/failure if assignment is complete then return assignment var Select-Unassigned-Variable(Variables[csp], assignment, csp) for each value in Order-Domain-Values(var, assignment, csp) do if value is consistent with assignment given Constraints[csp] then add {var = value} to assignment result Recursive-Backtracking(assignment, csp) if result failure then return result remove {var = value} from assignment return failure Chapter 5 12

Backtracking example Chapter 5 13

Backtracking example Chapter 5 14

Backtracking example Chapter 5 15

Backtracking example Chapter 5 16

Improving backtracking efficiency General-purpose methods can give huge gains in speed: 1. Which variable should be assigned next? 2. In what order should its values be tried? 3. Can we detect inevitable failure early? 4. Can we take advantage of problem structure? Chapter 5 17

Minimum remaining values Minimum remaining values (MRV): choose the variable with the fewest legal values Chapter 5 18

Tie-breaker among MRV variables Degree heuristic Degree heuristic: choose the variable with the most constraints on remaining variables Chapter 5 19

Least constraining value Given a variable, choose the least constraining value: the one that rules out the fewest values in the remaining variables Allows 1 value for SA Allows 0 values for SA Combining these heuristics makes 1000 queens feasible Chapter 5 20

Forward checking Idea: Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values WA NT Q NSW V SA T Chapter 5 21

Forward checking Idea: Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values WA NT Q NSW V SA T Chapter 5 22

Forward checking Idea: Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values WA NT Q NSW V SA T Chapter 5 23

Forward checking Idea: Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values WA NT Q NSW V SA T Chapter 5 24

Constraint propagation Forward checking propagates information from assigned to unassigned variables, but doesn t provide early detection for all failures: WA NT Q NSW V SA T NT and SA cannot both be blue! Constraint propagation repeatedly enforces constraints locally Chapter 5 25

Arc consistency Simplest form of propagation makes each arc consistent X Y is consistent iff for every value x of X there is some allowed y WA NT Q NSW V SA T Chapter 5 26

Arc consistency Simplest form of propagation makes each arc consistent X Y is consistent iff for every value x of X there is some allowed y WA NT Q NSW V SA T Chapter 5 27

Arc consistency Simplest form of propagation makes each arc consistent X Y is consistent iff for every value x of X there is some allowed y WA NT Q NSW V SA T If X loses a value, neighbors of X need to be rechecked Chapter 5 28

Arc consistency Simplest form of propagation makes each arc consistent X Y is consistent iff for every value x of X there is some allowed y WA NT Q NSW V SA T If X loses a value, neighbors of X need to be rechecked Arc consistency detects failure earlier than forward checking Can be run as a preprocessor or after each assignment Chapter 5 29

Arc consistency algorithm function AC-3( csp) returns the CSP, possibly with reduced domains inputs: csp, a binary CSP with variables {X 1,X 2,..., X n } local variables: queue, a queue of arcs, initially all the arcs in csp while queue is not empty do (X i,x j ) Remove-First(queue) if Remove-Inconsistent-Values(X i,x j ) then for each X k in Neighbors[X i ] do add (X k,x i )toqueue function Remove-Inconsistent-Values( X i,x j ) returns true iff succeeds removed false for each x in Domain[X i ] do if no value y in Domain[X j ] allows (x,y) to satisfy the constraint X i X j then delete x from Domain[X i ]; removed true return removed Chapter 5 30

Problem structure WA NT Q SA NSW V Victoria T Tasmania and mainland are independent subproblems Chapter 5 31

Problem structure contd. Suppose each subproblem has c variables out of n total Worst-case solution cost is n/c d c, linear in n E.g., n =80, d =2, c =20 2 80 = 4 billion years at 10 million nodes/sec 4 2 20 = 0.4 seconds at 10 million nodes/sec Chapter 5 32

Tree-structured CSPs A C B D E F Theorem: if the constraint graph has no loops, the CSP can be solved in O(nd 2 ) time Compare to general CSPs, where worst-case time is O(d n ) Chapter 5 33

Algorithm for tree-structured CSPs 1. Choose a variable as root, order variables from root to leaves such that every node s parent precedes it in the ordering A C B D E F A B C D E F 2. For j from n down to 2, apply RemoveInconsistent(Parent(X j ),X j ) 3. For j from 1 to n, assign X j consistently with Parent(X j ) Chapter 5 34

Nearly tree-structured CSPs Conditioning: instantiate a variable, prune its neighbors domains WA NT Q WA NT Q SA NSW NSW V Victoria V Victoria T T Cutset conditioning: instantiate (in all ways) a set of variables such that the remaining constraint graph is a tree Cutset size c runtime O(d c (n c)d 2 ), very fast for small c Chapter 5 35

Iterative algorithms for CSPs Hill-climbing, simulated annealing typically work with complete states, i.e., all variables assigned To apply to CSPs: allow states with unsatisfied constraints operators reassign variable values Variable selection: randomly select any conflicted variable Value selection by min-conflicts heuristic: choose value that violates the fewest constraints i.e., hillclimb with h(n) = total number of violated constraints Chapter 5 36

Example: 4-Queens States: 4 queens in 4 columns (4 4 = 256 states) Operators: move queen in column Goal test: no attacks Evaluation: h(n) = number of attacks h = 5 h = 2 h = 0 Chapter 5 37

Summary CSPs are a special kind of problem: states defined by values of a fixed set of variables goal test defined by constraints on variable values Backtracking = depth-first search with one variable assigned per node Variable ordering and value selection heuristics help significantly Forward checking prevents assignments that guarantee later failure Constraint propagation (e.g., arc consistency) does additional work to constrain values and detect inconsistencies The CSP representation allows analysis of problem structure Tree-structured CSPs can be solved in linear time Iterative min-conflicts is usually effective in practice Chapter 5 38

End of Chapter 5 Thanks & Questions! Chapter 5 39