## Search in the document preview

Homework 3

Informed search

CompSci 171: Intro AI

4.1 A* search: From Lugoj to Bucharest

f(n) = g(n) + h(n) A* search is guided by evaluation function f(n)

100

A* search: From Lugoj to Bucharest

Lugoj

Timisoara Mehadia

f = 111 + 329 = 440 **f = 70 + 241 = 311**

A* search: From Lugoj to Bucharest

Lugoj

Timisoara Mehadia

f = 111 + 329 = 440 f = 70 + 241 = 311

Dobreta

**f = (70 + 75) + 242 = 387**

A* search: From Lugoj to Bucharest

Lugoj

Timisoara Mehadia

f = 111 + 329 = 440 f = 70 + 241 = 311

Dobreta

f = (70 + 75) + 242 = 387

Craiova

**f = (145 + 120) + 160 = 425**

A* search: From Lugoj to Bucharest

Lugoj

Timisoara Mehadia

**f = 111 + 329 = 440 **f = 70 + 241 = 311

Dobreta

f = (70 + 75) + 242 = 387

Craiova

f = (145 + 120) + 160 = 425

Rimnicu Pitesti

f = 503f = 604

A* search: From Lugoj to Bucharest

Lugoj

Timisoara Mehadia

f = 111 + 329 = 440 f = 70 + 241 = 311

Dobreta

f = (70 + 75) + 242 = 387

Craiova

f = (145 + 120) + 160 = 425

Rimnicu Pitesti

**f = 503**f = 604

Arad

f = (111 + 118) + 366 = 595

A* search: From Lugoj to Bucharest

Lugoj

Timisoara Mehadia

f = 111 + 329 = 440 f = 70 + 241 = 311

Dobreta

f = (70 + 75) + 242 = 387

Craiova

f = (145 + 120) + 160 = 425

Rimnicu Pitesti

f = 503f = 604

Dobreta

f = (111 + 118) + 366 = 595

Rimnicu Bucharest

**f = 504**f = 693

**f = 70+75+120+138+101 = 504**

4.2 Heuristic path algorithm

f(n) = (2 – w)g(n) + wh(n) For what value of w is this algorithm guaranteed to be

optimal?

g(n): a path cost to n from a start state h(n): a heuristic estimate of cost from n to a goal state

4.2 Heuristic path algorithm If h(n) is admissible, the algorithm is guaranteed to be optimal

which behaves exactly like A* search with a heuristic

To be optimal, we require

*f **n *=2−*w *[*g **n* *w
*2−*w
*

*h**n* ]

*f **n *=*g **n * *w
*2−*w
*

*h**n*

*w
*2−*w
*

1

*w*1

4.2 Heuristic path algorithm

For w = 0: f(n) = 2g(n) -> Uniform-cost search

For w = 1: f(n) = g(n) + h(n) -> A* search

For w = 2: f(n) = 2h(n) -> Greedy best search

4.3

(a) Breadth-first search is a special case of uniform-cost search

When all step costs are equal (and let’s assume equal to 1), g(n) is just a multiple of depth n. Thus, breadth-first search and uniform-cost search would behave the same in this case

f(n) = g(n) = 1*(depth of n)

4.3

(b) BFS, DFS and uniform-cost search are special cases of best-first search

–

BFS: f(n) = depth(n)

–

DFS: f(n) = -depth(n)

–

UCS: f(n) = g(n)

4.3

(c) Uniform-cost search is special case of A* search

A* search: f(n) = g(n) + h(n) Uniform-cost search: f(n) = g(n)

Thus, for h(n) = 0, uniform cost search will produce the same result as A* search

4. Prove that the Manhattan Distance heuristic for 8-puzzle is admissible

Manhattan Distance for points
*P1(x1,y1), P2(x2,y2)* is defined by:

*d * *p*1 *, p*2 =∣*x*1− *x*2∣∣*y*1− *y*2∣

Heuristic:

•Tiles cannot move along diagonals, so each tile has to move at least *d(n)*
steps to its goal

•Any move can only move one tile at a time

*h*=∑
*n*=1

8

*d **n*

5. Eight Queens problem

h – number of pairs of queens that are attacking each other

5. Eight Queens problem

h = 2

However, number of conflicts for Queen at “b3” are:

**1
2
2
3
0
2
2
2**

5. Eight Queens problem

Therefore, the true cost to reach the goal state h* is 1

Thus, h>h* heuristic is not admissible

5. Eight Queens problem

We can propose another heuristic. For example, we can propose heuristic derived form a relaxed (and trivial) version of 8-Queens problem, that the eight queens must be placed in the board so that no two queens are on the same row.

Thus, h = Σ( # queens that are on the same row – 1) for all conflicting rows

4.11

(a) Local beam search with k=1

– We would randomly generate 1 start state

– At each step we would generate all the successors, and retain the 1 best state

– Equivalent to HILL-CLIMBING

4.11

(b) Local beam search with k=∞

– 1 initial state and no limit of the number of states retained

– We start at initial state and generate all successor states (no limit how many)

– If one of those is a goal, we stop – Otherwise, we generate all successors of those states

(2 steps from the initial state), and continue

– Equivalent to BREADTH-FIRST SEARCH

4.11

(c) Simulated annealing with T = 0 at all times

– If T is very small, the probability of accepting an arbitrary neighbor with lower value is approximately 0

– This means that we choose a successor state randomly and move to that state if it is better than the current state

– Equivalent to FIRST-CHOICE HILL CLIMBING

4.11

(d) Genetic algorithm with population size N = 1

– If selection step necessarily chooses the single population member twice, so the crossover steo does nothing.

– Moreover, if we think of the mutation step as selecting a successor at random, there is no guarantee that the successor is an improvement over the parent

– Equivalent to RANDOM WALK

4-Queens problem

Min-conflict algorithm:

1. Randomly choose a variable from set of problematic variables

2. Reassign its value to the one that results in the fewest conflicts overall

3. Continue until there are no conflicts

**Q1
**

**Q2
**

**Q3
**

**Q4**

4-Queens problem

3 1 2 1

1 3 1 2

2 1 3 1

1 2 1 3

A B C D

4

3

2

1

Q1

Q2

Q3

Q4

Number of conflicts

All queens are attacked.

Pick Q2 randomly

We can move Q2 to B2 or B4

Randomly, move Q2 to B4