You are on page 1of 10

CS 188 Introduction to

Fall 2019 Artificial Intelligence Written HW 1 Sol.


Solutions for HW 1 (Written)

1
Q1. Uninformed Search
We are in a world where a disease is slowly taking over, and you have miraculously discovered a part of the cure.
While fighting off the disease, you're trying to reach the other medical center with the final piece of the cure. You can imagine
the world modeled as the following, where H is your Home base, D is the starting node of the disease, and M is the other
Medical Center.

Disease D infects 1 extra square during each time step from its current location, exploring in the direction cycling between
North, East, South, West, and only changes direction when it is not able to infect the next square. If the disease has no
available adjacent square to infect, it does not move. Any square that the disease has been in at any time will be considered
infected, and the disease will not move into an infected square.

The cost of exiting a non-infected square is 1, and the cost of exiting an infected square is 3. For each

of the following questions, give a quick justification of your answer.

(a) What would be the minimum state space representation and its size? Successor function? Goal test?

State space representation:


The state space representation should include our location and the time-step of the environment. Location can be
represented by an x-y coordinate, and time-step by a number. Note that we do not need a boolean array to represent
infected positions since the disease’s path is deterministic, and can be fully reconstructed given the time-step.

State space size:

There are MN possible grid positions, and the time-step is bounded by MN, so we have (MN)2

Successor function:

We move one square over in the direction given, as long as it does not travel off the edge of the graph. If
the disease has a next available open slow to move it, we increment our timestep, otherwise we don’t

Goal test:

Is our location (xH , yH ) = (xM , yM )?

(b) Assuming that ties are broken in the order East, North, West, South, what is the cost of this path using BFS Tree Search
if you start at H, want to move to M?
19. All edges are equal, so BFS returns the path going East until it hits the wall, and North until it reaches the goal. It
takes 10 steps until it reaches an infected square, and the next 3 steps have a cost of 3.

(c) Lets say you have a power to stun the disease so it does not progress for an additional time unit. You can
use the power when you share the square where the disease head is, or you are adjacent to that square, before taking a
step as you usually would (meaning you can both move and stun within a time step). What is the new
minimal state space? What is it’s size? How will your successor function and goal test be affected, if at all?
State space representation:
The state space representation should include our location and the time-step of the environment. Location can be
represented by an x-y coordinate, and time-step by a number, which is the same as the previous formulation. We don’t
need to include number of times stunned because the stunning logic can be incorporated into the successor
function. This is the same state space as (a)

State space size:

There are MN possible grid positions, and the time-step is bounded by MN. The state space size is (MN)2

Successor function:

We move one square over in the direction given, as long as it does not travel off the edge of the graph. If
we choose to stun, we do not increment the timestep. Otherwise, we increment timestep only when the disease as an
available next location to travel to.

Goal test:

Is our location (xH , yH ) = (xM , yM )?

(d) Would we want to use game trees in this scenario? Why or why not?
The disease is not necessarily an adversarial agent, as we know the disease travels deterministically independent of
where we go, and we can account for that in our state space.
Q2. Trolley Transport Problems
Five Animal Crossing An eccentric billionaire has tasked you with transporting a collection of animals (and a rare
flower) from the base of its mountain to its peak using a trolley. Thankfully, the trolley is currently at the base of the
mountain, so your quest has some chance of succeeding.

Specifically, you will need to transport (1) a rare orchid, (2) an aggressive plant-devouring grasshopper, (3) an
insect-eating shrew, (4) a rodent-swallowing grass snake, and (5) a snake-killing mongoose. If left unattended (at
either the base of the mountain or its peak), the mongoose will kill the snake, the snake will swallow the shrew, the
shrew will eat the grasshopper, and the grasshopper will devour the rare orchid. However, the animals (and orchid) will leave
each other alone otherwise. Needless to say, the billionaire will be extremely angry if any of these organism die, an outcome
you will try to avoid at any cost.

As you only have two hands, you will only be able to safely transport two animals at a time in the trolley.

