Constraint Satisfaction Problems

Similar documents
Chapter 6 Constraint Satisfaction Problems

Introduction to Arti Intelligence

Constraint Satisfaction

Constraint Satisfaction [RN2] Sec [RN3] Sec Outline

Outline What are CSPs? Standard search and CSPs Improvements. Constraint Satisfaction. Introduction. Introduction

Constraint satisfaction search. Combinatorial optimization search.

CS 4100 // artificial intelligence. Recap/midterm review!

Constraint Satisfaction Problems - CSP. March 23, 2017

LOCAL SEARCH. Today. Reading AIMA Chapter , Goals Local search algorithms. Introduce adversarial search 1/31/14

Summary. Local Search and cycle cut set. Local Search Strategies for CSP. Greedy Local Search. Local Search. and Cycle Cut Set. Strategies for CSP

Artificial Intelligence

What we will try to do...

Lecture 9: Search 8. Victor R. Lesser. CMPSCI 683 Fall 2010

Finding optimal configurations ( combinatorial optimization)

CSC242: Intro to AI. Lecture 7 Games of Imperfect Knowledge & Constraint Satisfaction

Search and Lookahead. Bernhard Nebel, Julien Hué, and Stefan Wölfl. June 4/6, 2012

Constraint Satisfaction 101

Chapter 7 R&N ICS 271 Fall 2017 Kalev Kask

Improving Repair-based Constraint Satisfaction Methods by Value Propagation

PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE

Chapter 7 Propositional Satisfiability Techniques

Announcements. Solution to Assignment 3 is posted Assignment 4 is available. c D. Poole and A. Mackworth 2017 CPSC 322 Lecture 8 1 / 25

Intelligent Agents. Formal Characteristics of Planning. Ute Schmid. Cognitive Systems, Applied Computer Science, Bamberg University

PROBABILITY. Inference: constraint propagation

Section Handout 5 Solutions

The exam is closed book, closed calculator, and closed notes except your one-page crib sheet.

Constraint sat. prob. (Ch. 6)

Complexity Theory Part II

Chapter 3 Deterministic planning

CS:4420 Artificial Intelligence

Foundations of Artificial Intelligence

Minimax strategies, alpha beta pruning. Lirong Xia

Logic in AI Chapter 7. Mausam (Based on slides of Dan Weld, Stuart Russell, Dieter Fox, Henry Kautz )

Local and Stochastic Search

CS360 Homework 12 Solution

Mock Exam Künstliche Intelligenz-1. Different problems test different skills and knowledge, so do not get stuck on one problem.

Logical Inference. Artificial Intelligence. Topic 12. Reading: Russell and Norvig, Chapter 7, Section 5

Local Search & Optimization

Min-Max Message Passing and Local Consistency in Constraint Networks

Chapter 7 Propositional Satisfiability Techniques

Chapter 4 Beyond Classical Search 4.1 Local search algorithms and optimization problems

Distributed Constraints

Principles of AI Planning

Friday Four Square! Today at 4:15PM, Outside Gates

SAT, NP, NP-Completeness

Q = Set of states, IE661: Scheduling Theory (Fall 2003) Primer to Complexity Theory Satyaki Ghosh Dastidar

Announcements. Friday Four Square! Problem Set 8 due right now. Problem Set 9 out, due next Friday at 2:15PM. Did you lose a phone in my office?

Methods for finding optimal configurations

Principles of AI Planning

Notes for Lecture Notes 2

Solvers for the Problem of Boolean Satisfiability (SAT) Will Klieber Aug 31, 2011

A.I.: Beyond Classical Search

CS/COE

Artificial Intelligence

Integer and Combinatorial Optimization: Introduction

Logic in AI Chapter 7. Mausam (Based on slides of Dan Weld, Stuart Russell, Subbarao Kambhampati, Dieter Fox, Henry Kautz )

The exam is closed book, closed calculator, and closed notes except your one-page crib sheet.

1. Tony and his three best friends (Steven, Donna, and Randy) were each at a different table.

Title: Logical Agents AIMA: Chapter 7 (Sections 7.4 and 7.5)

Projection in Logic, CP, and Optimization

Bayesian networks. Chapter AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 14.

Logic. proof and truth syntacs and semantics. Peter Antal

Price: $25 (incl. T-Shirt, morning tea and lunch) Visit:

Local Search and Optimization

Logical Agents. Outline

Local Search & Optimization

CSE 555 HW 5 SAMPLE SOLUTION. Question 1.

Chapter 2. Reductions and NP. 2.1 Reductions Continued The Satisfiability Problem (SAT) SAT 3SAT. CS 573: Algorithms, Fall 2013 August 29, 2013

