• No results found

PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE

N/A
N/A
Protected

Academic year: 2022

Share "PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE"

Copied!
47
0
0

Loading.... (view fulltext now)

Full text

(1)

Artificial Intelligence, Computational Logic

PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE

Lecture 4 Constraint Satisfaction Problems

Sarah Gaggl

(2)

Agenda

1 Introduction

2 Uninformed Search versus Informed Search (Best First Search, A*

Search, Heuristics)

3 Constraint Satisfaction

4 Structural Decomposition Techniques (Tree/Hypertree Decompositions)

5 Local Search, Stochastic Hill Climbing, Simulated Annealing

6 Tabu Search

7 Evolutionary Algorithms/ Genetic Algorithms

8 Adversial Search and Game Playing

(3)

Outline

CSP examples

Backtracking search for CSPs

Problem structure and problem decomposition

(4)

Constraint satisfaction problems (CSPs)

Standard search problem:

– stateis a “black box”—any old data structure that supports goal test, eval, successor

CSP:

– stateis defined byvariablesXiwithvaluesfromdomainDi – goal testis a set ofconstraintsspecifying allowable combinations of

values for subsets of variables

Simple example of aformal representation language

Allows usefulgeneral-purposealgorithms with more power than standard search algorithms

(5)

Defining CSPs

Constraint Satisfaction Problem (CSP)

A CSP is defined as a tuple C = hX, D, Ci, with

Xa set of variables, {X1, . . . , Xn}.

Da set of domains, {D1, . . . , Dn}, for each variable.

Ca set of constraints that specify allowable combinations of values.

Eachdomain Diconsists of a set of allowable values, {v1, . . . , vk} for variable Xi.

Eachconstraint Ciconsists of a pair hscope, reli, where scope is a tuple of variables in the constraint, and rel defines the possible values.

(6)

Defining CSPs ctd.

If X1and X2both have domain {A, B}, the constraint saying they have different values can be written as:

h(X1, X2), [(A, B), (B, A)]i, or

h(X1, X2), X16= X2i.

To solve a CSP, we define astate spaceand the notion of a solution.

Each state in a CSP is defined by anassignmentof values to some (or all variables), {Xi= vi, Xj= vj, . . . }.

An assignment isconsistentif it does not violate any constraints.

Acomplete assignmenthas a value assigned to each variable.

Asolutionis a consistent, complete assignment.

Apartial assignmentis one that assigns values to only some of the variables.

(7)

Example: Map-Coloring

Western Australia

Northern Territory

South Australia

Queensland

New South Wales

Victoria

Tasmania

Variables WA,NT,Q,NSW,V,SA,T

(8)

Example: Map-Coloring ctd.

Western Australia

Northern Territory

South Australia

Queensland

New South Wales

Victoria

Tasmania

Solutionsare assignments satisfying all constraints, e.g.,

{WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = green}

(9)

Constraint graph

Binary CSP: each constraint relates at most two variables Constraint graph: nodes are variables, arcs show constraints

Victoria

WA

NT

SA

Q

NSW V

(10)

Varieties of CSPs

Discrete variables

finite domains; sized =⇒ O(dn)complete assignments

– e.g., Boolean CSPs, incl. Boolean satisfiability (NP-complete)

infinite domains (integers, strings, etc.)

– e.g., job scheduling, variables are start/end days for each job – need aconstraint language, e.g.,StartJob1+ 5 ≤ StartJob3 – linearconstraints solvable,nonlinearundecidable Continuous variables

e.g., start/end times for Hubble Telescope observations

linear constraints solvable in poly time by LP methods

(11)

Varieties of constraints

Unary constraints involve a single variable, e.g.,SA6= green

Binary constraints involve pairs of variables, e.g.,SA6= WA

Higher-order constraints involve 3 or more variables, e.g., cryptarithmetic column constraints Preferences (soft constraints), e.g.,redis better thangreen

often representable by a cost for each variable assignment

→ constrained optimization problems

(12)

Example: Cryptarithmetic

O

W T

F U R

+

O W T

O W T

F O U R

X

2

X

1

X

3

Variables: F T U W R O X1X2X3 Domains: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}

Constraints alldiff(F, T, U, W, R, O),O+ O = R + 10 · X1, etc.

(13)

Real-world CSPs

Assignment problems

– e.g., who teaches what class

Timetabling problems

– e.g., which class is offered when and where?

Hardware configuration

Spreadsheets

Transportation scheduling

Factory scheduling

Floorplanning

Notice that many real-world problems involve real-valued variables

(14)

Constraint Propagation: Inference in CSPs

In regular state-space search, an algorithm can only perform search. In CSPs there is a choice

an algorithm can search (choose a new variable assignment form several possibilities), or

do a specific type ofinferencecalledconstraint propagation:

– using the constraints to reduce the number of legal values for a variable

– this can reduce the legal values for another variable, – and so on.

Constraint propagation may be

intertwined with search, or

