artificial intelligence - noppa · hill-climbing is a search algorithm that proceeds like...

12
Artificial Intelligence Exercises & Solutions Chapters 3-4: Search methods 1. Defining a search problem You want to design a search algorithm for finding person B in a social media network who has the most similar music taste to person A. First you have to define the problem formally. What kind of initial state, successor function, goal test and path cost there might be? The algorithm can access each person's details only through other people who are connected to her/him. 2. Search efficiency a) Use a depth-first search to find B in the following search tree: b) Compute the number of operations required for finding B. Opening a node is considered an operation. A E C D D G C B G B G B

Upload: vuongdang

Post on 20-Mar-2019

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Artificial Intelligence - Noppa · Hill-climbing is a search algorithm that proceeds like depth-first search but so that the search order of the nodes is determined by the estimated

Artificial IntelligenceExercises & Solutions

Chapters 3-4: Search methods

1. Defining a search problem

You want to design a search algorithm for finding person B in a social medianetwork who has the most similar music taste to person A. First you have todefine the problem formally. What kind of initial state, successorfunction, goal test and path cost there might be? The algorithm canaccess each person's details only through other people who are connected toher/him.

2. Search efficiency

a) Use a depth-first search to find B in the following search tree:

b) Compute the number of operations required for finding B. Opening a nodeis considered an operation.

A

E C D

D G C

B

G

BG

B

Page 2: Artificial Intelligence - Noppa · Hill-climbing is a search algorithm that proceeds like depth-first search but so that the search order of the nodes is determined by the estimated

3. Search tree

Draw the complete search tree (starting from S and ending at G) of the graph below.The numbers beside the nodes represent the estimated distances from the goalstate. Show how the search procedureproceeds in the tree by using:

depth-first

breadth-first

hill-climbing

beam-search (w=2)

best-first

methods.

4. Search traces

Consider the graph shown in the figure to the right. Wecan search it with a variety of different algorithms,resulting in different search trees. Each of the trees(labelled G1 though G7, next page) was generated bysearching this graph, but with a different algorithm.Assume that children of a node are visited inalphabetical order when no other order is specified bythe search. Each tree shows all the nodes that havebeen seen during search. Numbers next to nodesindicate the relevant “score” used by the algorithm forthose nodes. For each tree, indicate whether it wasgenerated with

Depth first search

Breadth first search

Uniform cost search

A* search

Best-first (greedy) search

In all cases a strict expanded list was used. Furthermore, if you choose an algorithmthat uses a heuristic function, say whether we used

H1: heuristic 1 = {h(A) = 3, h(B) = 6, h(C) = 4, h(D) = 3}

Page 3: Artificial Intelligence - Noppa · Hill-climbing is a search algorithm that proceeds like depth-first search but so that the search order of the nodes is determined by the estimated

H2: heuristic 2 = {h(A) = 3, h(B) = 3, h(C) = 0, h(D) = 2}

Also, for all algorithms, say whether the result was an optimal path (measured bysum of link costs), and if not, why not.

5. Search problem

Consider the 3-puzzle problem, which is a simpler version of the 8-puzzle where theboard is 2 x 2 and there are three tiles, numbered 1, 2, and 3, and one blank. Thereare four operators, which move the blank up, down, left, and right. The start andgoal states are given below. Show how the path to the goal can be found using:

a) breath first searh

b) depth first search

c) A* search with the heuristic being the sum ofnumber of moves and the number of misplaced tiles.

Page 4: Artificial Intelligence - Noppa · Hill-climbing is a search algorithm that proceeds like depth-first search but so that the search order of the nodes is determined by the estimated

Assume that there is no possibility to remember states that have been visitedearlier. Also, use the given operators in the given order unless the search methoddefines otherwise. Label each visited node with a number indicating the order inwhich they are visited. If a search method doesn’t find a solution, explain why thishappened.

