Constraint Satisfaction [RN2] Sec [RN3] Sec Outline

Similar documents
Constraint Satisfaction

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

What we will try to do...

Constraint Satisfaction Problems

Chapter 6 Constraint Satisfaction Problems

Constraint Satisfaction Problems - CSP. March 23, 2017

Introduction to Arti Intelligence

Constraint satisfaction search. Combinatorial optimization search.

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

Outline First-order logic. First-order Logic. Introduction. Recall: 4-Queens problem. First-order Logic. First-order Logic Syntax.

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

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

Finding optimal configurations ( combinatorial optimization)

Artificial Intelligence

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

Constraint sat. prob. (Ch. 6)

CS360 Homework 12 Solution

Section Handout 5 Solutions

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

NP-Hardness reductions

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

Propositional Logic. Methods & Tools for Software Engineering (MTSE) Fall Prof. Arie Gurfinkel

Constraint Satisfaction 101

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

Chapter 7 R&N ICS 271 Fall 2017 Kalev Kask

Notes for Lecture Notes 2

CS 374: Algorithms & Models of Computation, Spring 2017 Greedy Algorithms Lecture 19 April 4, 2017 Chandra Chekuri (UIUC) CS374 1 Spring / 1

Temporal Constraint Networks

An Introduction to SAT Solving

Second Assignment (out on February 3) CS-E4800 Artificial Intelligence. Example of the modeling language for logic used in the 2nd assignment

CS-E4800 Artificial Intelligence

Temporal Constraint Networks

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

Improving Repair-based Constraint Satisfaction Methods by Value Propagation

Reasoning with Deterministic and Probabilistic graphical models Class 2: Inference in Constraint Networks Rina Dechter

CS221 Practice Midterm

PROBABILITY. Inference: constraint propagation

SAT, NP, NP-Completeness

POLYNOMIAL SPACE QSAT. Games. Polynomial space cont d

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

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

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

Introduction to Artificial Intelligence Propositional Logic & SAT Solving. UIUC CS 440 / ECE 448 Professor: Eyal Amir Spring Semester 2010

Lecture Notes on From Rules to Propositions

COMP219: Artificial Intelligence. Lecture 20: Propositional Reasoning

Space and Nondeterminism

Temporal Constraint Networks

Introduction to Solving Combinatorial Problems with SAT

Satisfiability and SAT Solvers. CS 270 Math Foundations of CS Jeremy Johnson

CS 188 Introduction to Fall 2007 Artificial Intelligence Midterm

More NP-Complete Problems

Principles of AI Planning

CS100: DISCRETE STRUCTURES. Lecture 3 Matrices Ch 3 Pages:

1 Computational Problems

AUTOMATED REASONING. Agostino Dovier. Udine, October 2, Università di Udine CLPLAB

Geometric Steiner Trees

Final exam of ECE 457 Applied Artificial Intelligence for the Fall term 2007.

Indian Institute of Information Technology Design and Manufacturing, Kancheepuram Chennai , India. Assignment 1 - Propositional Logic

1 Primals and Duals: Zero Sum Games

Name: UW CSE 473 Final Exam, Fall 2014

Bernhard Nebel, Julien Hué, and Stefan Wölfl. June 27 & July 2/4, 2012

Principles of AI Planning

PROPOSITIONAL LOGIC. VL Logik: WS 2018/19

Complexity Theory Part II

Final Examination CS 540-2: Introduction to Artificial Intelligence

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

A* Search. 1 Dijkstra Shortest Path

NP-complete problems. CSE 101: Design and Analysis of Algorithms Lecture 20

1 More finite deterministic automata

Alpha-Beta Pruning: Algorithm and Analysis

Show that the following problems are NP-complete

Foundations of Artificial Intelligence

Classical Propositional Logic

Min-Max Message Passing and Local Consistency in Constraint Networks

Introduction to Quantum Logic. Chris Heunen

Circuits. Lecture 11 Uniform Circuit Complexity

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

Alpha-Beta Pruning: Algorithm and Analysis

Algorithms and Theory of Computation. Lecture 22: NP-Completeness (2)

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 22 Lecturer: David Wagner April 24, Notes 22 for CS 170

Automata-based Verification - III

Essential facts about NP-completeness:

Algorithm Design Strategies V

Searching in non-deterministic, partially observable and unknown environments

HW8. Due: November 1, 2018

CS311 Computational Structures. NP-completeness. Lecture 18. Andrew P. Black Andrew Tolmach. Thursday, 2 December 2010

Chapter 3: Proving NP-completeness Results

Local Search & Optimization

Integer vs. constraint programming. IP vs. CP: Language

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

Chapter 0 Introduction. Fourth Academic Year/ Elective Course Electrical Engineering Department College of Engineering University of Salahaddin