done as apre-processingstep (could solve the whole problem; no search is required).

(15)

Constraint Propagation

The key idea islocal consistency.

Treat each variable as a node in a graph.

Each binary constraint represents an arc.

Enforcing local consistency in each part of the graph eliminates inconsistent values throughout the graph.

Different types of local consistency:

Node consistency

Arc consistency

Path consistency

(16)

Node Consistency

Node consistency

A variable X isnode-consistentif all values in the domain of X satisfy theunary constraints of X. A CSP is node-consistent if every variable is node consistent.

Example

South Australia dislikes green.

Variable SA starts with {red, green, blue},

make it node consistent by eliminating green,

reduced domain of SA is {red, blue}.

(17)

Arc Consistency

Arc consistency

A variable isarc-consistentif every value in its domain satisfies the variable’s binary constraints. Xiis arc-consistent wrt. Xjif for every value in Dithere is some value in Djthat satisfies the binary constraint on the arc (Xi, Xj). A CSP is arc-consistent if every variable is arc-consistent with every other variable.

Example

Consider the constraint Y = X2, where the domain of both X and Y is the set of digits. We can write the constraint explicitly as

h(X, Y), {(0, 0), (1, 1), (2, 4), (3, 9)}i.

(18)

Path Consistency

Arc consistency can reduce domains of variables and sometimes find a solution (or failure).

But for other networks, arc consistency fails to make enough inferences.

Example of map coloring of Australia with two colors.

Path consistency

A two-variable set {Xi, Xj} ispath-consistentwrt. a third variable Xmif, for every assignment {Xi= a, Xj= b}consistent with constraints on {Xi, Xj}, there is an assignment to Xmthat satisfies the constraints on {Xi, Xm} and {Xm, Xj}.

(19)

Example: Path Consistency

Western Australia

Northern Territory

South Australia

Queensland

New South Wales Victoria

Tasmania

Consider two-coloring of Australia. We make {WA, SA} path consistent wrt. NT.

Start by enumerating the consistent assignments to the set.

– {WA = red, SA = blue}

– {WA = blue, SA = red}

(20)

Standard search formulation (incremental)

Let’s start with the straightforward, dumb approach, then fix it

States are defined by the values assigned so far Initial state: the empty assignment,{}

Successor function: assign a value to an unassigned variable that does not conflict with current assignment.

=⇒ fail if no legal assignments (not fixable!) Goal test: the current assignment is complete

1 This is the same for all CSPs!,

2 Every solution appears at depthnwithnvariables

=⇒ use depth-first search

3 Path is irrelevant, so can also use complete-state formulation

