0% found this document useful (0 votes)
5 views

HW02

The document outlines the homework assignment for the CSC14003 Artificial Intelligence course, detailing submission guidelines, problem statements, and solutions for various AI concepts including local search algorithms, genetic algorithms, Expectimax, CSP, and Minimax. It emphasizes the importance of proper formatting and originality in submissions. Additionally, it provides specific tasks related to optimization problems, decision-making algorithms, and scheduling constraints.
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)
5 views

HW02

The document outlines the homework assignment for the CSC14003 Artificial Intelligence course, detailing submission guidelines, problem statements, and solutions for various AI concepts including local search algorithms, genetic algorithms, Expectimax, CSP, and Minimax. It emphasizes the importance of proper formatting and originality in submissions. Additionally, it provides specific tasks related to optimization problems, decision-making algorithms, and scheduling constraints.
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/ 9

Class 23CLC – Term II/2024-2025

Course: CSC14003 – Artificial Intelligence

Homework 02

Submission Notices:
●​ Conduct your homework by filling answers into the placeholders given in this file (in Microsoft Word
format). Questions are shown in black color, instructions/hints are shown in italic and blue color, and your
content should use any color that is different from those.
●​ After completing your homework, prepare the file for submission by exporting the Word file (filled with
answers) to a PDF file, whose filename follows the following format,
<StudentID-1>_<StudentID-2>_HW01.pdf (Student IDs are sorted in ascending order)
E.g., 2252001_2252002_HW01.pdf
and then submit the file to Moodle directly WITHOUT any kinds of compression (.zip, .rar, .tar, etc.).
●​ Note that you will get zero credit for any careless mistake, including, but not limited to, the following
things.
1.​ Wrong file/filename format, e.g., not a pdf file, use “-” instead of “_” for separators, etc.
2.​ Disorder format of problems and answers
3.​ Conducted not in English
4.​ Cheating, i.e., copying other students’ works or letting the other student(s) copy your work.

Problem 1 (2pt) Answer the following simple questions.


Questions (0.25pt each) Answers
What is the state space in a local search -​ The space in a local search algorithm for
algorithm for optimization problems? optimization problems is a set of states in
the world and all actions that define how
one state can transition to another.
-​ The state-space landscape has the “location”
(defined by state) and “elevation” (defined by
the heuristic function or objective function)
-​ If elevation corresponds to cost, then aim is
finding the lowest valley. If elevation
corresponds to an objective function, then
aim is to find the highest peak.
How does simulated annealing differ from hill -​ Simulated annealing allows “downhill” move
climbing in local search? with probability and picks a random move
instead of the best move (which is in hill
climbing).
-​ The selection probability of a “downhill
move” is proportional to the temperature
function T (which is eΔE/T)

1
-​ Hill climbing only continues if the successor
is better than the current state and it always
chooses the best successor.
What is the purpose of a tabu list in Tabu -​ Tabu list in Tabu keeps a small list of
search? recently visited states to prevent revisiting
recently explored solutions, avoiding cycles
and to find its way off the plateau.
-​ It guides exploring toward better solutions.

What does the Minimax algorithm aim to -​ Maximize the best possible outcome for the
achieve in a two-player game? maximum player.
-​ Minimize the opponent's best response for
the minimum player
-​ Assume both players play optimally and
explore all possible state games to find the
best move.

How does alpha-beta pruning improve the -​ Alpha-beta pruning improves efficiency of
Minimax algorithm? the minimax algorithm by pruning
branches that do not affect the results.
With the perfect ordering, it may reduce
𝑑/2
time complexity is O(𝑏 ), with d is the
maximum depth of the tree.

How does Expectimax differ from Minimax Minimax:


in handling game uncertainty? -​ Has no stochastic event, thus, can assume
that both players play optimally to achieve
their “goal”.
-​ Has only 2 types of nodes, MAX and MIN.
Expectimax:
-​ Has stochastic events in the game (e.g,
dice), so can only assume randomly in the
game environment (dice,..)
-​ Has chance nodes besides MAX, MIN
nodes.
-​ Because it cannot calculate definite
minimax values, it computes the expected
value of all possible outcomes in the
chance node.
-​ It uses the probability formula to compute
the expected value.

