csc 480: artificial...

110
© 2000-2012 Franz Kurfess Agents Logistics AI Nugget presentations Section 1: Thomas Soria, Gagandeep Singh Kohli, Alex Ledwith Section 3: Martin Silverio Project Team Wikis, pages project description refined: Features, Requirements, Schedule PolyLearn: Does everybody have access? groups set up for project teams; some team membership info incomplete Lab and Homework Assignments Lab 2 due tonight (23:59); demos during the lab time Tue, Thu Lab 3 available: breadth-first, depth-first search Quizzes Quiz 2 - Available Tue, Sep. 24, all day (0:00 - 23:59) Make-up question details TBA soon; most likely submission formats: Web form, tab-delimited, NL-delimited 2 submitted questions are the equivalent of one quiz questions (10 points) Monday, October 8, 12

Upload: others

Post on 13-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Agents

Logisticsu AI Nugget presentations

u Section 1: Thomas Soria, Gagandeep Singh Kohli, Alex Ledwithu Section 3: Martin Silverio

u Project Team Wikis, pagesu project description refined:

v Features, Requirements, Schedule

u PolyLearn: Does everybody have access?u groups set up for project teams; some team membership info incomplete

u Lab and Homework Assignmentsu Lab 2 due tonight (23:59); demos during the lab time Tue, Thuu Lab 3 available: breadth-first, depth-first search

u Quizzesu Quiz 2 - Available Tue, Sep. 24, all day (0:00 - 23:59)u Make-up question details TBA soon; most likely

v submission formats: Web form, tab-delimited, NL-delimitedv 2 submitted questions are the equivalent of one quiz questions (10 points)

Monday, October 8, 12

Page 2: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Chapter OverviewSearch

u Motivationu Objectivesu Search as Problem-Solving

u problem formulationu problem types

u Uninformed Searchu breadth-firstu depth-firstu uniform-cost searchu depth-limited searchu iterative deepeningu bi-directional search

u Informed Searchu best-first searchu search with heuristicsu memory-bounded searchu iterative improvement search

u Non-Traditional Searchu local search and optimizationu constraint satisfactionu search in continuous spacesu partially observable worlds

u Important Concepts and Terms

u Chapter Summary

Monday, October 8, 12

Page 3: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Examplesu getting from home to Cal Poly

u start: home on Clearview Laneu goal: Cal Poly CSC Dept.u operators: move one block, turn

u loading a moving trucku start: apartment full of boxes and furnitureu goal: empty apartment, all boxes and furniture in the trucku operators: select item, carry item from apartment to truck, load item

u getting settledu start: items randomly distributed over the placeu goal: satisfactory arrangement of itemsu operators: select item, move item

Monday, October 8, 12

Page 4: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Motivationusearch strategies are important methods for many

approaches to problem-solvinguthe use of search requires an abstract formulation of

the problem and the available steps to construct solutions

usearch algorithms are the basis for many optimization and planning methods

Monday, October 8, 12

Page 5: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Objectivesu formulate appropriate problems as search tasks

u states, initial state, goal state, successor functions (operators), costu know the fundamental search strategies and algorithms

u uninformed searchv breadth-first, depth-first, uniform-cost, iterative deepening, bi-directional

u informed searchv best-first (greedy, A*), heuristics, memory-bounded, iterative improvement

u evaluate the suitability of a search strategy for a problemu completeness, time & space complexity, optimality

Monday, October 8, 12

Page 6: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Problem-Solving Agentsuagents whose task it is to solve a particular problem

u goal formulationv what is the goal statev what are important characteristics of the goal statev how does the agent know that it has reached the goalv are there several possible goal states

v are they equal or are some more preferable

u problem formulationv what are the possible states of the world relevant for solving the

problemv what information is accessible to the agentv how can the agent progress from state to state

Monday, October 8, 12

Page 7: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Problem Formulationuformal specification for the task of the agent

u goal specificationu states of the worldu actions of the agent

uidentify the type of the problemu what knowledge does the agent have about the state of

the world and the consequences of its own actionsu does the execution of the task require up-to-date

informationv sensing is necessary during the execution

Monday, October 8, 12

Page 8: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Well-Defined Problemsuproblems with a readily available formal specification

u initial statev starting point from which the agent sets out

u actions (operators, successor functions)v describe the set of possible actions

u state spacev set of all states reachable from the initial state by any sequence of

actionsu path

v sequence of actions leading from one state in the state space to another

u goal testv determines if a given state is the goal state

Monday, October 8, 12

Page 9: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Well-Defined Problems (cont.)u solution

v path from the initial state to a goal stateu search cost

v time and memory required to calculate a solutionu path cost

v determines the expenses of the agent for executing the actions in a path

v sum of the costs of the individual actions in a pathu total cost

v sum of search cost and path costv overall cost for finding a solution

Monday, October 8, 12

Page 10: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Selecting States and Actionsustates describe distinguishable stages during the

problem-solving processu dependent on the task and domain

