Constraint Satisfaction Problems - CSP. March 23, 2017

Similar documents
Constraint Satisfaction [RN2] Sec [RN3] Sec Outline

Constraint Satisfaction

Constraint Satisfaction Problems

Chapter 6 Constraint Satisfaction Problems

Introduction to Arti Intelligence

What we will try to do...

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

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

Constraint satisfaction search. Combinatorial optimization search.

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

Artificial Intelligence

Finding optimal configurations ( combinatorial optimization)

Constraint sat. prob. (Ch. 6)

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

Constraint Satisfaction 101

CS360 Homework 12 Solution

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

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

CISC681/481 AI Midterm Exam

Alternative Methods for Obtaining. Optimization Bounds. AFOSR Program Review, April Carnegie Mellon University. Grant FA

CS 188 Introduction to Fall 2007 Artificial Intelligence Midterm

Show that the following problems are NP-complete

CS 4700: Foundations of Artificial Intelligence Homework 2 Solutions. Graph. You can get to the same single state through multiple paths.

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

Homework Assignment 4 Solutions

Min-Max Message Passing and Local Consistency in Constraint Networks

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

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

CS/COE

Complexity Theory Part II

The P versus NP Problem. Ker-I Ko. Stony Brook, New York

CSCI3390-Lecture 14: The class NP

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

CS221 Practice Midterm

Introduction to Mathematical Programming IE406. Lecture 21. Dr. Ted Ralphs

Chapter 4 Deliberation with Temporal Domain Models

Probability & Combinatorics Test and Solutions February 18, 2012

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

State Space Search Problems

1 Sequences and Summation

Toward Quandle Dichotomy

Hybrid tractability of valued constraint problems

An Algebraic Approach to Constraint Satisfaction Problems

Gestion de la production. Book: Linear Programming, Vasek Chvatal, McGill University, W.H. Freeman and Company, New York, USA

CMSC 722, AI Planning. Planning and Scheduling

Alpha-Beta Pruning: Algorithm and Analysis

Alpha-Beta Pruning: Algorithm and Analysis

KU Leuven Department of Computer Science

Constraint Programming Overview based on Examples

Data Structures in Java. Session 22 Instructor: Bert Huang

DIMACS Technical Report March Game Seki 1

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

Part 4. Decomposition Algorithms

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

Alpha-Beta Pruning: Algorithm and Analysis

Local Search & Optimization

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

Analysis of Algorithms. Unit 5 - Intractable Problems

Organization Team Team ID#

Resource Constrained Project Scheduling Linear and Integer Programming (1)

Temporal Constraint Networks

Improving Repair-based Constraint Satisfaction Methods by Value Propagation

Lecture 4. 1 Circuit Complexity. Notes on Complexity Theory: Fall 2005 Last updated: September, Jonathan Katz

Projection, Consistency, and George Boole

Section Handout 5 Solutions

5 Integer Linear Programming (ILP) E. Amaldi Foundations of Operations Research Politecnico di Milano 1

2013 University of New South Wales School Mathematics Competition

CS 301: Complexity of Algorithms (Term I 2008) Alex Tiskin Harald Räcke. Hamiltonian Cycle. 8.5 Sequencing Problems. Directed Hamiltonian Cycle

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

P C max. NP-complete from partition. Example j p j What is the makespan on 2 machines? 3 machines? 4 machines?

Stochastic Decision Diagrams

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

Final Examination CS 540-2: Introduction to Artificial Intelligence

Temporal Constraint Networks

Linear Algebra March 16, 2019

Computational Models Lecture 11, Spring 2009

Lecture 3 (Notes) 1. The book Computational Complexity: A Modern Approach by Sanjeev Arora and Boaz Barak;

ELEMENTARY LINEAR ALGEBRA

Consistency algorithms. Chapter 3

CSC 1700 Analysis of Algorithms: Warshall s and Floyd s algorithms

Consistency as Projection

is called an integer programming (IP) problem. model is called a mixed integer programming (MIP)

Lecture 29: Tractable and Intractable Problems

