1 / 66

CSPs

CSPs. Tamara Berg CS 590-133 Artificial Intelligence. Many slides throughout the course adapted from Svetlana Lazebnik , Dan Klein, Stuart Russell, Andrew Moore, Percy Liang, Luke Zettlemoyer. Review from last class. What is search for?.

willow
Télécharger la présentation

CSPs

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSPs Tamara Berg CS 590-133 Artificial Intelligence Many slides throughout the course adapted from Svetlana Lazebnik, Dan Klein, Stuart Russell, Andrew Moore, Percy Liang, Luke Zettlemoyer

  2. Review from last class

  3. What is search for? • Assumptions: single agent, deterministic, fully observable, discrete environment • Search for planning • The path to the goal is the important thing • Paths have various costs, depths • Search for assignment • Assign values to variables while respecting certain constraints • The goal (complete, consistent assignment) is the important thing

  4. Constraint satisfaction problems (CSPs) • Definition: • Xi is a set of variables {X1,… Xn} • Di is a set of domains {D1 ,...Dn}one for each variable • C is a set of constraints that specify allowable combinations of values • Solution is a complete, consistent assignment • How does this compare to the “generic” tree search formulation? • A more structured representation for states, expressed in a formal representation language • Allows useful general-purpose algorithms with more power than standard search algorithms • by eliminating large portions of search space (identifying var/val combinations that violate constraints).

  5. Example: Map Coloring • Variables:WA, NT, Q, NSW, V, SA, T • Domains: {red, green, blue} • Constraints: adjacent regions must have different colorse.g., WA ≠ NT, or (WA, NT) in {(red, green), (red, blue), (green, red), (green, blue), (blue, red), (blue, green)}

  6. Example: Map Coloring • Solutions are complete and consistent assignments, e.g., WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = green

  7. Example: Cryptarithmetic • Variables: T, W, O, F, U, R X1, X2 • Domains: {0, 1, 2, …, 9} • Constraints: O + O = R + 10 * X1 W + W + X1 = U + 10 * X2 T + T + X2 = O + 10 * F Alldiff(T, W, O, F, U, R) T ≠ 0, F ≠ 0 X2 X1

  8. Example: Sudoku • Variables:Xij • Domains: {1, 2, …, 9} • Constraints: Alldiff(Xij in the same unit) Xij

  9. Real-World CSPs • Assignment problems • e.g., who teaches what class • hard constraint - no prof can teach 2 classes at the same time. • preference constraints – Jan prefers teaching in the morning while Alex prefers teaching in the afternoon (soft constraints/costs). For example an afternoon slot for Jan can cost 2 points whereas a morning slot costs 1.

  10. Real-World CSPs • Timetable problems • e.g., which class is offered when and where? • Classroom size & enrollment can put hard constraints on where a class can be held • Avoiding simultaneous scheduling of two related classes can be a soft constraint

  11. Real-World CSPs • Transportation Scheduling • E.g. airline scheduling Flights F1,F2 with capacities 165 and 385 • Domains D1=[0,165] D2=[0,385] • Suppose we have an additional constraint that the two flights must carry 420 people: ie F1+F2=420 • Then we can reduce the domains to: D1=[35,165] D2=[255,385] Enforcing Bounds consistency

  12. Real-World CSPs • Job-shop scheduling • e.g. assembling a car • Variables – X = tasks {Axlef, Axleb, Wheelrf, Wheellf, Wheelrb, Wheellb,Nutsrf,Nutslf, Nutslb, Nutsrb, Caprf, Caplf, Caprb, CAPlb, Inspect} • Values – Di time task starts • Constraints – one ask must occur before other, a task takes a certain amount of time to complete. • e.g. AxleF + 10 ≤ Wheelrf, Wheelrf+1≤Nutsrf, Nutsrf+2≤Caprf… • 4 workers, but only 1 axle tool: • Axlef+10≤Axleb or Axleb+10≤Axlef • For each variable, X, except Inspect: • X+dx≤ Inspect • Want total time less than 30 minutes and inspect takes 3 minutes: • Di = {1,2,3,….,27}

  13. More examples of CSPs: http://www.csplib.org/

  14. Types of Constraints • Unary • restricts value of a single variable, e.g. SA≠green. • Binary • relates two variables, e.g. SA≠NSW • Higher order • relates more than two variables, e.g. Between (X,Y,Z) • Global • arbitrary number of variables • commonly Alldiff – all variables must have different values. e.g. in sudoku all variables in a unit must satisfy Alldiff. • Preference constraint • Red is better than green • Often representable by a cost for each variable assignment • Resource constraint • Atmost constraint. e.g. scheduling P1,P2,P3,P4 denote personnel assigned to each task. Constrain is that you only have ≤ 10 people. So Atmost(10,P1,P2,P3,P4)

  15. Variations on CSPs Simplest CSPs – discrete, finite domains map coloring, scheduling with time limits, 8-queens Discrete with infinite domain no deadline scheduling Continuous domains scheduling of experiments on Hubble telescope Linear programming problems constraints must be linear equalities or inequalities (can be solved in time polynomial in # vars)

  16. Why are constraints useful? • Variables:Xij • Domains: {1, 2, …, 9} • Constraints: Alldiff(Xij in the same unit) ? ? Xij They let us eliminate portions of assignment space • By identifying var/val combinations that violate constraints

  17. Standard search formulation (incremental) • States: • Variables and values assigned so far • Initial state: • The empty assignment • Action: • Choose any unassigned variable and assign to it a value that does not violate any constraints • Fail if no legal assignments • Goal test: • The current assignment is complete and satisfies all constraints

  18. Standard search formulation (incremental) • What is the depth of any solution (assuming n variables)? n (this is good) • Given that there are m possible values for any variable, how many paths are there in the search tree? n! · mn(this is bad) • How can we reduce the branching factor?

  19. Backtracking search • In CSP’s, variable assignments are commutative • For example, [WA = red then NT = green] is the same as [NT = green then WA = red] • We only need to consider assignments to a single variable at each level (i.e., we fix the order of assignments)

  20. Example

  21. Example

  22. Example

  23. Example

  24. Backtracking search • In CSP’s, variable assignments are commutative • For example, [WA = red then NT = green] is the same as [NT = green then WA = red] • We only need to consider assignments to a single variable at each level (i.e., we fix the order of assignments) • Depth-first search for CSPs with single-variable assignments is called backtracking search

  25. Backtracking search algorithm

  26. Backtracking search algorithm

  27. Which variable should be assigned next? • Most constrained variable: • Choose the variable with the fewest legal values • A.k.a. minimum remaining values (MRV) heuristic

  28. Which variable should be assigned next? • Most constrained variable: • Choose the variable with the fewest legal values • A.k.a. minimum remaining values (MRV) heuristic

  29. Which variable should be assigned next? • Most constraining variable: • Choose the variable that imposes the most constraints on the remaining variables

  30. Which variable should be assigned next? • Most constraining variable: • Choose the variable that imposes the most constraints on the remaining variables • Tie-breaker among most constrained variables

  31. Backtracking search algorithm

  32. Given a variable, in which order should its values be tried? • Choose the least constraining value: • The value that rules out the fewest values in the remaining variables

  33. Given a variable, in which order should its values be tried? • Choose the least constraining value: • The value that rules out the fewest values in the remaining variables Which assignment for Q should we choose?

  34. Early detection of failure Apply inference to reduce the space of possible assignments and detect failure early

  35. Early detection of failure:Forward checking • Keep track of remaining legal values for unassigned variables • Terminate search when any variable has no legal values

  36. Early detection of failure:Forward checking • Keep track of remaining legal values for unassigned variables • Terminate search when any variable has no legal values

  37. Early detection of failure:Forward checking • Keep track of remaining legal values for unassigned variables • Terminate search when any variable has no legal values

  38. Early detection of failure:Forward checking • Keep track of remaining legal values for unassigned variables • Terminate search when any variable has no legal values

  39. Early detection of failure:Forward checking • Keep track of remaining legal values for unassigned variables • Terminate search when any variable has no legal values

  40. Constraint propagation • Forward checking propagates information from assigned to unassigned variables, but doesn't provide early detection for all failures • NT and SA cannot both be blue! • Constraint propagation repeatedly enforces constraints locally

  41. Arc consistency • Simplest form of propagation makes each pair of variables consistent: • X Y is consistent ifffor every value of X there is some allowed value of Y Consistent!

  42. Arc consistency • Simplest form of propagation makes each pair of variables consistent: • X Y is consistent ifffor every value of X there is some allowed value of Y

  43. Arc consistency • Simplest form of propagation makes each pair of variables consistent: • X Y is consistent ifffor every value of X there is some allowed value of Y • When checking X Y, throw out any values of X for which there isn’t an allowed value of Y • If Xloses a value, all pairs Z  Xneed to be rechecked

  44. Arc consistency • Simplest form of propagation makes each pair of variables consistent: • X Y is consistent iff for every value of X there is some allowed value of Y • When checking X Y, throw out any values of X for which there isn’t an allowed value of Y • If Xloses a value, all pairs Z  X need to be rechecked

  45. Arc consistency • Simplest form of propagation makes each pair of variables consistent: • X Y is consistent iff for every value of X there is some allowed value of Y • When checking X Y, throw out any values of X for which there isn’t an allowed value of Y • If Xloses a value, all pairs Z  X need to be rechecked

  46. Arc consistency • Simplest form of propagation makes each pair of variables consistent: • X Y is consistent iff for every value of X there is some allowed value of Y • When checking X Y, throw out any values of X for which there isn’t an allowed value of Y

  47. Arc consistency • Simplest form of propagation makes each pair of variables consistent: • X Y is consistent iff for every value of X there is some allowed value of Y • When checking X Y, throw out any values of X for which there isn’t an allowed value of Y • Arc consistency detects failure earlier than forward checking • Can be run before or after each assignment

  48. Arc consistency algorithm AC-3

More Related