Constraint Satisfaction and Scheduling

Similar documents
Y. Xiang, Constraint Satisfaction Problems

Smart Graphics: Methoden 3 Suche, Constraints

Introduction Solvability Rules Computer Solution Implementation. Connect Four. March 9, Connect Four

Sudoku puzzles and how to solve them

Decision Making under Uncertainty

PARALLELIZED SUDOKU SOLVING ALGORITHM USING OpenMP

Methods for Solving Sudoku Puzzles

CPS122 Lecture: State and Activity Diagrams in UML

Cross-validation for detecting and preventing overfitting

Introduction to ANSYS ICEM CFD

(Refer Slide Time: 2:03)

WRITING PROOFS. Christopher Heil Georgia Institute of Technology

Example Problems. Channel Routing. Lots of Chip Real-estate. Same connectivity, much less space. Slide 1. Slide 2

E XPLORING QUADRILATERALS

OA4-13 Rounding on a Number Line Pages 80 81

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

The 5 P s in Problem Solving *prob lem: a source of perplexity, distress, or vexation. *solve: to find a solution, explanation, or answer for

EFFICIENT KNOWLEDGE BASE MANAGEMENT IN DCSP


Session 6 Number Theory

Lecture 3. Linear Programming. 3B1B Optimization Michaelmas 2015 A. Zisserman. Extreme solutions. Simplex method. Interior point method

Scheduling Shop Scheduling. Tim Nieberg

Using Mail Merge in Microsoft Word 2003

How to Make the Most of Excel Spreadsheets

ALGEBRA. sequence, term, nth term, consecutive, rule, relationship, generate, predict, continue increase, decrease finite, infinite

Acquisition Lesson Planning Form Key Standards addressed in this Lesson: MM2A3d,e Time allotted for this Lesson: 4 Hours

Lesson 26: Reflection & Mirror Diagrams

Symbol Tables. Introduction

OA3-10 Patterns in Addition Tables

Genetic Algorithms and Sudoku

Clock Arithmetic and Modular Systems Clock Arithmetic The introduction to Chapter 4 described a mathematical system

MD5-26 Stacking Blocks Pages

Random Map Generator v1.0 User s Guide

2 SYSTEM DESCRIPTION TECHNIQUES

Lecture 16 : Relations and Functions DRAFT

Regular Expressions and Automata using Haskell

M. Sugumaran / (IJCSIT) International Journal of Computer Science and Information Technologies, Vol. 2 (3), 2011,

Graph Theory Problems and Solutions

Unit 6 Number and Operations in Base Ten: Decimals

Optimization Modeling for Mining Engineers

A search based Sudoku solver

A Review And Evaluations Of Shortest Path Algorithms

Introduction to Fractions, Equivalent and Simplifying (1-2 days)

Resource Allocation and Scheduling

Degeneracy in Linear Programming

Goals of the Unit. spm adolfo villafiorita - introduction to software project management

Session 7 Fractions and Decimals

Working with whole numbers

Introduction to Learning & Decision Trees

Tessellating with Regular Polygons

Excel -- Creating Charts

1 Review of Newton Polynomials

Introduction & Overview

Enumerating possible Sudoku grids

Project Scheduling: PERT/CPM

NF5-12 Flexibility with Equivalent Fractions and Pages

So today we shall continue our discussion on the search engines and web crawlers. (Refer Slide Time: 01:02)

Guessing Game: NP-Complete?

each college c i C has a capacity q i - the maximum number of students it will admit

Linear Programming. March 14, 2014

An Introduction to The A* Algorithm

Computational Geometry. Lecture 1: Introduction and Convex Hulls

Battleship. Big bands

This puzzle is based on the following anecdote concerning a Hungarian sociologist and his observations of circles of friends among children.

2. Select Point B and rotate it by 15 degrees. A new Point B' appears. 3. Drag each of the three points in turn.

Heuristics for Dynamically Adapting Constraint Propagation in Constraint Programming

Tutorial: Biped Character in 3D Studio Max 7, Easy Animation

