Docsity

Problem Solving: Search Algorithms and Strategies, Assignments of Computer Science

Toggle sidebar
bg1
1
Problem Solving
Problem Solving
Russell and Norvig: Chapter 3
CSMSC 421 – Fall 2003
Announcements and Outline
Announcements:
Lise’s office hours: Thu 1:30-3:00 and by
appt
HW1 due next Tue
Outline:
Problem Solving Agents
Problem Formulation
Basic Search
Problem
Problem-
-Solving Agent
Solving Agent
environment
agent
?
sensors
actuators
Problem
Problem-
-Solving Agent
Solving Agent
environment
agent
?
sensors
actuators
• Formulate Goal
• Formulate Problem
•States
•Actions
• Find Solution
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download Problem Solving: Search Algorithms and Strategies and more Assignments Computer Science in PDF only on Docsity!

Problem SolvingProblem Solving

Russell

and Norvig: Chapter 3

CSMSC 421 – Fall 2003

Announcements and Outline^ Announcements:^ „^ Lise’s office hours: Thu 1:30-3:00 and byappt^ „^ HW1 due next Tue^ Outline:^ „^ Problem Solving Agents^ „^ Problem Formulation^ „^ Basic Search

Problem-^ Problem

-Solving AgentSolving Agent

environment

sensors? agent

actuators

ProblemProblem-

-Solving AgentSolving Agent

environment

sensors? agent

actuators

  • Formulate Goal• Formulate Problem•States•Actions• Find Solution

Example: Route findingExample: Route finding

Holiday Planning^ On holiday in Romania; Currently in Arad.Flight leaves tomorrow from Bucharest.^ Formulate Goal:Be in Bucharest^ Formulate Problem:States: various citiesActions: drive between cities^ Find solution:Sequence of cities: Arad, Sibiu, Fagaras, Bucharest

Problem Formulation

Urziceni Giurgiu

Hirsova Eforie Neamt

OradeaZerind Arad Timisoara

LugojMehadiaDobreta Sibiu^ Fagaras Pitesti Craiova

Iasi Vaslui

Rimnicu Vilcea

Bucharest

71 75 118 11170 75 151 14099 80 97 120

(^211101138) 146

(^8590) 87 92 142 98 86^ Goal

Start

States Actions

Solution

Vacuum World

R L S^

S S^

S R L

R L R L S

S S

S

L L

L

L^

R R R R

Search ProblemSearch Problem^ State space^ Initial state^ Successor function^ Goal test^ Path cost:^ „^ [path

Æ^ positive number]

„^ usually, path cost = sum of step costs „^ e.g., number of moves of the empty tile

Example: 8-^ Example: 8

-puzzlepuzzle 28 3 47 15 6

Initial state

Goal state

Example: 8Example: 8-

-puzzlepuzzle 28 3 47 15 6

Example: 8Example: 8-

-puzzlepuzzle Size of the state space = 9!/2 = 181,44015-puzzle

Æ^ .65^ x

24-puzzle

Æ^ .5^ x^

10 millions states/sec

0.18 sec 6 days 12 billion years

Your Turn: Search ProblemYour Turn: Search Problem^ State space^ Initial state^ Successor function^ Goal test^ Path cost

Search of State Space^ Search of State Space

Search of State Space^ Search of State Space

Search State SpaceSearch State Space

Example: 8-Example: 8

-queensqueens

Place 8 queens in a chessboard so that no two queensare in the same row, column, or diagonal.A solution

Not a solution

Example: 8-^ Example: 8

-queensqueens^ Formulation #1:•States: any arrangement of0 to 8 queens on the board• Initial state: 0 queens on theboard• Successor function: add aqueen in any square• Goal test: 8 queens on theboard, none attacked^ Æ^64

8 states with 8 queens

Example: 8Example: 8-

-queensqueens^ Formulation #2:•States: any arrangement ofk = 0 to 8 queens in the

k

leftmost columns with noneattacked• Initial state: 0 queens on theboard• Successor function: add aqueen to any square in theleftmost empty column suchthat it is not attackedby any other queen• Goal test: 8 queens on theboard

