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

using constraints
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Informatics 2D ⋅ Agents and Reasoning ⋅ 2019/2020

Lecture 8 ⋅ Smart Searching Using Constraints

Claudia Chirita

School of Informatics, University of Edinburgh

30thJanuary 2020

Based on slides by: Jacques Fleuriot, Michael Rovatsos, Michael Herrmann, Vaishak Belle

slide-2
SLIDE 2

Outline

  • Constraint Satisfaction Problems (CSP)
  • Backtracking search for CSP
  • Effjciency matters

2 / 33

slide-3
SLIDE 3

Constraint Satisfaction Problems (CSP)

Standard search problem

  • A state is a black box – any data structure that supports

a successor function, a heuristic function and a goal test. CSP

  • A state is defjned by a set of variables, each of which

has a value.

  • Solution: when each variable has a value that satisfjes

all its constraints.

  • Allows useful general-purpose algorithms with more

power than standard search algorithms.

  • Main idea: eliminate large portions of the search space

by identifying variable/value combinations that violate the constraints.

3 / 33

slide-4
SLIDE 4

Constraint Satisfaction Problems (CSP)

A CSP consists of:

  • 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

combinations of values. A constraint 𝑑 ∈ 𝐷 consists of a scope – tuple of variables involved in the constraint – and a relation that defjnes the values that the variables can take.

4 / 33

slide-5
SLIDE 5

Example ⋅ Map-Colouring

Variables:

{WA, NT, Q, NSW, V, SA, T}

Domains:

𝐸 = {red, black, blue}

Constraints: adjacent regions must have difgerent colours

⋅ e.g. WA ≠ NT or ⋅ (WA, NT) ∈ {(red, black), (red, blue), (black, red), (black, blue), (blue, red), (blue, black)}

5 / 33

slide-6
SLIDE 6

Example ⋅ Map-Colouring

Solutions are complete and consistent assignments.

⋅ e.g. WA ↦ red, NT ↦ black, Q ↦ red, NSW ↦ black, V ↦ red, SA ↦ blue, T ↦ black.

6 / 33

slide-7
SLIDE 7

Constraint graph

Binary CSP

  • Each constraint relates two variables.
  • Constraint graph:

⋅ nodes are variables ⋅ arcs (edges) represent constraints

7 / 33

slide-8
SLIDE 8

Varieties of CSP

Discrete variables

  • fjnite domains:

⋅ 𝑜 variables, domain size 𝑒, 𝑃(𝑒) complete assignments ⋅ e.g. Boolean CSPs, including Boolean satisfjability

(NP-complete)

  • infjnite domains:

⋅ integers, strings, etc. ⋅ e.g. job scheduling – variables are start/end days for each job – we need a constraint language to express

StartJob + 5 ≤ StartJob

Continuous variables

  • e.g. start/end times for Hubble Space Telescope observations
  • linear constraints solvable in polynomial time by linear

programming

8 / 33

slide-9
SLIDE 9

Varieties of constraints

Unary constraints involve a single variable.

  • e.g. SA ≠ black

Binary constraints involve pairs of variables.

  • e.g. SA ≠ WA

Higher-order constraints involve 3 or more variables.

  • e.g. crypt-arithmetic column constraints

Global constraints involve an arbitrary number of variables.

9 / 33

slide-10
SLIDE 10

Example ⋅ Crypt-arithmetic

Variables:

{𝐺, 𝑈, 𝑉, 𝑋, 𝑆, 𝑃, 𝑌, 𝑌, 𝑌}

Domains:

{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

Constraints:

Alldiff(𝐺, 𝑈, 𝑉, 𝑋, 𝑆, 𝑃)

⟵ global constraint

𝑃 + 𝑃 = 𝑆 + 10 ⋅ 𝑌 𝑌 + 𝑋 + 𝑋 = 𝑉 + 10 ⋅ 𝑌 𝑌 + 𝑈 + 𝑈 = 𝑃 + 10 ⋅ 𝑌 𝑌 = 𝐺, 𝑈 ≠ 0, 𝐺 ≠ 0

10 / 33

slide-11
SLIDE 11

Real-world CSP

Assignment problems

  • e.g. who teaches what class

Timetabling problems

  • e.g. which class is ofgered when and where

Transportation scheduling Factory scheduling Many real-world problems involve real-valued variables.

11 / 33

slide-12
SLIDE 12

Standard search formulation (incremental)

Let’s start with the straightforward approach, then adapt it.

  • States are defjned by the values assigned so far.

Initial state: the empty assignment {} Successor function: assign a value to an unassigned variable that does not confmict with the current assignment

→ fail if no legal assignments

Goal test: the current assignment is complete

  • This is the same for all CSPs.
  • For CSPs with with 𝑜 variables, any solution appears at

depth 𝑜 ⇒ use depth-fjrst search.

12 / 33

slide-13
SLIDE 13

Backtracking search

  • Variable assignments are commutative.

⋅ e.g. [WA ↦ red then NT ↦ black]

is the same as

[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.

13 / 33

slide-14
SLIDE 14

Backtracking search

14 / 33

slide-15
SLIDE 15

Backtracking example

15 / 33

slide-16
SLIDE 16

Backtracking example

16 / 33

slide-17
SLIDE 17

Backtracking example

17 / 33

slide-18
SLIDE 18

Backtracking example

18 / 33

slide-19
SLIDE 19

Improving backtracking effjciency

General-purpose methods can give huge gains in speed. Which variable should be assigned next?

  • SELECT-UNASSIGNED-VARIABLE

Then, in what order should its values be tried?

  • ORDER-DOMAIN-VALUES

What inferences should be performed at each search step?

  • INFERENCE

Can we detect inevitable failure early?

19 / 33

slide-20
SLIDE 20

Most constrained variable

var ← SELECT-UNASSIGNED-VARIABLE(csp) Most constrained variable heuristic

⋅ choose the variable with the fewest legal values ⋅ a.k.a. minimum-remaining-values (MRV) heuristic

20 / 33

slide-21
SLIDE 21

Most constraining variable

Tie-breaker among most constrained variables. Most constraining variable heuristic

⋅ choose the variable with the most constraints on

remaining variables, thus reducing branching

⋅ a.k.a. degree heuristic

21 / 33

slide-22
SLIDE 22

Least constraining value

ORDER-DOMAIN-VALUES Given a variable, choose the least constraining value

⋅ the one that rules out the fewest values in the remaining

variables Combining these heuristics: 𝑜-queens feasible for 𝑜 ≈ 1000.

22 / 33

slide-23
SLIDE 23

Inference ⋅ Forward checking

Idea Keep track of remaining legal values for unassigned variables. Terminate the search when a variable has no more legal values.

23 / 33

slide-24
SLIDE 24

Inference ⋅ Forward checking

Idea Keep track of remaining legal values for unassigned variables. Terminate the search when a variable has no more legal values.

24 / 33

slide-25
SLIDE 25

Inference ⋅ Forward checking

Idea Keep track of remaining legal values for unassigned variables. Terminate the search when a variable has no more legal values.

25 / 33

slide-26
SLIDE 26

Inference ⋅ Forward checking

Idea Keep track of remaining legal values for unassigned variables. Terminate the search when a variable has no more legal values.

26 / 33

slide-27
SLIDE 27

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.

27 / 33

slide-28
SLIDE 28

Arc consistency

Simplest form of propagation makes each arc consistent.

𝑌 → 𝑍 is consistent ifg

for every value 𝑦 in the domain of 𝑌 there is some allowed value 𝑧 in the domain of 𝑍

28 / 33

slide-29
SLIDE 29

Arc consistency

Simplest form of propagation makes each arc consistent.

𝑌 → 𝑍 is consistent ifg

for every value 𝑦 in the domain of 𝑌 there is some allowed value 𝑧 in the domain of 𝑍

29 / 33

slide-30
SLIDE 30

Arc consistency

Simplest form of propagation makes each arc consistent.

𝑌 → 𝑍 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.

30 / 33

slide-31
SLIDE 31

Arc consistency

Simplest form of propagation makes each arc consistent.

𝑌 → 𝑍 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. Detects failure earlier than forward checking. Can be run as a preprocessor or after each assignment.

31 / 33

slide-32
SLIDE 32

Arc consistency algorithm ⋅ AC-3

𝑒 – maximum size of the domains 𝑑 – number of binary constraints

Time complexity: 𝑃(𝑑𝑒) Space complexity: 𝑃(𝑑)

32 / 33

slide-33
SLIDE 33

Summary

In CSPs:

  • 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

assigned per node.

  • Variable-ordering and value-selection heuristics help.
  • Forward checking prevents assignments that are certain

to lead to later failure.

  • Constraint propagation does additional work to limit

values and detect inconsistencies.

33 / 33