Uninformed search Lirong Xia Todays schedule Rational agents - - PowerPoint PPT Presentation

uninformed search
SMART_READER_LITE
LIVE PREVIEW

Uninformed search Lirong Xia Todays schedule Rational agents - - PowerPoint PPT Presentation

Uninformed search Lirong Xia Todays schedule Rational agents Search problems State space graph: modeling the problem Search trees: scratch paper for solution Uninformed search Depth first search (DFS) algorithm


slide-1
SLIDE 1

Lirong Xia

Uninformed search

slide-2
SLIDE 2

ØRational agents ØSearch problems

  • State space graph: modeling the problem
  • Search trees: scratch paper for solution

ØUninformed search

  • Depth first search (DFS) algorithm
  • Breadth first search (BFS) algorithm

2

Today’s schedule

slide-3
SLIDE 3

ØYou entered a maze in darkness ØNo map but you build one as you explore ØLimited sight, only know which direction does not have a wall

  • know nothing about enemies, traps, etc.
  • you only see the exit when you step on it

ØGoal: write a walkthrough to minimize the cost of reaching the next level ØHow would you do it?

3

Example 0: Roguelike game

slide-4
SLIDE 4

ØAn agent is an entity that perceives and acts. ØA rational agent selects actions that maximize its utility function. ØCharacteristics of the percepts, environment, and action space dictate techniques for selecting rational actions.

Rational Agents

4

Environment Agent

Sensors Actuators Actions Percepts

slide-5
SLIDE 5

Example 1: Pacman as an Agent

5

Environment

?

Agent

Sensors Actuators Percepts Actions

slide-6
SLIDE 6

6

When goal = search for something (no cost yet)

slide-7
SLIDE 7

Search Problems

7

ØA search problem consists of:

  • A state space
  • A successor function

(with actions, costs)

  • A start state and a goal test

ØA solution is a sequence of actions (a plan) which transforms the start state to a goal state

. . .

(E, 1)

. . .

(N, 1)

slide-8
SLIDE 8

ØA directed weighted graph of all states

  • aàb: b is a successor of a
  • weight(aàb): the cost of traveling from a to b
  • Note: just for analysis, usually the state space

graph is not fully built

8

State space graph: modeling the problem

. . .

Start Goal (N, 1) (S, 1) (E, 1) (W, 1) (E, 1)

slide-9
SLIDE 9

What’s in a State Space?

9

A search state keeps only the details needed (abstraction) The world state specifies every last detail of the environment

  • Problem: Pathing
  • States: (x,y) location
  • Actions: NSEW
  • Successor: adjacent

locations

  • Goal test: is (x,y) = END
  • Problem: Eat-All-Dots
  • States: {(x,y), dot booleans}
  • Actions: NSEW
  • Successor: updated

location and dot booleans

  • Goal test: dots all false
slide-10
SLIDE 10

State Space Sizes?

10

Ø World state:

  • Agent positions: 120
  • Food count: 30
  • Ghost positions: 12
  • Agent facing: NSEW

Ø How many

  • World states?

120×230×122×4

  • States for pathing?

120

  • States for eat-all-dots?

120×230

slide-11
SLIDE 11

Search Trees: scratch paper for solution

11

  • A search tree:
  • Start state at the root node
  • Children correspond to successors
  • Nodes contain states, correspond to PLANS to those states
  • For most problems, we can never actually build the whole

tree

slide-12
SLIDE 12

Space graph vs. search tree

12

  • Nodes in state space graphs are problem states:
  • Represent an abstracted state of the world
  • Have successors, can be goal/non-goal, have multiple predecessors
  • Nodes in search trees are plans
  • Represent a plan (sequence of actions) which results in the node’s state
  • Have a problem state and one parent, a path length, a depth and a cost
  • The same problem state may be achieved by multiple search tree nodes

Problem States Search Nodes

slide-13
SLIDE 13

Uninformed search

ØUninformed search: given a state, we only know whether it is a goal state or not

  • Cannot say one non-goal state looks better than another

non-goal state

  • Can only traverse state space blindly in hope of

somehow hitting a goal state at some point

ØAlso called blind search

  • Blind does not imply unsystematic!
slide-14
SLIDE 14

Breadth-first search (search tree)

slide-15
SLIDE 15

Ø Never expand a node whose state has been visited Ø Fringe can be maintained as a First-In-First-Out (FIFO) queue (class Queue in util.py) Ø Maintain a set of visited states