Æ^ 2,067 states

Example: Robot navigationExample: Robot navigation^ What is the state space

Example: Robot navigationExample: Robot navigation^ Cost of one horizontal/vertical step = 1Cost of one diagonal step =

√^2

Example: Robot navigation^ Example: Robot navigation

Example: Assembly PlanningExample: Assembly Planning

Initial state

Goal state

Complex function:it must find if a collision-freemerging motion existsSuccessor function:• Merge two subassemblies

Example: Assembly PlanningExample: Assembly Planning

Basic Search ConceptsBasic Search Concepts^ Search tree^ Search node^ Node expansion^ Search strategy: At each stage itdetermines which node to expand

Search Nodes^ Search Nodes

≠^ States ≠ States

28 3 47 15 6 278 3 4 15 6 28 3 47 15 6

8 3 15 6

48 37 15 6 2 4 7

2

28 3 47 15 6

The search tree may be infinite evenThe search tree may be infinite evenwhen the state space is finitewhen the state space is finite

FringeFringe^ Set of search nodes that have not beenexpanded yet^ Implemented as a queue FRINGE^ „^ INSERT(node,FRINGE)^ „^ REMOVE(FRINGE)^ The ordering of the nodes in FRINGEdefines the search strategy

Search AlgorithmSearch Algorithm^ 1.^ If GOAL?(initial-state) then return initial-state2.^ INSERT(initial-node,FRINGE)3.^ Repeat:

If FRINGE is empty then return failure n^ Å^ REMOVE(FRINGE) s^ Å^ STATE(n) For every state s’ in SUCCESSORS(s) ƒ^ Create a node n’ ƒ^ If GOAL?(s’) then return path or goal state ƒ^ INSERT(n’,FRINGE)

Search Strategies^ A strategy is defined by picking the order of nodeexpansion^ Strategies are evaluated along the followingdimensions:^ „^ 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 brancing factor of the search tree^ „^ d – depth of the least-cost solution^ „^ m – maximum depth of the state space (may be

∞)

Important Remark^ Important Remark^ Some problems formulated as searchproblems are NP-hard problems.

We

cannot expect to solve such a problemin less than exponential time in theworst-case^ But we can nevertheless strive to solveas many instances of the problem aspossible

Blind vs. Heuristic StrategiesBlind vs. Heuristic Strategies^ Blind (or uninformed) strategies do notexploit any of the information containedin a state^ Heuristic (or informed) strategiesexploits such information to assess thatone node is “more promising” thananother

Blind Search…^ …[the ant] knew that a certain arrangement had to be made,but it could not figure out how to make it.

It was like a man

with a tea-cup in one hand and a sandwich in the other, whowants to light a cigarette with a match.

But, where the man

would invent the idea of putting down the cup and sandwich—before picking up the cigarette and the match—this ant wouldhave put down the sandwich and picked up the match, then itwould have been down with the match and up with thecigarette, then down with the cigarette and up with thesandwich, then down with the cup and up with the cigarette,until finally it had put down the sandwich and picked up thematch.^ It was inclined to rely on a series of accidents toachieve its object.

It was patient and did not think…

Wart

watched the arrangements with a surprise which turned intovexation and then into dislike.

He felt like asking why it did not

think things out in advance…

T.H. White,

The Once and Future King

Breadth-Breadth

-First StrategyFirst Strategy

New nodes are inserted at the end of FRINGE

FRINGE = (4, 5, 6, 7)

Evaluation^ Evaluation^ b: branching factor^ d: depth of shallowest goal node^ Complete^ Optimal if step cost is 1^ Number of nodes generated:1 + b + b

2 + … + b

d^ + b(b

d-1) = O(b

d+1^ )

Time and space complexity is O(b

d+1 )

Time and Memory RequirementsTime and Memory Requirements

10,000 Tb

3.2 years

100 Tbytes

11.6 days

1 Tbyte

2.8 hours

10 Gbytes

100 sec

100 Mb

1 sec

1 Mbyte

