Revisionsss
Revisionsss
Prof. Sara Bernardini, Dr. Santiago Franco, Alexandra Neacsu, Hyosun Choi
Revision Session
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.
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:
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:
3
limit=0 No 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.
(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:
(a) (b)
(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. ()
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:
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:
9
Exercise 5: CSP-Arc Consistency. ()
• Variables: V = {a, b, c, d}
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
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.
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:
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:
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 .
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
a b
c g d
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