Ø fringe := {node corresponding to initial state} Ø loop:

  • if fringe empty, declare failure
  • choose and remove the top node v from fringe
  • check if v’s state s is a goal state; if so, declare success
  • if v’s state has been visited before, skip
  • if not, expand v, insert resulting nodes into fringe

Ø This is the BFS you should implement in project 1

15

BFS

slide-16
SLIDE 16

Properties of breadth-first search

Ø May expand more nodes than necessary Ø BFS is complete: if a solution exists, one will be found Ø BFS finds a shallowest solution

  • Not necessarily an optimal solution if the cost is non-uniform

Ø If every node has b successors (the branching factor), shallowest solution is at depth d, then fringe size will be at least bd at some point

  • This much space (and time) required L
slide-17
SLIDE 17

Depth-first search

slide-18
SLIDE 18

Properties of depth-first search

ØNot complete (might cycle through non-goal states) ØIf solution found, generally not optimal/shallowest ØIf every node has b successors (the branching factor), and we search to at most depth m, fringe is at most bm

  • Much better space requirement J
  • Saves even more space by recursion

ØTime: still need to check every node

  • bm + bm-1 + … + 1 (for b>1, O(bm))
  • Inevitable for uninformed search methods…
slide-19
SLIDE 19

ØNever add a visited state to the fringe ØThis version of DFS is complete (avoid cycling) ØSpace requirement can be as bad as BFS

19

If we keep a set of visited stages

slide-20
SLIDE 20

Ø Never expand a node whose state has been visited Ø Fringe can be maintained as a Last-In-First-Out (LIFO) queue (class Stack in util.py) Ø Maintain a set of visited states

Ø fringe := {node corresponding to initial state} Ø loop:

  • if fringe empty, declare failure
  • choose and remove the top node v from fringe
  • check if v’s state s is a goal state; if so, declare success
  • if v’s state has been visited before, skip
  • if not, expand v, insert resulting nodes into fringe

Ø This is the DFS you should implement in project 1

20

DFS

slide-21
SLIDE 21

ØRead the instructions on course website and the comments in search.py first ØQ1: DFS

  • LIFO

ØQ2: BFS

  • FIFO

ØDue in two weeks (Feb 3) ØCheck util.py for LIFO and FIFO implementation ØUse piazza for Q/A

21

You can start to work on Project 1 now

slide-22
SLIDE 22

Ø The auto-grader is very strict

  • 0 point for expanding more-than-needed states
  • no partial credit

Ø Hint 1: do not include print "Start:", problem.getStartState() in your formal submission

  • comment out all debuging commands

Ø Hint 2: remember to check if a state has been visited before Ø Hint 3: return a path from start to goal. You should pass the local test before submission (details and instructions on project 1 website)

22

Dodging the bullets

slide-23
SLIDE 23

State Space Graphs

23

  • State space graph: A

mathematical representation of a search problem

  • For every search problem,

there’s a corresponding state space graph

  • The successor function is

represented by arcs

  • We can rarely build this

graph is memory (so we don’t)

Ridiculously tiny search graph for a tiny search problem

slide-24
SLIDE 24

Example 2: Capital Region

24

  • State space:
  • Cities
  • Successor function:
  • Roads: Go to

adjacent city with cost = dist

  • Start state:
  • Cohoes
  • Goal test:
  • Is state == Delmar
  • Solution?

Cohoes Latham Troy Loudonville Albany Guilderland Rensselaer Delmar

4.4 4 4.1 5.3 3.1 4.3 8 1.5 5.2 8.7

10.7

slide-25
SLIDE 25

Another Search Tree

25

  • Search:
  • Expand out possible plans
  • Maintain a fringe of unexpanded plans
  • Try to expand as few tree nodes as possible

Cohoes Latham Troy Loudonville Troy Loudonville Cohoes Cohoes Latham C La T A La Lo

slide-26
SLIDE 26

State Graphs vs. Search Trees

26

Ø State graphs: a representation of the search problem

  • each node is an abstract of the state of the world

Ø Search tree: a tool that helps us to find the solution

  • each node represents an entire path in the graph
  • tree nodes are constructed on demand and we construct as little as possible

State graph Search trees

slide-27
SLIDE 27

27

Example

Start a b c d e GOAL

slide-28
SLIDE 28

28

Example

Start a b c d e GOAL