• Keine Ergebnisse gefunden

Foundations of Artificial Intelligence 24. Constraint Satisfaction Problems: Backtracking Malte Helmert

N/A
N/A
Protected

Academic year: 2022

Aktie "Foundations of Artificial Intelligence 24. Constraint Satisfaction Problems: Backtracking Malte Helmert"

Copied!
32
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)Foundations of Artificial Intelligence 24. Constraint Satisfaction Problems: Backtracking. Malte Helmert University of Basel. April 8, 2019.

(2) CSP Algorithms. Naive Backtracking. Variable and Value Orders. 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. Summary.

(3) CSP Algorithms. Naive Backtracking. Variable and Value Orders. CSP Algorithms. Summary.

(4) CSP Algorithms. Naive Backtracking. Variable and Value Orders. 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. Summary.

(5) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking. Summary.

(6) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking (= Without Inference) function NaiveBacktracking(C, α): hV , dom, (Ruv )i := 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: α0 := α ∪ {v 7→ d} α00 := NaiveBacktracking(C, α0 ) if α00 6= inconsistent: return α00 return inconsistent input: constraint network C and partial assignment α for C (first invocation: empty assignment α = ∅) result: solution of C or inconsistent. Summary.

(7) CSP Algorithms. Naive Backtracking. Variable and Value Orders. 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 α assignv ,d. transition α −−−−−→ α ∪ {v 7→ d} for each d ∈ dom(v ). Summary.

(8) CSP Algorithms. Naive Backtracking. Variable and Value Orders. 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.. Summary.

(9) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking: Example Consider the constraint network for the following graph coloring problem: v1. v7. b, g, r. b, r. v2. v6. b, g. g, r, y b, g. b, r v3. b, r v4. v5. Summary.

(10) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking: Example search tree for naive backtracking with fixed variable order v1 , v7 , v4 , v5 , v6 , v3 , v2 alphabetical order of the values (without inconsistent nodes; continued at goal nodes). v1 v7 v4 v5 v6 v3 v2. Summary.

(11) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking: Example search tree for naive backtracking with fixed variable order v1 , v7 , v4 , v5 , v6 , v3 , v2 alphabetical order of the values (without inconsistent nodes; continued at goal nodes). v1 v7 v4 v5 v6 v3 v2. b r. g. r b. Summary.

(12) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking: Example search tree for naive backtracking with fixed variable order v1 , v7 , v4 , v5 , v6 , v3 , v2 alphabetical order of the values (without inconsistent nodes; continued at goal nodes). v1 v7 v4 v5 v6 v3 v2. b r. g. r b. Summary.

(13) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking: Example search tree for naive backtracking with fixed variable order v1 , v7 , v4 , v5 , v6 , v3 , v2 alphabetical order of the values (without inconsistent nodes; continued at goal nodes). v1 v7 v4 v5 v6 v3 v2. g. b r. b. r r. b. Summary.

(14) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking: Example search tree for naive backtracking with fixed variable order v1 , v7 , v4 , v5 , v6 , v3 , v2 alphabetical order of the values (without inconsistent nodes; continued at goal nodes). v1 v7 v4 v5 v6 v3 v2. g. b r. b r. r r. b. Summary.

(15) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking: Example search tree for naive backtracking with fixed variable order v1 , v7 , v4 , v5 , v6 , v3 , v2 alphabetical order of the values (without inconsistent nodes; continued at goal nodes). v1 v7. g. b r. b. v4. r. v5. g. v6 v3 v2. r r. b. Summary.

(16) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking: Example search tree for naive backtracking with fixed variable order v1 , v7 , v4 , v5 , v6 , v3 , v2 alphabetical order of the values (without inconsistent nodes; continued at goal nodes). v1 v7. g. b r. b. v4. r. v5. g. v6 v3 v2. r r. b. Summary.

(17) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking: Example search tree for naive backtracking with fixed variable order v1 , v7 , v4 , v5 , v6 , v3 , v2 alphabetical order of the values (without inconsistent nodes; continued at goal nodes). v1 v7. g. b r. r. b. r. v4. r. b. v5. g. g. b. v6. r. y. r. y. v3. r. r. b. b. v2. b. b. b. b. Summary.

(18) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking: Example search tree for naive backtracking with fixed variable order v1 , v7 , v4 , v5 , v6 , v3 , v2 alphabetical order of the values (without inconsistent nodes; continued at goal nodes). v1 v7. g. b r. r. b. r. v4. r. b. v5. g. g. b. v6. r. y. r. y. v3. r. r. b. b. v2. b. b. b. b. Summary.

