You are on page 1of 1

Report of COMP7404 Assignment1

An Yuao
jeremyan@connect.hku.hk
3036198451
Feb 22, 2024

Problem completed
All problem were completed and all test cases were passed.

Struggled problem
5 time-consuming problems occurred in this assignment.

- Data structure of the problem description (parse)


Using dictionary as the data structure of the problem description is mainly considering the scalability and
efficiency in accessing and storing the problem's components. Dictionaries in Python provide constant time
complexity for lookups, insertions, and deletions.

- Formatted output for 8-queens problem (p6, p8)


For p6, the standard output attack number occupies 2 space each, while the list of raw result contains many
1-digit number. We use f-string to solve this out.
For p8, the raw output of function all_solutions() is a list in shape 92*8*8. We first transform it into string
list, then sort by function sorted(), and output in given format.

- Coding for attack number calculation (p6)


Designing the architecture of attack number calculation cost quite a long period (60min+).

- Priority of element in heap sorting (p5, test case 6)


The original explore priority is F-score(numeric), G-score(numeric), node name (alphabetic), and path
(alphabetic), same as the data structure of each heap. However, test case 6 of problem 5 is a boundary test
case, in which the node ‘c’ and ‘e’ have the same f-score in the step. If not modified, the sequence of the
explored list will be different from the the solution. After many attempts, we modified the data structure of
the heap element to give the node name a higher priority in sorting.

- Local search falls into local optimum (p8)


At the beginning, we set a fixed start condition as all the queen lie in the first column of the board, the search
could be seen as a incremental process. However, this method will fall into local optimum and never change.
We first modified the initialisation that randomly put the queen in different positions, then set a variable
max_attempt() to avoid meaningless searching. This mechanism worked and the runtime of this problem
decreased a lot.

Runtime and time spent

Note that the runtime is measured by time package in python and time spent refers to an estimate based on
subjective perception.

Problem parse 1 2 3 4 5 6 7 8

Runtime - < 1s < 1s < 1s < 1s < 1s < 1s < 1s 4.76 s

Time spent 30 min 20 min < 10 min 20 min < 10 min 45 min 150 min 20 min 80 min

You might also like