Travelling Salesman Problem

An Introduction to SAT Solving

SOLVING FINITE-DOMAIN LINEAR CONSTRAINTS IN PRESENCE OF THE ALLDIFFERENT

CS412: Lecture #17. Mridul Aanjaneya. March 19, 2015

Automatic Generation of Redundant Models for Permutation Constraint Satisfaction Problems

Introduction to Solving Combinatorial Problems with SAT

Chapter 7 Propositional Satisfiability Techniques

Informatique Fondamentale IMA S8

Column Generation. i = 1,, 255;

BBM402-Lecture 11: The Class NP

arxiv: v1 [math.co] 18 May 2018

Chapter 9. PSPACE: A Class of Problems Beyond NP. Slides by Kevin Wayne Pearson-Addison Wesley. All rights reserved.

Interleaved Alldifferent Constraints: CSP vs. SAT Approaches

X-MA2C01-1: Partial Worked Solutions

Introduction to Spring 2009 Artificial Intelligence Midterm Exam

Data Structures and Algorithms

On Detecting Multiple Faults in Baseline Interconnection Networks

Transcription:

Constraint Satisfaction Problems - CSP March 23, 2017

Examples of Applications 8-puzzle blocks world (e.g.: Hanoi tower) n-queens cryptarithmetic missionaires and cannibals solitaire many others...

n-queens Problem: place n queens in a board n n so that no queens attack each other in the rows, columns or diagonals 2 ways of solving the problem: incremental and complete Possible states (a) and moves (b): 1. Incremental 1 a) any arrangement of 0 to n queens in the board b) add 1 queen to any position in the board 2. Incremental 2 a) arrangements of 0 to n queens with no attacks b) add 1 queen to the next leftmost empty column such that this does not attack the others already placed 3. Completo a) arrangements of n queens, 1 em cada coluna b) mover qq rainha atacada para outra posição na mesma coluna

Cryptarithmtic SOLUTION FORTY 29786 com: F = 2 + TEN 850 O = 9 + TEN 850 R = 7 etc -------- ------ SIXTY 31486

Cryptarithmetic states: set of letters that are replaced by digits operators (moves): replace all occurrences of a letter by a digit that was never used before possible rules to select digits: numerical order to avoid repetitions, more strict obeying the mathematical properties of the problem final state: solution contains only digits and represent a correct sum cost of the solution: zero

Missionaires and Cannibals 3 missionaires and 3 cannibals are by in a river bank with a boat that fits only 2 people Problem: find a way of moving all people from one river bank to the other : Constraint: we can never leave a number of cannibals larger than missionaires in a river bank :)

Missionaires and Cannibals 3 missionaires and 3 cannibals are by in a river bank with a boat that fits only 2 people Problem: find a way of moving all people from one river bank to the other : Constraint: we can never leave a number of cannibals larger than missionaires in a river bank :) states: any ordered sequence of 3 numbers representing the missionaires, the cannibals and the boat initial state: (3,3,1) final state: (0,0,0) cost: number of river traversals rules (moves): take a missionaire, take a cannibal, take 2 cannibals etc...

Missionaires and Cannibals

Other Approach and Representation Constraint Satisfaction special type of problem that satisfies structural properties besides the basic requirements for general search problems states: set of variables variables can take values from a domain: set of possible values a variable can take (discrete/continuous, finite/infinite) initial state: all variables with possible initial values from the domain final state: final assignment of variable-value that does not violate the problem constraints maximum search tree depth: number of variables Explicit representation for constraints (Portuguese translation: restrições)

Example CSP: Map-Coloring Variables: WA, NT, Q, NSW, V, SA, T Domain: D=red,green,blue Constraints: adjacent regions must have different colors WA NT (WA,NT) { (red,green),(red,blue),(green,red),...} Solutions are assignments satisfying all constraints, e.g: {WA=red, NT=green, Q=red, NSW=green, V=red, SA=blue, T=green}