Generalized Widening

The Taxman Game. Robert K. Moniot September 5, 2003

Page 18. Using Software To Make More Money With Surveys. Visit us on the web at:

Years after US Student to Teacher Ratio

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

CS 3719 (Theory of Computation and Algorithms) Lecture 4

Probability Distributions

Assignment 2: Animated Transitions Due: Oct 12 Mon, 11:59pm, 2015 (midnight)

Session 7 Bivariate Data and Analysis

PowerScore Test Preparation (800)

Load balancing Static Load Balancing

Five Tips for Presenting Data Analyses: Telling a Good Story with Data

Universality in the theory of algorithms and computer science

Today s topic: So far, we have talked about. Question. Task models

CONTENTS. Please note:

Kenken For Teachers. Tom Davis June 27, Abstract

Why? A central concept in Computer Science. Algorithms are ubiquitous.

Lesson #13 Congruence, Symmetry and Transformations: Translations, Reflections, and Rotations

Lecture 17 : Equivalence and Order Relations DRAFT

MATH STUDENT BOOK. 8th Grade Unit 6

Decision Trees. Andrew W. Moore Professor School of Computer Science Carnegie Mellon University.

From Last Time: Remove (Delete) Operation

Just the Factors, Ma am

On the Unique Games Conjecture

DESIGN AND DEVELOPMENT OF CSP TECHNIQUES FOR FINDING ROBUST SOLUTIONS IN JOB-SHOP SCHEDULING PROBLEMS WITH OPERATORS

Scheduling Home Health Care with Separating Benders Cuts in Decision Diagrams

SuperViz: An Interactive Visualization of Super-Peer P2P Network

Permutation Groups. Tom Davis April 2, 2003

Algebra I Notes Relations and Functions Unit 03a

Hooray for the Hundreds Chart!!

Triangulation by Ear Clipping

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

Introduction. Real World Planning. Planning with Time. Time 15/11/2012. COMP219: Artificial Intelligence. COMP219: Artificial Intelligence

Transcription:

Constraint Satisfaction and Scheduling Andrew W. Moore Professor School of Computer Science Carnegie Mellon University www.cs.cmu.edu/~awm awm@cs.cmu.edu 4-68-7599 Note to other teachers and users of these slides. Andrew would be delighted if you found this source material useful in giving your own lectures. Feel free to use these slides verbatim, or to modify them to fit your own needs. PowerPoint originals are available. If you make use of a significant portion of these slides in your own lecture, please include this message, or the following link to the source repository of Andrew s tutorials: http://www.cs.cmu.edu/~awm/tutorials. Comments and corrections gratefully received. Slide Overview CSPs defined Using standard search for CSPs Blindingly obvious improvements Backtracking search Forward Checking Constraint Propagation Some example CSP applications Overview Waltz Algorithm Job Shop Scheduling ariable ordering alue ordering Tedious Discussion Slide A Constraint Satisfaction Problem Inside each circle marked.. we must assign:, or B. No two connected circles may be assigned the same symbol. Notice that two circles have already been given an assignment. Formal Constraint Satisfaction Problem A CSP is a triplet {, D, C }. A CSP has a finite set of variables = {,.. N }. Each variable may be assigned a value from a domain D of values. C are binary constraints. Each member of C is a pair. The first member of each pair is a set of variables. The second element is a set of legal values which that set may take. Example: = {,,,,, } D = {,, B } C = { (, ) : { (,), (,B), (,), (,B), (B,) (B,)}, { (, ) : { (,), (,B), (,), (,B), (B,) (B,)}, : : } Slide Obvious point: Usually C isn t represented explicitly, but by a function. Slide 4 How to solve our CSP? How to solve our CSP? How about using a search algorithm? Define: a search state has variables k assigned. alues k+ n, as yet unassigned. Start state: All unassigned. oal state: All assigned, and all constraints satisfied. Successors of a stated with k assigned and rest unassigned are all states (with k the same) with k+ assigned a value from D. Cost on transitions: is fine. We don t care. We just want any solution. Slide 5 STAT =( =? =? =? =? =? =?) succs(stat) = ( = =? =? =? =? =?) ( = =? =? =? =? =?) ( =B =? =? =? =? =?) What search algorithms could we use? It turns out BFS is not a popular choice. Why not? Slide 6

