Artificial Intelligence: Tutorial 2 Solutions State Space Search and Strategies

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

TRNG I HC BCH KHOA TP.

HCM Khoa Khoa hc & K thut My tnh

ARTIFICIAL INTELLIGENCE
Tutorial 2 Solutions STATE SPACE SEARCH AND STRATEGIES
Question 1.

Figure 1 A road map of Romania Figure 1 gives a simplified road map of Romania. Find a path from Bucharest to Timisoara using Depth-First-Search and Breadth-First-Search. Assume that when performing the traversal, the cities will be considered in counter-alphabetical order when in the same level. Solution: DFS:
Bucharest -> Urzicenl -> Vasiul -> Iasi -> Neamt Bucharest -> Urzicenl -> Hirsova -> Eforie Bucharest -> Pitesti -> Rimnicu Vilcea -> Sibiu -> Oradea -> Zerind -> Arad -> Timisoara

BFS:
Bucharest -> Urzicenl Bucharest -> Pitesti

TRNG I HC BCH KHOA TP.HCM Khoa Khoa hc & K thut My tnh


Bucharest -> Glurgiu Bucharest -> Fagaras Bucharest -> Urzicenl -> Vasiul Bucharest -> Urzicenl -> Hirsova Bucharest -> Pitesti -> Rimnicu Vilcea Bucharest -> Pitesti -> Craiova Bucharest -> Fagaras -> Sibiu Bucharest -> Urzicenl -> Vasiul -> Iasi Bucharest -> Urzicenl -> Hirsova -> Eforie Bucharest -> Pitesti -> Rimnicu Vilcea -> Sibiu Bucharest -> Pitesti -> Rimnicu Vilcea -> Craiova Bucharest -> Pitesti -> Craiova -> Rimnicu Vilcea Bucharest -> Pitesti -> Craiova -> Dobreta Bucharest -> Fagaras -> Sibiu -> Rimnicu Vilcea Bucharest -> Fagaras -> Sibiu -> Oradea Bucharest -> Fagaras -> Sibiu -> Arad Bucharest -> Urzicenl -> Vasiul -> Iasi -> Neamt Bucharest -> Pitesti -> Rimnicu Vilcea -> Sibiu -> Oradea Bucharest -> Pitesti -> Rimnicu Vilcea -> Sibiu -> Fagaras Bucharest -> Pitesti -> Rimnicu Vilcea -> Sibiu -> Arad Bucharest -> Pitesti -> Rimnicu Vilcea -> Craiova -> Dobreta Bucharest -> Pitesti -> Craiova -> Rimnicu Vilcea -> Sibiu Bucharest -> Pitesti -> Craiova -> Dobreta -> Mehadia Bucharest -> Fagaras -> Sibiu -> Rimnicu Vilcea -> Pitesti Bucharest -> Fagaras -> Sibiu -> Rimnicu Vilcea -> Craiova Bucharest -> Fagaras -> Sibiu -> Oradea -> Zerind Bucharest -> Fagaras -> Sibiu -> Arad -> Zerind Bucharest -> Fagaras -> Sibiu -> Arad -> Timisoara

Question 2. For each of the following problems, specify (i) a representation for a state; (ii) the start and goal states and (iii) the operators, each of which is followed by an example. Example problem: The water-jug problem in the lecture notes. State representation: a pair (x,y) where x and y are respectively the amounts of water in 4-litre and 3-litre jugs. Start state: (0,0) Goal state: (2,n) 0<=n<=3 Operators: - Fill up the first jug: (2,2) (4,2) - Fill up the second jug: (2,2) (2,3) - Empty the first jug: (2,2) (0,2) 2

TRNG I HC BCH KHOA TP.HCM Khoa Khoa hc & K thut My tnh - Empty the second jug: (2,2) (2,0) - Fill up the first jug by the water in the second one: (2,3) - Fill up the second jug by the water in the first one: (2,1) - Empty the first jug to the second one: (1,1) (0,2) - Empty the second jug to the first one: (2,1) (3,0)

(4,1) (0,3)

a. The 8-puzzle problem: The 8-puzzle is a small board game for a single player; it consists of 8 square tiles numbered 1 through 8 and one blank space on a 3 x 3 board, as depicted in left board in Figure 2. Moves of the puzzle are made by sliding an adjacent tile into the position occupied by the blank space, which has the effect of exchanging the positions of the tile and blank space. Only tiles that are horizontally or vertically adjacent (not diagonally adjacent) may be moved into the blank space. The object is to reach the configuration in the right board of Figure 2.