Example CSP: N-queens Formulation 1: Variables: X ij Domains: {0,1} Constraints: i, j, k(x ij, X ik ) {(0, 0), (0, 1), (1, 0)} i, j, k(x ij, X kj ) {(0, 0), (0, 1), (1, 0)} i, j, k(x ij, X i+k,j+k ) {(0, 0), (0, 1), (1, 0)} i, j, k(x ij, X i+k,j k ) {(0, 0), (0, 1), (1, 0)} X ij = N i,j

Example CSP: N-queens Formulation 2: Variables: Qk Domains: {1,2,3,... } Constraints: i, j non-threatening(q i, Q j )or (Q1, Q2) {(1, 3), (1, 4),...}...

Constraint Graphs Binary CSP: each constraint relates (at most) two variables Binary constraint graph: nodes are variables, arcs show constraints General-purpose CSP algorithms use the graph structure to speed up search. E.g., Tasmania is an independent subproblem Solutions are assignments satisfying all constraints, e.g: {WA=red, NT=green, Q=red, NSW=green, V=red, SA=blue, T=green}

Example CSP: Cryptarithmetic Variables (circles): F T U W R O X1 X2 X3 T W O + T W O -------- F O U R Domains: {0,1,2,3,4,5,6,7,8,9} Constraints (boxes): alldiff(f,t,u,w,r,o) O + O = R + 10. X1...

Example CSP: Sudoku Variables: Each (open) square Domains: {1,2,...,9} Constraints: 9-way alldiff for each column 9-way alldiff for each row 9-way alldiff for each region

Varieties of CSPs Discrete variables Finite domains Size d means O(d n ) complete assignments E.g., Boolean CSPs, including Boolean satisfiability (NP-complete) Infinite domains (integers, strings, etc.) E.g., job scheduling, variables are start/end times for each job Linear constraints solvable, nonlinear undecidable Continuous variables E.g., start-end state of a robot Linear constraints solvable in polynomial time by LP methods

Varieties of Constraints Variables of Constraints Unary constraints involve a single variable (equiv. to shrinking domains): SA green Binary constraints involve pairs of variables: SA WA Higher-order constraint 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 Gives constrained optimization problems