DFS for CSPs Blindingly obvious improvement Consistency Checking: Backtracking Search What about DFS? Much more popular. At least it has a chance of finding an easy answer quickly. What happens if we do DFS with the order of assignments as B tried first, then then? This makes DFS look very, very stupid! Slide 7 Don t ever try successor which causes inconsistency with its neighbors. Again, what happens if we do DFS with the order of assignments as B tried first, then then? What s the computational overhead for this? Backtracking still looks a little stupid! Slide 8 Obvious improvement Forward Checking At start, for each variable, record the current set of possible legal values for it. When you assign a value in the search, update set of legal values for all variables. Backtrack immediately if you empty a variable s constraint set. Again, what happens if we do DFS with the order of assignments as B tried first, then then? What s the computational overhead? Slide 9 Constraint Propagation Forward checking computes the domain of each variable independently at the start, and then only updates these domains when assignments are made in the DFS that are directly relevant to the current variable. Constraint Propagation carries this further. When you delete a value from your domain, check all variables connected to you. If any of them change, delete all inconsistent values connected to them, etc Often constraint propagation is only performed at the start. In our example it is useless. But Slide Constraint Propagation being non-useless In this example, constraint propagation solves the problem without search Not always that lucky! Constraint propagation can be done as a preprocessing step. (Cheap). Or it can be maintained dynamically during the search. Expensive: when you backtrack, you must undo some of your additional constraints. Extra Arc Slide raph-coloring-specific Constraint Propagation In the case of raph Coloring, CP looks simple: after we ve made a search step (instantiated a node with a color), propagate the color at that node. PropagateColorAtNode(node,color). remove color from all of available lists of our uninstantiated neighbors.. If any of these neighbors gets the empty set, it s time to backtrack.. Foreach n in these neighbors: if n previously had two or more available colors but now has only one color c, run PropagateColorAtNode(n,c) Slide

raph-coloring-specific Constraint Propagation In the case of raph Coloring, CP looks simple: after we ve made a search step (instantiated a node with a color), propagate the color at that node. PropagateColorAtNode(node,color). remove color from all of available lists of our uninstantiated neighbors.. If any of these neighbors gets the empty set, it s time to backtrack.. Foreach n in these neighbors: if n previously had two or more available colors but now has only one color c, run PropagateColorAtNode(n,c) But for eneral CSP problems, constraint propagation can do much more than only propagating when a node gets a unique value Slide A New CSP (where fancier propagation is possible) The semi magic square Each variable can have value, or 7 8 9 Slide 4 eneral Constraint Propagation Propagate(A, A, A n ) Specification: Takes a set of availability-lists while not finished for each and every node and uses all the finished = TUE constraints to filter out impossible values that are currently in availability lists foreach constraint C Assume C concerns variables,, k Set NewA = {}, NewA = {}, NewA k = {} Foreach assignment ( =x, =x, k =x k ) in C If x in A and x in A and x k in A k Add x to NewA, x to NewA, x k to NewA k for i =, k A i := A i intersection NewA i If A i was made smaller by that intersection If A i is empty, we re toast. Break out with Backtrack signal. Details on next slide Slide 5 eneral Constraint Propagation Propagate(A, A, A n ) A i denotes the current set of possible values for variable i. This is call-by-reference. Some of the A i while not finished sets may be changed by this call (they ll have one finished = TUE or more elements removed) foreach constraint C Assume C concerns variables,, k Set NewA = {}, NewA = {}, NewA k = {} Foreach assignment ( =x, =x, k =x k ) in C If x in A and x in A and x k in A k Add x to NewA, x to NewA, x k to NewA k for i =, k A i := A i intersection NewA i We ll keep iterating If A i until was we made do a smaller by that intersection full iteration in which finished none of the = FALSE availability lists If change. A i is empty, The we re toast. Break out with Backtrack signal. finished flag is just to record whether a change took place. Slide 6 eneral Constraint Propagation Propagate(A, A, A n ) while not finished finished = TUE foreach constraint C Assume C concerns variables,, k Set NewA = {}, NewA = {}, NewA k = {} Foreach assignment ( =x, =x, k =x k ) in C If x in A and x in A and x k in A k Add x to NewA, x to NewA, x k to NewA k for i =, k A i := A i intersection NewA i If A i was made smaller by that intersection NewA i is going to be filled up with the possible values for variable i taking into account the effects of constraint C After we ve finished all the iterations of the foreach loop, NewA i contains the full set of possible values of variable i taking into account the effects of If A i is empty, we re toast. Break out with Backtrack signal. constraint C. Slide 7 eneral Constraint Propagation If this test is satisfied that means that there s at least one Propagate(A, A, A n ) value q such that we originally thought q was an available value for i but we now know q is impossible. while not finished finished = TUE foreach constraint C Assume C concerns variables,, k Set NewA = {}, NewA = {}, NewA k = {} Foreach assignment ( =x, =x, k =x k ) in C If x in A and x in A and x k in A k Add x to NewA, x to NewA, x k to NewA k for i =, k A i := A i intersection NewA i If A i was made smaller by that intersection If A i is empty, we re toast. Break out with Backtrack signal. If A i is empty we ve proved that there are no solutions for the Slide 8 availability-lists that we originally entered the function with

