Foundations of Artificial Intelligence 24. Constraint Satisfaction - - PowerPoint PPT Presentation

foundations of artificial intelligence
SMART_READER_LITE
LIVE PREVIEW

Foundations of Artificial Intelligence 24. Constraint Satisfaction - - PowerPoint PPT Presentation

Foundations of Artificial Intelligence 24. Constraint Satisfaction Problems: Backtracking Malte Helmert and Thomas Keller University of Basel April 8, 2020 CSP Algorithms Naive Backtracking Variable and Value Orders Summary Constraint


slide-1
SLIDE 1

Foundations of Artificial Intelligence

  • 24. Constraint Satisfaction Problems: Backtracking

Malte Helmert and Thomas Keller

University of Basel

April 8, 2020

slide-2
SLIDE 2

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Constraint Satisfaction Problems: Overview

Chapter overview: constraint satisfaction problems: 22.–23. Introduction 24.–26. Basic Algorithms

  • 24. Backtracking
  • 25. Arc Consistency
  • 26. Path Consistency

27.–28. Problem Structure

slide-3
SLIDE 3

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

CSP Algorithms

slide-4
SLIDE 4

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

CSP Algorithms

In the following chapters, we consider algorithms for solving constraint networks. basic concepts: search: check partial assignments systematically backtracking: discard inconsistent partial assignments inference: derive equivalent, but tighter constraints to reduce the size of the search space

slide-5
SLIDE 5

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking

slide-6
SLIDE 6

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking (= Without Inference)

function NaiveBacktracking(C, α): V , dom, (Ruv) := C if α is inconsistent with C: return inconsistent if α is a total assignment: return α select some variable v for which α is not defined for each d ∈ dom(v) in some order: α′ := α ∪ {v → d} α′′ := NaiveBacktracking(C, α′) if α′′ = inconsistent: return α′′ return inconsistent input: constraint network C and partial assignment α for C (first invocation: empty assignment α = ∅) result: solution of C or inconsistent

slide-7
SLIDE 7

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Is This a New Algorithm?

We have already seen this algorithm: Backtracking corresponds to depth-first search (Chapter 12) with the following state space: states: consistent partial assignments initial state: empty assignment ∅ goal states: consistent total assignments actions: assignv,d assigns value d ∈ dom(v) to variable v action costs: all 0 (all solutions are of equal quality) transitions:

for each non-total assignment α, choose variable v = select(α) that is unassigned in α transition α

assignv,d

− − − − − → α ∪ {v → d} for each d ∈ dom(v)

slide-8
SLIDE 8

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Why Depth-First Search?

Depth-first search is particularly well-suited for CSPs: path length bounded (by the number of variables) solutions located at the same depth (lowest search layer) state space is directed tree, initial state is the root no duplicates (Why?) Hence none of the problematic cases for depth-first search occurs.

slide-9
SLIDE 9

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

Consider the constraint network for the following graph coloring problem: b, g, r v1 b, g v2 b, r v3 b, r v4 b, g v5 g, r, y v6 b, r v7

slide-10
SLIDE 10

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2

slide-11
SLIDE 11

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2 b b r b r g

slide-12
SLIDE 12

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2 b b r b r g

slide-13
SLIDE 13

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2 b b r b r g

slide-14
SLIDE 14

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2 b b r b r g

slide-15
SLIDE 15

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2 b b r b r g

slide-16
SLIDE 16

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2 b b r b r g b r

slide-17
SLIDE 17

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2 b b r b r g b b r r

slide-18
SLIDE 18

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2 b b r b r g b b r r

slide-19
SLIDE 19

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2 b b r b r g b b r r

slide-20
SLIDE 20

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2 b b r b r g b b r b g r

slide-21
SLIDE 21

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2 b b r b r g b b r b g r

slide-22
SLIDE 22

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2 b b r b r g b b r b g g r y r

slide-23
SLIDE 23

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2 b b r b r g b b r b g g r y r

slide-24
SLIDE 24

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2 b b r b r g b b r b g g r b r y r

slide-25
SLIDE 25

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2 b b r b r g b b r b g g r b r y r

slide-26
SLIDE 26

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Example

search tree for naive backtracking with fixed variable order v1, v7, v4, v5, v6, v3, v2 alphabetical order of the values

v1 v7 v4 v5 v6 v3 v2 b b r b r g b b r b g g r b r b g y r

slide-27
SLIDE 27

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking: Discussion

Naive backtracking often has to exhaustively explore similar search paths (i.e., partial assignments that are identical except for a few variables). “Critical” variables are not recognized and hence considered for assignment (too) late. Decisions that necessarily lead to constraint violations are only recognized when all variables involved in the constraint have been assigned. more intelligence by focusing on critical decisions and by inference of consequences of previous decisions

slide-28
SLIDE 28

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Variable and Value Orders

slide-29
SLIDE 29

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Naive Backtracking

function NaiveBacktracking(C, α): V , dom, (Ruv) := C if α is inconsistent with C: return inconsistent if α is a total assignment: return α select some variable v for which α is not defined for each d ∈ dom(v) in some order: α′ := α ∪ {v → d} α′′ := NaiveBacktracking(C, α′) if α′′ = inconsistent: return α′′ return inconsistent

slide-30
SLIDE 30

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Variable Orders

Backtracking does not specify in which order variables are considered for assignment. Such orders can strongly influence the search space size and hence the search performance. example: exercises German: Variablenordnung

slide-31
SLIDE 31

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Value Orders

Backtracking does not specify in which order the values of the selected variable v are considered. This is not as important because it does not matter in subtrees without a solution. (Why not?) If there is a solution in the subtree, then ideally a value that leads to a solution should be chosen. (Why?) German: Werteordnung

slide-32
SLIDE 32

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Static vs. Dynamic Orders

we distinguish: static orders (fixed prior to search) dynamic orders (selected variable or value order depends on the search state) comparison: dynamic orders obviously more powerful static orders no computational overhead during search The following ordering criteria can be used statically, but are more effective combined with inference ( later) and used dynamically.

slide-33
SLIDE 33

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Variable Orders

two common variable ordering criteria: minimum remaining values: prefer variables that have small domains

intuition: few subtrees smaller tree extreme case: only one value forced assignment

most constraining variable: prefer variables contained in many nontrivial constraints

intuition: constraints tested early inconsistencies recognized early smaller tree

combination: use minimum remaining values criterion, then most constraining variable criterion to break ties

slide-34
SLIDE 34

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Value Orders

Definition (conflict) Let C = V , dom, (Ruv) be a constraint network. For variables v = v′ and values d ∈ dom(v), d′ ∈ dom(v′), the assignment v → d is in conflict with v′ → d′ if d, d′ / ∈ Rvv′. value ordering criterion for partial assignment α and selected variable v: minimum conflicts: prefer values d ∈ dom(v) such that v → d causes as few conflicts as possible with variables that are unassigned in α

slide-35
SLIDE 35

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Summary

slide-36
SLIDE 36

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Summary: Backtracking

basic search algorithm for constraint networks: backtracking extends the (initially empty) partial assignment step by step until an inconsistency or a solution is found is a form of depth-first search depth-first search particularly well-suited because state space is directed tree and all solutions at same (known) depth

slide-37
SLIDE 37

CSP Algorithms Naive Backtracking Variable and Value Orders Summary

Summary: Variable and Value Orders

Variable orders influence the performance

  • f backtracking significantly.

goal: critical decisions as early as possible

Value orders influence the performance

  • f backtracking on solvable constraint networks significantly.

goal: most promising assignments first