Warm- up. IteraAve version, not recursive. class TreeNode TreeNode[] children() boolean isgoal() DFS(TreeNode start)

Similar documents
PEAS: Medical diagnosis system

Announcements. Project 0: Python Tutorial Due last night

CSC 2114: Artificial Intelligence Search

Graphs vs trees up front; use grid too; discuss for BFS, DFS, IDS, UCS Cut back on A* optimality detail; a bit more on importance of heuristics,

CSE 473: Ar+ficial Intelligence

CS 188: Ar)ficial Intelligence

CS 5522: Artificial Intelligence II

CS 4100 // artificial intelligence

521495A: Artificial Intelligence

AGENTS AND ENVIRONMENTS. What is AI in reality?

AGENTS AND ENVIRONMENTS. What is AI in reality?

Solving Problems by Searching

CS486/686 Lecture Slides (c) 2015 P.Poupart

CS486/686 Lecture Slides (c) 2014 P.Poupart

Week 3: Path Search. COMP9414/ 9814/ 3411: Artificial Intelligence. Motivation. Example: Romania. Romania Street Map. Russell & Norvig, Chapter 3.

Problem solving and search

4. Solving Problems by Searching

COMP9414/ 9814/ 3411: Artificial Intelligence. 5. Informed Search. Russell & Norvig, Chapter 3. UNSW c Alan Blair,

Graph Search. Chris Amato Northeastern University. Some images and slides are used from: Rob Platt, CS188 UC Berkeley, AIMA

CS:4420 Artificial Intelligence

Introduction to Artificial Intelligence. Informed Search

Robot Programming with Lisp

Overview. Path Cost Function. Real Life Problems. COMP219: Artificial Intelligence. Lecture 10: Heuristic Search

Solving Problems using Search

Informed search algorithms

COSC343: Artificial Intelligence

CS:4420 Artificial Intelligence

Artificial Intelligence, CS, Nanjing University Spring, 2018, Yang Yu. Lecture 2: Search 1.

COMP219: Artificial Intelligence. Lecture 10: Heuristic Search

Artificial Intelligence: Search Part 1: Uninformed graph search

Informed search algorithms. Chapter 4, Sections 1 2 1

Artificial Intelligence. Informed search methods

Problem solving and search

Informed Search and Exploration

Solving Problems by Searching

Solving Problems by Searching

Problem solving and search

COMP219: Artificial Intelligence. Lecture 10: Heuristic Search

Searching and NetLogo

Informed Search and Exploration

Problem solving and search

Artificial Intelligence, CS, Nanjing University Spring, 2018, Yang Yu. Lecture 3: Search 2.

COMP219: Artificial Intelligence. Lecture 7: Search Strategies

Solving Problems by Searching. Artificial Intelligence Santa Clara University 2016

Informed search algorithms

PROBLEM SOLVING AND SEARCH IN ARTIFICIAL INTELLIGENCE

CS414-Artificial Intelligence

Artificial Intelligence: Search Part 2: Heuristic search

CS-E4800 Artificial Intelligence

Artificial Intelligence

Introduction to Artificial Intelligence (G51IAI)

Planning and search. Lecture 1: Introduction and Revision of Search. Lecture 1: Introduction and Revision of Search 1

Informed Search Algorithms. Chapter 4

Seminar: Search and Optimization

Informed Search. Topics. Review: Tree Search. What is Informed Search? Best-First Search

Foundations of Artificial Intelligence

Artificial Intelligence

Outline. Solving Problems by Searching. Introduction. Problem-solving agents

Informed search algorithms

Artificial Intelligence

Informed Search and Exploration

16.1 Introduction. Foundations of Artificial Intelligence Introduction Greedy Best-first Search 16.3 A Weighted A. 16.

ARTIFICIAL INTELLIGENCE (CSC9YE ) LECTURES 2 AND 3: PROBLEM SOLVING

Foundations of Artificial Intelligence

Automated Planning & Artificial Intelligence

Search. Intelligent agents. Problem-solving. Problem-solving agents. Road map of Romania. The components of a problem. that will take me to the goal!

Artificial Intelligence

Introduction to Artificial Intelligence (G51IAI) Dr Rong Qu. Blind Searches

Outline for today s lecture. Informed Search I. One issue: How to search backwards? Very briefly: Bidirectional search. Outline for today s lecture

Planning, Execution & Learning 1. Heuristic Search Planning

Problem solving and search: Chapter 3, Sections 1 5