uactions move the agent from one state to another one by applying an operator to a stateu dependent on states, capabilities of the agent, and

properties of the environmentuchoice of suitable states and operators

u can make the difference between a problem that can or cannot be solved (in principle, or in practice)

Monday, October 8, 12

Page 11: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Example: From Home to Cal Polyustates

u locations: v obvious: buildings that contain your home, Cal Poly CSC dept.v more difficult: intermediate states

v blocks, street corners, sidewalks, entryways, ...v continuous transitions

u agent-centric statesv moving, turning, resting, ...

uoperatorsu depend on the choice of statesu e.g. move_one_block

uabstraction is necessary to omit irrelevant detailsu valid: can be expanded into a detailed versionu useful: easier to solve than in the detailed version

Monday, October 8, 12

Page 12: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Example Problemsu toy problems

u vacuum worldu 8-puzzleu 8-queensu cryptarithmeticu vacuum agentu missionaries and cannibals

u real-world problemsu route findingu touring problems

v traveling salespersonu VLSI layoutu robot navigationu assembly sequencingu Web search

Monday, October 8, 12

Page 13: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Example: Vacuum World

Monday, October 8, 12

Page 14: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Example: vacuum worldu Single-state, start in #5.

Solution?

http://aima.eecs.berkeley.edu/slides-ppt/Monday, October 8, 12

Page 15: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Example: vacuum world

http://aima.eecs.berkeley.edu/slides-ppt/Monday, October 8, 12

Page 16: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Example: vacuum worldu Sensorless, start in

{1,2,3,4,5,6,7,8} e.g., Right goes to {2,4,6,8} Solution? [Right,Suck,Left,Suck]

u Contingency u Nondeterministic: Suck may

dirty a clean carpetu Partially observable: location, dirt at current location.u Percept: [L, Clean], i.e., start in #5 or #7

Solution?

http://aima.eecs.berkeley.edu/slides-ppt/Monday, October 8, 12

Page 17: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Example: vacuum worldu Sensorless, start in

{1,2,3,4,5,6,7,8} e.g., Right goes to {2,4,6,8} Solution? [Right,Suck,Left,Suck]

u Contingency u Nondeterministic: Suck may

dirty a clean carpetu Partially observable: location, dirt at current location.u Percept: [L, Clean], i.e., start in #5 or #7

Solution? [Right, if dirt then Suck]

http://aima.eecs.berkeley.edu/slides-ppt/Monday, October 8, 12

Page 18: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Vacuum world state space graph

ustates?uactions?ugoal test?upath cost?

http://aima.eecs.berkeley.edu/slides-ppt/Monday, October 8, 12

Page 19: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Vacuum world state space graph

u states? integer dirt and robot location u actions? Left, Right, Sucku goal test? no dirt at all locationsu path cost? 1 per action

http://aima.eecs.berkeley.edu/slides-ppt/Monday, October 8, 12

Page 20: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Simple Vacuum Worldu states

u two locationsu dirty, clean

u initial stateu any legitimate state

u successor function (operators)u left, right, suck

u goal testu all squares clean

u path costu one unit per action

Properties: discrete locations, discrete dirt (binary), deterministic

Monday, October 8, 12

Page 21: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

More Complex Vacuum Agentu states

u configuration of the roomv dimensions, obstacles, dirtiness

u initial stateu locations of agent, dirt

u successor function (operators)u move, turn, suck

u goal testu all squares clean

u path costu one unit per action

Properties: discrete locations, discrete dirt, deterministic, d * 2n states for dirt degree d,n locations

Monday, October 8, 12

Page 22: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Example: The 8-puzzle

u states?u actions?u goal test?u path cost?

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

http://aima.eecs.berkeley.edu/slides-ppt/Monday, October 8, 12

Page 23: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

8-Puzzleu states

u location of tiles (including blank tile)u initial state

u any legitimate configurationu successor function (operators)

u move tileu alternatively: move blank

u goal testu any legitimate configuration of tiles

u path costu one unit per move

Properties: abstraction leads to discrete configurations, discrete moves, deterministic 9!/2 = 181,440 reachable states

Monday, October 8, 12

Page 24: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Example: n-queensuPut n queens on an n × n board with no two queens

on the same row, column, or diagonal

Monday, October 8, 12

Page 25: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

8-Queensu incremental formulation

u statesv arrangement of up to 8 queens on

the boardu initial state

v empty boardu successor function (operators)

v add a queen to any squareu goal test

v all queens on boardv no queen attacked

u path costv irrelevant (all solutions equally

valid)

u Properties: 3*1014 possible sequences; can be reduced to 2,057

u complete-state formulationu states

v arrangement of 8 queens on the board

u initial statev all 8 queens on board

u successor function (operators)v move a queen to a different

squareu goal test

v no queen attackedu path cost

v irrelevant (all solutions equally valid)

u Properties: good strategies can reduce the number of possible sequences considerably

Monday, October 8, 12

Page 26: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

8-Queens Refinedusimple solutions may lead to very high search costs

