• Keine Ergebnisse gefunden

Foundations of Artificial Intelligence 23. Constraint Satisfaction Problems: Constraint Networks Malte Helmert

N/A
N/A
Protected

Academic year: 2022

Aktie "Foundations of Artificial Intelligence 23. Constraint Satisfaction Problems: Constraint Networks Malte Helmert"

Copied!
25
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

23. Constraint Satisfaction Problems: Constraint Networks

Malte Helmert

University of Basel

April 12, 2021

(2)

Constraint Satisfaction Problems: Overview

Chapter overview: constraint satisfaction problems 22.–23. Introduction

22. Introduction and Examples 23. Constraint Networks 24.–26. Basic Algorithms 27.–28. Problem Structure

(3)

Constraint Networks

(4)

Constraint Networks: Informally

Constraint Networks: Informal Definition Aconstraint networkis defined by

a finite set of variables

a finitedomain for each variable

a set of constraints (here: binary relations)

The objective is to find asolution for the constraint network, i.e., an assignment of the variables that complies with all constraints.

Informally, people often just speak ofconstraint satisfaction problems(CSP) instead of constraint networks.

More formally, a “CSP” is the algorithmic problem of finding a solution for a constraint network.

(5)

Constraint Networks: Formally

Definition (binary constraint network) A(binary) constraint network

is a 3-tupleC=hV,dom,(Ruv)i such that:

V is a non-empty and finite set ofvariables,

dom is a function that assigns a non-empty and finite domain to each variable v∈V, and

(Ruv)u,v∈V,u6=v is a family of binary relations (constraints) overV where for allu 6=v: Ruv ⊆dom(u)×dom(v) German: (bin¨ares) Constraint-Netz, Variablen, Wertebereich, Constraints

possible generalizations:

infinite domains (e.g., dom(v) =Z) constraints of higher arity

(e.g., satisfiability in propositional logic)

(6)

Binary Constraints

binary constraints:

For variables u,v, the constraint Ruv expresses

which joint assignments tou andv are allowed in a solution.

IfRuv = dom(u)×dom(v), the constraint is trivial:

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

Constraints Ruv and Rvu refer to the same variables.

Hence, usually only one of them is given in the description.

German: gemeinsame Belegungen, triviale Constraints

(7)

Binary Constraints

binary constraints:

For variables u,v, the constraint Ruv expresses

which joint assignments tou andv are allowed in a solution.

IfRuv = dom(u)×dom(v), the constraint istrivial:

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

Constraints Ruv and Rvu refer to the same variables.

Hence, usually only one of them is given in the description.

German: gemeinsame Belegungen, triviale Constraints

(8)

Unary Constraints

unary constraints:

It is often useful to have additional restrictions onsingle variables as constraints.

Such constraints are calledunary constraints.

A unary constraint Rv forv ∈V corresponds to a restriction of dom(v) to the values allowed by Rv.

Formally, unary constraints are not necessary, but they often allow to describe constraint networks more clearly.

German: un¨are Constraints

(9)

Compact Encodings and General Constraint Solvers

Constraint networks allow forcompact encodings of large sets of assignments:

Consider a network withn variables with domains of size k. kn assignments

For the description as constraint network, at most n2 , i.e., O(n2) constraints have to be provided.

Every constraint in turn consists of at most O(k2) pairs.

encoding sizeO(n2k2)

We observe: The number of assignments is exponentially larger than the description of the constraint network.

As a consequence, such descriptions can be used as inputs of general constraint solvers.

(10)

Compact Encodings and General Constraint Solvers

Constraint networks allow forcompact encodings of large sets of assignments:

Consider a network withn variables with domains of size k. kn assignments

For the descriptionas constraint network, at most n2 , i.e., O(n2) constraints have to be provided.

Every constraint in turn consists of at most O(k2) pairs.

encoding sizeO(n2k2)

We observe: The number of assignments isexponentially larger than the description of the constraint network.

As a consequence, such descriptions can be used as inputs of general constraint solvers.

(11)

Compact Encodings and General Constraint Solvers

Constraint networks allow forcompact encodings of large sets of assignments:

Consider a network withn variables with domains of size k. kn assignments

For the descriptionas constraint network, at most n2 , i.e., O(n2) constraints have to be provided.

Every constraint in turn consists of at most O(k2) pairs.

encoding sizeO(n2k2)

We observe: The number of assignments isexponentially larger than the description of the constraint network.

As a consequence, such descriptions can be used as inputs of generalconstraint solvers.

(12)

Examples

(13)

Example: 4 Queens Problem

4 Queens Problem as Constraint Network variables: V ={v1,v2,v3,v4}

vi encodes the rank of the queen in the i-th file domains:

dom(v1) = dom(v2) = dom(v3) = dom(v4) ={1,2,3,4}

constraints: for all 1≤i <j ≤4, we set: Rvi,vj ={hk,li ∈ {1,2,3,4} × {1,2,3,4} |k 6=l∧ |k−l| 6=|i−j|}