Problem solving and search: Chapter 3, Sections 1 5

Problem Solving and Search. Geraint A. Wiggins Professor of Computational Creativity Department of Computer Science Vrije Universiteit Brussel

Outline. Informed search algorithms. Best-first search. Review: Tree search. A search Heuristics. Chapter 4, Sections 1 2 4

CS 5100: Founda.ons of Ar.ficial Intelligence

Princess Nora University Faculty of Computer & Information Systems ARTIFICIAL INTELLIGENCE (CS 370D) Computer Science Department

Clustering (Un-supervised Learning)

Solving problems by searching

Lecture Plan. Best-first search Greedy search A* search Designing heuristics. Hill-climbing. 1 Informed search strategies. Informed strategies

CS 771 Artificial Intelligence. Problem Solving by Searching Uninformed search

ARTIFICIAL INTELLIGENCE. Pathfinding and search

TDT4136 Logic and Reasoning Systems

Why Search. Things to consider. Example, a holiday in Jamaica. CSE 3401: Intro to Artificial Intelligence Uninformed Search

Artificial Intelligence CS 6364

Solving Problem by Searching. Chapter 3

Algorithm. December 7, Shortest path using A Algorithm. Phaneendhar Reddy Vanam. Introduction. History. Components of A.

HW#1 due today. HW#2 due Monday, 9/09/13, in class Continue reading Chapter 3

Basic Search. Fall Xin Yao. Artificial Intelligence: Basic Search

Problem Solving and Search. Chapter 3

ARTIFICIAL INTELLIGENCE SOLVING PROBLEMS BY SEARCHING. Chapter 3

Problem solving and search

CAP 4630 Artificial Intelligence

Problem solving and search

Informed Search and Exploration

CS 4700: Foundations of Artificial Intelligence. Bart Selman. Search Techniques R&N: Chapter 3

EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS

Informed search methods

Uninformed search strategies (Section 3.4) Source: Fotolia

Optimal Control and Dynamic Programming

521495A: Artificial Intelligence

Transcription:

Warm- up We ll o-en have a warm- up exercise for the 10 minutes before class starts. Here s the first one Write the pseudo code for breadth first search and depth first search IteraAve version, not recursive class TreeNode TreeNode[] children() boolean isgoal() BFS(TreeNode start) DFS(TreeNode start)

Announcements Upcoming due dates F 5 pm Proj 0 M 11:59 pm HW 1 Be careful of edx Amezone (UTC)! Account forms Pick- up a-er lecture (if you like) Step- by- step videos Found in edx Courseware (linked on edx Syllabus)

CS 188: ArAficial Intelligence Search Instructors: Stuart Russell and Pat Virtue

Today Agents that Plan Ahead Search Problems Uninformed Search Methods Depth- First Search Breadth- First Search Uniform- Cost Search

Reflex agents: Choose acaon based on current percept (and maybe memory) May have memory or a model of the world s current state Do not consider the future consequences of their acaons Consider how the world IS Reflex Agents

Agents that Plan Ahead Planning agents: Decisions based on predicted consequences of acaons Must have a transi/on model: how the world evolves in response to acaons Must formulate a goal Consider how the world WOULD BE Spectrum of deliberaaveness: Generate complete, opamal plan offline, then execute Generate a simple, greedy plan, start execuang, replan when something goes wrong

Demo Mastermind

Demo Replanning

Search Problems

A search problem consists of: A state space Search Problems For each state, a set AcAons(s) of allowable acaons A transiaon model Result(s,a) {N, E} N 1 A step cost funcaon c(s,a,s ) E 1 A start state and a goal test A soluaon is a sequence of acaons (a plan) which transforms the start state to a goal state

Search Problems Are Models

Example: Travelling in Romania 71 Oradea Neamt State space: CiAes Arad 118 75 Zerind 140 Timisoara 111 70 75 Drobeta 151 Sibiu 99 Fagaras 80 Rimnicu Vilcea Lugoj Mehadia 120 Pitesti 211 97 146 101 85 138 Bucharest 90 Craiova Giurgiu 87 Iasi 92 142 98 Urziceni Vaslui Hirsova 86 Eforie AcAons: Go to adjacent city TransiAon model Result(A, Go(B)) = B Step cost Distance along road link Start state: Arad Goal test: Is state == Bucharest? SoluAon?