𝐸𝑥𝑝𝑒𝑐𝑡 𝑉𝑎𝑙𝑢𝑒(𝑥) = ∑ 𝑉𝑎𝑙𝑢𝑒(𝑠𝑢𝑐𝑐𝑒𝑠𝑠𝑜𝑟 𝑛𝑜𝑑𝑒) *

P (successor node), P is probability of state.

2
What is the role of the Minimum Remaining -​ The Minimum Remaining Values (MRV)
Values (MRV) heuristic in CSP solving? heuristic in CSP selects the variable that
has fewest “legal” values. It picks a variable
that is most likely to cause a failure soon,
thereby pruning the search tree. Thus,
MRV helps reducing the search space,
detecting failure early, and minimizing
backtracking

What does backtracking do in a CSP solver -​ Undo the last variable assignment.
when a constraint is violated? -​ Try the different values (if still have) for
that variable.
-​ Backtrack further if no valid values remain.

Problem 2 (2pts) You are tasked with solving a Knapsack Problem using a Genetic Algorithm. The
problem is defined as follows:
●​ Items:
o​ Item 1: weight = 2, value = 10
o​ Item 2: weight = 3, value = 15
o​ Item 3: weight = 5, value = 25
o​ Item 4: weight = 7, value = 35
●​ Knapsack Capacity: 10
Your task: Implement a Genetic Algorithm to find a near-optimal solution. Your solution should
include:
●​ A clear definition of the chromosome representation (e.g., how you encode the selection of
items).
●​ The fitness function (e.g., how you evaluate the quality of a solution).
●​ The selection method (e.g., tournament selection or roulette wheel).
●​ The crossover operation (e.g., single-point crossover).
●​ The mutation operation (e.g., flipping a bit with some probability).
Show the initial population (with at least 4 chromosomes) and the population after one generation,
including the steps of selection, crossover, and mutation.

Answer:
-​ We define the chromosome representation as a 4-bit string, each bit corresponds to the
selection choice of the item. For example, if bit 2-th is 1, then item 2 is selected. The order of
bits is based 1 from left to right. 1110 means that item 1, 2, and 3 is selected.

-​ The initial population size in (a) at figure P2 will have 8 individuals, all 8 individuals are
valid.

3
-​ The fitness function (b) (figure P2) is the sum of values of selected items, it is an increasing
function as better state will have better fitness score.

-​ The selection method that we chose is roulette wheel. The probability of being chosen for
reproducing is directly proportional to the fitness score. The fitness percentage and the roulette
wheel is shown in the below image P1.

P1: The fitness percentage and the roulette wheel

-​ The crossover point for each parent couple is randomly chosen from the positions in the
string. In (d) (figure P2), the offspring themselves are created by crossing over the parent strings
at the crossover point.

-​ Finally, in (e) (figure P2), each new-generation individual has a random mutation at a location
with a small independent probability. Because of the mutation operation, some children such as
the 2th, 4th, and the 8th one, is invalid with the knapsack capacity (marked with X).

-​ Through the first generation, we can see that the best new-generation individuals are the 1st,
3rd, and 6th one.

4
P2: The process of producing first generation in genetic algorithm

Problem 3 Expectimax (2pts) In a game with chance elements, you are at a decision node with two
options: Option A and Option B. The outcomes are:
●​ Option A:
o​ 60% chance of winning $50
o​ 40% chance of winning $10
●​ Option B: Leads to another decision node with two further choices:
o​ Option C: Win $20 for sure
o​ Option D:
▪​ 50% chance of winning $100

▪​ 50% chance of winning $0


Your task: Use the Expectimax algorithm to determine the best choice at the initial decision node.
Compute the expected value for each option, showing your calculations step-by-step.

Answer:

5
-​ At node D, Expected value = 100 * 50% + 0 * 50% = 50.
-​ At node C, Expected value = 20 * 100% = 20.
-​ At node B, choose the successor node with the highest value between C and D. Choose D
(expected value = 50 > 20).
-​ At node A, Expected value = 50 * 60% + 10 * 40% = 34.
-​ The best choice at the initial decision node is the successor node with the highest value
between A and B. Choose B (value: 50).