e.g. Rv1,v3 ={h1,2i,h1,4i,h2,1i,h2,3i,h3,2i,h3,4i,h4,1i,h4,3i}

v1 v2 v3 v4

1 2 3 4

(14)

Example: Sudoku

Sudoku as Constraint Network

variables: V ={vij |1≤i,j ≤9};vij: Value rowi, columnj domains: dom(v) ={1, . . . ,9}for all v ∈V

unary constraints: Rvij ={k},

if hi,jiis a cell with predefined value k binary constraints: for all vij,vi0j0 ∈V, we set Rvijvi0j0 ={ha,bi ∈ {1, . . . ,9} × {1, . . . ,9} |a6=b}, if i =i0 (same row), or j =j0 (same column), or hd3ie,d3jei=hdi30e,dj30ei(same block)

2 5 3 9 1

1 4

4 7 2 8

5 2 9 8 1

4 3

3 6 7 2

7 3

9 3 6 4

(15)

Assignments and Consistency

(16)

Assignments

Definition (assignment, partial assignment) LetC=hV,dom,(Ruv)i be a constraint network.

Apartial assignmentof C (or of V) is a function α:V0→S

v∈V dom(v) withV0 ⊆V andα(v)∈dom(v) for all v ∈V0.

IfV0 =V, thenα is also called total assignment(orassignment).

German: partielle Belegung, (totale) Belegung

partial assignments assign values to some or to all variables (total)assignments are defined on all variables

(17)

Consistency

Definition (inconsistent, consistent, violated)

A partial assignmentα of a constraint network C is called inconsistentif there are variables u,v such that α is defined for bothu andv, and hα(u), α(v)i∈/ Ruv.

In this case, we sayα violatesthe constraintRuv.

A partial assignment is calledconsistent if it is not inconsistent.

German: inkonsistent, verletzt, konsistent

trivial example: The empty assignment is always consistent.

(18)

Solution

Definition (solution, solvable) LetC be a constraint network.

A consistent and total assignment ofC is called a solutionof C.

If a solution ofC exists,C is called solvable.

If no solution exists,C is calledinconsistent.

German: L¨osung, l¨osbar, inkonsistent

(19)

Consistency vs. Solvability

Note: Consistent partial assignments α cannot necessarily be extended to a solution.

It only means thatso far(i.e., on the variables where α is defined) no constraint is violated.

Example (4 queens problem): α={v1 7→1,v27→4,v3 7→2}

v1 v2 v3 v4

1 q

2 q

3

4 q

(20)

Complexity of Constraint Satisfaction Problems

Proposition (CSPs are NP-complete) It is an NP-complete problem to decide whether a given constraint network is solvable.

Proof

Membership in NP:

Guess and check: guess a solution and check it for validity.

This can be done in polynomial time in the size of the input.

NP-hardness:

The graph coloring problem is a special case of CSPs and is already known to be NP-complete.

(21)

Tightness of Constraint Networks

Definition (tighter, strictly tighter)

LetC=hV,dom,Ruviand C0 =hV,dom0,Ruv0 i be constraint networks with equal variable setsV.

C is calledtighter thanC0, in symbolsC v C0, if dom(v)⊆dom0(v) for all v ∈V

Ruv ⊆Ruv0 for allu,v ∈V (including trivial constraints).

If at least one of these subset equations is strict,

thenC is called strictly tighterthanC0, in symbols C@C0. German: (echt) sch¨arfer

(22)

Equivalence of Constraint Networks

Definition (equivalent)

LetC andC0 be constraint networks with equal variable sets.

C andC0 are called equivalent, in symbolsC ≡ C0, if they have the same solutions.

German: ¨aquivalent

(23)

Outline and Summary

(24)

CSP Algorithms

In the following chapters, we will considersolution algorithms for 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

(25)

Summary

formal definition ofconstraint networks:

variables,domains,constraints

compact encodings of exponentially many configurations unary andbinary constraints

assignments: partial and total consistency of assignments;solutions deciding solvability is NP-complete tightnessof constraints

equivalenceof constraints

Referenzen

ÄHNLICHE DOKUMENTE

“[the automation of] activities that we associate with hu- man thinking, activities such as decision-making, problem solving, learning” (Bellman, 1978).. “the study of mental

several wrong proofs surviving for over 10 years solved by Appel and Haken in 1976: 4 colors suffice Appel and Haken reduced the problem to 1936 cases, which were then checked

We have already seen this algorithm: Backtracking corresponds to depth-first search Chapter 12 with the following state space: states: partial assignments initial state:

enforcing arc consistency of all variables with respect to the just assigned variable corresponds to forward checking.. We will next consider algorithms that enforce

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

I arc consistency tightens unary constraints I path consistency tightens binary constraints I i-consistency tightens (i − 1)-ary constraints I higher levels of consistency

If the constraint graph of C has multiple connected components, the subproblems induced by each component can be solved separately.. The union of the solutions of these subproblems is

If the constraint graph of C has multiple connected components, the subproblems induced by each component can be solved separately.. The union of the solutions of these subproblems is