What s in a State Space? The real world state includes every last detail of the environment A search state abstracts away details not needed to solve the problem Problem: Pathing State representaaon: (x,y) locaaon AcAons: NSEW TransiAon model: update locaaon Goal test: is (x,y)=end MN states Problem: Eat- All- Dots State representaaon: {(x,y), dot booleans} AcAons: NSEW TransiAon model: update locaaon and possibly a dot boolean Goal test: dots all false MN2 MN states

Quiz: Safe Passage Problem: eat all dots while keeping the ghosts perma- scared What does the state representaaon have to specify? (agent posiaon, dot booleans, power pellet booleans, remaining scared Ame)

State Space Graphs and Search Trees

State Space Graphs State space graph: A mathemaacal representaaon of a search problem Nodes are (abstracted) world configuraaons Arcs represent transiaons resulang from acaons The goal test is a set of goal nodes (maybe only one) In a state space graph, each state occurs only once! We can rarely build this full graph in memory (it s too big), but it s a useful idea

More Examples 71 Oradea Neamt Arad 118 75 Zerind 140 Timisoara 151 Sibiu 99 Fagaras 80 Rimnicu Vilcea 87 Iasi 92 Vaslui 111 Lugoj 97 Pitesti 211 142 70 75 Drobeta Mehadia 120 146 101 85 138 Bucharest 90 Craiova Giurgiu 98 Urziceni Hirsova 86 Eforie

More Examples L R L R S S R R L R L R L L S S S S R L R L S S

Search Trees This is now / start N, 1.0 E, 1.0 Possible futures A search tree: A what if tree of plans and their outcomes The start state is the root node Children correspond to possible acaon outcomes Nodes show states, but correspond to PLANS that achieve those states For most problems, we can never actually build the whole tree

Quiz: State Space Graphs vs. Search Trees Consider this 4- state graph: How big is its search tree (from S)? S a a b S G b G G a b G a b G Important: Lots of repeated structure in the search tree!

Tree Search

Search Example: Romania 71 Oradea Neamt Arad 118 75 Zerind Timisoara 140 151 Sibiu 99 Fagaras 80 Rimnicu Vilcea 87 Iasi 92 Vaslui 111 Lugoj 97 Pitesti 211 142 70 75 Drobeta Mehadia 120 146 101 85 138 Bucharest 90 Craiova Giurgiu Urziceni 98 Hirsova 86 Eforie

Searching with a Search Tree Search: Expand out potenaal plans (tree nodes) Maintain a fronaer of paraal plans under consideraaon Try to expand as few tree nodes as possible

General Tree Search function TREE-SEARCH(problem) returns a solution, or failure initialize the frontier using the initial state of problem loop do if the frontier is empty then return failure choose a leaf node and remove it from the frontier if the node contains a goal state then return the corresponding solution expand the chosen node, adding the resulting nodes to the frontier Important ideas: FronAer Expansion ExploraAon strategy Main quesaon: which fronaer nodes to explore?

A Note on ImplementaAon Nodes have state, parent, acaon, path- cost A child of node by acaon a has state = result(node.state,a) 5 4 Node PARENT ACTION = Right PATH-COST = 6 parent acaon = node = a 6 7 1 3 8 2 STATE path- cost = node.path- cost + step- cost(node.state, a, self.state) Extract soluaon by tracing back parent pointers, collecang acaons

Depth- First Search

Depth- First Search S a b d p a c e p h f r q q c G a q e p h f r q q c G a S G d b p q c e h a f r q p h f d b a c e r Strategy: expand a deepest node first Implementa4on: Fron/er is a LIFO stack

Search Algorithm ProperAes

Search Algorithm ProperAes Complete: Guaranteed to find a soluaon if one exists? OpAmal: Guaranteed to find the least cost path? Time complexity? Space complexity? b 1 node b nodes Cartoon of search tree: b is the branching factor m tiers b 2 nodes m is the maximum depth soluaons at various depths b m nodes Number of nodes in enare tree? 1 + b + b 2 +. b m = O(b m )

Depth- First Search (DFS) ProperAes What nodes does DFS expand? Some le- prefix of the tree. Could process the whole tree! If m is finite, takes Ame O(b m ) b 1 node b nodes b 2 nodes How much space does the fronaer take? Only has siblings on path to root, so O(bm) m tiers Is it complete? m could be infinite, so only if we prevent cycles (more later) b m nodes Is it opamal? No, it finds the le-most soluaon, regardless of depth or cost

Breadth- First Search

Breadth- First Search Strategy: expand a shallowest node first Implementa4on: Fron/er is a FIFO queue S b p a d q c h e r f G S Search Tiers b a d c a h e r p h q e r f p q p q f q c G q c G a a

Breadth- First Search (BFS) ProperAes What nodes does BFS expand? Processes all nodes above shallowest soluaon Let depth of shallowest soluaon be s Search takes Ame O(b s ) s tiers b 1 node b nodes b 2 nodes How much space does the fronaer take? b s nodes Has roughly the last Aer, so O(b s ) Is it complete? s must be finite if a soluaon exists, so yes! b m nodes Is it opamal? Only if costs are all 1 (more on costs later)

Quiz: DFS vs BFS

Quiz: DFS vs BFS When will BFS outperform DFS? When will DFS outperform BFS? [Demo: dfs/bfs maze water (L2D6)]

Video of Demo Maze Water DFS/BFS (part 1)

Video of Demo Maze Water DFS/BFS (part 2)

IteraAve Deepening Idea: get DFS s space advantage with BFS s Ame / shallow- soluaon advantages Run a DFS with depth limit 1. If no soluaon Run a DFS with depth limit 2. If no soluaon Run a DFS with depth limit 3... b Isn t that wastefully redundant? Generally most work happens in the lowest level searched, so not so bad!

Finding a Least- Cost Path b 2 3 1 a d 2 c 3 8 2 e 9 8 2 GOAL 2 f START 1 p 4 15 q 4 h r 2 BFS finds the shortest path in terms of number of acaons. It does not find the least- cost path. We will now cover a similar algorithm which does find the least- cost path.

Uniform Cost Search

Uniform Cost Search Strategy: expand a cheapest node first: Frontier is a priority queue (priority: cumulative cost) b 3 S 1 2 p 1 a d 15 8 9 q 2 c h e 8 2 r f G 2 1 S 0 d 3 e 9 p 1 b 4 c 11 e 5 h 17 r 11 q 16 Cost contours a 6 a h 13 r 7 p q f p q f 8 q c G q 11 c G a 10 a

Uniform Cost Search (UCS) ProperAes What nodes does UCS expand? Processes all nodes with cost less than cheapest soluaon! If that soluaon costs C* and arcs cost at least ε, then the effecave depth is roughly C*/ε Takes Ame O(b C*/ε ) (exponenaal in effecave depth) C*/ε tiers b c 1 c 2 c 3 How much space does the fronaer take? Has roughly the last Aer, so O(b C*/ε ) Is it complete? Assuming best soluaon has a finite cost and minimum arc cost is posiave, yes! Is it opamal? Yes! (Proof next lecture via A*)

Uniform Cost Issues Remember: UCS explores increasing cost contours The good: UCS is complete and opamal! c 1 c 2 c 3 The bad: Explores opaons in every direcaon No informaaon about goal locaaon Start Goal We ll fix that soon!

Video of Demo Empty UCS

Video of Demo Maze with Deep/Shallow Water - - - DFS, BFS, or UCS? (part 1)

Video of Demo Maze with Deep/Shallow Water - - - DFS, BFS, or UCS? (part 2)

Video of Demo Maze with Deep/Shallow Water - - - DFS, BFS, or UCS? (part 3)

Tree Search vs Graph Search

Tree Search: Extra Work! Failure to detect repeated states can cause exponenaally more work. State Graph Search Tree O(2 m ) O(m)

Tree Search: Extra Work! Failure to detect repeated states can cause exponenaally more work. State Graph Search Tree O(2m 2 ) O(4 m ) m=20: 800 states 1,099,511,627,776 tree nodes

General Tree Search function TREE-SEARCH(problem) returns a solution, or failure initialize the frontier using the initial state of problem loop do if the frontier is empty then return failure choose a leaf node and remove it from the frontier if the node contains a goal state then return the corresponding solution expand the chosen node, adding each child to the frontier

General Graph Search function GRAPH-SEARCH(problem) returns a solution, or failure initialize the frontier using the initial state of problem initialize the explored set to be empty loop do if the frontier is empty then return failure choose a leaf node and remove it from the frontier if the node contains a goal state then return the corresponding solution add the node to the explored set expand the chosen node, adding each child to the frontier but only if the child is not already in the frontier or explored set Theorem: each state appears at most once in the search tree constructed

Tree Search vs Graph Search Graph search Avoids infinite loops: m is finite in a finite state space Eliminates exponenaally many redundant paths Requires memory proporaonal to its runame!

Search Gone Wrong?