Page 5: Artificial Intelligence - Noppa · Hill-climbing is a search algorithm that proceeds like depth-first search but so that the search order of the nodes is determined by the estimated

1. Defining a search problem - solution

Initial state: This is the location in the network database where the search agentstarts. In this case, it is the data structure containing the personal details of theperson A. We could describe it as In(person A).

Successor function: This function returns a set of <action, successor> orderedpairs, where each successor is a state that can be reached from current state. Forexample, from the state In(person A) the successor could return {<Open(person C),In(person C)>, <Open(person D), In(person D)>} if person A is directly connected topersons C and D.

Goal test: This could be the comparison of music tastes by counting the number ofcommon artists, styles, etc. If there are a lot of similarities, it could also be a goodidea to go through the friends of this person. They might have even more similarmusic taste.

Path cost: For example, this could be the number of nodes opened while reachingthe current node from the root node (person A).

2. Search efficiency – solution

a) Depth-first search:

b) Opening sequence is {A, E, C, D, G, B}, so the number of operations is 6.

A

E C D

D G C

B

G

BG

B

Page 6: Artificial Intelligence - Noppa · Hill-climbing is a search algorithm that proceeds like depth-first search but so that the search order of the nodes is determined by the estimated

3. Search Tree – solution

The complete search tree can be generated by finding all possible routes that startfrom the node S and lead to a node that has not yet been visited on the route. Thetree below has been constructed by always choosing the rightmost (from the nodespoint of view) unvisited route. Note that the branches could be in different order ifroutes were selected in different order. The nodes are numbered (1-18) to ease theanalysis of the search methods.

In depth first search method the tree is searched in the depth direction. Thesearch always branches to the leftmost unvisited node. In case a leaf node isfound or there are no more unvisited nodes, the search returns to thepreceding level. In this case, the tree is searched in the order indicated by thenode numbers and is illustrated with the dotted line. If one solution forreaching G was enough, the search would end at the node five. If the wholetree is searched, the best route to G can be selected at the end.

Page 7: Artificial Intelligence - Noppa · Hill-climbing is a search algorithm that proceeds like depth-first search but so that the search order of the nodes is determined by the estimated

Breadth-first search method searches the tree in the breadth direction. In thiscase the nodes are searched in the following order: 1, 2, 10, 3, 4, 7, 11, 15, 5,6, 8, 12, 13, 16, 18, 9, 14 and 17. Again, if one solution was enough, thesearch would end at node 5.

Hill-climbing is a search algorithm that proceeds like depth-first search but sothat the search order of the nodes is determined by the estimated distancefrom a node to the goal node (depth first would choose the leftmost). Whenstarting from the node S, the search sees the estimated distances from thenodes 2 (9) and 10 (8) and chooses the node 10 that is estimated to be closerto the goal. From node 10 the nodes 11 (9) and 15 (5) become visible and thesearch proceeds to node 15. From node 15 the goal node becomes visible andthe search has found a solution. One solution is usually enough for Hill-climbing since it usually finds good solutions. However, the image illustratesthe search of the whole tree to better describe the search.

Page 8: Artificial Intelligence - Noppa · Hill-climbing is a search algorithm that proceeds like depth-first search but so that the search order of the nodes is determined by the estimated

Beam-search proceeds much like breath first, however, at each level only w number of nodes are checked. First, nodes 2 and 10 are opened. At this point five nodes can be seen (3 (10), 4 (5), 7 (8), 11 (9) and 15 (5)). Since only two nodes can be opened, nodes 4 and 15 are selected. After those nodes are opened four more nodes become visible and as the goal node becomes visible (actually twice) the search is completed. The nodes were visited in thefollowing order: 1, 2, 10, 4, 15 and 5.

Best-first search always chooses the best node, independent of where in the tree it is located. At first, the nodes 2 (9) and 10 (8) can be seen and the node 10 is opened. Now, the nodes 2 (9), 11 (9) and 15 (5) can be seen and the node 15 is opened. At this point the nodes nodes 2 (9), 11 (9), 16 (9) and 18 (0) can be seen and as 18 is the goal node, the search is finished.