4 b= (n − `)dat depth`, hencen!dnleaves!!!!/

(21)

Backtracking search

Variable assignments arecommutative, i.e.,

[WA= redthenNT= green] same as [NT= greenthenWA= red]

Only need to consider assignments to a single variable at each node

=⇒ b= dand there arednleaves

Depth-first search for CSPs with single-variable assignments is called backtrackingsearch

Backtracking search is the basic uninformed algorithm for CSPs

Can solven-queens forn≈ 25

(22)

Backtracking search

functionBacktracking-Search(csp)returnssolution/failure returnRecursive-Backtracking({ },csp)

functionRecursive-Backtracking(assignment, csp)returnssoln/failure ifassignmentis completethen returnassignment

var← Select-Unassigned-Variable(Variables[csp],assignment,csp) for eachvalueinOrder-Domain-Values(var,assignment,csp)do

ifvalueis consistent withassignmentgiven Constraints[csp]then add {var=value} toassignment

result← Recursive-Backtracking(assignment,csp) ifresult6=failurethen returnresult

remove {var=value} fromassignment returnfailure

(23)

Backtracking example

(24)

Backtracking example

(25)

Backtracking example

(26)

Backtracking example

(27)

Improving backtracking efficiency

General-purposemethods can give huge gains in speed:

1 Which variable should be assigned next?

2 In what order should its values be tried?

3 Can we detect inevitable failure early?

4 Can we take advantage of problem structure?

(28)

Minimum remaining values

Minimum remaining values (MRV):

choose the variable with the fewest legal values

(29)

Degree heuristic

Tie-breaker among MRV variables

Degree heuristic:

choose the variable with the most constraints on remaining variables

(30)

Least constraining value

Given a variable, choose the least constraining value:

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

Allows 1 value for SA

Allows 0 values for SA

Combining these heuristics makes 1000 queens feasible

(31)

Forward checking

Idea:

Keep track of remaining legal values for unassigned variables

Terminate search when any variable has no legal values

WA NT Q NSW V SA T

(32)

Forward checking

Idea:

Keep track of remaining legal values for unassigned variables

Terminate search when any variable has no legal values

WA NT Q NSW V SA T

(33)

Forward checking

Idea:

Keep track of remaining legal values for unassigned variables

Terminate search when any variable has no legal values

WA NT Q NSW V SA T

(34)

Forward checking

Idea:

Keep track of remaining legal values for unassigned variables

Terminate search when any variable has no legal values

WA NT Q NSW V SA T

(35)

Constraint propagation

Forward checking propagates information from assigned to unassigned variables, but doesn’t provide early detection for all failures:

WA NT Q NSW V SA T

(36)

Arc consistency

Simplest form of propagation makes each arcconsistent

X → Y is consistent iff

foreveryvaluexofXthere issomeallowedy

WA NT Q NSW V SA T

(37)

Arc consistency

Simplest form of propagation makes each arcconsistent

X → Y is consistent iff

foreveryvaluexofXthere issomeallowedy

WA NT Q NSW V SA T

(38)

Arc consistency

Simplest form of propagation makes each arcconsistent

X → Y is consistent iff

foreveryvaluexofXthere issomeallowedy

WA NT Q NSW V SA T

IfXloses a value, neighbors ofXneed to be rechecked

(39)

Arc consistency

Simplest form of propagation makes each arcconsistent

X → Y is consistent iff

foreveryvaluexofXthere issomeallowedy

WA NT Q NSW V SA T

(40)

Arc consistency algorithm

functionAC-3(csp)returnsthe CSP, possibly with reduced domains inputs:csp, a binary CSP with variables {X1, X2, . . . , Xn} local variables:queue, a queue of arcs, initially all the arcs incsp

whilequeueis not emptydo (Xi, Xj) ←Remove-First(queue) ifRemove-Inconsistent-Values(Xi, Xj)then

for eachXkinNeighbors[Xi]do add (Xk, Xi) toqueue

functionRemove-Inconsistent-Values(Xi, Xj)returnstrue iff succeeds removed←false

for eachxinDomain[Xi]do

ifno value y in Domain[Xj] allows (x,y) to satisfy the constraint Xi ↔ Xj thendeletexfrom Domain[Xi];removed←true

returnremoved

O(n2d3), can be reduced toO(n2d2)(but detectingallis NP-hard)

(41)

Problem structure

Victoria

WA

NT

SA

Q

NSW V

T

(42)

Problem structure ctd.

Suppose each subproblem hascvariables out ofntotal

Worst-case solution cost isn/c · dc,linearinn

E.g.,n= 80,d= 2,c= 20

– 280= 4 billion years at 10 million nodes/sec – 4 · 220= 0.4 seconds at 10 million nodes/sec

(43)

Tree-structured CSPs

A B C

D E

F

Theorem

If the constraint graph has no loops, the CSP can be solved inO(n d2)time.

(44)

Algorithm for tree-structured CSPs

1 Choose a variable as root, order variables from root to leaves such that every node’s parent precedes it in the ordering

A B C

D E F

A B C D E F

2 Forjfromndown to2, apply RemoveInconsistent(Parent(Xj), Xj)

3 Forjfrom1ton, assignXjconsistently withParent(Xj)

(45)

Nearly tree-structured CSPs

Conditioning: instantiate a variable, prune its neighbors’ domains

Victoria

WA

NT

Q

NSW

V

T T

Victoria

WA

NT

SA

Q

NSW

V

Cutset conditioning: instantiate (in all ways) a set of variables such that the remaining constraint graph is a tree

(46)

Summary

CSPs are a special kind of problem:

– states defined by values of a fixed set of variables – goal test defined byconstraintson variable values

Backtracking = depth-first search with one variable assigned per node

Variable ordering and value selection heuristics help significantly

Forward checking prevents assignments that guarantee later failure

Constraint propagation (e.g., arc consistency) does additional work to constrain values and detect inconsistencies

The CSP representation allows analysis of problem structure

Tree-structured CSPs can be solved in linear time

(47)

References

Stuart J. Russell and Peter Norvig.

Artificial Intelligence - A Modern Approach (3. edition). Pearson Education, 2010.

References

Related documents

If you were to put the data in the Active Directory database, in order to get a performance increase like this, you would need to install the application on a Domain Controller.. It

In areas with cold climate, available wind power is approximately 10% higher than other regions due to the increased air density at lower temperatures.... Icing on wind

Differences in the estimates can be attributed to (i) incorrect expected mortality due to inadequate life tables in the relative survival data setting, or (ii) errors in the cause

• Even in those cases where there is already a high level of information the knowl- edge and the required data to perform country-wide assessments are scattered in

The functions provided by the CAISE server, both in terms of supporting collaborative work and performing core software engineering tasks, allow the CSE tool developer to focus on

Developing leadership skills for educators interested in becoming a school leader or administrator, this degree combines the five National Board Certified Teaching (NBCT) courses

(NMR: Nuclear magnetic resonance spectroscopy, HT-SEC: High temperature liquid adsorption chromatography, HT-AF4: High temperature asymmetric flow field flow fractionation,

Proposition 4 When international trade is not intense, the demand of goods at equilibrium and the price of the high quality variant are higher under home bias than in the