Problem 4 (2pts) You need to schedule three meetings M1, M2, and M3 into two time slots, T1 and T2.
The constraints are:
●​ M2 cannot be scheduled in T1 (e.g., a key participant is unavailable).
●​ M1 and M2 cannot be scheduled in the same time slot (e.g., they share a participant).
●​ M1 and M3 can be scheduled in the same or different time slots (no shared constraints).
Your task:
●​ Formulate this as a Constraint Satisfaction Problem (CSP) by defining:
o​ Variables: The meetings (M1, M2, M3).
o​ Domains: The possible time slots for each meeting (T1, T2), after enforcing unary
constraints.
o​ Constraints: The restrictions listed above.

6
●​ Solve the CSP using backtracking with the Minimum Remaining Values (MRV) heuristic. Show
the steps taken, including variable assignments and any backtracking that occurs.

Answer:
●​ The constraint graph associated with CSP, in which each node represents the meeting variables
(M1,M2,M3) and an edge connecting two nodes represents the relations between two variables.

The domain of each variables:


Variables M1 M2 M3

Domain T1, T2 T2 T1, T2

Constraints:
M1 ≠ M2 T1 ∉ Domain(M2) M3 has no shared constraints
→None

M2 has the smallest MRV = 1. So assigned M2 = T2. Due to the constraint M1 ≠ M2, the T2 value of
M1 is deleted.

Variables M1 M2 M3

Domain T1, T2 T2 T1, T2

Now M1 has the smallest MRV = 1, and it only has one value left. So assigned M1 = T1.

Variables M1 M2 M3

Domain T1, T2 T2 T1, T2

M3 has no shared constraints with M1 and M2, thus its domain remains the same.

Variables M1 M2 M3

Domain T1, T2 T2 T1, T2

7
One of many solutions: M1 = T1, M2 = T2, M3 = T2

Problem 5 Minimax (2pts) Consider a two-player game where players Max and Min take turns making
moves. The game tree for this problem is structured as follows:
●​ The root node is a Max node with three choices: A, B, or C.
●​ Each of these choices leads to a Min node, where Min has two choices.
●​ Each Min choice then leads to a Max node, where Max has two choices.
●​ Finally, each of these Max choices leads to leaf nodes with the following payoff values (higher
values are better for Max):
Game Tree Structure and Payoffs:
●​ Root (Max): Choose A, B, or C
o​ Choice A (Min): Choose A1 or A2
▪​ Choice A1 (Max): Choose between leaf values 3 or 5

▪​ Choice A2 (Max): Choose between leaf values 2 or 7


o​ Choice B (Min): Choose B1 or B2
▪​ Choice B1 (Max): Choose between leaf values 4 or 6

▪​ Choice B2 (Max): Choose between leaf values 1 or 8


o​ Choice C (Min): Choose C1 or C2
▪​ Choice C1 (Max): Choose between leaf values 0 or 9

▪​ Choice C2 (Max): Choose between leaf values 2 or 3


Your task:
a)​ (1pt) Use the Minimax algorithm to determine the best move for Max at the root node. Show the
Minimax value computed at each node in the tree.
Answer: The best move for Max would be choosing choice B for yielding the maximum score: 6.
Optimal move is marked with a red arrow.

8
b)​ (1pt) Apply Alpha-beta pruning to the same game tree, assuming a left-to-right evaluation order.
Indicate which branches (if any) are pruned and explain your reasoning.

Answer:
In the figure below, +inf indicates positive infinity value, -inf indicates negative infinity value. a stands
for alpha and b stands for beta.

Even though Alpha-beta pruning is applied, because the order of the leaves is ascending, it still
traverses through the whole tree without pruning any branches. This is the worst case of Alpha-beta
pruning, which equals the Minimax algorithm.

If we swap positions of some successors, such as leaf 7 and 2. Then the MAX node above them will
prun the edge leading to leaf 2.

You might also like