Part of Speech Tagging: Viterbi, Forward, Backward, Forward- Backward, Baum-Welch. COMP-599 Oct 1, 2015

Chapter 7 Propositional Satisfiability Techniques

Writing: Algorithms, Mathematics, Definitions

Lecture Notes on SAT Solvers & DPLL

Lecture 23: More PSPACE-Complete, Randomized Complexity

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

Analyzing a Heuristic Strategy. for Constraint-Satisfaction and Scheduling. Mark D. Johnston and Steven Minton. Abstract

Transcription:

Constraint Satisfaction [RN2] Sec 5.1-5.2 [RN3] Sec 6.1-6.3 CS 486/686 Lecture 4: Jan 12, 2012 University of Waterloo 1 Outline What are CSPs? Standard search and CSPs Improvements Backtracking Backtracking + heuristics Forward checking 2 1

Introduction In the last couple of lectures we have been solving problems by searching in a space of states Treating states as black boxes, ignoring any structure inside them Using problem-specific routines Today we study problems where the state structure is important 3 States: all arrangements of 0,1,, or 8 queens on the board Initial state: 0 queens on the board Successor function: Add a queen to the board Goal test: 8 queens on the board with no two of them attacking each other 64x63x 57 3x10 14 states 4 2

States: all arrangements k queens (0 k 8), one per column in the leftmost k columns, with no queen attacking another Initial state: 0 queens on the board Successor function: Add a queen to the leftmost empty column such that it is not attacked Goal test: 8 queens on the board 2057 States 5 Introduction Earlier search methods studied often make choices in an arbitrary order In many problems the same state can be reached independent of the order in which the moves are chosen (commutative actions) Can we solve problems efficiently by being smart in the order in which we take actions? 6 3

4-queens Constraint Propagation Place a queen in a square Remove conflicting squares from consideration 7 4-queens Constraint Propagation Place a queen in a square Remove conflicting squares from consideration 8 4

4-queens Constraint Propagation Place a queen in a square Remove conflicting squares from consideration 9 4-queens Constraint Propagation Place a queen in a square Remove conflicting squares from consideration 10 5

CSP Definition A constraint satisfaction problem (CSP) is defined by {V,D,C} where V ={V 1,V 2,,V n } is a set of variables D={D 1,,D n } is the set of domains, D i is the domain of possible values for variable V i C={C 1,,C m } is the set of constraints Each constraint involves some subset of the variables and specifies the allowable combinations of values for that subset 11 CSP Definition A state is an assignment of values to some or all of the variables {V i =x i, V j =x j, } An assignment is consistent if it does not violate any constraints A solution is a complete, consistent assignment ( hard constraints ) Some CSPs also require an objective function to be optimized ( soft constraints ) 12 6

Example 1: 8-Queens 64 variables V ij, i=1 to 8, j=1 to 8 Domain of each variable is {0,1} Constraints V ij =1 V ik =0 for all k j V ij =1 V kj =0 for all k i Similar constraint for diagonals i,j V ij =8 Binary constraints relate two variables 13 Example 2 8 queens 8 variables V i, i=1 to 8 Domain of each variable is {1,2,,8} Constraints V i =k V j k for all j i Similar constraints for diagonals Binary constraints relate two variables 14 7

Example 3 - Map Coloring WA NT SA Q NSW V T 7 variables {WA,NT,SA,Q,NSW,V,T} Each variable has the same domain: {red, green, blue} No two adjacent variables have the same value: WA NT SA WA NT, WA SA, NT SA, NT Q, SA Q, SA NSW, SA V,Q NSW, NSW V Q NSW T V Constraint graph 15 Example from R and N, Annotations from Stanford CS121 Example 4 - Street Puzzle 1 2 3 4 5 N i = {English, Spaniard, Japanese, Italian, Norwegian} C i = {Red, Green, White, Yellow, Blue} D i = {Tea, Coffee, Milk, Fruit-juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, Doctor} A i = {Dog, Snails, Fox, Horse, Zebra} The Englishman lives in the Red house The Spaniard has a Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctor s The Horse is next to the Diplomat s Who owns the Zebra? Who drinks Water? 16 8