COMP219: Artificial Intelligence. Lecture 20: Propositional Reasoning

An instance of SAT is defined as (X, S)

A* Search. 1 Dijkstra Shortest Path

POLYNOMIAL SPACE QSAT. Games. Polynomial space cont d

Local Search (Greedy Descent): Maintain an assignment of a value to each variable. Repeat:

Deterministic planning

Logical Agents. Chapter 7

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65

Algorithms. NP -Complete Problems. Dong Kyue Kim Hanyang University

Artificial Intelligence

A brief introduction to Logic. (slides from

CS 580: Algorithm Design and Analysis. Jeremiah Blocki Purdue University Spring 2018

The core of solving constraint problems using Constraint Programming (CP), with emphasis on:

Recap from Last Time

Local search algorithms. Chapter 4, Sections 3 4 1

Chapter 11. Approximation Algorithms. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

Local search and agents

Intelligent Agents. Pınar Yolum Utrecht University

Adding Flexibility to Russian Doll Search

Chapter 4 Deliberation with Temporal Domain Models

CS 331: Artificial Intelligence Local Search 1. Tough real-world problems

Combining Symmetry Breaking with Other Constraints: lexicographic ordering with sums

1 Basic Definitions. 2 Proof By Contradiction. 3 Exchange Argument

Bayesian networks. Chapter 14, Sections 1 4

Foundations of Artificial Intelligence

A Little Logic. Propositional Logic. Satisfiability Problems. Solving Sudokus. First Order Logic. Logic Programming

8. INTRACTABILITY I. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley. Last updated on 2/6/18 2:16 AM

Planning as Satisfiability

Consistency as Projection

A Local Search Approach to Modelling and Solving Interval Algebra Problems

Comp487/587 - Boolean Formulas

CS 380: ARTIFICIAL INTELLIGENCE

Transcription:

Constraint Satisfaction Problems Chapter 5 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 1

Outline CSP examples Backtracking search for CSPs Problem structure and problem decomposition Local search for CSPs AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 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),...} AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 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} AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 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! AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 6

Varieties of CSPs Discrete variables finite domains; size d O(d n ) complete assignments e.g., Boolean CSPs, incl. Boolean satisfiability (NP-complete) infinite domains (integers, strings, etc.) e.g., job scheduling, variables are start/end days for each job need a constraint language, e.g., StartJob 1 + 5 StartJob 3 linear constraints solvable, nonlinear undecidable Continuous variables e.g., start/end times for Hubble Telescope observations linear constraints solvable in poly time by LP methods AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 7

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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 8

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: F T U W R O X 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. AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 9

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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 10

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!!!! AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 11

Backtracking search Variable assignments are commutative, i.e., [WA = red then NT = green] same as [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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 12

Backtracking search function Backtracking-Search(csp) returns solution/failure return Recursive-Backtracking([ ], csp) function Recursive-Backtracking(assigned, csp) returns solution/failure if assigned is complete then return assigned var Select-Unassigned-Variable(Variables[csp], assigned, csp) for each value in Order-Domain-Values(var, assigned, csp) do if value is consistent with assigned according to Constraints[csp] then result Recursive-Backtracking([var = value assigned], csp) if result failure then return result end return failure AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 13

Backtracking example AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 14

Backtracking example AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 15

Backtracking example AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 16

Backtracking example AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 17

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? AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 18

Minimum remaining values Minimum remaining values (MRV): choose the variable with the fewest legal values AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 19

Tie-breaker among MRV variables Degree heuristic Degree heuristic: choose the variable with the most constraints on remaining variables AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 20

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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 24

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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 25

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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 29

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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 30

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 ) to queue function Remove-Inconsistent-Values( X i, X j ) returns true iff we remove a value 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 between X i and X j then delete x from Domain[X i ]; removed true return removed O(n 2 d 3 ), can be reduced to O(n 2 d 2 ) (but detecting all is NP-hard) AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 31

Problem structure WA NT Q SA NSW V Victoria T Tasmania and mainland are independent subproblems Identifiable as connected components of constraint graph AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 32

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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 33

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 ) This property also applies to logical and probabilistic reasoning: an important example of the relation between syntactic restrictions and the complexity of reasoning. AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 34

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 ) AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 35

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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 36

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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 37

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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 38

Performance of min-conflicts Given random initial state, can solve n-queens in almost constant time for arbitrary n with high probability (e.g., n = 10,000,000) The same appears to be true for any randomly-generated CSP except in a narrow range of the ratio R = number of constraints number of variables CPU time critical ratio R AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 39

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 AIMA2e Slides, Stuart Russell and Peter Norvig, Completed by Kazim Fouladi, Fall 2008 Chapter 5 40