Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Artificial Intelligence Problem Solving Ruth Bergman Fall 2002.

Similar presentations


Presentation on theme: "Introduction to Artificial Intelligence Problem Solving Ruth Bergman Fall 2002."— Presentation transcript:

1 Introduction to Artificial Intelligence Problem Solving Ruth Bergman Fall 2002

2 Problem Solving Missionaries & Cannibals There 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?

3 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

4 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

5 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!

6 Problem Formulation Define the state space S initial state, S i S Define operators on states succ: S 2 S A goal set S f S A path cost, usually by assigning a cost to each action Missionaries & Canibals S = {S i } S k = M L = {0, 1, 2, 3} C L = {0, 1, 2, 3} B = {L, R} S i = S f = O = {o m,o c,o mc,o mm, o cc } O m : one missionary, o c : one cannibal o mc: : missionary and cannibal, etc.

7 Operator Definition

8 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) … ))))

9 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)))

10 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))…)

11 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

12 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

13 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 54 618 732 123 84 765

14 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 (64 8 states) legal arrangement of queens (2057 sequences) Any arrangement of 8 queens in separate column (8 8 states)

15 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.

16 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

17 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.

18 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 SibiuTimisoaraZerind Arad SibiuTimisoaraZerind SibiuTimisoaraOradea Rimnicu Vilcea goal test choosing one option Which node to expand? Which nodes to store in memory?

19 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


Download ppt "Introduction to Artificial Intelligence Problem Solving Ruth Bergman Fall 2002."

Similar presentations


Ads by Google