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

Similar documents
Constraint Satisfaction Problems

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

Constraint Satisfaction Problems

Constraint Satisfaction

Constraint Satisfaction Problems

Constraint Satisfaction Problems

Constraint Satisfaction Problems. Chapter 6

Constraint Satisfaction Problems

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

Lecture 6: Constraint Satisfaction Problems (CSPs)

CS W4701 Artificial Intelligence

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

Constraint Satisfaction Problems (CSPs)

Spezielle Themen der Künstlichen Intelligenz

Constraint Satisfaction. AI Slides (5e) c Lin

CSE 473: Artificial Intelligence

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

Chapter 6 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

CS 343: Artificial Intelligence

Artificial Intelligence

CS 188: Artificial Intelligence Fall 2011

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

Constraint Satisfaction Problems

Announcements. CS 188: Artificial Intelligence Fall 2010

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

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

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

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

Constraint Satisfaction Problems (CSPs) Introduction and Backtracking Search

ARTIFICIAL INTELLIGENCE (CS 370D)

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

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

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

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

CS 771 Artificial Intelligence. Constraint Satisfaction Problem

CS 188: Artificial Intelligence Spring Announcements

Outline. Best-first search

Constraint Satisfaction Problems Part 2

Constraint Satisfaction Problems

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

Week 8: Constraint Satisfaction Problems

CS 4100 // artificial intelligence

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

CS 188: Artificial Intelligence. Recap: Search

Constraint Satisfaction Problems

Artificial Intelligence Constraint Satisfaction Problems

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

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

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

Constraint Satisfaction Problems

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

Constraint Satisfaction Problems

CS 188: Artificial Intelligence Spring Announcements

CS 188: Artificial Intelligence Fall 2011

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

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

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

Constraint Satisfaction Problems

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

Discussion Section Week 1

Foundations of Artificial Intelligence

Outline. Best-first search

Constraint Satisfaction Problems

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

CONSTRAINT SATISFACTION

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

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

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

CS 188: Artificial Intelligence Fall 2008

Constraint Satisfaction Problems

Constraint Satisfaction Problems

Constraint Satisfaction Problems. Chapter 6

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

CS 188: Artificial Intelligence

Local Search and Constraint Reasoning. CS 510 Lecture 3 October 6, 2009

Example: Map coloring

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

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

Artificial Intelligence

Artificial Intelligence

CS 188: Artificial Intelligence

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

Map Colouring. Constraint Satisfaction. Map Colouring. Constraint Satisfaction

CS 4100/5100: Foundations of AI

Mathematical Programming Formulations, Constraint Programming

Solving Problems by Searching: Constraint Satisfaction Problems

General Methods and Search Algorithms

Review I" CMPSCI 383 December 6, 2011!

CONSTRAINT SATISFACTION

CSE 573: Artificial Intelligence

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

CS 188: Artificial Intelligence Spring Today

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

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

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

Review Adversarial (Game) Search ( ) Review Constraint Satisfaction ( ) Please review your quizzes and old CS-271 tests

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

Local Search for CSPs

Transcription:

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

Constraint satisfaction problems What is a CSP? Finite set of variables V, V 2,, V n Nonempty domain of possible values for each variable D V, D V2, D Vn Finite set of constraints C, C 2,, C m Each constraint C i limits the values that variables can take, e.g., V V 2 A state is an assignment of values to some or all variables. Consistent assignment: assignment does not violate the constraints. 2

Constraint satisfaction problems An assignment is complete when every variable has a value. A solution to a CSP is a complete assignment that satisfies all constraints. Some CSPs require a solution that maximizes an objective function. Applications: Scheduling the Hubble Space Telescope, Floor planning for VLSI, Map coloring, Cryptography 3

Example: Map-Coloring 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 So (WA,NT) must be in {(red,green),(red,blue),(green,red), } 4

Example: Map-Coloring Solutions are complete and consistent assignments, e.g., WA = red, NT = green,q = red,nsw = green, V = red,sa = blue,t = green 5

Constraint graph Binary CSP: each constraint relates two variables Constraint graph: nodes are variables arcs are constraints CSP benefits Standard representation pattern Generic goal and successor functions Generic heuristics (no domain specific expertise). Graph can be used to simplify search. e.g. Tasmania is an independent subproblem. 6

Varieties of CSPs Discrete variables finite domains: n variables, domain size d O(d n ) complete assignments e.g., Boolean CSPs, includes 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 + 5 StartJob 3 Continuous variables e.g., start/end times for Hubble Space Telescope observations linear constraints solvable in polynomial time by linear programming 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 Preference (soft constraints) e.g. red is better than green can be represented by a cost for each variable assignment => Constrained optimization problems. 8

Example: Cryptarithmetic Variables: F T U W R O X X 2 X 3 Domain: {0,,2,3,4,5,6,7,8,9} Constraints: Alldiff (F,T,U,W,R,O) O + O = R + 0 X X + W + W = U + 0 X 2 X 2 + T + T = O + 0 X 3 X 3 = F, T 0, F 0 9

CSP as a standard search problem A CSP can easily be expressed as a standard search problem. Initial State: the empty assignment {}. Operators: Assign value to unassigned variable provided that there is no conflict. Goal test: assignment consistent and complete. Path cost: constant cost for every step. Solution is found at depth n, for n variables Hence depth first search can be used 0

Backtracking search Variable assignments are commutative, Eg [ WA = red then NT = green ] equivalent to [ 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 basic uninformed algorithm for CSPs Can solve n-queens for n 25

Backtracking search function BACKTRACKING-SEARCH(csp) % returns a solution or failure return RECURSIVE-BACKTRACKING({}, csp) function RECURSIVE-BACKTRACKING(assignment, csp) % returns a solution or 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 according to CONSTRAINTS[csp] then return failure add {var=value} to assignment result RECURSIVE-BACKTRACKING(assignment, csp) if result failure then return result remove {var=value} from assignment 2

Backtracking example 3

Backtracking example 4

Backtracking example 5

Backtracking example 6

Improving backtracking efficiency General-purpose methods can give huge speed gains: Which variable should be assigned next? In what order should its values be tried? Can we detect inevitable failure early? 7

Most constrained variable Most constrained variable: choose the variable with the fewest legal values a.k.a. minimum remaining values (MRV) heuristic 8

Most constraining variable Tie-breaker among most constrained variables Most constraining variable: choose the variable with the most constraints on remaining variables 9

Least constraining value Given a variable, choose the least constraining value: the one that rules out the fewest values in the remaining variables Combining these heuristics makes 000 queens feasible 20

Forward Checking Idea: Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values 2

Forward checking Idea: Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values 22

Forward checking Idea: Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values 23

Forward checking Idea: Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values No more value for SA: backtrack 24

Example: 4-Queens Problem 2 3 4 X {,2,3,4} X2 {,2,3,4} 2 3 4 X3 {,2,3,4} X4 {,2,3,4} [4-Queens slides copied from B.J. Dorr] 25

Example: 4-Queens Problem 2 3 4 X {,2,3,4} X2 {,2,3,4} 2 3 4 X3 {,2,3,4} X4 {,2,3,4} 26

Example: 4-Queens Problem 2 3 4 X {,2,3,4} X2 {,,3,4} 2 3 4 X3 {,2,,4} X4 {,2,3, } 27

Example: 4-Queens Problem 2 3 4 X {,2,3,4} X2 {,,3,4} 2 3 4 X3 {,2,,4} X4 {,2,3, } 28

Example: 4-Queens Problem 2 3 4 X {,2,3,4} X2 {,,3,4} 2 3 4 X3 {,,, } X4 {,2,, } 29

Example: 4-Queens Problem 2 3 4 X {,2,3,4} X2 {,,,4} 2 3 4 X3 {,2,,4} X4 {,2,3, } 30

Example: 4-Queens Problem 2 3 4 X {,2,3,4} X2 {,,,4} 2 3 4 X3 {,2,, } X4 {,,3, } 3

Example: 4-Queens Problem 2 3 4 X {,2,3,4} X2 {,,,4} 2 3 4 X3 {,2,, } X4 {,,3, } 32

Example: 4-Queens Problem 2 3 4 X {,2,3,4} X2 {,,,4} 2 3 4 X3 {,2,, } X4 {,,, } 33

Example: 4-Queens Problem 2 3 4 X {,2,3,4} X2 {,2,3,4} 2 3 4 X3 {,2,3,4} X4 {,2,3,4} 34

Example: 4-Queens Problem 2 3 4 X {,2,3,4} X2 {,,,4} 2 3 4 X3 {,,3, } X4 {,,3,4} 35

Example: 4-Queens Problem 2 3 4 X {,2,3,4} X2 {,,,4} 2 3 4 X3 {,,3, } X4 {,,3,4} 36

Example: 4-Queens Problem 2 3 4 X {,2,3,4} X2 {,,,4} 2 3 4 X3 {,,, } X4 {,,3, } 37

Example: 4-Queens Problem 2 3 4 X {,2,3,4} X2 {,,,4} 2 3 4 X3 {,,, } X4 {,,3, } 38

Example: 4-Queens Problem 2 3 4 X {,2,3,4} X2 {,,,4} 2 3 4 X3 {,,, } X4 {,,3, } 39

Example: 4-Queens Problem 2 3 4 X {,2,3,4} X2 {,,,4} 2 3 4 X3 {,,, } X4 {,,3, } 40

Constraint Propagation Simplest form of propagation makes each arc consistent Arc X Y (link in constraint graph) is consistent iff for every value x of X there is some allowed y 4

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 42

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 If X loses a value, neighbors of X need to be rechecked 43

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 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 44

Arc Consistency Algorithm AC-3 function AC-3(csp) % returns the CSP, possibly with reduced domains inputs: csp, a binary csp with variables {X, X 2,, X n } local variables: queue, a queue of arcs initially 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 a value is removed removed false for each x in DOMAIN[X i ] do if no value y in DOMAIN[X j ] allows (x,y) to satisfy the constraints between X i and X j then delete x from DOMAIN[X i ]; removed true return removed Time complexity: O(n 2 d 3 ) 45

Local Search for CSPs Hill-climbing methods 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., hill-climb with h(n) = number of violated constraints 46

Example: n-queens States: 4 queens in 4 columns (4 4 = 256 states) Actions: move queen in column Goal test: no attacks Evaluation: h(n) = number of attacks Given random initial state, we can solve n-queens for large n with high probability 47

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

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) additionally constrains values and detects inconsistencies Iterative min-conflicts is usually effective in practice 49