Lab: Uninformed Search
CSC261 - Artificial Intelligence - Weinman
- Summary:
- We familiarize ourselves with the interface for search
problems and nodes in preparation for implementing
uninformed search algorithms.
Preparation
- Copy the starter files to a directory for this lab.
-
$ cd somewhere
$ cp -R ~weinman/courses/CSC261/code/search ./
$ cd search
- Create a new Scheme file in your search directory called
search-prep.scm and open it in your Scheme environment. For
example,
-
$ touch search-prep.rkt
$ drracket search-prep.rkt &
Add the remaining preparatory commands (in Exercises, below) to that
file.
Exercises
Eight puzzle, states, and successors
- Set the language and load the relevant files:
-
#lang racket
(require "problem.rkt")
(require "node.rkt")
(require "8puzzle.rkt")
- Create an instance of a problem for the eight puzzle:
-
(define eight-puzzle (eight-puzzle-problem))
Note that eight-puzzle-problem is a procedure. It may seem
silly to call this with no parameters, since it will always give the
same result. However, other problems may be parameterized (requiring
a procedure to generate the problem), so we've made this generator
a procedure as well, for structural parallelism.
- Because we won't be needing any heuristics for this assignment, let's
define the always-zero function mentioned in the assignment
-
(define zero-fun (lambda (x) 0))
Despite the name, we hope you don't find this lab to be zero fun.
- Create a random state for your eight puzzle problem involving only
three moves
-
(define eight-puzzle-state (random-eight-puzzle-state 3))
- Display a visualization of this board, akin to that found in AIMA
Figure 3.4 (p. 71).
-
> (display (eight-puzzle-state-board-list eight-puzzle-state))
Note that the three rows may be collapsed onto one line.
- Can you determine the moves necessary to solve the puzzle?
- Create a search node for this state. Note that node-init
requires a heuristic procedure, which we can largely ignore for now
by using the form given above
-
(define eight-puzzle-start-node (node-init eight-puzzle-state zero-fun))
- Generate the list of successors (resulting nodes) for your state.
-
(define successors
(problem-expand-node eight-puzzle
eight-puzzle-start-node
zero-fun))
- Examine the list of actions corresponding to each successor.
-
> (map node-action successors)
These symbols indicate the direction the blank tile would be moved.
- Examine the first resulting successor state. (Remember
a node is distinct from a state!)
-
> (display (eight-puzzle-state-board-list
(node-state (car successors))))
Note that the example above gives you the "pretty" visualization
of the state, not its raw representation (as used by the internal
eight-puzzle problem procedures).
- Test whether the state of the first successor node is the goal state
by applying the procedure returned by (problem-goal? eight-puzzle)
to it. Note that problem-goal? returns a goal predicate
for the given problem; it is not a predicate itself.
- Write an expression using map and node-state to
generate a list of "pretty" versions of the successor states.
You may create an anonymous procedure with lambda or use
compose.
Search routines
- Open search.scm and read the 6-P documentation for search.
You will be implementing this procedure as a Scheme version of TREE-SEARCH
as desribed in the lab. If you do not understand any of the 6-Ps,
discuss them with your partner or the instructor.
- Read the 6-P documentation for depth-first-search. Explain
to your partner why the enqueing procedure
-
(lambda (new-nodes frontier) (append new-nodes frontier))
makes search behave in a depth-first fashion.
- Read the 6-P documentation for uniform-cost-search. Study
the enqueueing routine and convince yourself that the "POP"
instruction of the search procedure will always produce the
node in the frontier with the lowest path cost.
Lab Assignment
Between this lab and snippets in the assignment document, you now
have all the pieces necessary to implement tree search! Proceed to
begin the lab's assignment.
Copyright © 2011, 2013, 2015, 2018, 2020 Jerod
Weinman.
This work is licensed under a Creative
Commons Attribution-Noncommercial-Share Alike 4.0 International License.