Propagate on Semi-magic Square The semi magic square Each variable can have value, or Propagate on Semi-magic (,,) Square The semi magic square Each variable can have value, or (,, ) must be one of (,,) (,,) (,,) (,,) (,,) (,,) Slide 9 Slide Propagate on Semi-magic (,,) Square NewAL = { } NewAL = {, } NewAL The semi = {, magic } square Each variable can have value, or (,, ) must be one of (,,) (,,) (,,) (,,) (,,) (,,) After doing first row constraint Slide Slide After doing all row constraints and column constraints Slide And after doing diagonal constraint CP has now iterated through all constraints once. But does it make further progress when it tries iterating through them again? Slide 4 4

And after doing another round of constraints CSP Search with Constraint Propagation YES! And this showed a case of a constraint applying even when none of the variables involved was down to a unique value. So.. any more changes on the next iteration? Slide 5 CPSearch(A, A, A n ) Let i = lowest index such that A i has more than one value foreach available value x in A i foreach k in,.. n Define A k := A k A i := { x } Call Propagate(A, A, A n ) If no Backtrack signal If A, A, A n are all unique we re done! ecursively Call CPSearch(A, A, A n ) Details on next slide Slide 6 CSP Search Specification: with Constraint Find out if there s Propagation any combination of values in the combination of the given availability lists that satisifes all constraints. CPSearch(A, A, A n ) Let i = lowest index such that A i has more than one value foreach available value x in A i foreach k in,.. n Define A k := A k A i := { x } Call Propagate(A, A, A n ) If no Backtrack signal If A, A, A n are all unique we re done! ecursively Call CPSearch(A, A, A n ) At this point the A-primes are a copy of the original availability lists except A i has committed to value x. This call may prune away some values in some of the copied availability lists CSP Search with Constraint Propagation CPSearch(A, A, A n ) Let i = lowest index such that A i has more than one value foreach available value x in A i foreach k in,.. n Define A k := A k A i := { x } Call Propagate(A, A, A n ) If no Backtrack signal If A, A, A n are all unique we re done! ecursively Call CPSearch(A, A, A n ) What s the top-level call? Assuming that we terminate deep in the recursion if we find a solution, the CPSeach function only terminates normally if no Call with that A i = complete set of possible values for i. solution is found. Slide 7 Slide 8 CSP Search with Constraint Propagation CPSearch(A, A, A n ) Let i = lowest index such that A i has more than one value foreach available value x in A i foreach k in,.. n Define A k := A k A i := { x } Call Propagate(A, A, A n ) If no Backtrack signal If A, A, A n are all unique we re done! ecursively Call CPSearch(A, A, A n ) What s the top-level call? Call with that A i = complete set of possible values for i. Slide 9 Semi-magic Square CPSearch Tree Slide 5