u 64 fields, 8 queens ==> 648 possible sequencesumore refined solutions trim the search space, but

may introduce other constraintsu place queens on “unattacked” places

v much more efficientv may not lead to a solutions depending on the initial moves

u move an attacked queen to another square in the same column, if possible to an “unattacked” squarev much more efficient

Monday, October 8, 12

Page 27: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Crypt-arithmetic

u statesu puzzle with letters and digits

u initial stateu only letters present

u successor function (operators)u replace all occurrences of a letter by a digit not used yet

u goal testu only digits in the puzzleu calculation is correct

u path costu all solutions are equally valid

Monday, October 8, 12

Page 28: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Missionaries and Cannibalsu states

v number of missionaries, cannibals, and boats on the banks of a riverv illegal states

v missionaries are outnumbered by cannibals on either banku initial states

v all missionaries, cannibals, and boats are on one banku successor function (operators)

v transport a set of up to two participants to the other bankv {1 missionary} | { 1cannibal} | {2 missionaries} | {2 cannibals} |

{1 missionary and 1 cannibal}u goal test

v nobody left on the initial river banku path cost

v number of crossings

also known as “goats and cabbage”, “wolves and sheep”, etc

Monday, October 8, 12

Page 29: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Route Findingu states

u locationsu initial state

u starting pointu successor function (operators)

u move from one location to anotheru goal test

u arrive at a certain locationu path cost

u may be quite complexv money, time, travel comfort, scenery, ...

Monday, October 8, 12

Page 30: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Traveling Salespersonu states

u locations / cities u illegal states

v each city may be visited only oncev visited cities must be kept as state information

u initial stateu starting pointu no cities visited

u successor function (operators)u move from one location to another one

u goal testu all locations visitedu agent at the initial location

u path costu distance between locations

Monday, October 8, 12

Page 31: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

VLSI Layoutu states

u positions of components, wires on a chipu initial state

u incremental: no components placedu complete-state: all components placed (e.g. randomly, manually)

u successor function (operators)u incremental: place components, route wireu complete-state: move component, move wire

u goal testu all components placedu components connected as specified

u path costu may be complex

v distance, capacity, number of connections per component

Monday, October 8, 12

Page 32: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Robot Navigationu states

u locationsu position of actuators

u initial stateu start position (dependent on the task)

u successor function (operators)u movement, actions of actuators

u goal testu task-dependent

u path costu may be very complex

v distance, energy consumption

Monday, October 8, 12

Page 33: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Assembly Sequencingustates

u location of componentsuinitial state

u no components assembledusuccessor function (operators)

u place componentugoal test

u system fully assembled upath cost

u number of moves

Monday, October 8, 12

Page 34: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Example: robotic assembly

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

uactions?: continuous motions of robot joints

ugoal test?: complete assembly

upath cost?: time to executehttp://aima.eecs.berkeley.edu/slides-ppt/

Monday, October 8, 12

Page 35: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Searching for Solutionsu traversal of the search space

u from the initial state to a goal stateu legal sequence of actions as defined by successor function (operators)

u general procedureu check for goal stateu expand the current state

v determine the set of reachable statesv return “failure” if the set is empty

u select one from the set of reachable statesu move to the selected state

u a search tree is generatedu nodes are added as more states are visited

Monday, October 8, 12

Page 36: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Search Terminologyu search tree

u generated as the search space is traversedv the search space itself is not necessarily a tree, frequently it is a graphv the tree specifies possible paths through the search space

u expansion of nodesv as states are explored, the corresponding nodes are expanded by applying

the successor functionv this generates a new set of (child) nodes

v the fringe (frontier) is the set of nodes not yet visitedv newly generated nodes are added to the fringe

u search strategyv determines the selection of the next node to be expandedv can be achieved by ordering the nodes in the fringe

v e.g. queue (FIFO), stack (LIFO), “best” node w.r.t. some measure (cost)

Monday, October 8, 12

Page 37: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Example: Graph Search

S3

A4

C2

D3

E1

B2

G0

1 1 1 3

1 3 3 4

5

1

2

2

u the graph describes the search (state) spaceu each node in the graph represents one state in the search space

v e.g. a city to be visited in a routing or touring problem

u this graph has additional informationu names and properties for the states (e.g. S, 3)u links between nodes, specified by the successor function

v properties for links (distance, cost, name, ...)

Monday, October 8, 12

Page 38: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Graph and Tree

S3

A4

C2

D3

E1

B2

G0

1 1 1 3

1 3 3 4

5

1

2

2

S3

5

A4

D3

1

1

33

4

2

C2

D3

G0

G0

G0

E1

G0

1

1

3

3

4

2

C2

D3

G0

G0

E1

G0

1

3

B2

1

3

C2

D3

G0

G0

E1

G0

1

3

4E1

G0

2 4

3 2

4

u the tree is generated by traversing the graph

u the same node in the graph may appear repeatedly in the tree

u the arrangement of the tree depends on the traversal strategy (search method)

u the initial state becomes the root node of the tree

