CSE 150 – Introduction to Artificial Intelligence

advertisement
CSE 150 – Introduction to Artificial Intelligence
Week 1 –Discussion Notes
September 27, 2004
1.)
2.)
3.)
4.)
5.)
Introduction to CSE 150 Discussion
Search Problem Formulation
The General Search Algorithm
Uninformed Search Algorithms: BFS and DFS
Formulating the Missionaries-and-Cannibals problem
1.) Introduction to CSE 150 Discussion Section
The CSE 150 discussion section meets twice a week:
- Wednesday from 3:00pm to 3:50pm in HSS 1330
- Friday from 12:00pm-12:50pm in CSB 004
We will cover topics that related to both Prof. Elkan’s Lectures and the course
programming assignments. It is important that you attend one of the discussion sections,
but they will cover the same material so you need not attend both.
Doug Turnbull will organize the discussion sections. My office hours are will be:
- Tuesday from 11am-12:00pm in EBU-1 6307C
- Thursday from 2:00pm to 3:00pm in EBU-1 6307C
You can always email me at dturnbul@cs.ucsd.edu to arrange a time to receive addition
help.
The two web resources for the course are:
- Prof. Elkan’s CSE 150 Website (http://www-cse.ucsd.edu/%7Eelkan/150/).
This is where you can find course announcements, lecture notes, and
programming assignments.
- Webct Web Portal (webct.ucsd.edu). This site contains the discussion boards
and grade-reporting interface. If you cannot log in, contact Academic
Computing Services (ACS).
Please check both sites frequently.
2.) Search Problem Formulation
The AI first topic covered in this course is “Solving Problems by Searching.” The main
example throughout chapter 3 and 4 of Russell and Norvig’s Artificial Intelligence: A
Modern Approach (AIMA) involves finding a route from Arad to city with an
international airport. The following figure is a simplified version of Figure 3.2 on page 66
of AIMA.
Initial State
O
A
A Goal State
F
S
B
R
C
P
Figure1: Romanian Airport Problem Search Graph
Our state space is the set of Romanian cities. They are represented by letters in our
graph. (The graph is sometimes called a “state diagram”.) Our initial state is Arad, which
is denoted by “A”. The goal description is any city with an international airport. The
only city that fits this description is Bucharest. Thus “B” is a valid goal state and denoted
by a double circle. (Note that there is only one initial state, but there maybe one or more
goal states.)
The operators, or actions, we consider involve moving from our current state to an
adjacent state. For example, if we are in A, our potential operators are moving to O, S or
C.
A search is the process of imagining sequences of operators applied to the initial state
and checking to see if we have reached a goal state. A specific set of operators is called a
search path. Three possible search paths are A-S-R-P-B or A-S-O-A-C-R-P-B or A-S-OA-S-O-A. Note that the third search path never finds a state that matches the goal
description.
We can represent multiple potential search paths with a search tree. Although the search
tree may look like the search graph, it is very different. First, each node in the search tree
contains one of the states of the search graph. Note that multiple nodes can contain the
same state. In addition, a node can contain additional information such as the parent node
information. Second, the search tree is a directed graph whereas the search graph is
undirected. There can thus be cycles in a search graph but no cycles in a search tree.
A
S
R
O
P
A
B
S
O
A
C
R
P
B
Figure 2: Example of Search Tree for Romanian Airport Problem
3.) The General Search Algorithm
In the previous section, we introduced search graphs as a representation of a search
problem. We also introduced search trees as a representation of multiple search paths
along a search graph. Now we need to translate these abstract concepts into concrete
pseudo-code.
In class, Prof. Elkan described the general search algorithm. (Whenever I see pseudocode in class notes, I tend to gloss over it. In this particular case, glossing over the
following pseudo-code will make understanding the course material and completing
assignment 1 very hard. It is very important that you UNDERSTAND THIS CODE!)
This code can also be found in Figure 3.7 on page 70 of AIMA.
General Search Algorithm:
input:
a properly formulated search problem
a function "insert" to place new nodes into a queue
1 fringe := make-queue(initial-node)
2 loop
3
if empty?(fringe) then return FAIL
4
else
5
X := remove-front(fringe)
6
if satisfies-goal(state(X)) then return X
7
else
8
fringe := insert(fringe,expand(X))
9 end loop
Figure 3: Pseudo-code for General Search Algorithm
The “queue” is the main data structure created and manipulated by this algorithm. The
term “queue” is generic and can be implemented by First-In-First-Out (FIFO) queue, a
Last-In-First-Out (LIFO) stack, or a priority queue. (A priority queue is simply a sorted
list of nodes. Next week we will discuss priority queues in detail.)
In line 1, we initialize our queue with a node containing the initial state. We then loop
over the following:
2. If we have no more nodes to explore, our search is a failure
5. If not, we explore the next node.
6. If that node contains a state that fits the goal description, we return our solution
8. Otherwise we consider all possible actions from our current state.
This algorithm is intuitive. We will be discussing a number of algorithms that reuse the
same code. All that differs is the type of queue.
4.) Uninformed Search Algorithms: BFS and DFS
Section 3.4 in AIMA covers a number of “uninformed” search algorithms. The term
“uninformed” may be hard to define until next weeks lectures when we cover “informed”
search algorithms, which make use of “heuristic” functions, or additional information, to
guide our decisions about what actions to take. If you want to know more, read section
4.1 in AMIA.
The two main “uninformed” search algorithms of interest are Breadth-First Search (BFS)
or Depth-First Search (DFS). They both use the pseudo-code described in the previous
section. One is implemented with a FIFO queue and one is implement with a LIFO stack.
Your job is to figure out which search goes with type of queue/stack. (Simply
memorizing the relationship is constitutes rote memorization. You must be able to
conceptualize the general search algorithm with different queue implementations.)
The best way to learn how BFS and DFS work is to go over a concrete example. We will
do an example of both on the board the Week 1 Discussion Section. If you missed it,
there is an example of BFS on page74 and an example of DFS on page 76. Otherwise
come find me during office hours.
5.) Formulating the Missionaries-and-Cannibals Problem
Often, the hardest part of solving a search problem is formulating the problem. The third
problem on Assignment 1 is to solve the famous Missionaries-and-Cannibals (MC)
problem. The problem is described in question 3.9 on page 90:
Three Missionaries (M) and three Cannibals(C) are on one side of a river, along with a boat that can
hold one or two people. Find a way to get to get every to the other side, without leaving a group of
missionaries in one place outnumbered by the cannibals in that place.
M
C
M
C
M
C
West Shore
Boat
East Shore
Figure 4: Missionaries and Cannibals (MC) Problem Representation
Unlike that Romanian Airport Problem we introduced in section 2, it is not obvious how
this problem is related to search problems. However, we the first thing we can notice is
that we are given an initial state: three missionaries and three cannibals start one shore of
a river. Since the side does matter, we will say that the all begin on the west shore. We
will denote our initial state by:
{West{3M, 3C}, Boat{West}, East{0M, 0C}}
However, this notation is a little cumbersome. We can simplify the notation if we note
that the total number of missionaries and cannibals on both shores is always three. Thus
we reduce our notation by not including how many people are on the East shore since this
number can always be calculated by subtracting the number of missionaries or cannibals
on the West Shore by three. We can also designate our boat by W or E since in must be
on one side or the other. That is, we need not worry about when the boat is crossing the
river. Our new notation for the initial state becomes:
{3M, 3C, W}
Let’s consider the possible actions from any state. There are five possible actions:
1. One Missionary moves to the East Shore
2.
3.
4.
5.
Two Missionaries move to the East Shore
One Cannibal moves to the East Shore
Two Cannibals move to the East Shore
One Cannibal and one Missionary move to the East Shore
The two important things to note are that the each action results in a boat movement and
there are at most five actions. Note that, starting from the initial state, 2 of the the 5
action violate the constraints of the problem. That is, if we choose actions 1 or 2, the
missionaries on the West Shore will be outnumbered.
{3M, 3C, W}
{2M, 3C, E}
{1M, 3C, E}
{3M, 2C,E}
{3M, 1C, E}
{2M, 2C, E}
The above figure represents an incomplete search graph. It is NOT a search tree. We
know this because it undirected. It is “incomplete” since we have only expanded the
initial state. Your program will have to expand nodes until a node with a state that
satisfies the goal description is found. (Hint: The goal description is when all the people
are on the East Shore. What is a state that satisfies this description?)
Download