© J. Christopher Beck Lecture 11: Constraint Programming 1
© J. Christopher Beck Outline The Crystal Maze & CP Heuristics, propagation, B&B Propagation Temporal Propagation Constraint Based Analysis Heuristics Slack & Flexibility
© J. Christopher Beck Crystal Maze Place the numbers 1 through 8 in the nodes such that: Each number appears exactly once ? ? ? ? ? ? ?? –No connected nodes have consecutive numbers
© J. Christopher Beck Modeling Each node a variable {1, …, 8} values in the domain of each variable No consecutive numbers a constraint (v i, v j ) |v i – v j | > 1 All values used all-different constraint
© J. Christopher Beck Heuristic Search ? ? ? ? ? ? ?? 18 {1, 2, 3, 4, 5, 6, 7, 8}
© J. Christopher Beck Inference/Propagation ? ? ? ? ? ? ?? 18 {1, 2, 3, 4, 5, 6, 7, 8}
© J. Christopher Beck Inference/Propagation ? ? ? ? ? ? ?? 18 {3, 4, 5, 6} {3, 4, 5, 6, 7}{2, 3, 4, 5, 6}
© J. Christopher Beck Branch-and-Bound Inference is a form of bounding Branches are pruned when we know there is no solution below them May need to backtrack (if the heuristic decision has made a mistake) In an optimization context, once a solution is found you need to backtrack to search for a better one
© J. Christopher Beck With CP You Are … Guaranteed to find a solution if one exists If not you can prove there is no solution But you need to have enough time! On average, for many problems you can find a solution within a reasonable time CP is commercially successful for scheduling and other applications
© J. Christopher Beck The Core of CP Modeling How to represent the problem Heuristic search How to branch How much effort to find a good branch Inference/propagation How much effort Backtracking
© J. Christopher Beck Heuristic Search or Propagation? ? ? ? ? ? ? ?? 18 {1, 2, 3, 4, 5, 6, 7, 8} There must be a 1 or 8 here. Why?
© J. Christopher Beck Propagators for Scheduling 3 examples Temporal propagation (easy) Constraint-based analysis (medium) Edge-finding (tricky) – next lecture
© J. Christopher Beck Temporal Propagation (Arc Consistency - AC) [0[20[35[4540]60]75]85] [20[40[55[6540]60]75]85]20 The same as CPM!
© J. Christopher Beck Constraint-Based Analysis (CBA) Operations on the same unary capacity resource What can you infer here?
© J. Christopher Beck CBA Rules For all pairs of activities, A i and A j : Case 1: If lft i – est j < p i + p j lft j – est i then A i must be before A j. Case 2: If p i + p j > lft j – est i and p i + p j > lft i – est j then dead-end. Case 3: If p i + p j lft j – est i and p i + p j lft i – est j then either OK. On the same unary-capacity resource
© J. Christopher Beck CBA Find all CBA inferences A A A 2 5 A