Constraint Satisfaction and Scheduling

Constraint Satisfaction and Scheduling

Constraint Overview Satisfaction and • CSPs defined • Using standard search for CSPs Scheduling • Blindingly obvious improvements Backtracking search Forward Checking Andrew W. Moore Constraint Propagation Professor • Some example CSP applications School of Computer Science Overview Carnegie Mellon University Waltz Algorithm www.cs.cmu.edu/~awm Job Shop Scheduling [email protected] • Variable ordering 412-268-7599 • Value ordering Note to other teachers and users of these slides. Andrew would be delighted if you found this source • Tedious Discussion 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 Slide 1 Slide 2 Andrew’s tutorials: http://www.cs.cmu.edu/~awm/tutorials . Comments and corrections gratefully received. A Constraint Satisfaction Problem Formal Constraint Satisfaction Problem V 5 A CSP is a triplet { V , D , C }. A CSP has a finite set of variables V = { V , V V3 1 2 V1 .. V }. V2 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 V6 R that set may take. Example: V4 G V = { V1 , V2 , V3 , V4 , V5 , V6 } D = { R , G , B } C = { (V1,V2) : { (R,G), (R,B), (G,R), (G,B), (B,R) (B,G)}, Inside each circle marked V1 .. V6 we must assign: R, G or B. { (V1,V3) : { (R,G), (R,B), (G,R), (G,B), (B,R) (B,G)}, No two connected circles may be assigned the same symbol. : Notice that two circles have already been given an assignment. : } Obvious point: Usually C isn’t represented explicitly, but by a function. Slide 3 Slide 4 How to solve our CSP? How to solve our CSP? V5 V5 V3 V3 V1 V1 V2 V2 V6 R V6 R V4 G V4 G •How about using a search algorithm? START =(V1=? V2=? V3=? V4=? V5=? V6=?) •Define: a search state has variables 1 … k assigned. Values k+1 … n, succs(START) = as yet unassigned. (V1=RV2=? V3=? V4=? V5=? V6=?) •Start state: All unassigned. (V1=GV2=? V3=? V4=? V5=? V6=?) •Goal state: All assigned, and all constraints satisfied. (V1=BV2=? V3=? V4=? V5=? V6=?) •Successors of a stated with V1 … Vk assigned and rest unassigned are What search algorithms could we use? all states (with V1 … Vk the same) with Vk+1 assigned a value from D. It turns out BFS is not a popular choice. Why not? •Cost on transitions: 0 is fine. We don’t care. We just want any solution. Slide 5 Slide 6 1 DFS for CSPs Blindingly obvious improvement – Consistency Checking: V5 V3 V1 V2 “Backtracking Search” V5 V3 V6 R V1 V2 V4 G What about DFS? V6 R Much more popular. At least it has a chance of finding an easy answer V4 G quickly. Don’t ever try successor which causes inconsistency with its neighbors. What happens if we do DFS with the order of assignments as B tried Again, what happens if we do DFS with the order of assignments as first, then G then R? B tried first, then G then R? This makes DFS look very, very stupid! What’s the computational overhead for this? Backtracking still looks a little stupid! Slide 7 Slide 8 Obvious improvement – Forward Constraint Propagation Checking V5 V3 V V1 5 V2 V3 V1 V2 V6 R V R 6 V4 G V4 G Forward checking computes the domain of each variable independently At start, for each variable, record the current set of possible legal values at the start, and then only updates these domains when assignments are for it. made in the DFS that are directly relevant to the current variable. When you assign a value in the search, update set of legal values for all Constraint Propagation carries this further. When you delete a value variables. Backtrack immediately if you empty a variable’s constraint from your domain, check all variables connected to you. If any of them set. change, delete all inconsistent values connected to them, etc… Again, what happens if we do DFS with the order of assignments as Often constraint propagation is only performed at the start. In our B tried first, then G then R? example it is useless. But… What’s the computational overhead? Slide 9 Slide 10 Constraint Propagation being non-useless Graph-coloring-specific Constraint V5 Propagation V3 V V1 2 In the case of Graph Coloring, CP looks simple: after we’ve made a search step (instantiated a V R 6 node with a color), propagate the color at that V G 4 Extra Arc node. • In this example, constraint propagation solves the problem PropagateColorAtNode(node,color) without search … Not always that lucky! 1. remove color from all of “available lists” of our uninstantiated neighbors. • Constraint propagation can be done as a preprocessing 2. If any of these neighbors gets the empty set, it’s time to step. (Cheap). backtrack. • Or it can be maintained dynamically during the search. 3. Foreach n in these neighbors: if n previously had two or more available colors but now has only one color c, run Expensive: when you backtrack, you must undo some of PropagateColorAtNode(n,c) your additional constraints. Slide 11 Slide 12 2 Graph-coloring-specific Constraint A New CSP (where fancier Propagation propagation is possible) In the case of Graph Coloring, CP looks simple: • The semi magic square after we’ve made a search step (instantiated a • Each variable can have value 1, 2 or 3 node with a color), propagate the color at that node. This row must V1 V2 V3 PropagateColorAtNode(node,color) sum to 6 This row must 1. remove color from all of “available lists” of our V4 V5 V6 uninstantiated neighbors. sum to 6 nstraint 2. If any of these neighbors gets theem emptys, c oset, it’s time to This row must SP probl only V7 V8 V9 backtrack. eneral C ore than sum to 6 But for G much m e 3. Foreach n in othesen can neighbors: do if n previouslyts a uni hadqu two or opagati node ge morepr available colorswhe butn a now has only one color c, run This column This column This column This diagonal agating PropagateColorAtNode(n,c)prop must sum to 6 must sum to 6 must sum to 6 must sum to 6 value… Slide 13 Slide 14 General Constraint Propagation General Constraint Propagation Propagate(A , A ,… A ) Propagate(A , A ,… A ) 1 2 n 1 2 n A denotes the current set of possible values for finished = FALSE finished = FALSE i Specification: Takes a set of availability-lists variable i. This is call-by-reference. Some of the Ai while not finished for each and every node and uses all the while not finished sets may be changed by this call (they’ll have one finished = TRUE constraints to filter out impossible values that finished = TRUE or more elements removed) are currently in availability lists foreach constraint C foreach constraint C Assume C concerns variables V1, V2 ,… Vk Assume C concerns variables V1, V2 ,… Vk Set NewAV1 = {} , NewAV2 = {} , … NewAVk = {} Set NewAV1 = {} , NewAV2 = {} , … NewAVk = {} Foreach assignment (V1=x1, V2=x2, … Vk=xk) in C Foreach assignment (V1=x1, V2=x2, … Vk=xk) in C If x1 in AV1 and x2 in AV2 and … xk in AVk If x1 in AV1 and x2 in AV2 and … xk in AVk Add x1 to NewAV1 , x2 to NewAV2 ,… xk to NewAVk Add x1 to NewAV1 , x2 to NewAV2 ,… xk to NewAVk for i = 1 , 2 … k for i = 1 , 2 … k AVi := AVi intersection NewAVi AVi := AVi intersection NewAVi If AVi was made smaller by that intersection We’ll keep iteratingIf AVi untilwas we made do a smaller by that intersection finished = FALSE full iteration in whichfinished none of the= FALSE availability lists change. The If AVi is empty, we’re toast. Break out with “Backtrack” signal. If AVi is empty, we’re toast. Break out with “Backtrack” signal. Deta “finished” flag is just to record ils on next slide Slide 15 whether a change took place. Slide 16 General Constraint Propagation General Constraint Propagation NewA is going to be filled up If this test is satisfied that means that there’s at least one Propagate(A , A ,… A ) i Propagate(A , A ,… A ) 1 2 n with the possible values for 1 2 n value q such that we originally thought q was an finished = FALSE finished = FALSE variable Vi taking into account available value for Vi but we now know q is impossible. while not finished the effects of constraint C while not finished finished = TRUE finished = TRUE foreach constraint C foreach constraint C Assume C concerns variables V1, V2 ,… Vk Assume C concerns variables V1, V2 ,… Vk Set NewAV1 = {} , NewAV2 = {} , … NewAVk = {} Set NewAV1 = {} , NewAV2 = {} , … NewAVk = {} Foreach assignment (V1=x1, V2=x2, … Vk=xk) in C Foreach assignment (V1=x1, V2=x2, … Vk=xk) in C If x1 in AV1 and x2 in AV2 and … xk in AVk If x1 in AV1 and x2 in AV2 and … xk in AVk Add x1 to NewAV1 , x2 to NewAV2 ,… xk to NewAVk Add x1 to NewAV1 , x2 to NewAV2 ,… xk to NewAVk for i = 1 , 2 … k After we’ve finished all the for i = 1 , 2 … k iterations of the foreach AVi := AVi intersection NewAVi AVi := AVi intersection NewAVi loop, NewAi contains the If AVi was made smaller by that intersectionfull set of possible values of If AVi was made smaller by that intersection finished = FALSE variable Vi taking into finished = FALSE If A is empty, we’re toast.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    9 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us