Semi-magic Square CPSearch Tree In fact, we never even consider these because we stop at first success Slide Some real CSPs raph coloring is a real, and useful, CSP. Applied to problems with many hundreds of thousands of nodes. Not very AI-esque. LSI or PCB board layout. Selecting a move in the game of minesweeper. Which squares have a bomb? Squares with numbers don t. Other squares might. Numbers tell how many of the eight adjacent squares have bombs. We want to find out if a given square can possibly have a bomb. Slide Minesweeper CSP 8 7 The Waltz algorithm One of the earliest examples of a computation posed as a CSP. The Waltz algorithm is for interpreting line drawings of solid polyhedra. = {,,,,,, 7, 8 }, D = { B (bomb), S (space) } C = { (, ) : { (B,S), (S,B) }, (,,,) : { (B,S,S), (S,B,S), (S,S,B)}, } 8 7 Slide Look at all intersections. What kind of intersection could this be? A concave intersection of three faces? Or an external convex intersection? Adjacent intersections impose constraints on each other. Use CSP to find a unique set of labelings. Important step to understanding the image. Slide 4 Waltz Alg. on simple scenes Assume all objects: Have no shadows or cracks Three-faced vertices eneral position : no junctions change with small movements of the eye. Then each line on image is one of the following: Boundary line (edge of an object) (<) with right hand of arrow denoting solid and left hand denoting space Interior convex edge (+) Interior concave edge (-) 8 legal kinds of junctions Slide 5 iven a representation of the diagram, label each junction in one of the above manners. The junctions must be labeled so that lines are labeled consistently at both ends. Can you formulate that as a CSP? FUN FACT: Constraint Propagation always works perfectly. Slide 6 6

Waltz Examples Slide 7 Slide 8 Scheduling A very big, important use of CSP methods. Used in many industries. Makes many multi-million dollar decisions. Used extensively for space mission planning. Military uses. People really care about improving scheduling algorithms! Problems with phenomenally huge state spaces. But for which solutions are needed very quickly. Many kinds of scheduling problems e.g.: Job shop: Discrete time; weird ordering of operations possible; set of separate jobs. Batch shop: Discrete or continuous time; restricted operation of ordering; grouping is important. Manufacturing cell: Discrete, automated version of open job shop. Slide 9 Job Shop scheduling At a job-shop you make various products. Each product is a job to be done. E.. Job = Make a polished-thing-with-a-hole Job = Paint and drill a hole in a widget Each job requires several operations. E.. Operations for Job : Polish, Drill Operations for Job : Paint, Drill Each operation needs several resources. E.. Polishing needs the Polishing machine Polishing needs Pat (a Polishing expert) Drilling needs the Drill Drilling needs Pat (also a Drilling expert) Or Drilling can be done by Chris Some operations need to be done in a particular order (e.g. Paint after you ve Drilled) Slide 4 Job Shop Formalized A Job Shop problem is a pair ( J, ES ) J is a set of jobs J = {j, j, j n } ES is a set of resources ES = {.. m } Each job j I is specified by: a set of operations O I = {O I OI OI n(i) } and must be carried out between release-date rd I and due-date dd I. and a partial order of operations: (O I i OI j ), (OI i OI j ), etc Each operation O I i has a variable start time sti i and a fixed duration dui i and requires a set of resources. e.g.: O I i requires { I i, I i }. Each resource can be accomplished by one of several possible physical resources, e.g. I i might be accomplished by any one of {ri ij, ri ij, }. Each of the r I ijks are a member of ES. Slide 4 Job Shop Example j = polished-hole-thing = { O, O } j = painted-hole-widget = { O, O } ES = { Pat,Chris,Drill,Paint,Drill,Polisher } O = polish-thing: need resources { = Pat, = Polisher } O = drill-thing: need resources { = (r =Pat or r =Chris), = Drill } O = paint-widget: need resources { = Paint } O = drill-widget : need resources { = (r =Pat or r =Chris), = Drill } Precedence constraints : O O. All operations take one time unit dui i = forall i,i. Both jobs have release-date rd I = and due-date dd I =. Slide 4 7

