0% found this document useful (0 votes)
17 views16 pages

Revisionsss

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views16 pages

Revisionsss

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

University of Royal Holloway CS5960

Prof. Sara Bernardini, Dr. Santiago Franco, Alexandra Neacsu, Hyosun Choi

Revision Session

Exercise 1: Uninform Cost Search. ()

Assume that you have a puzzle consisting of four cells as seen in figure 1. The first cell
contains a black tile, the next two are white ones, and the last cell is empty.

Figure 1: Puzzle domain

A tile can be moved into a neighbored empty cell (costing one unit) or a tile can “jump”
over at most one cells into an empty cell (costing the number of cells jumped over). The
goal of the game is to have the black tile to the right of the white tiles, while the empty
cell may have an arbitrary position. Draw a Uniform-Cost graph for the problem described
above. For this problem, you can stop expanding nodes once the first goal node has been
generated. Use the following representation of the initial node for all nodes: BWWE 1
where the letters represent Black,White,White,Empty and expansion order 1.

1
Solution:

Figure 2: Uniform Cost Graph

2
Exercise 2: Uninformed Iterative Search. ()

Consider the initial state Victoria and the goal state Western Australia for the colouring
problem depicted in figure 3. Explain how Iterative-Deepening works. Draw the Iterative-
Deepening search graphs from limit=0 to limit=2.

Northern
Territory
Western Queensland
Australia

South
Australia
New South Wales

Victoria

Tasmania

Figure 3: Map of Australia, you can only move between adjacent states. Note that Tas-
mania is reachable and adjacent to Victoria for this lab.

Solution:

Iterative-deepening search is an iterative search algorithm which combines Depth-First


Search and Breadth-First Search. In the first iteration the depth is set to 0 and it is
gradually increase by 1 until a goal node is generated. At each iteration the tree is traversed
in a DFS order up to the depth limit. Note that there is no duplicate-check for this
algorithm.
Figure 4 shows the iterative-deepening search graphs from Victoria to Western Australia
from limit=0 to limit=2.

3
limit=0 No goal found

limit=1 No goal found

limit=2 Goal found

Figure 4: Iterative-Deepening search of the Australian map starting from Victoria and
traversing to the goal state of Western Australia for each limit from 0 to 2

4
Exercise 3: Heuristics. ()

The planning task for this exercise is based on the 2D grid world in figure 5. The task is
to find the minimal number of agent movements to collect all coins on the grid. The agent’s
actions are given by moving to horizontally and vertically adjacent cells (i.e., diagonal
movements are not allowed). The agent cannot move onto walls. A coin is automatically
collected when the agent moves onto the respective cell. The goal is to collect all coins.
This exercise analyzes heuristics and its properties. For the following heuristics, deter-
mine if they are admissible.

Figure 5: Graphical illustration of the initial state in the grid world

The Manhattan distance is defined as d(⟨x, y⟩, ⟨x′ , y ′ ⟩) = |x − x′ | + |y − y ′ |. Let C be


the set of all coins. For every coin c ∈ C, let ⟨cx , cy ⟩ denote its position on the grid. A
state s is triple ⟨sx , sy , Cs ⟩ where ⟨sx , sy ⟩ gives the agent’s current position, and Cs ⊆ C is
the set of all collected coins. The heuristic functions are formally defined as follows:
(i) The maximal Manhattan distance between the agent’s current location to any coin
that has not been collected. Formally, h1 (s) = maxc∈C\Cs d(⟨sx , sy ⟩, ⟨cx , cy ⟩).
(ii) The sum of thePManhattan distances to all coins that have not been collected. For-
mally, h2 (s) = c∈C\Cs d(⟨sx , sy ⟩, ⟨cx , cy ⟩).

(iii) Let C \ Cs = {c1 , . . . , cn }, and assume that c1 , . . . , cn are ordered so that

(1) for all 1 < i ≤ n, it holds that d(⟨sx , sy ⟩, ⟨c1x , c1y ⟩) ≤ d(⟨sx , sy ⟩, ⟨cix , ciy ⟩),
(2) for all 1 ≤ i < n and i + 1 < j ≤ n it holds that d(⟨cix , ciy ⟩, ⟨ci+1 i+1
x , cy ⟩) ≤
d(⟨cix , ciy ⟩, ⟨cjx , cjy ⟩).

5
Pn−1
The heuristic is given by h3 (s) = d(⟨sx , sy ⟩, ⟨c1x , c1y ⟩) + i=1 d(⟨cix , ciy ⟩, ⟨ci+1 i+1
x , cy ⟩).
Solution:

(iv) Come up with and implement an arbitrary other heuristic with the following proper-
ties:

(1) Your heuristic is admissible. Justify why it is admissible (on paper)!


(2) Your heuristic works for arbitrary maps, arbitrary initial positions, arbitrarily
many coins, and arbitrary coin locations.

(a) (b)

Figure 6: Counter examples

(i) The Maximal Manhattan distance heuristic is admissible: Manhattan distance be-
tween two points is a lower bound on the actual distance (i.e., number of move
actions to do) between the points. Since the agent has to visit every cell containing a
coin that has not been collected, the agent must in particular move from its current
location to the location of the farest coin that has not been collected.

(ii) Is not admissible. Consider the state shown in Figure 6 (a). An optimal plan for this
state has cost 3. However, h2 (s) = 2 + 3 = 5.

(iii) Is not admissible. Consider the state shown in Figure 6 (b). An optimal plan for this
state has cost 10. However, h3 (s) = 2 + 2 + 7 = 11.

(iv) A simple heuristic that fulfills all the requirements is the PerfectMax heuristic, i.e.,
the same heuristic as (i) but replacing Manhattan distance by the real distance on
the board.

6
Exercise 4: Informed Search. ()

For the same problem in exercise 1 do the following:

1. Formulate an admissible heuristic for this problem. Explain why your heuristic is
admissible.

2. Draw the search graph for the A* algorithm until you find the optimal solution. Mark
the order of expansion if the node has been expanded and halt the algorithm when
you first generate the goal state.

Solution:

1. One possible admissible heuristic is the following instantiation of the “out-of-place”


heuristic; each white tile to the right of the black title adds 1 to the heuristic value
(e.g., h(I) = 3). “Out-of-place” heuristic will be admissible (h(s) ≤ h∗ (s) for all
states s) for this problem because any single move can only reposition at most one
tile to the left of the black tile. Hence, there is no solution which is shorter than the
number of white tiles to the right of the black tile.

2. A* search halting once goal node is generated:

7
Figure 7: A* search, stopping once goal is generated

8
Note that the standard A* halting condition is to stop when a goal node is pulled from
the frontier for expansion. In that case, the solution graph would be as in figure 8:

Figure 8: A* standard goal-check

9
Exercise 5: CSP-Arc Consistency. ()

Consider the following constraint network: γ = (V, D, C):

• Variables: V = {a, b, c, d}

• Domains: For all v ∈ V : Dv = {5, 10, 15, 20}

• Constraints: a > b + 10; b + d ≤ 15; 20 < d + c; a + c > 30;

1. Draw the constraint graph.

2. Can you solve the problem using the AC-3 algorithm? Please explain why and if you
can, proceed to solve the problem using the algorithm.

Show each of the steps for the used algorithm(s). When tie-braking use lexicographical
order for selecting variables (or variable pairs).

Solution:

1. Constraint graph

Figure 9: Constraint graph for exercise 5.

2. Yes, you can. AC-3 is applicable to any constraint graph. Solution follows:

10
(a) M = {(a, b), (a, c), (b, a), (b, d), (c, a), (c, d), (d, b), (d, c)} ;
Pair selected: (a,b);
a > b + 10, hence Da = {20};
Da is changed → Do we have any other (*, a)? - Yes, but (c, a) is already in
M , so nothing to do.
(b) M = {(a, c), (b, a), (b, d), (c, a), (c, d), (d, b), (d, c)} ;
Pair selected: (a,c);
a > 30 − c, hence Da = {20};
Da is unchanged → Nothing to do.
(c) M = {(b, a), (b, d), (c, a), (c, d), (d, b), (d, c)} ;
Pair selected: (b,a);
b < a − 10, hence Db = {5};
Db is changed → Do we have any other (*, b)? - Yes, but (d, b) is already in M ,
so nothing to do.
(d) M = {(b, d), (c, a), (c, d), (d, b), (d, c)} ;
Pair selected: (b,d);
b ≤ 15 − d, hence Db = {5};
Db is unchanged → Nothing to do.
(e) M = {(c, a), (c, d), (d, b), (d, c)} ;
Pair selected: (c,a);
c > 30 − a, hence Dc = {15, 20};
Dc is changed → Do we have any other (*, c)? - Yes, (d, c) is already in M , so
nothing to do.
(f) M = {(c, d), (d, b), (d, c)} ;
Pair selected: (c,d);
c > 20 − d, hence Dc = {15, 20}; (Note that if d is 20, then c can be 15)
Dc is unchanged → So nothing to do.
(g) M = {(d, b), (d, c)} ;
Pair selected: (d,b);
d ≤ 15 − b, hence Dd = {5, 10};
Dd is changed → Do we have any other (*, d)? - Yes, we need to add (c, d) to
M.
(h) M = {(d, c), (c, d)} ;
Pair selected: (d,c);
d > 20 − c, hence Dd = {5, 10};
Dd is unchanged → Nothing to do.

