using constraints
play

Using Constraints Claudia Chirita School of Informatics, University - PowerPoint PPT Presentation

Using Constraints Claudia Chirita School of Informatics, University of Edinburgh 30 th January 2020 Based on slides by: Jacques Fleuriot, Michael Rovatsos, Michael Herrmann, Vaishak Belle Informatics 2D Agents and Reasoning 2019/2020


  1. Using Constraints Claudia Chirita School of Informatics, University of Edinburgh 30 th January 2020 Based on slides by: Jacques Fleuriot, Michael Rovatsos, Michael Herrmann, Vaishak Belle Informatics 2D ⋅ Agents and Reasoning ⋅ 2019/2020 Lecture 8 ⋅ Smart Searching

  2. Outline 2 / 33 • Constraint Satisfaction Problems (CSP) • Backtracking search for CSP • Effjciency matters

  3. Constraint Satisfaction Problems (CSP) Standard search problem a successor function, a heuristic function and a goal test. CSP has a value. all its constraints. power than standard search algorithms. by identifying variable/value combinations that violate the constraints. 3 / 33 • A state is a black box – any data structure that supports • A state is defjned by a set of variables, each of which • Solution: when each variable has a value that satisfjes • Allows useful general-purpose algorithms with more • Main idea: eliminate large portions of the search space

  4. Constraint Satisfaction Problems (CSP) A CSP consists of: combinations of values. variables involved in the constraint – and a relation that defjnes the values that the variables can take. 4 / 33 • a set 𝑌 = {𝑌 � , … , 𝑌 � } of variables • a set 𝐸 = {𝐸 � , … , 𝐸 � } of domains; each domain 𝐸 � is a set of possible values for variable 𝑌 � • a set 𝐷 of constraints that specify accepted A constraint 𝑑 ∈ 𝐷 consists of a scope – tuple of

  5. Variables: Domains: Constraints: adjacent regions must have difgerent colours 5 / 33 Example ⋅ Map-Colouring { WA , NT , Q , NSW , V , SA , T } 𝐸 � = { red , black , blue } ⋅ e.g. WA ≠ NT or ⋅ ( WA , NT ) ∈ {( red , black ), ( red , blue ), ( black , red ), ( black , blue ), ( blue , red ), ( blue , black )}

  6. Solutions are complete and consistent assignments. 6 / 33 Example ⋅ Map-Colouring ⋅ e.g. WA ↦ red , NT ↦ black , Q ↦ red , NSW ↦ black , V ↦ red , SA ↦ blue , T ↦ black .

  7. Constraint graph Binary CSP 7 / 33 • Each constraint relates two variables. • Constraint graph: ⋅ nodes are variables ⋅ arcs (edges) represent constraints

  8. Varieties of CSP Discrete variables programming Continuous variables – we need a constraint language to express – variables are start/end days for each job 8 / 33 (NP-complete) • fjnite domains: ⋅ 𝑜 variables, domain size 𝑒 , 𝑃(𝑒 � ) complete assignments ⋅ e.g. Boolean CSPs, including Boolean satisfjability • infjnite domains: ⋅ integers, strings, etc. ⋅ e.g. job scheduling StartJob � + 5 ≤ StartJob � • e.g. start/end times for Hubble Space Telescope observations • linear constraints solvable in polynomial time by linear

  9. Varieties of constraints Binary constraints involve pairs of variables. Higher-order constraints involve 3 or more variables. Global constraints involve an arbitrary number of variables. 9 / 33 Unary constraints involve a single variable. • e.g. SA ≠ black • e.g. SA ≠ WA • e.g. crypt-arithmetic column constraints

  10. Variables: Domains: Constraints: 10 / 33 Example ⋅ Crypt-arithmetic {𝐺, 𝑈, 𝑉, 𝑋, 𝑆, 𝑃, 𝑌 � , 𝑌 � , 𝑌 � } {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Alldiff (𝐺, 𝑈, 𝑉, 𝑋, 𝑆, 𝑃) ⟵ global constraint 𝑃 + 𝑃 = 𝑆 + 10 ⋅ 𝑌 � 𝑌 � + 𝑋 + 𝑋 = 𝑉 + 10 ⋅ 𝑌 � 𝑌 � + 𝑈 + 𝑈 = 𝑃 + 10 ⋅ 𝑌 � 𝑌 � = 𝐺 , 𝑈 ≠ 0 , 𝐺 ≠ 0

  11. Real-world CSP Assignment problems Timetabling problems Transportation scheduling Factory scheduling Many real-world problems involve real-valued variables. 11 / 33 • e.g. who teaches what class • e.g. which class is ofgered when and where

  12. Standard search formulation (incremental) Let’s start with the straightforward approach, then adapt it. Successor function: assign a value to an unassigned variable that does not confmict with the current assignment Goal test: the current assignment is complete 12 / 33 • States are defjned by the values assigned so far. Initial state: the empty assignment {} → fail if no legal assignments • This is the same for all CSPs. • For CSPs with with 𝑜 variables, any solution appears at depth 𝑜 ⇒ use depth-fjrst search.

  13. Backtracking search is the same as 13 / 33 • Variable assignments are commutative. ⋅ e.g. [ WA ↦ red then NT ↦ black ] [ NT ↦ black then WA ↦ red ] • We only need to consider assignments to a single variable at each node. Thus, 𝑐 = 𝑒 , and there are 𝑒 � leaves. • Depth-fjrst search for CSPs with single-variable assignments is called backtracking search. • Backtracking search: the basic uninformed algorithm for CSP. • Can solve the 𝑜 -queens problem for 𝑜 ≈ 25 .

  14. Backtracking search 14 / 33

  15. Backtracking example 15 / 33

  16. Backtracking example 16 / 33

  17. Backtracking example 17 / 33

  18. Backtracking example 18 / 33

  19. Improving backtracking effjciency General-purpose methods can give huge gains in speed. Then, in what order should its values be tried? What inferences should be performed at each search step? Can we detect inevitable failure early? 19 / 33 Which variable should be assigned next? • SELECT-UNASSIGNED-VARIABLE • ORDER-DOMAIN-VALUES • INFERENCE

  20. Most constrained variable Most constrained variable heuristic 20 / 33 var ← SELECT-UNASSIGNED-VARIABLE ( csp ) ⋅ choose the variable with the fewest legal values ⋅ a.k.a. minimum-remaining-values (MRV) heuristic

  21. Most constraining variable Tie-breaker among most constrained variables. Most constraining variable heuristic remaining variables, thus reducing branching 21 / 33 ⋅ choose the variable with the most constraints on ⋅ a.k.a. degree heuristic

  22. Least constraining value ORDER-DOMAIN-VALUES Given a variable, choose the least constraining value variables 22 / 33 ⋅ the one that rules out the fewest values in the remaining Combining these heuristics: 𝑜 -queens feasible for 𝑜 ≈ 1000 .

  23. Idea Keep track of remaining legal values for unassigned variables. Terminate the search when a variable has no more legal values. 23 / 33 Inference ⋅ Forward checking

  24. Idea Keep track of remaining legal values for unassigned variables. Terminate the search when a variable has no more legal values. 24 / 33 Inference ⋅ Forward checking

  25. Idea Keep track of remaining legal values for unassigned variables. Terminate the search when a variable has no more legal values. 25 / 33 Inference ⋅ Forward checking

  26. Idea Keep track of remaining legal values for unassigned variables. Terminate the search when a variable has no more legal values. 26 / 33 Inference ⋅ Forward checking

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

  28. Arc consistency Simplest form of propagation makes each arc consistent. 28 / 33 𝑌 → 𝑍 is consistent ifg for every value 𝑦 in the domain of 𝑌 there is some allowed value 𝑧 in the domain of 𝑍

  29. Arc consistency Simplest form of propagation makes each arc consistent. 29 / 33 𝑌 → 𝑍 is consistent ifg for every value 𝑦 in the domain of 𝑌 there is some allowed value 𝑧 in the domain of 𝑍

  30. Arc consistency Simplest form of propagation makes each arc consistent. 30 / 33 𝑌 → 𝑍 is consistent ifg for every value 𝑦 in the domain of 𝑌 there is some allowed value 𝑧 in the domain of 𝑍 If 𝑌 loses a value, its neighbours need to be rechecked.

  31. Arc consistency Simplest form of propagation makes each arc consistent. Detects failure earlier than forward checking. Can be run as a preprocessor or after each assignment. 31 / 33 𝑌 → 𝑍 is consistent ifg for every value 𝑦 in the domain of 𝑌 there is some allowed value 𝑧 in the domain of 𝑍 If 𝑌 loses a value, its neighbours need to be rechecked.

  32. 32 / 33 Arc consistency algorithm ⋅ AC-3 𝑒 – maximum size of the domains 𝑑 – number of binary constraints Time complexity: 𝑃(𝑑𝑒 � ) Space complexity: 𝑃(𝑑)

  33. Summary In CSPs: assigned per node. to lead to later failure. values and detect inconsistencies. 33 / 33 • States defjned by values of a fjxed set of variables. • Goal test defjned by constraints on variable values. • Backtracking: depth-fjrst search with one variable • Variable-ordering and value-selection heuristics help. • Forward checking prevents assignments that are certain • Constraint propagation does additional work to limit

Recommend


More recommend