u in the fully expanded tree, the goal states are the leaf nodes

u cycles in graphs may result in infinite branches

Monday, October 8, 12

Page 39: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Agents

LogisticsuAI Nugget presentations

u Section 1: v Ray Tam: Image Processingv Andrew Sinclair: Autonomous Bitcoin Agents

u Section 3: -

Monday, October 8, 12

Page 40: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

General Tree Search Algorithmfunction TREE-SEARCH(problem, fringe) returns solution! fringe := INSERT(MAKE-NODE(INITIAL-STATE[problem]), fringe)! loop do

if EMPTY?(fringe) then return failure node := REMOVE-FIRST(fringe) if GOAL-TEST[problem] applied to STATE[node] succeeds

then return SOLUTION(node) fringe! := INSERT-ALL(EXPAND(node, problem), fringe)

u generate the node from the initial state of the problemu repeat

u return failure if there are no more nodes in the fringeu examine the current node; if it’s a goal, return the solutionu expand the current node, and add the new nodes to the fringe

Note: This method is called “General-Search” in earlier AIMA editions

Monday, October 8, 12

Page 41: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Implementation: states vs. nodes

u A state is a (representation of) a physical configurationu A node is a data structure constituting part of a search tree

includes state, parent node, action, path cost g(x), depth

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

http://aima.eecs.berkeley.edu/slides-ppt/Monday, October 8, 12

Page 42: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Evaluation Criteriaucompleteness

u if there is a solution, will it be founduoptimality

u the best solution will be foundutime complexity

u time it takes to find the solutionu does not include the time to perform actions

uspace complexityu memory required for the search

main factors for complexity considerations: branching factor b, depth d of the shallowest goal node, maximum path length m

Monday, October 8, 12

Page 43: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Search Cost and Path Costuthe search cost indicates how expensive it is to

generate a solutionu time complexity (e.g. number of nodes generated) is

usually the main factoru sometimes space complexity (memory usage) is

considered as wellupath cost indicates how expensive it is to execute the

solution found in the searchu distinct from the search cost, but often related

utotal cost is the sum of search and path costs

Monday, October 8, 12

Page 44: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Selection of a Search Strategyumost of the effort is often spent on the selection of an

appropriate search strategy for a given problemu uninformed search (blind search)

v number of steps, path cost unknownv agent knows when it reaches a goal

u informed search (heuristic search)v agent has background information about the problem

v map, costs of actions

Monday, October 8, 12

Page 45: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Search Strategies

u Uninformed Searchu breadth-firstu depth-firstu uniform-cost searchu depth-limited searchu iterative deepeningu bi-directional search

u Informed Searchu best-first searchu search with heuristicsu memory-bounded searchu iterative improvement search

u Local Search and Optimizationu hill-climbingu simulated annealingu local beam searchu genetic algorithmsu constraint satisfaction

u Search in Continuous Spaces

u Non-deterministic Actionsu Partial Observationsu Online Search

Monday, October 8, 12

Page 46: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

uall the nodes reachable from the current node are explored firstu achieved by the TREE-SEARCH method by appending

newly generated nodes at the end of the search queue

function BREADTH-FIRST-SEARCH(problem) returns solution!! return TREE-SEARCH(problem, FIFO-QUEUE())

Breadth-First

b branching factor

d depth of the tree

Time Complexity bd+1

Space Complexity bd+1

Completeness yes (for finite b)Optimality yes (for non-negative

path costs)

Monday, October 8, 12

Page 47: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 1InitialVisitedFringeCurrentVisibleGoal

1

2 3

Fringe: [] + [2,3]

Monday, October 8, 12

Page 48: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 2InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5

Fringe: [3] + [4,5]

Monday, October 8, 12

Page 49: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 3InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

Fringe: [4,5] + [6,7]

Monday, October 8, 12

Page 50: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 4InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9

Fringe: [5,6,7] + [8,9]

Monday, October 8, 12

Page 51: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 5InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11

Fringe: [6,7,8,9] + [10,11]

Monday, October 8, 12

Page 52: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 6InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13

Fringe: [7,8,9,10,11] + [12,13]

Monday, October 8, 12

Page 53: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 7InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

Fringe: [8,9.10,11,12,13] + [14,15]

Monday, October 8, 12

Page 54: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 8InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17

Fringe: [9,10,11,12,13,14,15] + [16,17]

Monday, October 8, 12

Page 55: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 9InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19

Fringe: [10,11,12,13,14,15,16,17] + [18,19]

Monday, October 8, 12

Page 56: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 10InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21

Fringe: [11,12,13,14,15,16,17,18,19] + [20,21]

Monday, October 8, 12

Page 57: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 11InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23

Fringe: [12, 13, 14, 15, 16, 17, 18, 19, 20, 21] + [22,23]

Monday, October 8, 12

Page 58: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 12InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25

Fringe: [13,14,15,16,17,18,19,20,21] + [22,23]

Note: The goal node is “visible” here, but we can not perform the goal test yet.

Monday, October 8, 12

Page 59: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 13InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27

