• Nu S-Au Găsit Rezultate

contingency problem percepts provide new information about current state solution is a contingent plan or a policy often interleave search, execution Unknown state space

N/A
N/A
Protected

Academic year: 2022

Share "contingency problem percepts provide new information about current state solution is a contingent plan or a policy often interleave search, execution Unknown state space"

Copied!
74
0
0

Text complet

(1)

Problem solving and search

Chapter 3

(2)

Reminders

Assignment 0 due 5pm today Assignment 1 posted, due 2/9

Section 105 will move to 9-10am starting next week

(3)

Outline

♦ Problem-solving agents

♦ Problem types

♦ Problem formulation

♦ Example problems

♦ Basic search algorithms

(4)

Problem-solving agents

Restricted form of general agent:

function Simple-Problem-Solving-Agent(percept) returns an action static: seq, an action sequence, initially empty

state, some description of the current world state goal, a goal, initially null

problem, a problem formulation stateUpdate-State(state, percept) if seq is empty then

goalFormulate-Goal(state)

problemFormulate-Problem(state, goal) seqSearch(problem)

actionRecommendation(seq, state) seqRemainder(seq, state)

return action

(5)

Example: Romania

On holiday in Romania; currently in Arad.

Flight leaves tomorrow from Bucharest Formulate goal:

be in Bucharest Formulate problem:

states: various cities

actions: drive between cities Find solution:

sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest

(6)

Example: Romania

Urziceni

Hirsova Neamt

Oradea

Zerind Arad

Timisoara

Lugoj Mehadia Dobreta

Sibiu Fagaras

Pitesti

Vaslui Iasi

Rimnicu Vilcea

Bucharest 71

75

118

111

70 75

120 151 140

99 80

97

101 211

138

146 85

98 142

92 87

86

(7)

Problem types

Deterministic, fully observable =⇒ single-state problem

Agent knows exactly which state it will be in; solution is a sequence Non-observable =⇒ conformant problem

Agent may have no idea where it is; solution (if any) is a sequence Nondeterministic and/or partially observable =⇒ contingency problem

percepts provide new information about current state solution is a contingent plan or a policy

often interleave search, execution

Unknown state space =⇒ exploration problem (“online”)

(8)

Example: vacuum world

Single-state, start in #5. Solution??

1 2

3 4

5 6

7 8

(9)

Example: vacuum world

Single-state, start in #5. Solution??

[Right, Suck]

Conformant, start in {1, 2, 3,4,5, 6, 7,8}

e.g., Right goes to {2, 4, 6,8}. Solution??

1 2

3 4

5 6

7 8

(10)

Example: vacuum world

Single-state, start in #5. Solution??

[Right, Suck]

Conformant, start in {1, 2, 3,4,5, 6, 7,8}

e.g., Right goes to {2, 4, 6,8}. Solution??

[Right, Suck, Lef t, Suck]

Contingency, start in #5

Murphy’s Law: Suck can dirty a clean carpet Local sensing: dirt, location only.

Solution??

1 2

3 4

5 6

7 8

(11)

Example: vacuum world

Single-state, start in #5. Solution??

[Right, Suck]

Conformant, start in {1, 2, 3,4,5, 6, 7,8}

e.g., Right goes to {2, 4, 6,8}. Solution??

[Right, Suck, Lef t, Suck]

Contingency, start in #5

Murphy’s Law: Suck can dirty a clean carpet Local sensing: dirt, location only.

Solution??

[Right,if dirt then Suck]

1 2

3 4

5 6

7 8

(12)

Single-state problem formulation

A problem is defined by four items:

initial state e.g., “at Arad”

successor function S(x) = set of action–state pairs

e.g., S(Arad) = {hArad → Zerind, Zerindi, . . .}

goal test, can be

explicit, e.g., x = “at Bucharest”

implicit, e.g., N oDirt(x) path cost (additive)

e.g., sum of distances, number of actions executed, etc.

c(x, a, y) is the step cost, assumed to be ≥ 0 A solution is a sequence of actions

(13)

Selecting a state space

Real world is absurdly complex

⇒ state space must be abstracted for problem solving (Abstract) state = set of real states

(Abstract) action = complex combination of real actions e.g., “Arad → Zerind” represents a complex set

of possible routes, detours, rest stops, etc.

For guaranteed realizability, any real state “in Arad”

must get to some real state “in Zerind”

(Abstract) solution =

set of real paths that are solutions in the real world

Each abstract action should be “easier” than the original problem!

(14)

Example: vacuum world state space graph

R

L

S S

S S

R

L

R

L

R

L S