(19) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking: Example search tree for naive backtracking with fixed variable order v1 , v7 , v4 , v5 , v6 , v3 , v2 alphabetical order of the values (without inconsistent nodes; continued at goal nodes). v1 v7. g. b r. r. b. r. v4. r. b. v5. g. g. b. v6. r. y. r. y. v3. r. r. b. b. v2. b. b. b. b. Summary.

(20) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking: Example search tree for naive backtracking with fixed variable order v1 , v7 , v4 , v5 , v6 , v3 , v2 alphabetical order of the values (without inconsistent nodes; continued at goal nodes). v1 v7. g. b r. r. b. r. v4. r. b. v5. g. g. b. v6. r. y. r. y. v3. r. r. b. b. v2. b. b. b. b. Summary.

(21) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking: Example search tree for naive backtracking with fixed variable order v1 , v7 , v4 , v5 , v6 , v3 , v2 alphabetical order of the values (without inconsistent nodes; continued at goal nodes). v1 v7. g. b r. r. b. r. v4. r. b. v5. g. g. b. v6. r. y. r. y. v3. r. r. b. b. v2. b. b. b. b. Summary.

(22) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking: Example search tree for naive backtracking with fixed variable order v1 , v7 , v4 , v5 , v6 , v3 , v2 alphabetical order of the values (without inconsistent nodes; continued at goal nodes). v1 v7. g. b r. r. b. r. v4. r. b. v5. g. g. b. v6. r. y. r. y. v3. r. r. b. b. v2. b. b. b. b. Summary.

(23) CSP Algorithms. Naive Backtracking. Variable and Value Orders. 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. Summary.

(24) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Variable and Value Orders. Summary.

(25) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Naive Backtracking function NaiveBacktracking(C, α): hV , dom, (Ruv )i := 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: α0 := α ∪ {v 7→ d} α00 := NaiveBacktracking(C, α0 ) if α00 6= inconsistent: return α00 return inconsistent. Summary.

(26) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Variable and Value Orders 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 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. Summary.

(27) 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..

(28) CSP Algorithms. Naive Backtracking. Variable and Value Orders. 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. Summary.

(29) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Summary. Value Orders. Definition (conflict) Let C = hV , dom, (Ruv )i be a constraint network. For variables v 6= v 0 and values d ∈ dom(v ), d 0 ∈ dom(v 0 ), the assignment v 7→ d is in conflict with v 0 7→ d 0 if hd, d 0 i ∈ / Rvv 0 . value ordering criterion for partial assignment α and selected variable v : minimum conflicts: prefer values d ∈ dom(v ) such that v 7→ d causes as few conflicts as possible with variables that are unassigned in α.

(30) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Summary. Summary.

(31) CSP Algorithms. Naive Backtracking. Variable and Value Orders. 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. Summary.

(32) CSP Algorithms. Naive Backtracking. Variable and Value Orders. Summary: Variable and Value Orders. Variable orders influence the performance of backtracking significantly. goal: critical decisions as early as possible. Value orders influence the performance of backtracking on solvable constraint networks significantly. goal: most promising assignments first. Summary.

(33)

Referenzen

ÄHNLICHE DOKUMENTE

recognize duplicates: when a state is reached on multiple paths, only keep one search node search nodes correspond 1:1 to reachable states search tree bounded, as number of states

breadth-first search ( this chapter) uniform cost search ( Chapter 11) depth-first search ( Chapter 12) depth-limited search ( Chapter 12) iterative deepening search ( Chapter

breadth-first search optimal if all action costs equal otherwise no optimality guarantee example:.. remedy: uniform

space complexity O(bm) if m maximal search depth reached low memory complexity main reason why depth-first search interesting despite its disadvantages.. Depth-first

heuristics estimate distance of a state to the goal can be used to focus search on promising states soon: search algorithms that

In IDDFS, we grow the limit from the smallest limit that gives a non-empty search tree (0) by 1 at a time. This usually leads to exponential growth of

there is no restriction, and the constraint is typically not given explicitly in the constraint network description (although it formally always exists!).. Constraints R uv and R

arc consistency (considers pairs of variables) to path consistency (considers triples of variables) and i -consistency (considers i -tuples of variables) arc consistency tightens