Fringe: [14,15,16,17,18,19,20,21,22,23,24,25] + [26,27]

Monday, October 8, 12

Page 60: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 14InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29

Fringe: [15,16,17,18,19,20,21,22,23,24,25,26,27] + [28,29]

Monday, October 8, 12

Page 61: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 15InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [15,16,17,18,19,20,21,22,23,24,25,26,27,28,29] + [30,31]

Monday, October 8, 12

Page 62: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 16InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]

Monday, October 8, 12

Page 63: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 17InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [18,19,20,21,22,23,24,25,26,27,28,29,30,31]

Monday, October 8, 12

Page 64: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 18InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [19,20,21,22,23,24,25,26,27,28,29,30,31]

Monday, October 8, 12

Page 65: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 19InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [20,21,22,23,24,25,26,27,28,29,30,31]

Monday, October 8, 12

Page 66: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 20InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [21,22,23,24,25,26,27,28,29,30,31]

Monday, October 8, 12

Page 67: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 21InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [22,23,24,25,26,27,28,29,30,31]

Monday, October 8, 12

Page 68: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 22InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [23,24,25,26,27,28,29,30,31]

Monday, October 8, 12

Page 69: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 23InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [24,25,26,27,28,29,30,31]

Monday, October 8, 12

Page 70: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First Snapshot 24InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [25,26,27,28,29,30,31]

Note: The goal test is positive for this node, and a solution is found in 24 steps.

Monday, October 8, 12

Page 71: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

uthe nodes with the lowest cost are explored firstu similar to BREADTH-FIRST, but with an evaluation of the

cost for each reachable nodeu g(n) = path cost(n) = sum of individual edge costs to reach

the current node

function UNIFORM-COST-SEARCH(problem) returns solution!! return TREE-SEARCH(problem, COST-FN, FIFO-QUEUE())

Uniform-Cost -First

Time Complexity bC*/e

Space Complexity bC*/e

Completeness yes (finite b, step costs >= e)Optimality yes

b branching factor

C* cost of the optimal solution

e minimum cost per action

Monday, October 8, 12

Page 72: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Uniform-Cost SnapshotInitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

4 3

7

2

2 2 4

5 4 4 4 3 6 9

3 4 7 2 4 8 6 4 3 4 2 3 9 25 8

Fringe: [27(10), 4(11), 25(12), 26(12), 14(13), 24(13), 20(14), 15(16), 21(18)] + [22(16), 23(15)]

Edge Cost 9

Monday, October 8, 12

Page 73: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Uniform Cost Fringe Trace1. [1(0)]2. [3(3), 2(4)]3. [2(4), 6(5), 7(7)]4. [6(5), 5(6), 7(7), 4(11)]5. [5(6), 7(7), 13(8), 12(9), 4(11)]6. [7(7), 13(8), 12(9), 10(10), 11(10), 4(11)]7. [13(8), 12(9), 10(10), 11(10), 4(11), 14(13), 15(16)]8. [12(9), 10(10), 11(10), 27(10), 4(11), 26(12), 14(13), 15(16)]9. [10(10), 11(10), 27(10), 4(11), 26(12), 25(12), 14(13), 24(13), 15(16)]10. [11(10), 27(10), 4(11), 25(12), 26(12), 14(13), 24(13), 20(14), 15(16), 21(18)]11. [27(10), 4(11), 25(12), 26(12), 14(13), 24(13), 20(14), 23(15), 15(16), 22(16), 21(18)]12. [4(11), 25(12), 26(12), 14(13), 24(13), 20(14), 23(15), 15(16), 23(16), 21(18)]13. [25(12), 26(12), 14(13), 24(13),8(13), 20(14), 23(15), 15(16), 23(16), 9(16), 21(18)]14. [26(12), 14(13), 24(13),8(13), 20(14), 23(15), 15(16), 23(16), 9(16), 21(18)]15. [14(13), 24(13),8(13), 20(14), 23(15), 15(16), 23(16), 9(16), 21(18)]16. [24(13),8(13), 20(14), 23(15), 15(16), 23(16), 9(16), 29(16),21(18), 28(21)] Goal reached!

Notation: [Bold+Yellow: Current Node; White: Old Fringe Node; Green+Italics: New Fringe Node].Assumption: New nodes with the same cost as existing nodes are added after the existing node.

Monday, October 8, 12

Page 74: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Breadth-First vs. Uniform-Costubreadth-first always expands the shallowest node

u only optimal if all step costs are equaluuniform-cost considers the overall path cost

u optimal for any (reasonable) cost functionv non-zero, positive

u gets bogged down in trees with many fruitless, short branchesv low path cost, but no goal node

uboth are complete for non-extreme problemsu finite number of branchesu strictly positive search function

Monday, October 8, 12

Page 75: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

ucontinues exploring newly generated nodesu achieved by the TREE-SEARCH method by appending

newly generated nodes at the beginning of the search queuev utilizes a Last-In, First-Out (LIFO) queue, or stack