If one would want to find an alternative route to the goal node, the search would be continued from where the nodes 2 (9), 11 (9), 16 (9) were seen. Now all the nodes have the same distance. If the leftmost node of same

Page 9: Artificial Intelligence - Noppa · Hill-climbing is a search algorithm that proceeds like depth-first search but so that the search order of the nodes is determined by the estimated

valued nodes was opened first the search would continue through nodes 2, 4 and 5. If on the other hand the node that was seen last of the same valued nodes was to be opened first, the search would continue through nodes 16, 11 ,13 and 14.

4. Search traces – solution

G1:

1. Algorithm: Breadth First Search

2. Heuristic (if any): None

3. Did it find least-cost path? If not, why? No. Breadth first search is only guaranteedto find a path with the shortest number of links; it does not consider link cost at all.

G2:

1. Algorithm: Best First Search

2. Heuristic (if any): H1

3. Did it find least-cost path? If not, why?

No. Best first search is not guaranteed to find an optimal path. It takes the first pathto goal it finds.

G3:

1. Algorithm: A*

2. Heuristic (if any): H1

3. Did it find least-cost path? If not, why? No. A* is only guaranteed to find anoptimal path when the heuristic is admissible (or consistent with a strict expandedlist). H1 is neither: the heuristic value for C is not an underestimate of the optimalcost to goal.

G4:

1. Algorithm: Best First Search

2. Heuristic (if any): H2

3. Did it find least-cost path? If not, why? Yes. Though best first search is notguaranteed to find an optimal path, in this case it did

G5:

1. Algorithm: Depth First Search

2. Heuristic (if any): None

Page 10: Artificial Intelligence - Noppa · Hill-climbing is a search algorithm that proceeds like depth-first search but so that the search order of the nodes is determined by the estimated

3. Did it find least-cost path? If not, why? No. Depth first search is an any-pathsearch; it does not consider link cost at all.

G6:

1. Algorithm: A*

2. Heuristic (if any): H2

3. Did it find least-cost path? If not, why? Yes. A* is guaranteed to find an optimalpath when the heuristic is admissible (or consistent with a strict expanded list). H2is admissible but not consistent, since the link from D to C decreases the heuristiccost by 2, which is greater than the link cost of 1. Still, the optimal path was found.

G7:

1. Algorithm: Uniform Cost Search

2. Heuristic (if any): None

3. Did it find least-cost path? If not, why? Yes. Uniform Cost is guaranteed to find ashortest path.

5. Search problem - solution

a)

Breadth first search will start from theroot node, then expands all thesuccessors of the root node, and thenall their successors and so on.Breadth first search stops when firstsolution is found.

Page 11: Artificial Intelligence - Noppa · Hill-climbing is a search algorithm that proceeds like depth-first search but so that the search order of the nodes is determined by the estimated

b)

Depth-first search expands thedeepest node in the search tree.Notice that there was no mechanismto remember states that have beenvisited earlier. Depth first will not finda solution as it will start oscillatingbetween movements U and D

c)

A* is a search method that opens thenode with smallest cost function value.The search begins from the start state.

1. When the start state is opened wesee two states

2. The leftmost state has a lower costso that one is choosen and opened. Wenow see states with costs 5,3 and 4

Page 12: Artificial Intelligence - Noppa · Hill-climbing is a search algorithm that proceeds like depth-first search but so that the search order of the nodes is determined by the estimated

3. The state with lowest cost is openedand we see two more nodes includingthe goal node. We notice that the goalnode has the lowest cost so we choosethat and can finish the search. If someother node with a lower cost functionvalue was still visible, A* search wouldchoose that instead of the higher costgoal node. This is because A* tries tofind the path with lowest cost.