11
(i) M = {(c, d)} ;
Pair selected: (c,d);
c > 20 − d, hence Dc = {15, 20};
Dc is unchanged → Nothing to do.

Da = {20}; Db = {5}; Dc = {15, 20}; Dd = {5, 10};

12
Exercise 6: CSP-AcyclicCG. ()

Consider the following constraint network γ = (V, D, C). Lisa is moving out of Egham
soon, and has many tasks to finish in only 5 days. These tasks are:

(a) arrange a farewell party for her friends,

(b) book a bus ticket,

(c) clean her apartment,

(d) de-register from the council,

(e) end all her contracts,

(f) find a subtenant for her apartment,

(g) get packing cases.

The time slots in which she can schedule these tasks are Monday (M), Tuesday (Tu),
Wednesday (W), Thursday (Th) and Friday (F). To define the constraints we will use the
+ operation on days of the weeks. To do that, we interpret every day as a number from
Monday (1) to Friday (5). For example, F = T h + 1, and T h = M + 3 but M ̸= F + 1.
Formally, the network is defined as follows:

• Variables: V = {a, b, c, d, e, f, g}.

• Domains: For all v ∈ V : Dv = {M, Tu, W, Th, F}.

13
• Constraints :

– Since Lisa will need to go to the city to get party supplies and packing cases,
she wants to do both on the same day. (a=g)
– She cannot end her contracts without de-registering first, so she needs to end
her contracts two days after de-registering. (e=d+2)
– She needs to find a subtenant before the apartment gets filled with the party
stuff, so she wants to do it two days before the party. (f=a-2)
– She can only book her bus ticket after finding a subtenant. (b=f+1)
– She cannot clean the apartment before the party, since the apartment will get
dirty afterwards. So she wants to clean the apartment a day after the party.
(c=a+1)
– She will only de-register from the city once she knows when her bus is. (d=b+1)

Run the AcyclicCG algorithm for the just described problem. More precisely, execute
its 4 steps as follows:

(a) Draw the constraint graph of γ. Pick “f” as the root and draw the directed tree
obtained by step 1 (Chapter 6 post-handout slides 35 onwards). Give the resulting
variable order obtained by step 2. If the ordering of variables is not unique, break ties
by using the alphabetical order.

(b) List the calls to Revise(γ, vparent(i) , vi ) in the order executed by step 3, and for each of
them give the resulting domain of vparent(i) .

(c) For each recursive call to BacktrackingWithInference during step 4, give the domain
Dv′ i of the selected variable vi after Forward Checking, and give the value d ∈ Dv′ i
assigned to vi .

Note: Step 4 runs BacktrackingWithInference with variable order v1 , . . . , vn . This


means that, at the ith recursion level, “select some variable v for which a is not defined”
will select vi .

Solution:

a) Variable ordering: f, a, b, c, d, e, g. The constraint graph and directed tree are given in
Figures 10, and 11.

14
b=f+1 d=b+1 e=d+2
f b d e

f=a-2
a=g
a g

c=a+1

Figure 10: The constraint graph of Exercise 6.

a b

c g d

Figure 11: The directed tree of Exercise 6.

b) The calls to Revise(γ, vparent(i) , vi ) and the resulting domains are:

• i=7: Revise(γ, a, g): Da = Dg = {M, T u, W, T h, F }.


• i=6: Revise(γ, d, e): Dd = {M, T u, W }.
• i=5: Revise(γ, b, d): Db = {M, T u}.
• i=4: Revise(γ, a, c): Da = {M, T u, W, T h}.
• i=3: Revise(γ, f, b): Df = {M }.
• i=2: Revise(γ, f, a): Df = {M }.

15
c) Possible Dv′ i and d ∈ Dv′ i are:

• Df′ = {M }; d = M .
• Da′ = {W }; d = W .
• Db′ = {T u}; d = T u.
• Dc′ = {T h}; d = T h.
• Dd′ = {W }; d = W .
• De′ = {F }; d = F .
• Dg′ = {W }; d = W .

16

You might also like