S S

S L

L

L

L R

R R

R

states??

actions??

goal test??

path cost??

(15)

Example: vacuum world state space graph

R

L

S S

S S

R

L

R

L

R

L S

S S

S L

L

L

L R

R R

R

states??: integer dirt and robot locations (ignore dirt amounts etc.) actions??

goal test??

path cost??

(16)

Example: vacuum world state space graph

R

L

S S

S S

R

L

R

L

R

L S

S S

S L

L

L

L R

R R

R

states??: integer dirt and robot locations (ignore dirt amounts etc.) actions??: Lef t, Right, Suck, N oOp

goal test??

path cost??

(17)

Example: vacuum world state space graph

R

L

S S

S S

R

L

R

L

R

L S

S S

S L

L

L

L R

R R

R

states??: integer dirt and robot locations (ignore dirt amounts etc.) actions??: Lef t, Right, Suck, N oOp

goal test??: no dirt path cost??

(18)

Example: vacuum world state space graph

R

L

S S

S S

R

L

R

L

R

L S

S S

S L

L

L

L R

R R

R

states??: integer dirt and robot locations (ignore dirt amounts etc.) actions??: Lef t, Right, Suck, N oOp

goal test??: no dirt

path cost??: 1 per action (0 for N oOp)

(19)

Example: The 8-puzzle

2

Start State Goal State

51 3

4 6

7 8

5 1

2

3

4 6 7

8 5

states??

actions??

goal test??

path cost??

(20)

Example: The 8-puzzle

2

Start State Goal State

51 3

4 6

7 8

5 1

2

3

4 6 7

8 5

states??: integer locations of tiles (ignore intermediate positions) actions??

goal test??

path cost??

(21)

Example: The 8-puzzle

2

Start State Goal State

51 3

4 6

7 8

5 1

2

3

4 6 7

8 5

states??: integer locations of tiles (ignore intermediate positions) actions??: move blank left, right, up, down (ignore unjamming etc.) goal test??

path cost??

(22)

Example: The 8-puzzle

2

Start State Goal State

51 3

4 6

7 8

5 1

2

3

4 6 7

8 5

states??: integer locations of tiles (ignore intermediate positions) actions??: move blank left, right, up, down (ignore unjamming etc.) goal test??: = goal state (given)

path cost??

(23)

Example: The 8-puzzle

2

Start State Goal State

51 3

4 6

7 8

5 1

2

3

4 6 7

8 5

states??: integer locations of tiles (ignore intermediate positions) actions??: move blank left, right, up, down (ignore unjamming etc.) goal test??: = goal state (given)

path cost??: 1 per move

[Note: optimal solution of n-Puzzle family is NP-hard]

(24)

Example: robotic assembly

R

R R P

R R

states??: real-valued coordinates of robot joint angles parts of the object to be assembled

actions??: continuous motions of robot joints

goal test??: complete assembly with no robot included!

path cost??: time to execute

(25)

Tree search algorithms

Basic idea:

offline, simulated exploration of state space

by generating successors of already-explored states (a.k.a. expanding states)

function Tree-Search(problem, strategy) returns a solution, or failure initialize the search tree using the initial state of problem

loop do

if there are no candidates for expansion then return failure choose a leaf node for expansion according to strategy

if the node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree

end

(26)

Tree search example

Rimnicu Vilcea Lugoj

Zerind Sibiu

Arad Fagaras Oradea

Timisoara

Arad

Arad Oradea

Arad

(27)

Tree search example

Rimnicu Vilcea Lugoj

Arad Fagaras Oradea Arad Arad Oradea

Zerind Arad

Sibiu Timisoara

(28)

Tree search example

Lugoj Arad

Arad Oradea

Rimnicu Vilcea

Zerind Arad

Sibiu

Arad Fagaras Oradea

Timisoara

(29)

Implementation: states vs. nodes

A state is a (representation of) a physical configuration

A node is a data structure constituting part of a search tree includes parent, children, depth, path cost g(x)

States do not have parents, children, depth, or path cost!

1

2 3

4 5

6 7

1 8

2 3

4 5

6 7

8

State Node depth = 6

g = 6

state

parent, action

The Expand function creates new nodes, filling in the various fields and using the SuccessorFn of the problem to create the corresponding states.

(30)

Implementation: general tree search

function Tree-Search(problem, fringe) returns a solution, or failure fringeInsert(Make-Node(Initial-State[problem]),fringe) loop do

if fringe is empty then return failure nodeRemove-Front(fringe)

if Goal-Test(problem,State(node)) then return node fringeInsertAll(Expand(node,problem),fringe)