Use your knowledge of CS 188 to safely move all the organisms to the peak using the trolley, and complete the
billionaire’s quest as fast as possible. Assume that using the trolley will incur a cost of 1.

(a) Assume that the trolley will only move with you on it.
(i) How many different states are there where the trolley is docked at either the base or peak of the mountain?
Label the orchid 1, grasshopper 2, shrew 3, grasshopper 4, and snake 5.
Each organism can be in 2 positions, and there are 5 organisms, so there 25 ways to arrange the organisms. Then,
there are 2 places to dock the trolley. So there are 26 = 64 states in total.

(ii) How many legal states are there where no animals (or orchids) will be harmed? The only way no plants or animals
are harmed are when all the organisms on the side without the trolley won’t hurt each other. The combinations
which won’t hurt each other are the empty set of 0 plants or animals, the 5 singleton sets with each of the plants or
animals, and the sets

{1, 3}, {2, 4}, {2, 5}, {3, 5}, {1, 4}, {1, 5}{1, 3, 5}.

So there are 13 such combinations and so there are 26 states where no animals hurt each other (we can place that
combination at either the mountain peak or base).

(b) Being a savvy CS 188 student, you decide to use A∗ search. Your first idea is to use the heuristic of ”the
number of animals at the base”. Is the heuristic:

Admissible? Yes # No
Explain: Consider the situation where the snake and grasshopper are on the left side with the trolley. Then in
one move, you can move all two remaining animals over at the cost of 1.

Consistent? Yes # No
Explain: Since the heuristic is not admissible, then also cannot be consistent.

(c) A friend proposed another heuristic, which is simply 1 if the trolley is at the base and 0 if the trolley is at the peak. Is the
heuristic:

Admissible? Yes No #
Explain: Since it is consistent, it is also admissible

Consistent? Yes No #
Explain: As the heuristic is zero except when the trolley is at the base, and the problem is only solved when
the trolley is at the top, it is admissible. As the cost of moving the trolley is 1, and the heuristic is always 1 or 0, it is
consistent.

(d) Consider the heuristic which is half the animals at the base, rounded up, plus 1 if the trolley is at the peak. Is
the heuristic:

Admissible? Yes # No
Explain: This heuristic is not admissible, as its value at the goal state is 1.

Consistent? Yes # No
Explain: Since the heuristic is not admissible, it is also not consistent

(e) Finally, consider the heuristic which is simply the number of animals at the base, minus 1 if the trolley is at the bottom.
Is the heuristic:

Admissible? Yes No #
Explain: The heuristic is admissible, as it takes at least N-1 trips to move N animals from the base to the peak.
(You can move 2 animals and return the trolley to its starting position in 2 rounds.

Consistent? Yes No #
Explain: This heuristic is consistent, because if any two adjacent positions only differ by at most 1.

(f) Of the four heuristics mentioned above, is there an admissible heuristic that dominates all other ones on all
legal states? If not, why not?

The heuristic in (e) dominates the only other admissible heuristic (c). This is because the only time the trolley is at the bottom
is when there are at most 3 animals/plants at the top (no arrangement of 4 animals/plants can be left alone). So there must be
at least 2 animals/plants at the bottom, meaning the cost of (e) is higher in every case than (c).

(c) doesn’t dominate (e). For example, in the start state where all 5 animals are at the bottom, (e) gives a cost of
4, while (c) gives a cost of 1.
Q3. The Office Hour Assignment Problem
Eight Teaching Assistants (TA) are assigned to eight office hour slots. Each TA will take only one slot and each
slot can only be taken by one TA. Before the assignment is conducted, the head TA has kindly asked every TA to indicate their
preferences toward the slots (e.g. TA 1 cannot take Slot 8, or TA 2 prefers to take the slot earlier than TA3, etc.). The head
TA would then assign the slots according to the preferences provided by all the TAs. This assignment problem can
be formulated into a CSP.

(a) If all the TAs are available for all the slots and there are no preferences indicated by any TA, is this CSP
equivalent to the eight-queen problem introduced in the class? To answer this question, the head TA asked
you to help to formulate this into a CSP with regard to Variables, Domain, and Constraints. Do not use the same
formulation as part (b).

Variables: . A total of variables.

Domain: . A total of elements in the domain.

Constraints: .

This problem is (“the same as” or “different from”) the eight-queens problem

because:
• Variables: {Xi,j }; i = 1, ..., 8; j = 1, ..., 8. 64 variables.
• Domain: {0, 1}. 2 elements in the domain.
• Constraints:
Xi,j + Xi0,j0 <= 1, ∀i = i0, j = j0, or ∀i = i0, j = j0.
P8 P8
i=1 j=1 Xi,j = 8

Different from. Because this CSP has fewer constraints compared to the eight-queen problem. If there is no
diagonal attacks for the queens, these two questions become the same.
You can also write the above constraints to be in the similar form as in the lecture notes. Just leave out the diagonal
ones (Constraint 3 and 4 on the Note 2).
Grading: Other valid formulations (as long as any part of the answer (e.g. the constraints) is different from the
next question) will also be accepted.

(b) The head TA instead proposed to formulate this CSP in the following way: if we represent the 8 TAs numbered from 1 to
8, and the 8 slots numbered from 1 to 8, we have
• Variables: {Xj }j=18 where Xj represents the slot ID of the j-th TA.
• Domain: {1, 2, 3, 4, 5, 6, 7, 8}.
• Constraints:
1. Xi = Xj ∀i = j
2. X3k = 3Xk ∀k ∈ {1, 2}
3. X4k = 4Xk ∀k ∈ {1, 2}
4. X5 > X6 > X7
The constraints above are all binary, and reflect the preferences of all the TAs towards all the slots.
Is the solution to the CSP unique? (yes or no). Do we arrive at a valid solution by only enforcing arc
consistency (are the domains for all variables size 1)? (yes or no). Write down the remaining values for each
variable after enforcing arc consistency.
X1 : , X2 : , X3 : , X4 : ,

X5 : , X6 : , X7 : , X8 : .
Yes. No. X1 : {1, 2}, X2 : {1, 2}, X3 : {3, 6}, X4 : {4, 8}, X5 : {4, 5, 6, 7, 8}, X6 : {3, 6}, X7 : {1, 2, 3, 4, 5},
X8 : {4, 8}.

(c) To solve the CSP in Question (b) via backtracking search, after the filtering step in Question (b), we wish to
pick a variable to assign values. Which variable(s) would be the most reasonable choice based on domain size? .
What is this selection process called? .
X1, X2, X3, X4, X6, X8. Minimum Remaining Values heuristic.

(d) If we wish to use local search to solve the CSP in Question (b), with the initial value assignments to all the
variables as Xk = k, ∀k = 1, ..., 8, which variables have conflicting constraints? . What is the
minimum number of iterations to refine the initial assignment into the correct solution? .
{X5, X6, X7}. 2
If your answer is 3, you can also get the credit - if you also treat X5 > X7 as one constraint. Thus, the first step is to set
X5 to be 8 (resulting in only 1 conflict: X5 = X8). Setting X5 to be 7 will cause 2 conflicts X5 > X7 and X5
= X7. The second step is to set X7 to be 5, and the final step is to set X5 to be 7.
We will make sure that during the exam, the binary constraints will be explicitly listed.
Q4. Go Bears

The historical game of Go is played on a 19x19 grid by two adversaries, black and white, who alternately place pieces at the
intersections of the grid lines. While rules and strategies for this game are abound, the only information required for
this problem is that the game ends when no more valid moves exist for either player (e.g. when the board is full),
and that the player with the most pieces on the board wins.

(a) We would like to tackle the problem of finding the optimal Go playing strategy using the minimax algorithm.
(i) What properties of this game make it amenable to analysis via minimax?

1. This problem can be formulated as a search problem. State space could consist of a 361D vector, each
element either 0, 1, 2 for white, black, or neither.
2. Zero-sum: one player wins and one loses at the end. The players cannot mutually benefit from
cooperation.
3. Deterministic: when a player chooses to put a piece down, there is no uncertainty about the new state of the
board.
4. Fully Observed/Perfect Information: No part of the state is obscured; we can see exactly where all
the pieces are on the board.
(ii) What properties of this game make it difficult to analyze via minimax?

The branching factor of the search tree is huge. At the top level, the first player has 361 moves to choose from,
the next player has 360, and so on. Running minimax tree search which involves traversing the entire
search tree depth-first would be computationally intractable.
(b) Because the search tree is so unwieldy, we will employ the strategy of cutting off our search at a certain depth and
evaluating the utility of the leaf nodes. One way to evaluate the utilities is to start the game from that state and
simulate many games, with both black and white randomly choosing moves. The utility of the leaf nodes for each player
can then be approximated as the average number of games they won.
Let’s say that we are playing as black, and we have employed this strategy that results in the game tree below (which is
simplified for the purposes of this problem). Each Xi is the number of games that black won in 10 simulated games, and
we will estimate the utility of the leaf nodes as X /n. i

Let Xi ∼ Binomial(n = 10, p = pi) where p1 = 0.3, p2 = 0.8, p3 = 0.1, p4 = 0.5. All games are simulated
independently of each other.
(i) In expectation, what move should the black player take, and what is their expected win rate?
In expectation, E[Xi/n] = pi, and the black and white players should both take the left move, yielding a value of 0.3
for black. Therefore black can expect to win 30% of their games.
(ii) What is the probability that the black and white players both choose their optimal moves in expectation (i.e. that
black chooses their move from part (i) and white chooses their optimal move in expectation after that)? In the
case of a tie, assume the left move is chosen. You may leave your answer in terms of the parameters
specified (but you are encouraged to compute a numerical answer, for which you may need a computer).
For the black and white players to choose their left moves, the leaf node utilities must work out so that X1 ≤ X2 and
X1 ≥ min(X3, X4). Note that we can use ≥ and ≤ instead of > and < since ties are broken by choosing left.

P (X2 ≥ X1 ∧ (X3 ≤ X1 ∨ X4 ≤ X1))


Xn
= P (X2 ≥ x1 ∧ (X3 ≤ x1 ∨ X4 ≤ x1))P (X1 = x1)
x1=0
Xn
= P (X2 ≥ x1)P (X3 ≤ x1 ∨ X4 ≤ x1)P (X1 = x1)
x1=0
Xn
= P (X2 ≥ x1)[1 − P (X3 > x1)P (X4 > x1)]P (X1 = x1)
x1=0
Xn X x1 X
n nX
= P (X2 = x2) h1 − P (X3 = x3) P (X4 = x4)iP (X1 = x1)
x1=0 x2=0 x3=x1+1 x4=x1+1
Xn X nx1 h Xn Xn i
x n
= p 2 (1 − 2p )n−x2 1 − x
p 3 (1 − 3p )n−x3
x
nx p 4(1
4 − 4p )n−x4 x
p 1 (1 1 − 1p )n−p1
x1=0 x =0
x2 2
x3=x1+1
xn3 3 x4=x1+1 4 x1
2

≈ 0.93

Note that the probability is quite high!


(c) In the previous question, we considered the white player to be a deterministic minimizing agent. Now consider the white
player to take actions with some randomness. Instead of minimax search, we should now employ expectimax
search to discover the optimal strategy in expectation.
Our tree from part (b) was highly simplified with respect to the problem of Go. In reality, even if we did a
depth limited search, we would still have many branches to search through given the huge branching factor of the Go
tree. Therefore to save time we would like to prune branches that are unnecessary to explore.
(i) In general, we cannot expect to prune anything in expectimax tree search. Why not?
In general, leaf node values are unbounded, and therefore expectations are unbounded. Therefore we can never
prune since we have no bounds on what values nodes can take on.
(ii) However, in our problem we can expect pruning to make our computation more efficient. Why?
In our problem, the utilities of our leaf nodes are bounded between 0 and 1.

You might also like