function DEPTH-FIRST-SEARCH(problem) returns solution!! return TREE-SEARCH(problem, LIFO-QUEUE())

Depth-First

b branching factor

m maximum path length

Time Complexity bm

Space Complexity b*mCompleteness no (for infinite branch length)Optimality no

Monday, October 8, 12

Page 76: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Depth-First SnapshotInitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [3] + [22,23]

Monday, October 8, 12

Page 77: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Depth-First vs. Breadth-Firstu depth-first goes off into one branch until it reaches a leaf node

u not good if the goal is on another branchu neither complete nor optimalu uses much less space than breadth-first

v much fewer visited nodes to keep track ofv smaller fringe

u breadth-first is more careful by checking all alternativesu complete and optimal

v under most circumstancesu very memory-intensive

Monday, October 8, 12

Page 78: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Backtracking Searchuvariation of depth-first search

u only one successor node is generated at a timev even better space complexity: O(m) instead of O(b*m)v even more memory space can be saved by incrementally modifying

the current state, instead of creating a new onev only possible if the modifications can be undonev this is referred to as backtracking

v frequently used in planning, theorem proving

Monday, October 8, 12

Page 79: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Depth-Limited Searchusimilar to depth-first, but with a limit

u overcomes problems with infinite pathsu sometimes a depth limit can be inferred or estimated from

the problem descriptionv in other cases, a good depth limit is only known when the problem

is solvedu based on the TREE-SEARCH methodu must keep track of the depth

function DEPTH-LIMITED-SEARCH(problem, depth-limit) returns solution!! return TREE-SEARCH(problem, depth-limit, LIFO-QUEUE())

b branching factor

l depth limit

Time Complexity bl

Space Complexity b*lCompleteness no (goal beyond l, or infinite branch length)Optimality no

Monday, October 8, 12

Page 80: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

uapplies LIMITED-DEPTH with increasing depth limitsu combines advantages of BREADTH-FIRST and DEPTH-

FIRST methodsu many states are expanded multiple times

v doesn’t really matter because the number of those nodes is smallu in practice, one of the best uninformed search methods

v for large search spaces, unknown depth

function ITERATIVE-DEEPENING-SEARCH(problem) returns solution for depth := 0 to unlimited do result := DEPTH-LIMITED-SEARCH(problem, depth-limit)! if result != cutoff then return result

Iterative Deepening

b branching factor

d tree depth

Time Complexity bd

Space Complexity b*d

Completeness yes (finite b)

Optimality yes (all step costs identical)

Monday, October 8, 12

Page 81: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Iterative deepening search l =0

http://aima.eecs.berkeley.edu/slides-ppt/Monday, October 8, 12

Page 82: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search 82

Iterative deepening search l =1

http://aima.eecs.berkeley.edu/slides-ppt/Monday, October 8, 12

Page 83: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search 83

Iterative deepening search l =2

http://aima.eecs.berkeley.edu/slides-ppt/Monday, October 8, 12

Page 84: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search 84

Iterative deepening search l =3

http://aima.eecs.berkeley.edu/slides-ppt/Monday, October 8, 12

Page 85: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search 85

Iterative deepening searchu Number of nodes generated in a depth-limited search to depth d with

branching factor b: NDLS = b0 + b1 + b2 + … + bd-2 + bd-1 + bd

u Number of nodes generated in an iterative deepening search to depth d with branching factor b:

NIDS = (d+1)b0 + d b^1 + (d-1)b^2 + … + 3bd-2 +2bd-1 + 1bd

u For b = 10, d = 5,

u NDLS = 1 + 10 + 100 + 1,000 + 10,000 + 100,000 = 111,111

u NIDS = 6 + 50 + 400 + 3,000 + 20,000 + 100,000 = 123,456

u Overhead = (123,456 - 111,111)/111,111 = 11%

http://aima.eecs.berkeley.edu/slides-ppt/Monday, October 8, 12

Page 86: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Bi-directional Searchusearch simultaneously from two directions

u forward from the initial and backward from the goal stateumay lead to substantial savings if it is applicableuhas severe limitations

u predecessors must be generated, which is not always possible

u search must be coordinated between the two searchesu one search must keep all nodes in memory

b branching factor

d tree depth

Time Complexity bd/2

Space Complexity bd/2

Completeness yes (b finite, breadth-first for both directions)Optimality yes (all step costs identical, breadth-first for

both directions)

Monday, October 8, 12

Page 87: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Improving Search Methodsumake algorithms more efficient

u avoiding repeated statesu utilizing memory efficiently

uuse additional knowledge about the problemu properties (“shape”) of the search space

v more interesting areas are investigated firstu pruning of irrelevant areas

v areas that are guaranteed not to contain a solution can be discarded

Monday, October 8, 12

Page 88: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Avoiding Repeated Statesuin many approaches, states may be expanded

multiple timesu e.g. iterative deepeningu problems with reversible actions

ueliminating repeated states may yield an exponential reduction in search costu e.g. some n-queens strategies

v place queen in the left-most non-threatening columnu rectangular grid