Example from R and N, Annotations from Stanford CS121 1 2 3 4 5 Street Puzzle N i = {English, Spaniard, Japanese, Italian, Norwegian} C i = {Red, Green, White, Yellow, Blue} D i = {Tea, Coffee, Milk, Fruit-juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, Doctor} A i = {Dog, Snails, Fox, Horse, Zebra} The Englishman lives in the Red house (N i = English) (C i = Red) The Spaniard has a Dog The Japanese is a Painter (N i = Japanese) (J i = Painter) The Italian drinks Tea The Norwegian lives in the first house on the left (N 1 = Norwegian) The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctor s The Horse is next to the Diplomat s (C i = White) (C i+1 = Green) (C 5 White) (C 1 Green) left as an exercise 17 Example from R and N, Annotations from Stanford CS121 1 2 3 4 5 Street Puzzle N i = {English, Spaniard, Japanese, Italian, Norwegian} C i = {Red, Green, White, Yellow, Blue} D i = {Tea, Coffee, Milk, Fruit-juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, Doctor} A i = {Dog, Snails, Fox, Horse, Zebra} The Englishman lives in the Red house (N i = English) (C i = Red) The Spaniard has a Dog The Japanese is a Painter (N i = Japanese) (J i = Painter) The Italian drinks Tea The Norwegian lives in the first house on the left (N 1 = Norwegian) The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctor s The Horse is next to the Diplomat s (C i = White) (C i+1 = Green) (C 5 White) (C 1 Green) unary constraints 18 9

Example from R and N, Annotations from Stanford CS121 1 2 3 4 5 Street Puzzle N i = {English, Spaniard, Japanese, Italian, Norwegian} C i = {Red, Green, White, Yellow, Blue} D i = {Tea, Coffee, Milk, Fruit-juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, Doctor} A i = {Dog, Snails, Fox, Horse, Zebra} The Englishman lives in the Red house The Spaniard has a Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctor s The Horse is next to the Diplomat s i,j [1,5], i j, N i N j i,j [1,5], i j, C i C j... 19 Example from R and N, Annotations from Stanford CS121 Street Puzzle 1 2 3 4 5 N i = {English, Spaniard, Japanese, Italian, Norwegian} C i = {Red, Green, White, Yellow, Blue} D i = {Tea, Coffee, Milk, Fruit-juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, Doctor} A i = {Dog, Snails, Fox, Horse, Zebra} The Englishman lives in the Red house The Spaniard has a Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left N 1 = Norwegian The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk D 3 = Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctor s The Horse is next to the Diplomat s 20 10

Example from R and N, Annotations from Stanford CS121 Street Puzzle 1 2 3 4 5 N i = {English, Spaniard, Japanese, Italian, Norwegian} C i = {Red, Green, White, Yellow, Blue} D i = {Tea, Coffee, Milk, Fruit-juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, Doctor} A i = {Dog, Snails, Fox, Horse, Zebra} The Englishman lives in the Red house C 1 Red The Spaniard has a Dog A 1 Dog The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left N 1 = Norwegian The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk D 3 = Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice J 3 Violinist The Fox is in the house next to the Doctor s The Horse is next to the Diplomat s 21 Example 5 - Scheduling Four tasks T 1, T 2, T 3, and T 4 are related by time constraints: T 1 must be done during T 3 T 2 must be achieved before T 1 starts T 2 must overlap with T 3 T 4 must start after T 1 is complete Are the constraints compatible? What are the possible time relations between two tasks? What if the tasks use resources in limited supply? 22 11

Example 6-3-Sat n Boolean variables, V 1,,V n K constraints of the form V i v V j v V k where V i is either true or false NP-complete 23 Properties of CSPs Types of variables Discrete and finite Map colouring, 8-queens, boolean CSPs Discrete variables with infinite domains Scheduling jobs in a calendar Require a constraint language (Job 1 +3 Job 2 ) Continuous domains Scheduling on the Hubble telescope Linear programming 24 12

Properties of CSPs Types of contraints Unary constraint relates a variable to a single value Queensland=Blue, SA Green Binary constraints relates two variables SA NSW Can use a constraint graph to represent CSPs with only binary constraints Higher order constraints involve three of more variables Alldiff(V 1,,V n ) Can use a constraint hypergraph to represent the problem 25 CSPs and search N variables V 1,,V n Valid assignment: {V 1 =x 1,,V k =x k } for 0 k n such that values satisfy constraints on the variables States: valid assignments Initial state: empty assignment Successor: {V 1 =x 1,,V K =x k } {V 1 =x 1,,V k =x k, V k+1 =x k+1 } Goal test: complete assignment If all domains have size d, then there are O(d n ) complete assignments 26 13

CSPs and commutativity CSPs are commutative! The order of application of any given set of actions has no effect on the outcome When assigning values to variables we reach the same partial assignment, no matter the order All CSP search algorithms generate successors by considering possible assignments for only a single variable at each node in the search tree 27 CSPs and commutativity 3 variables V 1, V 2, V 3 Let the current assignment be A={V 1 =x 1 } Pick variable 3 Let domain of V 3 be {a,b,c} The successors of A are {V 1 =x 1,V 3 =a} {V 1 =x 1,V 3 =b} {V 1 =x 1,V 3 =c} 28 14