Standard Search Formulation Standard search formulation of CSPs (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 Goal test: the current assignment is complete and satisfies all constraints

Search Methods What does BFS do? What does DFS do?

Constraint Satisfaction: improving search n-queens variables: possible positions in the board constraints: no queen can attack each other initial variable values: V1 in 1..n, V 2 in 1..n etc, with n the width of the board

Constraint Satisfaction: possible algorithms aloca uma nova rainha para uma nova coluna a cada nível (solução incremental) complexidade: n n = πd i = D 1 D 2... D n fator de ramificação: n fator máximo de ramificação: n n = D i = D 1 + D 2 +... + D n se todas as variáveis fossem instanciadas com todos os valores possíveis no primeiro nível da árvore

Constraint Satisfaction: Possible algorithms n = 8 (0,0,0,0,0,0,0,0) N (1,0,0,0,0,0,0,0) (0,1,0,0,0,0,0,0) (0,0,1,0,0,0,0,0)... i (2,0,0,0,0,0,0,0) (0,2,0,0,0,0,0,0) (0,0,2,0,0,0,0,0)... v... 1 (8,0,0,0,0,0,0,0) (0,8,0,0,0,0,0,0) (0,0,8,0,0,0,0,0)... N (1,1,0,0,0,0,0,0) (0,1,1,0,0,0,0,0) (1,0,1,0,0,0,0,0)... i (2,2,0,0,0,0,0,0) (0,2,2,0,0,0,0,0) (2,0,2,0,0,0,0,0)... v... 2 (8,8,0,0,0,0,0,0) (0,8,8,0,0,0,0,0) (8,0,8,0,0,0,0,0)...

Constraint Satisfaction: Possible algorithms using DFS, the tree that contains (0,0,0,0,0,0,0,0) -> (1,0,0,0,0,0,0,0) -> (1,1,0,0,0,0,0,0) -> (1,1,1,0,0,0,0,0) -> (1,1,1,1,0,0,0,0) ->... will be explored even knowing that (1,1,1,1,1,1,1,1) is not a solution Class of algorithms generate-and-test

Constraint Satisfaction: Possible algorithms solution: test the constraint whenever a new queen is placed in the board it is not the best solution either Suppose that we managed to place 6 queens that are safe. This placement may threat the 8th queen and the algorithm does not know! DFS will end up testing ALL possibilities for placing the 7th queen in the board! Class of algorithms: constrain-and-generate

Constraint Satisfaction: Possible algorithms solution: Look ahead! Forward Checking: checks if the other unassigned variables domains are consistent with the new partial solution, removing from the domain of other variables all values that violate the constraints General Lookahead (arc-consistency): besides executing forward checking, checks if the new set of domains conflict with each other

Forward Checking: Example n = 8 (1) V1 = 1 ==> V2 = {3,4,5,6,7,8} V3 = {2,4,5,6,7,8} V4 = {2,3,5,6,7,8} V5 = {2,3,4,6,7,8} V6 = {2,3,4,5,7,8} V7 = {2,3,4,5,6,8} V8 = {2,3,4,5,6,7} (2) V2 = 3 ==> V3 = {5,6,7,8} V4 = {2,6,7,8} V5 = {2,4,7,8} V6 = {2,4,5,8} V7 = {2,4,5,6} V8 = {2,4,5,6,7}

Forward Checking: Example +---+---+---+---+---+---+---+---+ X +---+---+---+---+---+---+---+---+ n-queens +---+---+---+---+---+---+---+---+ n=8 X +---+---+---+---+---+---+---+---+ after V1=1 +---+---+---+---+---+---+---+---+ V2=3 +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+ +---+---+---+---+---+---+---+---+

Forward Checking: Example Constraints: V i = k V j k j = 1,..., 8; j i Vi = k i, V j = k j i j k i k j j = 1,..., 8; j i

Solutions to n-queens WITHOUT searching (Explicit Solutions to the N-Queens Problem for all N, by Bo Bernhardsson) for n even and not of the form 6k + 2 (j, 2j) n 2 + j, 2j 1, for j = 1, 2,..., n 2 for n even, but not in the form 6k (j, 1 + [2(j 1) + n 2 1 mod n]) (n + 1 j, n [2(j 1) + n 2 1 mod n]), for j = 1, 2,..., n 2 for n odd Use any case above for n-1 and extend with 1 queen (n, n)

Solutions for n-queens WITHOUT searching Other references: The n-queens Problem, by Igor Rivin, Ilan Vardi, and Paul Zimmermann A simplified solution of the N queens problem, by Matthias Reichling Observation: find all solutions for the n-queens problem is not trivial :(

Constraint Satisfaction: other algorithms for inifinite domains: linear programming, simplex, revised simplex, convex hull, Gauss elimination for finite domains: forward checking, lookahead, arc-consistency in general for finite domains, two problems to solve: choice of the variable: most-constrained: smaller domain most constraining: constrains the domain of other variables as much as possible choice of the value for a variable: first-fail principle. least constraining: value that leaves more choices open to other variables

Constraint Satisfaction most-constrained: allows to solve n-queens with n equals to 100. pure forward checking: solves at most 30 least-constraining value: allows to solve n-queens with n equals to 1000.

Algorithms Backtracking (systematic search) Constraint propagation: k-consistency All that use heuristics to order variables and their values Backjumping and dependency-directed backtracking

Basic Algorithm CSP-BACKTRACKING(PartialAssignment a) If a is complete then return a X <- select an unassigned variable D <- select an ordering for the domain of X For each value v in D do If v is consistent with a then Add (X = v) to a result <- CSP-BACKTRACKING(a) If result <> failure then return result Remove (X = v) from a Return failure Initial call: CSP-BACKTRACKING({}) Solves n-queens till n 25 Combination of constraint propagation and heuristics can solve instances of size 1000 Random algorithms with min-conflicts plus parallelization can solve 3M queens in less than a minute! (see recommended reading in the discipline page)