function Expand(node, problem) returns a set of nodes successorsthe empty set

for each action, result in Successor-Fn(problem,State[node]) do sa new Node

Parent-Node[s]node; Action[s]action; State[s]result Path-Cost[s]Path-Cost[node] + Step-Cost(node,action,s) Depth[s]Depth[node] + 1

(31)

Search strategies

A strategy is defined by picking the order of node expansion Strategies are evaluated along the following dimensions:

completeness—does it always find a solution if one exists?

time complexity—number of nodes generated/expanded space complexity—maximum number of nodes in memory optimality—does it always find a least-cost solution?

Time and space complexity are measured in terms of b—maximum branching factor of the search tree d—depth of the least-cost solution

m—maximum depth of the state space (may be ∞)

(32)

Uninformed search strategies

Uninformed strategies use only the information available in the problem definition

Breadth-first search Uniform-cost search Depth-first search Depth-limited search

Iterative deepening search

(33)

Breadth-first search

Expand shallowest unexpanded node Implementation:

fringe is a FIFO queue, i.e., new successors go at end

A

B C

D E F G

(34)

Breadth-first search

Expand shallowest unexpanded node Implementation:

fringe is a FIFO queue, i.e., new successors go at end

A

B C

D E F G

(35)

Breadth-first search

Expand shallowest unexpanded node Implementation:

fringe is a FIFO queue, i.e., new successors go at end

A

B C

D E F G

(36)

Breadth-first search

Expand shallowest unexpanded node Implementation:

fringe is a FIFO queue, i.e., new successors go at end

A

B C

D E F G

(37)

Properties of breadth-first search

Complete??

(38)

Properties of breadth-first search

Complete?? Yes (if b is finite) Time??

(39)

Properties of breadth-first search

Complete?? Yes (if b is finite)

Time?? 1 + b + b2 + b3 + . . . + bd + b(bd − 1) = O(bd+1), i.e., exp. in d Space??

(40)

Properties of breadth-first search

Complete?? Yes (if b is finite)

Time?? 1 + b + b2 + b3 + . . . + bd + b(bd − 1) = O(bd+1), i.e., exp. in d Space?? O(bd+1) (keeps every node in memory)

Optimal??

(41)

Properties of breadth-first search

Complete?? Yes (if b is finite)

Time?? 1 + b + b2 + b3 + . . . + bd + b(bd − 1) = O(bd+1), i.e., exp. in d

Space?? O(bd+1) (keeps every node in memory)

Optimal?? Yes (if cost = 1 per step); not optimal in general

Space is the big problem; can easily generate nodes at 100MB/sec so 24hrs = 8640GB.

(42)

Uniform-cost search

Expand least-cost unexpanded node Implementation:

fringe = queue ordered by path cost, lowest first Equivalent to breadth-first if step costs all equal

Complete?? Yes, if step cost ≥

Time?? # of nodes with g ≤ cost of optimal solution, O(bdC/e) where C is the cost of the optimal solution

Space?? # of nodes with g ≤ cost of optimal solution, O(bdC/e) Optimal?? Yes—nodes expanded in increasing order of g(n)

(43)

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

(44)

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

(45)

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

(46)

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

(47)

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

(48)

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

(49)

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

(50)

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

(51)

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

(52)

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

(53)

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

(54)

Depth-first search

Expand deepest unexpanded node Implementation:

fringe = LIFO queue, i.e., put successors at front

A

B C

D E F G

H I J K L M N O

(55)

Properties of depth-first search

Complete??

(56)

Properties of depth-first search

Complete?? No: fails in infinite-depth spaces, spaces with loops Modify to avoid repeated states along path

⇒ complete in finite spaces Time??

(57)

Properties of depth-first search

Complete?? No: fails in infinite-depth spaces, spaces with loops Modify to avoid repeated states along path

⇒ complete in finite spaces

Time?? O(bm): terrible if m is much larger than d

but if solutions are dense, may be much faster than breadth-first Space??

(58)

Properties of depth-first search

Complete?? No: fails in infinite-depth spaces, spaces with loops Modify to avoid repeated states along path

⇒ complete in finite spaces

Time?? O(bm): terrible if m is much larger than d

but if solutions are dense, may be much faster than breadth-first Space?? O(bm), i.e., linear space!

Optimal??

(59)

Properties of depth-first search

Complete?? No: fails in infinite-depth spaces, spaces with loops Modify to avoid repeated states along path

⇒ complete in finite spaces

Time?? O(bm): terrible if m is much larger than d

but if solutions are dense, may be much faster than breadth-first Space?? O(bm), i.e., linear space!

Optimal?? No

(60)

Depth-limited search

= depth-first search with depth limit l, i.e., nodes at depth l have no successors Recursive implementation:

function Depth-Limited-Search(problem,limit) returns soln/fail/cutoff Recursive-DLS(Make-Node(Initial-State[problem]),problem,limit)

function Recursive-DLS(node,problem,limit) returns soln/fail/cutoff cutoff-occurred?false

if Goal-Test(problem,State[node]) then return node else if Depth[node] = limit then return cutoff

else for each successor in Expand(node,problem) do resultRecursive-DLS(successor,problem,limit) if result = cutoff then cutoff-occurred?true

else if result 6= failure then return result

(61)

Iterative deepening search

function Iterative-Deepening-Search(problem) returns a solution inputs: problem, a problem

for depth 0 to do

resultDepth-Limited-Search(problem, depth) if result 6= cutoff then return result

end

(62)

Iterative deepening search

l = 0

Limit = 0 A A

(63)

Iterative deepening search

l = 1

Limit = 1 A

B C

A

B C

A

B C

A

B C

(64)

Iterative deepening search

l = 2

Limit = 2 A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

A

B C

D E F G

(65)

Iterative deepening search

l = 3

Limit = 3

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

A

B C

D E F G

H I J K L M N O

(66)

Properties of iterative deepening search

Complete??

(67)

Properties of iterative deepening search

Complete?? Yes Time??

(68)

Properties of iterative deepening search

Complete?? Yes

Time?? (d + 1)b0 + db1 + (d − 1)b2 + . . . + bd = O(bd) Space??

(69)

Properties of iterative deepening search

Complete?? Yes

Time?? (d + 1)b0 + db1 + (d − 1)b2 + . . . + bd = O(bd) Space?? O(bd)

Optimal??

(70)

Properties of iterative deepening search

Complete?? Yes

Time?? (d + 1)b0 + db1 + (d − 1)b2 + . . . + bd = O(bd) Space?? O(bd)

Optimal?? Yes, if step cost = 1

Can be modified to explore uniform-cost tree

Numerical comparison for b = 10 and d = 5, solution at far right leaf:

N(IDS) = 50 + 400 + 3,000 + 20, 000 + 100,000 = 123, 450

N(BFS) = 10 + 100 + 1,000 + 10, 000 + 100, 000 + 999,990 = 1,111,100

(71)

Summary of algorithms

Criterion Breadth- Uniform- Depth- Depth- Iterative

First Cost First Limited Deepening

Complete? Yes Yes No Yes, if l ≥ d Yes

Time bd+1 bdC/e bm bl bd

Space bd+1 bdC/e bm bl bd

Optimal? Yes Yes No No Yes

(72)

Repeated states

Failure to detect repeated states can turn a linear problem into an exponential one!

A

B

C

D

A

B B

C C

C C

(73)

Graph search

function Graph-Search(problem, fringe) returns a solution, or failure closedan empty set

fringeInsert(Make-Node(Initial-State[problem]),fringe) loop do

if fringe is empty then return failure nodeRemove-Front(fringe)

if Goal-Test(problem,State[node]) then return node if State[node] is not in closed then

add State[node] to closed

fringeInsertAll(Expand(node,problem),fringe) end

(74)

Summary

Problem formulation usually requires abstracting away real-world details to define a state space that can feasibly be explored

Variety of uninformed search strategies

Iterative deepening search uses only linear space

and not much more time than other uninformed algorithms

Graph search can be exponentially more efficient than tree search

Referințe

DOCUMENTE SIMILARE

below this new branch add a leaf node with label = the most common value of Target attribute in

There is a clever linear-time algorithm, however, that tests all the vertices of a connected graph using a single depth-first search. What might the depth-first search tree tell us

research and modeling efforts in some specific fields of AI (ontologies and knowledge sharing, knowledge processing, intelligent databases, knowledge discovery, data

We then go on to examine a number of prototype techniques proposed for engineering agent systems, including methodologies for agent-oriented analysis and design, formal

Key Words: American Christians, Christian Right, Christian Zionism, US-Israel Relations, Conservative Christians Theology, State of Israel, Jews, Millennial beliefs,

need to feed values from T+1,T+2… (use predicted values for next prediction) For prediction for 1 hour in the future we can train the model using input at T and expected output

I use a ConcurrentHashMap to store for every thread a HashMap of all the methods it calls and the statistics associated with

Understand the difference between the general problem and an instance of it Decide what a state is and appreciate the dimension of the search space2. Find a proper representation