Backtracking Search Depth first search which chooses values for one variable at a time Backtracks when a variable has no legal values to assign 29 Backtracking 0 WA NT SA Q V NSW T 30 15

Backtracking WA=blue 0 WA=red WA=green WA NT SA Q V NSW T 31 Backtracking WA=blue 0 WA=red WA=green NT=blue NT=red NT=green WA NT SA Q V NSW T 32 16

Backtracking WA=blue 0 WA=red WA=green NT=blue NT=red NT=green SA=blue SA=red SA=green WA NT SA Q V NSW T 33 Backtracking and efficiency Backtracking search is an uninformed search method Not very efficient We can do better by thinking about the following questions Which variable should be assigned next? In which order should its values be tried? Can we detect inevitable failure early (and avoid the same failure in other paths)? 34 17

Most constrained variable Choose the variable which has the fewest legal moves AKA minimum remaining values (MRV) heuristic D NT ={green, blue} D SA ={green, blue} D SA ={blue} D Q ={blue, red} D others ={red, green, blue} D others ={red,green,blue} 35 Most constraining variable Most constraining variable: choose the variable with the most constraints on remaining variables Tie-breaker among most constrained variables SA is involved in 5 constraints 36 18

Least-constraining value Given a variable, choose the least constraining value: the one that rules out the fewest values in the remaining variables 37 Forward checking The third question was Is there a way to detect failure early? Forward checking Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values 38 19

Forward Checking in Map Coloring WA NT SA Q NSW T V WA NT Q NSW V SA T RGB RGB RGB RGB RGB RGB RGB 39 Forward Checking in Map Coloring WA NT SA Q NSW T V WA NT Q NSW V SA T RGB RGB RGB RGB RGB RGB RGB R RGB RGB RGB RGB RGB RGB Forward checking removes the value Red of NT and of SA 40 20

Forward Checking in Map Coloring WA NT SA Q NSW T V WA NT Q NSW V SA T RGB RGB RGB RGB RGB RGB RGB R GB RGB RGB RGB GB RGB R GB G RGB RGB GB RGB 41 Forward Checking in Map Coloring WA NT SA Q NSW T V WA NT Q NSW V SA T RGB RGB RGB RGB RGB RGB RGB R GB RGB RGB RGB GB RGB R B G RB RGB B RGB R B G RB B B RGB 42 21

Forward Checking in Map Coloring Empty set: the current assignment {(WA R), (Q G), (V B)} does not lead to a solution WA NT Q NSW V SA T RGB RGB RGB RGB RGB RGB RGB R GB RGB RGB RGB GB RGB R B G RB RGB B RGB R B G RB B B RGB 43 Example: 4 Queens 1 2 1 2 3 4 X1 X2 3 4 X3 X4 44 22

Example: 4 Queens 1 2 1 2 3 4 X1 X2 3 4 X3 X4 45 Example: 4 Queens 1 2 1 2 3 4 X1 X2 {,,3,4} 3 4 X3 {,2,,4} X4 {,2,3, } 46 23

Example: 4 Queens 1 2 1 2 3 4 X1 X2 {,,3,4} 3 4 X3 {,2,,4} X4 {,2,3, } 47 Example: 4 Queens 1 2 1 2 3 4 X1 X2 {,,3,4} 3 4 X3 {,,, } X4 {,2,, } 48 24

Example: 4 Queens 1 2 1 2 3 4 X1 X2 { 1, 2,3,4} 3 4 X3 { 1,2,3,4} X4 { 1,2,3,4} 49 Example: 4 Queens 1 2 1 2 3 4 X1 X2 {,,,4} 3 4 X3 { 1,,3, } X4 {,2,3,4} 50 25

Example: 4 Queens 1 2 1 2 3 4 X1 X2 {,,,4} 3 4 X3 { 1,,3, } X4 {,2,3,4} 51 Example: 4 Queens 1 2 1 2 3 4 X1 X2 {,,,4} 3 4 X3 { 1,,, } X4 {,,3,4} 52 26

Example: 4 Queens 1 2 1 2 3 4 X1 X2 {,,,4} 3 4 X3 { 1,,, } X4 {,,3,4} 53 Example: 4 Queens 1 2 1 2 3 4 X1 X2 {,,,4} 3 4 X3 { 1,,, } X4 {,,,4} 54 27

Example: 4 Queens 1 2 1 2 3 4 X1 X2 {,,,4} 3 4 X3 { 1,,, } X4 {,,,4} 55 Summary What you should know How to formalize problems as CSPs Backtracking search Heuristics Variable ordering Value ordering Forward checking 56 28

Next class Local search techniques 57 29