1 msec

11 Kbytes

.01 msec

Memory

Time

#Nodes

d Assumptions: b = 10; 1,000,000 nodes/sec; 100bytes/node

Time and Memory RequirementsTime and Memory Requirements

10,000 Tb

3.2 years

100 Tbytes

11.6 days

1 Tbyte

2.8 hours

10 Gbytes

100 sec

100 Mb

1 sec

1 Mbyte

1 msec

11 Kbytes

.01 msec

Memory

Time

#Nodes

d Assumptions: b = 10; 1,000,000 nodes/sec; 100bytes/node

Bidirectional StrategyBidirectional Strategy^ 2 fringe queues: FRINGE1 and FRINGE2Time and space complexity = O(b

d/2^ ) << O(b

d^ )

Depth-^ Depth

-First StrategyFirst Strategy

New nodes are inserted at the front of FRINGE

FRINGE = (1)^5

DepthDepth-

-First StrategyFirst Strategy

New nodes are inserted at the front of FRINGE

FRINGE = (2, 3)^5

DepthDepth-

-First StrategyFirst Strategy

New nodes are inserted at the front of FRINGE

FRINGE = (4, 5, 3)^5

Depth-Depth

-First StrategyFirst Strategy

New nodes are inserted at the front of FRINGE

Depth-^ Depth

-First StrategyFirst Strategy

New nodes are inserted at the front of FRINGE

DepthDepth-

-First StrategyFirst Strategy

New nodes are inserted at the front of FRINGE

DepthDepth-

-First StrategyFirst Strategy

New nodes are inserted at the front of FRINGE

EvaluationEvaluation^ b: branching factor^ d: depth of shallowest goal node^ m: maximal depth of a leaf node^ Complete only for finite search tree^ Not optimal^ Number of nodes generated:1 + b + b

2 + … + b

m^ = O(b

m^ )

Time complexity is O(b

m^ )

Space complexity is O(bm)

Depth-^ Depth

-Limited StrategyLimited Strategy Depth-first with depth cutoff k(maximal depth below which nodes arenot expanded) Three possible outcomes: „ Solution „ Failure (no solution) „ Cutoff (no solution within cutoff)

Iterative Deepening StrategyIterative Deepening Strategy^ Repeat for k = 0, 1, 2, …:Perform depth-first with depth cutoff k^ Complete^ Optimal if step cost =1^ Time complexity is:(d+1)(1) + db + (d-1)b

2 + … + (1) b

d^ =^ O(b

d^ )

Space complexity is: O(bd)

Comparison of StrategiesComparison of Strategies^ Breadth-first is complete and optimal,but has high space complexity^ Depth-first is space efficient, but neithercomplete nor optimal^ Iterative deepening is asymptoticallyoptimal

Uniform-Uniform

-Cost StrategyCost Strategy

  • Each step has some cost

≥ ε^ > 0^.

  • The cost of the path to each fringe node N is

g(N) =^ Σ

costs of all steps.

  • The goal is to generate a solution path of minimal cost.• The queue FRINGE is sorted in increasing cost.

S^0

A^1

B^5

C^15

S^ A GB C 11055 515

G^11

G^10

Modified Search Algorithm^ Modified Search Algorithm^ 1.^ INSERT(initial-node,FRINGE)2.^ Repeat:

If FRINGE is empty then return failure n^ Å^ REMOVE(FRINGE) s^ Å^ STATE(n) If GOAL?(s) then return path or goal state For every state s’ in SUCCESSORS(s) ƒ^ Create a node n’ ƒ^ INSERT(n’,FRINGE)

ExercisesExercises^ Adapt uniform-cost search to avoidrepeated states while still finding theoptimal solution^ Uniform-cost looks like breadth-first (itis exactly breadth first if the step cost isconstant). Adapt iterative deepening ina similar way to handle variable stepcosts

Summary^ Search tree

≠^ state space Search strategies: breadth-first, depth-first, and variants Evaluation of strategies: completeness,optimality, time and space complexity Avoiding repeated states Optimal search with variable step costs