v 4d leaves, but only 2d2 distinct states

Monday, October 8, 12

Page 89: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Informed Searchurelies on additional knowledge about the problem or

domainu frequently expressed through heuristics (“rules of thumb”)

uused to distinguish more promising paths towards a goalu may be mislead, depending on the quality of the heuristic

uin general, performs much better than uninformed searchu but frequently still exponential in time and space for

realistic problems

Monday, October 8, 12

Page 90: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Best-First Searchu relies on an evaluation function that gives an indication of how

useful it would be to expand a nodeu family of search methods with various evaluation functions u usually gives an estimate of the distance to the goalu often referred to as heuristics in this context

u the node with the lowest value is expanded firstu the name is a little misleading: the node with the lowest value for the

evaluation function is not necessarily one that is on an optimal path to a goal

u if we really know which one is the best, there’s no need to do a search

function BEST-FIRST-SEARCH(problem, EVAL-FN) returns solution fringe := queue with nodes ordered by EVAL-FN

return TREE-SEARCH(problem, fringe)

Monday, October 8, 12

Page 91: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Greedy Best-First Searchuminimizes the estimated cost to a goal

u expand the node that seems to be closest to a goalu utilizes a heuristic function as evaluation function

v f(n) = h(n) = estimated cost from the current node to a goalv heuristic functions are problem-specificv often straight-line distance for route-finding and similar problems

u often better than depth-first, although worst-time complexities are equal or worse (space)

Completeness Time Complexity Space Complexity Optimality

no bm bm no

b: branching factor, d: depth of the solution, m: maximum depth of the search tree, l: depth limit

function GREEDY-SEARCH(problem) returns solution

return BEST-FIRST-SEARCH(problem, h)

Monday, October 8, 12

Page 92: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Greedy Best-First Search Snapshot

77 6 5 4 3 2 1 0 1 3 5 62 48

65 4 2 4 537

65 56

77

9 InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Fringe: [13(4), 7(6), 8(7)] + [24(0), 25(1)]

7Heuristics

Monday, October 8, 12

Page 93: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

A* Searchucombines greedy and uniform-cost search to find the

(estimated) cheapest path through the current nodeu f(n) = g(n) + h(n)

= path cost + estimated cost to the goalu heuristics must be admissible

v never overestimate the cost to reach the goalu very good search method, but with complexity problems

function A*-SEARCH(problem) returns solution

return BEST-FIRST-SEARCH(problem, g+h)

Completeness Time Complexity Space Complexity Optimality

yes bd bd yes

b: branching factor, d: depth of the solution, m: maximum depth of the search tree, l: depth limit

Monday, October 8, 12

Page 94: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

A* Snapshot

77 6 5 4 3 2 1 0 1 3 5 62 48

65 4 2 4 537

65 56

77

9 InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

4 3

7

2

2 2 4

5 4 4 4 3 6 9

3 4 7 2 4 8 6 4 3 4 2 3 9 25 8

Fringe: [2(4+7), 13(3+2+3+4), 7(3+4+6)] + [24(3+2+4+4+0), 25(3+2+4+3+1)]

Edge Cost

7Heuristics9

f-cost 10

9

11 10

11

10 13

12

13 13

Monday, October 8, 12

Page 95: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

A* Snapshot with all f-Costs

77 6 5 4 3 2 1 0 1 3 5 62 48

65 4 2 4 537

65 56

77

9 InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

4 3

7

2

2 2 4

5 4 4 4 3 6 9

3 4 7 2 4 8 6 4 3 4 2 3 9 25 8

Edge Cost

7Heuristics9

11 10

17 11 10 13

20 21 13 11 12 18 22

24 24 29 23 18 19 18 16 13 13 14 25 31 2513

f-cost 10

21

14

Monday, October 8, 12

Page 96: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

A* Propertiesuthe value of f never decreases along any path

starting from the initial nodeu also known as monotonicity of the functionu almost all admissible heuristics show monotonicity

v those that don’t can be modified through minor changes

uthis property can be used to draw contoursu regions where the f-cost is below a certain thresholdu with uniform cost search (h = 0), the contours are circularu the better the heuristics h, the narrower the contour around

the optimal path

Monday, October 8, 12

Page 97: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

A* Snapshot with Contour f=11

77 6 5 4 3 2 1 0 1 3 5 62 48

65 4 2 4 537

65 56

77

9 InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

4 3

7

2

2 2 4

5 4 4 4 3 6 9

3 4 7 2 4 8 6 4 3 4 2 3 9 25 8

Edge Cost

7Heuristics9

11 10

17 11 10 13

20 21 13 11 12 18 22

24 24 29 23 18 19 18 16 13 13 14 25 31 2513

f-cost 10

21

14

Contour

Monday, October 8, 12

Page 98: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

A* Snapshot with Contour f=13

77 6 5 4 3 2 1 0 1 3 5 6

2

48

65 4 2 4 537

65 56

77

9 InitialVisitedFringeCurrentVisibleGoal