Figure 2 An instance of the 8-puzzle problem Give all states that can be generated from the left board in Figure 2. b. The 8-queens problem: The eight-queens puzzle is the problem of putting eight chess queens on an 88 chessboard such that none of them is able to capture any other using the standard chess queen's moves. Figure 3 depicts one solution.

Figure 3 An example solution for the 8-queens problem c. The missionaries and cannibals problem: Three cannibals and three missionaries must cross a river from the bank to the right one. Their boat can only hold two people. If 3

TRNG I HC BCH KHOA TP.HCM Khoa Khoa hc & K thut My tnh the cannibals outnumber the missionaries, on either side of the river, the missionaries are in trouble. How can all six get across the river? Illustrate the state space (up to 3 levels) in which the duplicated states are eliminated. Solution: a. State representation: a 9-digit series corresponding to current configuration of the board in the left-to-right and top-to-bottom manner, 0 represents the blank. For example, the setting in Figure 2 can be represented as 540618732. Start state: 540618732 Goal state: 123804765 Operators: - Move the tile up: 123804765 123864705 - Move the tile down: 123804765 103824765 - Move the tile left: 123804765 123840765 - Move the tile right: 123804765 123084765 540618732 {504618732; 548610732}

b. State representation: a 2-D array representing an arrangement of 8 queens, one in each column. For example: (O for blank, X for queen) XOOOOOOO OOOOXOOO OXOOOOOO OOOOOXOO OOXOOOOO OOOXOOOO OOOOOOXO OOOOOOOX Start state: Any state satisfies the state representation above. Goal state: An arrangement of 8 queens such that none of them is able to capture any others. Operator: move any attacked queen to another square in the same column. XOOOOOOO XOOOOOOO OOOOXOOO OOOOXOOO OXOOOOOO OXOOOOOO OOOOOXOO OOOOOXOO OOXOOOOO OOXOOOOO OOOOOOOO OOOOOOXO OOOXOOXO OOOXOOOO OOOOOOOX OOOOOOOX

TRNG I HC BCH KHOA TP.HCM Khoa Khoa hc & K thut My tnh c. State representation: a triple (x,y,z) where x and y are respectively the numbers of missionaries and cannibals remaining in the left bank (0 <= x, y <= 3; x, y N); z is 0 if the boat is currently at the left bank, otherwise z is 1. Start state: (3,3,0) Goal state: (0,0,1) Operators: - Two missionaries cross the river: (3,1,0) (1,1,1) - One missionary crosses the river: (0,1,1) (1,1,0) - Two cannibals cross the river: (3,3,0) (3,1,1) - One cannibal crosses the river: (3,1,1) (3,2,0) - One missionary and one cannibal cross the river: (2,2,1) (3,3,0) State space (only two levels)

Question 3. Analyze each of three problems in Question 2 with respect to the seven problem characteristics discussed in Chapter 2. Solution: a. The 8-puzzle problem: Is the problem decomposable? No Can solution steps be ignored or undone? Can be undone Is the universe predictable? Yes Is a good solution absolute or relative? Absolute Is the solution a state or a path? A path What is the role of knowledge? Very little (just the rules for determining legal moves, constrain the search and speed up the execution of the program) Does the task require human-interaction? No

TRNG I HC BCH KHOA TP.HCM Khoa Khoa hc & K thut My tnh b. The 8-queens problem: Is the problem decomposable? No Can solution steps be ignored or undone? Can be undone Is the universe predictable? Yes Is a good solution absolute or relative? Absolute Is the solution a state or a path? A state What is the role of knowledge? Very little (just the rules for determining legal moves, constrain the search and speed up the execution of the program) Does the task require human-interaction? No

c. The missionaries and cannibals problem: Is the problem decomposable? No Can solution steps be ignored or undone? Can be undone Is the universe predictable? Yes Is a good solution absolute or relative? Absolute Is the solution a state or a path? A path What is the role of knowledge? Very little (just the rules for determining legal moves, constrain the search and speed up the execution of the program) Does the task require human-interaction? No -- End --

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy