CS 416 Artificial Intelligence Lecture 3 Uninformed Searches Lecture 3 Uninformed Searches.
-
Upload
loreen-bell -
Category
Documents
-
view
221 -
download
0
Transcript of CS 416 Artificial Intelligence Lecture 3 Uninformed Searches Lecture 3 Uninformed Searches.
CS 416Artificial Intelligence
Lecture 3Lecture 3
Uninformed SearchesUninformed Searches
Lecture 3Lecture 3
Uninformed SearchesUninformed Searches
Romania
On holiday in Romania; currently in Arad.On holiday in Romania; currently in Arad.
Flight leaves tomorrow from Bucharest at 1:00.Flight leaves tomorrow from Bucharest at 1:00.
Let’s configure this to be an AI problem.Let’s configure this to be an AI problem.
On holiday in Romania; currently in Arad.On holiday in Romania; currently in Arad.
Flight leaves tomorrow from Bucharest at 1:00.Flight leaves tomorrow from Bucharest at 1:00.
Let’s configure this to be an AI problem.Let’s configure this to be an AI problem.
Romania
What’s the problem?What’s the problem?
• Accomplish a Accomplish a goalgoal
– Reach Bucharest by 1:00Reach Bucharest by 1:00
So this is a goal-based problemSo this is a goal-based problem
What’s the problem?What’s the problem?
• Accomplish a Accomplish a goalgoal
– Reach Bucharest by 1:00Reach Bucharest by 1:00
So this is a goal-based problemSo this is a goal-based problem
Romania
Is there more to it?Is there more to it?
• Do it well… according to a Do it well… according to a performance measureperformance measure
– Minimize distance traveledMinimize distance traveled
Is there more to it?Is there more to it?
• Do it well… according to a Do it well… according to a performance measureperformance measure
– Minimize distance traveledMinimize distance traveled
Romania
What’s an example of a non-goal-based problem?What’s an example of a non-goal-based problem?
• Live long and prosperLive long and prosper
• Maximize the happiness of your trip to RomaniaMaximize the happiness of your trip to Romania
• Don’t get hurt too muchDon’t get hurt too much
What’s an example of a non-goal-based problem?What’s an example of a non-goal-based problem?
• Live long and prosperLive long and prosper
• Maximize the happiness of your trip to RomaniaMaximize the happiness of your trip to Romania
• Don’t get hurt too muchDon’t get hurt too much
Romania
What qualifies as a solution?What qualifies as a solution?
• You can/cannot reach Bucharest by 1:00You can/cannot reach Bucharest by 1:00
• You can reach Bucharest in You can reach Bucharest in xx hours hours
• The shortest path to Bucharest passes through these citiesThe shortest path to Bucharest passes through these cities
• The sequence of cities in the shortest path from Arad to The sequence of cities in the shortest path from Arad to Bucharest is ________Bucharest is ________
• The actions one takes to travel from Arad to Bucharest along The actions one takes to travel from Arad to Bucharest along the shortest paththe shortest path
What qualifies as a solution?What qualifies as a solution?
• You can/cannot reach Bucharest by 1:00You can/cannot reach Bucharest by 1:00
• You can reach Bucharest in You can reach Bucharest in xx hours hours
• The shortest path to Bucharest passes through these citiesThe shortest path to Bucharest passes through these cities
• The sequence of cities in the shortest path from Arad to The sequence of cities in the shortest path from Arad to Bucharest is ________Bucharest is ________
• The actions one takes to travel from Arad to Bucharest along The actions one takes to travel from Arad to Bucharest along the shortest paththe shortest path
Romania
What additional information does one need?What additional information does one need?
• A mapA map
What additional information does one need?What additional information does one need?
• A mapA map
More concrete problem definition
A state spaceA state space Which cities could you be inWhich cities could you be in
An initial stateAn initial state Which city do you start fromWhich city do you start from
A goal stateA goal state Which city do you aim to reachWhich city do you aim to reach
A function defining state A function defining state transitionstransitions
When in city foo, the following cities When in city foo, the following cities can be reachedcan be reached
A function defining the A function defining the “cost” of a state sequence“cost” of a state sequence
How long does it take to travel How long does it take to travel through a city sequencethrough a city sequence
More concrete problem definition
A state spaceA state space Choose a representationChoose a representation
An initial stateAn initial stateChoose an element from the Choose an element from the representationrepresentation
A goal stateA goal stateCreate Create goal_function(state)goal_function(state) such that TRUE is returned upon such that TRUE is returned upon reaching goalreaching goal
A function defining state A function defining state transitionstransitions
successor_function(state)successor_function(state) = ={<action, state>, <action, state>, …}{<action, state>, <action, state>, …}
A function defining the A function defining the “cost” of a state sequence“cost” of a state sequence
cost (sequence) cost (sequence) = number= number
State Space
Real world is absurdly complex Real world is absurdly complex state space must be state space must be abstracted for problem solvingabstracted for problem solving• (Abstract) state = set of real states(Abstract) state = set of real states
• (Abstract) action = complex combination of real actions, e.g., (Abstract) action = complex combination of real actions, e.g., “Arad“AradZerind” represents a complex set of possible routes, detours, Zerind” represents a complex set of possible routes, detours, rest stops, etc.rest stops, etc.
• (Abstract) solution = set of real paths that are solutions in the real world(Abstract) solution = set of real paths that are solutions in the real world
Each abstract action should be “easier” than the Each abstract action should be “easier” than the original problem and should permit expansion to a original problem and should permit expansion to a more detailed solutionmore detailed solution
Real world is absurdly complex Real world is absurdly complex state space must be state space must be abstracted for problem solvingabstracted for problem solving• (Abstract) state = set of real states(Abstract) state = set of real states
• (Abstract) action = complex combination of real actions, e.g., (Abstract) action = complex combination of real actions, e.g., “Arad“AradZerind” represents a complex set of possible routes, detours, Zerind” represents a complex set of possible routes, detours, rest stops, etc.rest stops, etc.
• (Abstract) solution = set of real paths that are solutions in the real world(Abstract) solution = set of real paths that are solutions in the real world
Each abstract action should be “easier” than the Each abstract action should be “easier” than the original problem and should permit expansion to a original problem and should permit expansion to a more detailed solutionmore detailed solution
Important notes about this example
• Static environment (available states, successor function, and Static environment (available states, successor function, and cost functions don’t change)cost functions don’t change)
• Observable (the agent knows where it is… percept == state)Observable (the agent knows where it is… percept == state)
• Discrete (the actions are discrete)Discrete (the actions are discrete)
• Deterministic (successor function is always the same)Deterministic (successor function is always the same)
• Static environment (available states, successor function, and Static environment (available states, successor function, and cost functions don’t change)cost functions don’t change)
• Observable (the agent knows where it is… percept == state)Observable (the agent knows where it is… percept == state)
• Discrete (the actions are discrete)Discrete (the actions are discrete)
• Deterministic (successor function is always the same)Deterministic (successor function is always the same)
Problem Solving Agents
Restricted form of general agent:Restricted form of general agent:functionfunction SIMPLE-PROBLEM-SOLVING-AGENT( SIMPLE-PROBLEM-SOLVING-AGENT(perceptpercept) ) returnsreturns an an actionaction staticstatic: : seqseq, an action sequence, initially empty, an action sequence, initially empty statestate, some description of the current world state, some description of the current world state goalgoal, a goal, initially null, a goal, initially null problemproblem, a problem definition, a problem definition state state <- UPDATE-STATE(<- UPDATE-STATE(statestate, , perceptpercept)) ifif seqseq is empty is empty thenthen goalgoal <- FORMULATE-GOAL( <- FORMULATE-GOAL(statestate)) problemproblem <- FORMULATE-PROBLEM( <- FORMULATE-PROBLEM(statestate, , goalgoal)) seq <- SEARCH(seq <- SEARCH(problemproblem)) actionaction <- RECOMMENDATION( <- RECOMMENDATION(seq, state)seq, state) seqseq <- REMAINDER( <- REMAINDER(seq, stateseq, state)) returnreturn actionaction
Restricted form of general agent:Restricted form of general agent:functionfunction SIMPLE-PROBLEM-SOLVING-AGENT( SIMPLE-PROBLEM-SOLVING-AGENT(perceptpercept) ) returnsreturns an an actionaction staticstatic: : seqseq, an action sequence, initially empty, an action sequence, initially empty statestate, some description of the current world state, some description of the current world state goalgoal, a goal, initially null, a goal, initially null problemproblem, a problem definition, a problem definition state state <- UPDATE-STATE(<- UPDATE-STATE(statestate, , perceptpercept)) ifif seqseq is empty is empty thenthen goalgoal <- FORMULATE-GOAL( <- FORMULATE-GOAL(statestate)) problemproblem <- FORMULATE-PROBLEM( <- FORMULATE-PROBLEM(statestate, , goalgoal)) seq <- SEARCH(seq <- SEARCH(problemproblem)) actionaction <- RECOMMENDATION( <- RECOMMENDATION(seq, state)seq, state) seqseq <- REMAINDER( <- REMAINDER(seq, stateseq, state)) returnreturn actionaction
Vacuum world example
• Floor has two locationsFloor has two locations
• Vacuum can move from Vacuum can move from one location to the otherone location to the other
• Locations are clean/dirtyLocations are clean/dirty
• Vacuum can clean the Vacuum can clean the location in which it islocation in which it is
• Clean the floorClean the floor
• Floor has two locationsFloor has two locations
• Vacuum can move from Vacuum can move from one location to the otherone location to the other
• Locations are clean/dirtyLocations are clean/dirty
• Vacuum can clean the Vacuum can clean the location in which it islocation in which it is
• Clean the floorClean the floor
Example: Vacuum World state space graph
States:States:
• Integer dirt and robot locations Integer dirt and robot locations (ignore dirt amounts)(ignore dirt amounts)
Actions:Actions:
• Left, Right, Suck, NoOpLeft, Right, Suck, NoOp
Goal test:Goal test:
• No dirtNo dirt
Path cost:Path cost:
• 1 per action (0 for 1 per action (0 for NoOpNoOp))
States:States:
• Integer dirt and robot locations Integer dirt and robot locations (ignore dirt amounts)(ignore dirt amounts)
Actions:Actions:
• Left, Right, Suck, NoOpLeft, Right, Suck, NoOp
Goal test:Goal test:
• No dirtNo dirt
Path cost:Path cost:
• 1 per action (0 for 1 per action (0 for NoOpNoOp))
Example: Vacuum World state space graph
States? Actions? Goal test? Path cost?States? Actions? Goal test? Path cost?States? Actions? Goal test? Path cost?States? Actions? Goal test? Path cost?
Other Examples
Fifteen PuzzleFifteen Puzzle
Robotic AssemblyRobotic Assembly
Traveling SalesmanTraveling Salesman
Protein DesignProtein Design
Fifteen PuzzleFifteen Puzzle
Robotic AssemblyRobotic Assembly
Traveling SalesmanTraveling Salesman
Protein DesignProtein Design
1010 33 11 99
1313 55 77 1111
1515 88 1414 1212
22 44 66
Tree Search AlgorithmsBasic idea:Basic idea:• Simulated exploration of state space by generating successors of already Simulated exploration of state space by generating successors of already
explored states (AKA explored states (AKA expandingexpanding states) states)
function TREE-SEARCH(function TREE-SEARCH(problem, strategyproblem, strategy))
returnsreturns a solution, or failure a solution, or failure initialize the search tree using the initial state of initialize the search tree using the initial state of problemproblem loop doloop do ifif there are no more candidates for expansion there are no more candidates for expansion
then returnthen return failure failure
choose a leaf node for expansion according to choose a leaf node for expansion according to strategystrategy
ifif the node contains a goal state the node contains a goal state then returnthen return the corresponding solution the corresponding solution
elseelse expand the node and add the resulting nodes to the search expand the node and add the resulting nodes to the search treetree
endend
Basic idea:Basic idea:• Simulated exploration of state space by generating successors of already Simulated exploration of state space by generating successors of already
explored states (AKA explored states (AKA expandingexpanding states) states)
function TREE-SEARCH(function TREE-SEARCH(problem, strategyproblem, strategy))
returnsreturns a solution, or failure a solution, or failure initialize the search tree using the initial state of initialize the search tree using the initial state of problemproblem loop doloop do ifif there are no more candidates for expansion there are no more candidates for expansion
then returnthen return failure failure
choose a leaf node for expansion according to choose a leaf node for expansion according to strategystrategy
ifif the node contains a goal state the node contains a goal state then returnthen return the corresponding solution the corresponding solution
elseelse expand the node and add the resulting nodes to the search expand the node and add the resulting nodes to the search treetree
endend
Example: Arad Bucharestfunction TREE-SEARCH(function TREE-SEARCH(problem, strategyproblem, strategy))
returnsreturns a solution, or failure a solution, or failure
initialize the search tree using the initial state of initialize the search tree using the initial state of problemproblem
loop doloop do ifif there are no more candidates for expansion there are no more candidates for expansion
then returnthen return failure failure
choose a leaf node for expansion according to choose a leaf node for expansion according to strategystrategy
ifif the node contains a goal state the node contains a goal state then returnthen return the corresponding solution the corresponding solution
elseelse expand the node and add the resulting nodes to the search tree expand the node and add the resulting nodes to the search tree endend
function TREE-SEARCH(function TREE-SEARCH(problem, strategyproblem, strategy))
returnsreturns a solution, or failure a solution, or failure
initialize the search tree using the initial state of initialize the search tree using the initial state of problemproblem
loop doloop do ifif there are no more candidates for expansion there are no more candidates for expansion
then returnthen return failure failure
choose a leaf node for expansion according to choose a leaf node for expansion according to strategystrategy
ifif the node contains a goal state the node contains a goal state then returnthen return the corresponding solution the corresponding solution
elseelse expand the node and add the resulting nodes to the search tree expand the node and add the resulting nodes to the search tree endend
Arad
Example: Arad Bucharestfunction TREE-SEARCH(function TREE-SEARCH(problem, strategyproblem, strategy))
returnsreturns a solution, or failure a solution, or failure
initialize the search tree using the initial state of initialize the search tree using the initial state of problemproblem loop doloop do
ifif there are no more candidates for expansion there are no more candidates for expansion then returnthen return failure failure
choose a leaf node for expansion according to choose a leaf node for expansion according to strategystrategy
ifif the node contains a goal state the node contains a goal state
then returnthen return the corresponding solution the corresponding solution elseelse expand the node and add the resulting nodes to the search tree expand the node and add the resulting nodes to the search tree endend
function TREE-SEARCH(function TREE-SEARCH(problem, strategyproblem, strategy))
returnsreturns a solution, or failure a solution, or failure
initialize the search tree using the initial state of initialize the search tree using the initial state of problemproblem loop doloop do
ifif there are no more candidates for expansion there are no more candidates for expansion then returnthen return failure failure
choose a leaf node for expansion according to choose a leaf node for expansion according to strategystrategy
ifif the node contains a goal state the node contains a goal state
then returnthen return the corresponding solution the corresponding solution elseelse expand the node and add the resulting nodes to the search tree expand the node and add the resulting nodes to the search tree endend
Arad
Example: Arad Bucharestfunction TREE-SEARCH(function TREE-SEARCH(problem, strategyproblem, strategy))
returnsreturns a solution, or failure a solution, or failure
initialize the search tree using the initial state of initialize the search tree using the initial state of problemproblem loop doloop do ifif there are no more candidates for expansion there are no more candidates for expansion
then returnthen return failure failure
choose a leaf node for expansion according to choose a leaf node for expansion according to strategystrategy
ifif the node contains a goal state the node contains a goal state
then returnthen return the corresponding solution the corresponding solution elseelse expand the node and add the resulting nodes to the search tree expand the node and add the resulting nodes to the search tree endend
function TREE-SEARCH(function TREE-SEARCH(problem, strategyproblem, strategy))
returnsreturns a solution, or failure a solution, or failure
initialize the search tree using the initial state of initialize the search tree using the initial state of problemproblem loop doloop do ifif there are no more candidates for expansion there are no more candidates for expansion
then returnthen return failure failure
choose a leaf node for expansion according to choose a leaf node for expansion according to strategystrategy
ifif the node contains a goal state the node contains a goal state
then returnthen return the corresponding solution the corresponding solution elseelse expand the node and add the resulting nodes to the search tree expand the node and add the resulting nodes to the search tree endend
Arad
Example: Arad Bucharestfunction TREE-SEARCH(function TREE-SEARCH(problem, strategyproblem, strategy))
returnsreturns a solution, or failure a solution, or failure
initialize the search tree using the initial state of initialize the search tree using the initial state of problemproblem loop doloop do ifif there are no more candidates for expansion there are no more candidates for expansion
then returnthen return failure failure
choose a leaf node for expansion according to choose a leaf node for expansion according to strategystrategy
ifif the node contains a goal state the node contains a goal state then returnthen return the corresponding solution the corresponding solution
elseelse expand the node and add the resulting nodes to expand the node and add the resulting nodes to the search treethe search tree
endend
function TREE-SEARCH(function TREE-SEARCH(problem, strategyproblem, strategy))
returnsreturns a solution, or failure a solution, or failure
initialize the search tree using the initial state of initialize the search tree using the initial state of problemproblem loop doloop do ifif there are no more candidates for expansion there are no more candidates for expansion
then returnthen return failure failure
choose a leaf node for expansion according to choose a leaf node for expansion according to strategystrategy
ifif the node contains a goal state the node contains a goal state then returnthen return the corresponding solution the corresponding solution
elseelse expand the node and add the resulting nodes to expand the node and add the resulting nodes to the search treethe search tree
endendArad
Zerind (75) Timisoara (118) Sibiu (140)
Example: Arad Bucharestfunction TREE-SEARCH(function TREE-SEARCH(problem, strategyproblem, strategy))
returnsreturns a solution, or failure a solution, or failure
initialize the search tree using the initial state of initialize the search tree using the initial state of problemproblem loop doloop do
ifif there are no more candidates for expansion there are no more candidates for expansion then returnthen return failure failure
choose a leaf node for expansion according to choose a leaf node for expansion according to strategystrategy
ifif the node contains a goal state the node contains a goal state
then returnthen return the corresponding solution the corresponding solution elseelse expand the node and add the resulting nodes to the search tree expand the node and add the resulting nodes to the search tree endend
function TREE-SEARCH(function TREE-SEARCH(problem, strategyproblem, strategy))
returnsreturns a solution, or failure a solution, or failure
initialize the search tree using the initial state of initialize the search tree using the initial state of problemproblem loop doloop do
ifif there are no more candidates for expansion there are no more candidates for expansion then returnthen return failure failure
choose a leaf node for expansion according to choose a leaf node for expansion according to strategystrategy
ifif the node contains a goal state the node contains a goal state
then returnthen return the corresponding solution the corresponding solution elseelse expand the node and add the resulting nodes to the search tree expand the node and add the resulting nodes to the search tree endend
Arad
Zerind (75) Timisoara (118) Sibiu (140)
Example: Arad Bucharestfunction TREE-SEARCH(function TREE-SEARCH(problem, strategyproblem, strategy))
returnsreturns a solution, or failure a solution, or failure
initialize the search tree using the initial state of initialize the search tree using the initial state of problemproblem loop doloop do ifif there are no more candidates for expansion there are no more candidates for expansion
then returnthen return failure failure
choose a leaf node for expansion according to choose a leaf node for expansion according to strategystrategy
ifif the node contains a goal state the node contains a goal state
then returnthen return the corresponding solution the corresponding solution elseelse expand the node and add the resulting nodes to the search tree expand the node and add the resulting nodes to the search tree endend
function TREE-SEARCH(function TREE-SEARCH(problem, strategyproblem, strategy))
returnsreturns a solution, or failure a solution, or failure
initialize the search tree using the initial state of initialize the search tree using the initial state of problemproblem loop doloop do ifif there are no more candidates for expansion there are no more candidates for expansion
then returnthen return failure failure
choose a leaf node for expansion according to choose a leaf node for expansion according to strategystrategy
ifif the node contains a goal state the node contains a goal state
then returnthen return the corresponding solution the corresponding solution elseelse expand the node and add the resulting nodes to the search tree expand the node and add the resulting nodes to the search tree endend
Arad
Zerind (75) Timisoara (118) Sibiu (140)
Example: Arad Bucharestfunction TREE-SEARCH(function TREE-SEARCH(problem, strategyproblem, strategy))
returnsreturns a solution, or failure a solution, or failure
initialize the search tree using the initial state of initialize the search tree using the initial state of problemproblem loop doloop do ifif there are no more candidates for expansion there are no more candidates for expansion
then returnthen return failure failure
choose a leaf node for expansion according to choose a leaf node for expansion according to strategystrategy
ifif the node contains a goal state the node contains a goal state then returnthen return the corresponding solution the corresponding solution
elseelse expand the node and add the resulting nodes to expand the node and add the resulting nodes to the search treethe search tree
endend
function TREE-SEARCH(function TREE-SEARCH(problem, strategyproblem, strategy))
returnsreturns a solution, or failure a solution, or failure
initialize the search tree using the initial state of initialize the search tree using the initial state of problemproblem loop doloop do ifif there are no more candidates for expansion there are no more candidates for expansion
then returnthen return failure failure
choose a leaf node for expansion according to choose a leaf node for expansion according to strategystrategy
ifif the node contains a goal state the node contains a goal state then returnthen return the corresponding solution the corresponding solution
elseelse expand the node and add the resulting nodes to expand the node and add the resulting nodes to the search treethe search tree
endendArad
Zerind (75) Timisoara (118) Sibiu (140)
Dradea (151) Faragas (99) Rimnicu Vilcea (80)
Implementation: states vs. nodes
StateState
• (Representation of) a physical configuration(Representation of) a physical configuration
NodeNode
• Data structure constituting part of a search treeData structure constituting part of a search tree
– Includes Includes parent, children, depth, path costparent, children, depth, path cost g(x) g(x)
States do not have parents, children, depth, or States do not have parents, children, depth, or path cost!path cost!
StateState
• (Representation of) a physical configuration(Representation of) a physical configuration
NodeNode
• Data structure constituting part of a search treeData structure constituting part of a search tree
– Includes Includes parent, children, depth, path costparent, children, depth, path cost g(x) g(x)
States do not have parents, children, depth, or States do not have parents, children, depth, or path cost!path cost!
Implementation: general tree searchfunction function TREE-SEARCH (TREE-SEARCH (problemproblem, , fringefringe) ) returnsreturns a solution, or failure a solution, or failure fringefringe INSERT(MAKE-NODE(INITIAL-STATE[problem]), INSERT(MAKE-NODE(INITIAL-STATE[problem]), fringefringe)) loop doloop do ifif fringe fringe is empty is empty then returnthen return false false nodenode REMOVE-FRONT( REMOVE-FRONT(fringefringe)) ifif GOAL-TEST[ GOAL-TEST[problemproblem] applied to STATE(] applied to STATE(nodenode) succeeds ) succeeds returnreturn nodenode fringefringe INSERTALL(EXPAND( INSERTALL(EXPAND(nodenode, , problemproblem), ), fringefringe))
function function EXPAND (EXPAND (nodenode, , problemproblem) ) returnsreturns a set of states a set of states successorssuccessors the empty set the empty set for each for each action, resultaction, result inin SUCCESSOR-FN[problem](STATE[ SUCCESSOR-FN[problem](STATE[nodenode]) ]) dodo ss a new NODE a new NODE PARENT-NODE[PARENT-NODE[ss] ] nodenode; ACTION[; ACTION[ss] ] actionaction; STATE(; STATE(ss) ) resultresult PATH-COST[PATH-COST[ss] ] PATH-COST[ PATH-COST[nodenode] + STEP-COST(] + STEP-COST(node, action, snode, action, s)) DEPTH[DEPTH[ss] ] DEPTH[ DEPTH[nodenode] + 1] + 1 add add ss to to successorssuccessorsreturn return successorssuccessors
Find the error on this page!Find the error on this page!
function function TREE-SEARCH (TREE-SEARCH (problemproblem, , fringefringe) ) returnsreturns a solution, or failure a solution, or failure fringefringe INSERT(MAKE-NODE(INITIAL-STATE[problem]), INSERT(MAKE-NODE(INITIAL-STATE[problem]), fringefringe)) loop doloop do ifif fringe fringe is empty is empty then returnthen return false false nodenode REMOVE-FRONT( REMOVE-FRONT(fringefringe)) ifif GOAL-TEST[ GOAL-TEST[problemproblem] applied to STATE(] applied to STATE(nodenode) succeeds ) succeeds returnreturn nodenode fringefringe INSERTALL(EXPAND( INSERTALL(EXPAND(nodenode, , problemproblem), ), fringefringe))
function function EXPAND (EXPAND (nodenode, , problemproblem) ) returnsreturns a set of states a set of states successorssuccessors the empty set the empty set for each for each action, resultaction, result inin SUCCESSOR-FN[problem](STATE[ SUCCESSOR-FN[problem](STATE[nodenode]) ]) dodo ss a new NODE a new NODE PARENT-NODE[PARENT-NODE[ss] ] nodenode; ACTION[; ACTION[ss] ] actionaction; STATE(; STATE(ss) ) resultresult PATH-COST[PATH-COST[ss] ] PATH-COST[ PATH-COST[nodenode] + STEP-COST(] + STEP-COST(node, action, snode, action, s)) DEPTH[DEPTH[ss] ] DEPTH[ DEPTH[nodenode] + 1] + 1 add add ss to to successorssuccessorsreturn return successorssuccessors
Find the error on this page!Find the error on this page!
Search strategiesA strategy is defined by picking the A strategy is defined by picking the order of node expansionorder of node expansion
Strategies are evaluated along the following dimensions:Strategies are evaluated along the following dimensions:
• Completeness – does it always find a solution if one exists?Completeness – does it always find a solution if one exists?
• Time complexity – number of nodes generated/expandedTime complexity – number of nodes generated/expanded
• Space complexity – maximum nodes in memorySpace complexity – maximum nodes in memory
• Optimality – does it always find a least cost solution?Optimality – does it always find a least cost solution?
Time and space complexity are measured in terms of:Time and space complexity are measured in terms of:
• b – maximum branching factor of the search treeb – maximum branching factor of the search tree
• d – depth of the least-cost solutiond – depth of the least-cost solution
• m – maximum depth of the state space (may be infinite)m – maximum depth of the state space (may be infinite)
A strategy is defined by picking the A strategy is defined by picking the order of node expansionorder of node expansion
Strategies are evaluated along the following dimensions:Strategies are evaluated along the following dimensions:
• Completeness – does it always find a solution if one exists?Completeness – does it always find a solution if one exists?
• Time complexity – number of nodes generated/expandedTime complexity – number of nodes generated/expanded
• Space complexity – maximum nodes in memorySpace complexity – maximum nodes in memory
• Optimality – does it always find a least cost solution?Optimality – does it always find a least cost solution?
Time and space complexity are measured in terms of:Time and space complexity are measured in terms of:
• b – maximum branching factor of the search treeb – maximum branching factor of the search tree
• d – depth of the least-cost solutiond – depth of the least-cost solution
• m – maximum depth of the state space (may be infinite)m – maximum depth of the state space (may be infinite)
Uninformed Search Strategies
Uninformed strategies use only the information Uninformed strategies use only the information available in the problem definitionavailable in the problem definition
• Breadth-first searchBreadth-first search
• Uniform-cost searchUniform-cost search
• Depth-first searchDepth-first search
• Depth-limited searchDepth-limited search
• Iterative deepening searchIterative deepening search
Uninformed strategies use only the information Uninformed strategies use only the information available in the problem definitionavailable in the problem definition
• Breadth-first searchBreadth-first search
• Uniform-cost searchUniform-cost search
• Depth-first searchDepth-first search
• Depth-limited searchDepth-limited search
• Iterative deepening searchIterative deepening search
Breadth-first search
Expand shallowest unexpanded nodeExpand shallowest unexpanded node
Implementation:Implementation:
• FringeFringe is a FIFO queue, i.e., new successors go at end is a FIFO queue, i.e., new successors go at end
• Execute first few expansions of Arad to Bucharest using Execute first few expansions of Arad to Bucharest using Breadth-first searchBreadth-first search
Expand shallowest unexpanded nodeExpand shallowest unexpanded node
Implementation:Implementation:
• FringeFringe is a FIFO queue, i.e., new successors go at end is a FIFO queue, i.e., new successors go at end
• Execute first few expansions of Arad to Bucharest using Execute first few expansions of Arad to Bucharest using Breadth-first searchBreadth-first search
Breadth-first Search
Arad
Zerind Timisoara Sibiu
Dradea FaragasRimnicu
VilceaArad Oradea Arad Lugoj
Zerind Timisoara Sibiu Zerind Sibiu
Computation cost of BFS
1
23
Level Nodes0 1
bb2
b3
Computation cost of BFS
If goal is in d = level 2If goal is in d = level 2
Cost = 1 + b + bCost = 1 + b + b22 + b + b33 – b = O (b – b = O (bd+1d+1))
If goal is in d = level 2If goal is in d = level 2
Cost = 1 + b + bCost = 1 + b + b22 + b + b33 – b = O (b – b = O (bd+1d+1))
1
23
Level Nodes0 1
bb2
b3
Computation cost of BFS
Cost = 1 + b + bCost = 1 + b + b22 + b + b33 – b = O (b – b = O (bd+1d+1))
Big Oh NotationBig Oh Notation
• There exist positive constants: c, bThere exist positive constants: c, b00, d, d00 such that such that
for all b >= bfor all b >= b00 and d >= d and d >= d00
Cost = 1 + b + bCost = 1 + b + b22 + b + b33 – b = O (b – b = O (bd+1d+1))
Big Oh NotationBig Oh Notation
• There exist positive constants: c, bThere exist positive constants: c, b00, d, d00 such that such that
for all b >= bfor all b >= b00 and d >= d and d >= d00
Figure 2.1 fromCormen, Leiserson, Rivest
Space cost of BFS
Because you must be able to generate the path upon Because you must be able to generate the path upon finding the goal state, all visited states must be storedfinding the goal state, all visited states must be storedBecause you must be able to generate the path upon Because you must be able to generate the path upon finding the goal state, all visited states must be storedfinding the goal state, all visited states must be stored
Properties of breadth-first search
Complete?? Complete?? Yes (if b Yes (if b (max branch factor)(max branch factor) is finite) is finite)
Time?? Time?? 1 + b + b1 + b + b22 + … + b + … + bdd + b(b + b(bdd-1) = O(b-1) = O(bd+1d+1), i.e., ), i.e., exponential in dexponential in d
Space?? Space?? O(bO(bd+1d+1) (keeps every node in memory)) (keeps every node in memory)
Optimal?? Optimal?? Only if cost = 1 per step, otherwise not Only if cost = 1 per step, otherwise not optimal in generaloptimal in general
Space is the big problem; Space is the big problem; can easily generate can easily generate nodes at 10 MB/s, so 24hrs = 860GB!nodes at 10 MB/s, so 24hrs = 860GB!
Complete?? Complete?? Yes (if b Yes (if b (max branch factor)(max branch factor) is finite) is finite)
Time?? Time?? 1 + b + b1 + b + b22 + … + b + … + bdd + b(b + b(bdd-1) = O(b-1) = O(bd+1d+1), i.e., ), i.e., exponential in dexponential in d
Space?? Space?? O(bO(bd+1d+1) (keeps every node in memory)) (keeps every node in memory)
Optimal?? Optimal?? Only if cost = 1 per step, otherwise not Only if cost = 1 per step, otherwise not optimal in generaloptimal in general
Space is the big problem; Space is the big problem; can easily generate can easily generate nodes at 10 MB/s, so 24hrs = 860GB!nodes at 10 MB/s, so 24hrs = 860GB!
Uniform-first search
Expand least-cost unexpanded nodeExpand least-cost unexpanded node
Implementation:Implementation:
• FringeFringe is a queue ordered by cost is a queue ordered by cost
• Execute first few expansions of Arad to Bucharest using Execute first few expansions of Arad to Bucharest using Breadth-first searchBreadth-first search
Expand least-cost unexpanded nodeExpand least-cost unexpanded node
Implementation:Implementation:
• FringeFringe is a queue ordered by cost is a queue ordered by cost
• Execute first few expansions of Arad to Bucharest using Execute first few expansions of Arad to Bucharest using Breadth-first searchBreadth-first search
Uniform-cost Search
Arad
Zerind (75) Timisoara (118) Sibiu (140)
Oradea (291) Faragas (139)Rimnicu (220)
VilceaArad (150) Oradea (146) Arad (193) Lugoj (229)
Bucharest (350) Sibiu (238)
Uniform-cost searchComplete?? If step cost Complete?? If step cost ≥≥ εε
Time?? Time??
• If all costs are equal = O (bIf all costs are equal = O (bdd))
Space?? Space?? O(bO(bC/ C/ εε))
Optimal?? Yes–nodes expanded in increasing order of Optimal?? Yes–nodes expanded in increasing order of g(n)g(n)
Complete?? If step cost Complete?? If step cost ≥≥ εε
Time?? Time??
• If all costs are equal = O (bIf all costs are equal = O (bdd))
Space?? Space?? O(bO(bC/ C/ εε))
Optimal?? Yes–nodes expanded in increasing order of Optimal?? Yes–nodes expanded in increasing order of g(n)g(n)
Depth-first search
Expand deepest unexpanded nodeExpand deepest unexpanded node
Implementation:Implementation:
• FringeFringe = LIFO queue, i.e., a stack = LIFO queue, i.e., a stack
• Execute first few expansions of Arad to Bucharest using Execute first few expansions of Arad to Bucharest using Depth-first searchDepth-first search
Expand deepest unexpanded nodeExpand deepest unexpanded node
Implementation:Implementation:
• FringeFringe = LIFO queue, i.e., a stack = LIFO queue, i.e., a stack
• Execute first few expansions of Arad to Bucharest using Execute first few expansions of Arad to Bucharest using Depth-first searchDepth-first search
Depth-first search
Complete??Complete??
Time??Time??
Space??Space??
Optimal??Optimal??
Complete??Complete??
Time??Time??
Space??Space??
Optimal??Optimal??
Depth-first searchComplete??Complete??
• No: fails in infinite-depth spaces, spaces with loops.No: fails in infinite-depth spaces, spaces with loops.
• Can be modified to avoid repeated states along path Can be modified to avoid repeated states along path complete in finite spaces complete in finite spaces
Time??Time??
• O(bO(bmm)): terrible if : terrible if mm is much larger than is much larger than dd, but if solutions are dense, may be much faster , but if solutions are dense, may be much faster than breadth-firstthan breadth-first
Space??Space??
• O(bm), i.e., linear space!O(bm), i.e., linear space!
Optimal??Optimal??
• NoNo
Complete??Complete??
• No: fails in infinite-depth spaces, spaces with loops.No: fails in infinite-depth spaces, spaces with loops.
• Can be modified to avoid repeated states along path Can be modified to avoid repeated states along path complete in finite spaces complete in finite spaces
Time??Time??
• O(bO(bmm)): terrible if : terrible if mm is much larger than is much larger than dd, but if solutions are dense, may be much faster , but if solutions are dense, may be much faster than breadth-firstthan breadth-first
Space??Space??
• O(bm), i.e., linear space!O(bm), i.e., linear space!
Optimal??Optimal??
• NoNo
Depth-limited search
Depth-first search with depth limit lDepth-first search with depth limit l
• i.e., nodes at depth i.e., nodes at depth ll have no have no successorssuccessors
Depth-first search with depth limit lDepth-first search with depth limit l
• i.e., nodes at depth i.e., nodes at depth ll have no have no successorssuccessors
Iterative deepening searchfunction function ITERATIVE-DEEPENING-SEARCH(ITERATIVE-DEEPENING-SEARCH(problemproblem) ) returnsreturns a solution a solution
inputsinputs: : problemproblem, a problem, a problem
for for depthdepth 0 0 toto ∞ ∞ dodo
resultresult DEPTH-LIMITED-SEARCH( DEPTH-LIMITED-SEARCH(problemproblem, , depthdepth))
ifif result result ≠ ≠ cutoffcutoff then returnthen return resultresult
endend
function function ITERATIVE-DEEPENING-SEARCH(ITERATIVE-DEEPENING-SEARCH(problemproblem) ) returnsreturns a solution a solution
inputsinputs: : problemproblem, a problem, a problem
for for depthdepth 0 0 toto ∞ ∞ dodo
resultresult DEPTH-LIMITED-SEARCH( DEPTH-LIMITED-SEARCH(problemproblem, , depthdepth))
ifif result result ≠ ≠ cutoffcutoff then returnthen return resultresult
endend
Properties of iterative deepening
Complete??Complete??• YesYes
Time??Time??• (d+1)b(d+1)b00 + db + db11 + (d-1)b + (d-1)b22 + … b + … bdd = O(b = O(bdd))
Space??Space??• O(bd)O(bd)
Optimal??Optimal??• If step cost = 1If step cost = 1
• Can be modified to explore uniform-cost treeCan be modified to explore uniform-cost tree
Complete??Complete??• YesYes
Time??Time??• (d+1)b(d+1)b00 + db + db11 + (d-1)b + (d-1)b22 + … b + … bdd = O(b = O(bdd))
Space??Space??• O(bd)O(bd)
Optimal??Optimal??• If step cost = 1If step cost = 1
• Can be modified to explore uniform-cost treeCan be modified to explore uniform-cost tree
SummaryAll tree searching techniques are more alike than differentAll tree searching techniques are more alike than different
Breadth-first has space issues, and possibly optimality issuesBreadth-first has space issues, and possibly optimality issues
Uniform-cost has space issuesUniform-cost has space issues
Depth-first has time and optimality issues, and possibly completeness Depth-first has time and optimality issues, and possibly completeness issuesissues
Depth-limited search has optimality and completeness issuesDepth-limited search has optimality and completeness issues
Iterative deepening is the best uninformed search we have exploredIterative deepening is the best uninformed search we have explored
Next class we study informed searchesNext class we study informed searches
All tree searching techniques are more alike than differentAll tree searching techniques are more alike than different
Breadth-first has space issues, and possibly optimality issuesBreadth-first has space issues, and possibly optimality issues
Uniform-cost has space issuesUniform-cost has space issues
Depth-first has time and optimality issues, and possibly completeness Depth-first has time and optimality issues, and possibly completeness issuesissues
Depth-limited search has optimality and completeness issuesDepth-limited search has optimality and completeness issues
Iterative deepening is the best uninformed search we have exploredIterative deepening is the best uninformed search we have explored
Next class we study informed searchesNext class we study informed searches