1

2 3

4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 24 25

26

27 28 29 30 31

4 3

7

2

2 2 4

5 4 4 4 3 6 9

3 4 7 2 4 8 6 4 3 4 2 3 9 25 8

Edge Cost

7Heuristics9

11 10

17 11 10 13

20 21 13 11 12 18 22

24 24 29 23 18 19 18 16 13 13

14

25 31 2513

f-cost 10

21

14

Contour

Monday, October 8, 12

Page 99: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Optimality of A*uA* will find the optimal solution

u the first solution found is the optimal oneuA* is optimally efficient

u no other algorithm is guaranteed to expand fewer nodes than A*

uA* is not always “the best” algorithmu optimality refers to the expansion of nodes

v other criteria might be more relevantu it generates and keeps all nodes in memory

v improved in variations of A*

Monday, October 8, 12

Page 100: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Complexity of A*uthe number of nodes within the goal contour search

space is still exponentialu with respect to the length of the solutionu better than other algorithms, but still problematic

ufrequently, space complexity is more severe than time complexityu A* keeps all generated nodes in memory

Monday, October 8, 12

Page 101: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Memory-Bounded Searchusearch algorithms that try to conserve memoryumost are modifications of A*

u iterative deepening A* (IDA*)u simplified memory-bounded A* (SMA*)

Monday, October 8, 12

Page 102: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Iterative Deepening A* (IDA*)uexplores paths within a given contour (f-cost limit) in

a depth-first manneru this saves memory space because depth-first keeps only

the current path in memoryv but it results in repeated computation of earlier contours since it

doesn’t remember its historyu was the “best” search algorithm for many practical

problems for some timeu does have problems with difficult domains

v contours differ only slightly between statesv algorithm frequently switches back and forth

v similar to disk thrashing in (old) operating systems

Monday, October 8, 12

Page 103: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Recursive Best-First Searchusimilar to best-first search, but with lower space

requirementsu O(bd) instead of O(bm)

uit keeps track of the best alternative to the current pathu best f-value of the paths explored so far from predecessors

of the current nodeu if it needs to re-explore parts of the search space, it knows

the best candidate pathu still may lead to multiple re-explorations

Monday, October 8, 12

Page 104: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Simplified Memory-Bounded A* (SMA*)

uuses all available memory for the searchu drops nodes from the queue when it runs out of space

v those with the highest f-costsu avoids re-computation of already explored area

v keeps information about the best path of a “forgotten” subtree in its ancestor

u complete if there is enough memory for the shortest solution path

u often better than A* and IDA*v but some problems are still too toughv trade-off between time and space requirements

Monday, October 8, 12

Page 105: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Heuristics for Searchingufor many tasks, a good heuristic is the key to finding

a solutionu prune the search spaceu move towards the goal

urelaxed problemsu fewer restrictions on the successor function (operators)u its exact solution may be a good heuristic for the original

problem

Monday, October 8, 12

Page 106: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

8-Puzzle Heuristicsu level of difficulty

u around 20 steps for a typical solutionu branching factor is about 3u exhaustive search would be 320 =3.5 * 109 u 9!/2 = 181,440 different reachable states

v distinct arrangements of 9 squares

u candidates for heuristic functions u number of tiles in the wrong positionu sum of distances of the tiles from their goal position

v city block or Manhattan distance

u generation of heuristicsu possible from formal specifications

Monday, October 8, 12

Page 107: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Admissible heuristicsE.g., for the 8-puzzle:

• h1(n) = number of misplaced tiles• h2(n) = total Manhattan distance(i.e., no. of squares from desired location of each tile)

• h1(S) = ? 8• h2(S) = ? 3+1+2+2+2+3+3+2 = 18

http://aima.eecs.berkeley.edu/slides-ppt/Monday, October 8, 12

Page 108: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Important Concepts and Termsu initial stateu iterative deepening searchu iterative improvementu local searchu memory-bounded searchu operatoru optimalityu pathu path cost functionu problemu recursive best-first searchu searchu space complexityu state u state spaceu time complexityu uniform-cost search

u agentu A* searchu best-first searchu bi-directional searchu breadth-first searchu depth-first searchu depth-limited searchu completenessu constraint satisfactionu depth-limited searchu genetic algorithmu general search algorithmu goalu goal test functionu greedy best-first searchu heuristics

Monday, October 8, 12

Page 109: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search

Chapter Summaryu tasks can often be formulated as search problems

u initial state, successor function (operators), goal test, path costu various search methods systematically comb the search

spaceu uninformed search

v breadth-first, depth-first, and variationsu informed search

v best-first, A*, iterative improvement

u the choice of good heuristics can improve the search dramaticallyu task-dependent

Monday, October 8, 12

Page 110: CSC 480: Artificial Intelligenceusers.csc.calpoly.edu/~fkurfess/Courses/480/F03/Slides/3-Search.pdf · ! puzzle with letters and digits! initial state! only letters present! successor

© 2000-2012 Franz Kurfess Search Monday, October 8, 12