Introduction to Artificial Intelligence Problem Solving Ruth Bergman Fall 2002.
-
date post
20-Dec-2015 -
Category
Documents
-
view
219 -
download
2
Transcript of Introduction to Artificial Intelligence Problem Solving Ruth Bergman Fall 2002.
Introduction to Artificial Intelligence
Problem Solving
Ruth Bergman
Fall 2002
Problem Solving
Missionaries & CannibalsThere are three missionaries and three cannibals on the
left bank of a river. There is a boat on the left bank that can hold no more than two people. The missionaries wish to cross to the right bank. But they have a problem: If on either bank the cannibals ever outnumber the missionaries, the outnumbered missionaries will be eaten.
Question: Is there a way for the missionaries to get their wish--to get to the right bank without losing anyone?
Problem-Solving Agents
• Problem-Solving Agents– one kind of goal-based agent– finding sequences of actions that lead to desirable
states.
• Steps– Goal Formulation
• limiting the objectives
– Problem Formulation• deciding what actions and states to consider
– Search• looking for the possible action sequence
– Execution
State Space Representation
• A node in the graph is a state• An arc from A to B in the graph implies there is an operator that
agent can perform that will transition from state A to state B.
initial goal
Solving problems by searching in the state
space• Find the lowest cost path from the initial state to the
goal state in the given state space using the available operators.
Graph not accurate!
Problem Formulation
• Define the state space S• initial state, Si S• Define operators on states
succ: S 2S • A goal set Sf S• A path cost, usually by
assigning a cost to each action
Missionaries & Canibals
S = {Si}
Sk = <ML, CL, B>
ML = {0, 1, 2, 3}
CL = {0, 1, 2, 3}
B = {L, R}
Si = <3, 3, W>
Sf = <0, 0, E>
O = {om,oc,omc,omm, occ}
Om: one missionary,
oc : one cannibal
omc:: missionary and cannibal, etc.
)}(,|,{:cos 2121 SsuccSSSSSt
Operator Definition
..
0,,1,1),,(
..)0(
&3,,1
),,(
..)3(
&0,,1
),,(
wo
cmRcmLcmO
wocm
mLcm
RcmO
wocm
mRcm
LcmO
LLLLLLmc
LL
LLL
LLm
LL
LLL
LLm
Lisp Solution for Missionaries & Cannibals
(defun is-goal (s)
(and (= (first s) 0)
(= (second s) 0)
(eq (third s) 'right)))
;; state (m c p par) (defun illegal-state (s)
(let* ((m1 (first s))
(m2 (- 3 m1))
(c1 (second s))
(c2 (- 3 c1)))
(or (and (> c1 m1) (> m1 0))
(and (> c2 m2) (> m2 0))
(< c1 0)
(< m1 0)
(< c2 0)
… ))))
Lisp Solution cont.
(defun next-states (s)
(let* ((m (first s)) (c (second s)) (p (third s))
(possibilities (if (eq p 'left)
(list (list m (- c 2) 'right s)
(list (- m 1) (- c 1) 'right s)
(list (- m 2) c 'right s)
(list m (- c 1) 'right s)
(list (- m 1) c 'right s))
(list … similar for right… ))))
(remove-if #'illegal-state possibilities)))
Lisp Solution cont.
(defun mc-search (start-state)
(let ((queue (list start-state)) (*NODES* 0))
(loop while (not (null queue)) do
(let ((s (pop queue)))
(if (not (examinedp s))
(progn
(incf *NODES*)
(when (= *NODES* 1000) (return))
(push s *examined*)
(if (is-goal s)
(printout s))
(setf queue (append queue (next-states s))…)
Road map of Romania
Oradea
Zerind
Arad
Sibiu Fagaras
Rimnicu Vilcea
Pitesti
Timisoara
Lugoj
Mehadia
Dobreta Craiova
Neamt Iasi
Vaslui
Urziceni
Bucharest
Giurgiu
Hirsova
Eforie
Road map of Romania
• Situation– On holiday in Romania: currently in Arad.– Flight leaves tomorrow from Bucharest.
• Formulate goal:– be in Bucharest
• Formulate problem:– initial state: be in Arad– state: various cities– operators: driving between cities
• Find solution:– sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
The 8-puzzle
• problem formulation– State : the location of each of the eight tiles in one of the
nine squares– Operators: blank moves left, right, up, or down– Goal test: state matches the right figure– Path cost: each step costs 1, that is the length of the path
5 46 1 87 3 2
1 2 38 47 6 5
The 8-queens problem
• problem formulation– State : any arrangement of 0 to 8 queens on board– Operators: add a queen to any square– Goal test: 8 queens on board, none attacked– Path cost: zero
• problem formulations are often not cut and dried – 8 queens alternatives
• any arrangement of queens (648 states) • legal arrangement of queens (2057 sequences) • Any arrangement of 8 queens in separate column (88 states)
Cryptarithmetic
• problem formulation– State : a cryptarithmetic puzzle with some letters replaced
by digits– Operators: replace all occurrences of a letter with a digit not
already appearing in the puzzle– Goal test: puzzle contains only digits, and represents a
correct sum– Path cost: zero
MARS Each of the ten letters (m, a, r, s, v, e, + VENUS n, u, t, and p) represents a unique number + URANUS in the range 0 .. 9. + SATURN------------ NEPTUNE Solution: NEPTUNE = 1078610 M=4, A=5, R=9, etc.
WEB Search
• Given the Technion home page, a predicate one WEB pages that returns TRUE only if the page is the home page for an Artificial Intelligence course. Find this course’s home page.
problem formulation
–State : WEB page
–Operators: follow a link from the current page
–Goal test: this course’s WEB page
–Path cost: zero
State Space Search vs. Graph Search
• The state space + operators define a directed graph• The solution to the problem is a path in the graph
from the initial state to the goal state• Can we use search algorithms from graph theory?• The graph is implicit. The agent must use operators
to explore the space.• Graph theory algorithms assume an explicit
representation.• Graph theory algorithm often mark states, which may
not be practical in large search spaces.
Searching for Solutions
• Partial search tree for route finding from Arad to Bucharest.
Arad(a) The initial state (search node)
(b) After expanding Arad
(c) After expanding Sibiu
Arad
Sibiu Timisoara Zerind
Arad
Sibiu Timisoara Zerind
Sibiu Timisoara OradeaRimnicu Vilcea
goal test
choosing one option
• Which node to expand?• Which nodes to store in memory?
Measuring Problem-Solving Performance
• Effectiveness of a search– Does it find a solution at all?– Is it a good solution (one with low path cost)?– What is the search cost associated with the time
and memory required to find a solution?– computation time– # nodes opened during search– # nodes discovered during search– # nodes in working memory (this is often the limiting factor
in search)
• total cost = path cost + search cost