Job-shop: the ariables and Constraints ariables The operation state times st I i The resources I ij (usually these are obvious from the definition of O I i. Only need to be assigned values when there are alternative physical resources available, e.g. Pat or Chris for operating the drill). Constraints: Precedence constraints. (Some O I is must be some other O I js). Capacity constraints. There must never be a pair of operations with overlapping periods of operation that use the same resources. Non-challenging question. Can you schedule our Job-shop? Slide 4 A slightly bigger example O O O O O O O O O 4 4 O 4 Example from [Sadeh and Fox, 96]: Norman M. Sadeh and Mark S. Fox, ariable and alue Ordering Heuristics for the Job Shop Scheduling Constraint Satisfaction Problem, Artificial Intelligence Journal, Number ol 86, No, pages -4, 996. Available from citeseer.nj.nec.com/sadeh96variable.html 4 jobs. Each units long. All jobs have release date and due date 5. All operations use only one resource each. Slide 44 Further CSP techniques Let s look at some other important CSP methods. Keep the job-shop example in mind. Here s another graph-coloring example (you re now allowed,, B and Y) 7 Y B Slide 45 eneral purpose ariable Ordering Heuristics. Most constrained variable.. Most constraining variable. 7 Y B Slide 46 eneral purpose alue Ordering Heuristics 7 A good general purpose one is leastconstrained-value. Choose the value which causes the smallest reduction in number of Y B eneral purpose CSP algorithm (From Sadeh+Fox). If all values have been successfully assigned then stop, else go on to.. Apply the consistency enforcing procedure (e.g. forward-checking if feeling computationally mean, or constraint propagation if extravagant. There are other possibilities, too.). If a deadend is detected then backtrack (simplest case: DFS-type backtrack. Other options can be tried, too). Else go on to step 4. 4. Select the next variable to be assigned (using your variable ordering heuristic). 5. Select a promising value (using your value ordering heuristic). 6. Create a new search state. Cache the info you need for backtracking. And go back to. available values for neighboring variables Slide 47 Slide 48 8

Job-shop example. Consistency enforcement Sadeh claims that generally forward-checking is better, computationally, than full constraint propagation. But it can be supplemented with a Job-shop specific TICK. The precedence constraints (i.e. the available times for the operations to start due to the ordering of operations) can be computed exactly, given a partial schedule, very efficiently. Slide 49 eactive CSP solutions Say you have built a large schedule. Disaster! Halfway through execution, one of the resources breaks down. We have to reschedule! Bad to have to wait 5 minutes for the scheduler to make a new suggestion. Important area of research: efficient schedule repair algorithms. Question: If you expect that resources may sometimes break, what could a scheduling program do to take that into account? Unrelated Question: Why has none of this lecture used A*? Slide 5 Other approaches. And What You Should Know Other Approaches: Hill-climbing, Tabu-search, Simulated annealing, enetic Algorithms. (to be discussed later) What you should know: How to formalize problems as CSPs Backtracking Search, Forward Checking, Constraint Propagation The Waltz algorithm You should understand and appreciate the way job-shop scheduling is formalized. It is an excellent representative example of how important well-studied constraint satisfaction problems are represented. Understand examples of ariable ordering and alue ordering heuristics In those cases where your lecturer or these handouts are too incomprehensible, consult the ussell and Norvig. Winston s Artificial Intelligence book also has good discussion of constraint satisfaction and Waltz algorithm. Slide 5 9