# © J. Christopher Beck 20081 Lecture 15: CP Search.

## Presentation on theme: "© J. Christopher Beck 20081 Lecture 15: CP Search."— Presentation transcript:

© J. Christopher Beck 20081 Lecture 15: CP Search

© J. Christopher Beck 2008 2 Outline Quick CP Review Standard CP Search Scheduling Specific Branching Heuristics

© J. Christopher Beck 2008 3 Readings P Ch 5.5, D.2, D.3

© J. Christopher Beck 2008 4 Generic CP Algorithm Assert Commitment Propagators Start Success Solution? Make Heuristic Decision Backtrack Technique Failure Nothing to retract? Dead-end?

© J. Christopher Beck 2008 5 Constraint Satisfaction Problem (CSP) Given: V, a set of variables {v 0, v 1, …, v n } D, a set of domains {D 0, D 1, …, D n } C, a set of constraints {c 0, c 1, …, c m } Each constraint, c i, has a scope c i (v 0, v 2, v 4, v 117, …), the variables that it constrains From Lecture 13

© J. Christopher Beck 2008 6 Idea #1: Partitioning Add constraint to the original problem to form a partition: P 1, P 2, P 3, … Partitions are easier to solve Partitions, sub-partitions, sub-sub- partitions Solution is the best one from all the partitions From Lecture 11

© J. Christopher Beck 2008 7 Standard CP Search Tree Search a, b, c є {0, 1} a = 0a = 1 b = 0b = 1 c = 0c = 1c = 0c = 1c = 0c = 1c = 0c = 1 b = 0b = 1 Branch In CSP there is no optimization function! (think of the Crystal Maze)

© J. Christopher Beck 2008 8 Standard CP Search Branch-and-Infer at each node, run constraint propagation For Constraint Optimization Problems: Branch-Infer-&-Bound Partition/Inference/Relax (see Lecture 11) Often bound calculation is “hidden” in constraint propagation

© J. Christopher Beck 2008 9 Basic MIP B&B Q.push(root) while Q is not empty n = Q.pop() solve LP(n) if better than incumbent if integral update incumbent else v = choose branching variable Q.push(children(n,v)) Priority queue (node selection) Relaxation Branching variable selection From Lecture 12

© J. Christopher Beck 2008 10 Basic CP BI&B CPSearch(Problem P) if propagate(P) == dead-end return dead-end if not all variables are assigned V = choose variable in P x = choose value for V if CPSearch(P + V=x) == solution return solution else return CPSearch(P + V≠x) return solution depth-first search variable ordering heuristic value ordering heuristic

© J. Christopher Beck 2008 11 MIP vs CP Search Conceptually (almost) the same thing Nice exam question: How do node selection & branch selection correspond to DFS, variable ordering, and value ordering?

© J. Christopher Beck 2008 12 CP Heuristics for Scheduling It is common to make a decision (branch) about the sequence of a pair of activities. What pair? Which sequence should be tried first? How do these map into variable and value ordering heuristics?

© J. Christopher Beck 2008 13 Slack slack(A i,A j ) = lft j – est i – p i – p j A 2 20 35100 A 1 15 12050 slack(A 1,A 2 ) = 100 – 50 – 15 – 20 = 15 slack(A 2,A 1 ) = 120 – 35 – 15 – 20 = 50 If you post A i  A j, how much time is left between the end of A j and lft j ?

© J. Christopher Beck 2008 14 MinSlack Heuristic Find operation pair with smallest slack Post the opposite sequence Example slack(A  B) = 50, slack(B  A) = 25 slack(A  C) = 150, slack(C  A) = 5 slack(B  C) = 15, slack(C  B) = 50 Pick A,C and post A  C Note: The text is wrong here!

© J. Christopher Beck 2008 15 Branch on Sequence A1  A2A2  A1 … A4  A1 …

© J. Christopher Beck 2008 16 CBA & Slack Find all CBA inferences Find first heuristic decision based on slack A 3 20 40 50 A 1 10 10 50 A 2 5 A 4 5 20 30 50 0

© J. Christopher Beck 2008 17 Generic CP Algorithm Assert Commitment Propagators Start Success Solution? Make Heuristic Decision Backtrack Technique Failure Nothing to retract? Dead-end?

© J. Christopher Beck 2008 18 CP on JSP Run CP on our JSP problem Use CBA, EF Exclusion Min Slack Heuristic JobsProcessing times 0 J0R0[15]  J0R1[50]  J0R2[60] 1 J1R1[50]  J1R0[50]  J1R2[15] 2 J2R0[30]  J2R1[15]  J2R2[20]