Report udpate

main
Gasper Spagnolo 2022-11-12 17:42:34 +01:00
parent 2e053488fd
commit c3744c43d7
9 changed files with 187 additions and 30 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 658 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -21,6 +21,12 @@
\@writefile{toc}{\contentsline {subsubsection}{\numberline {2.2.2}Mutation function}{7}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {2.3}Task 3}{8}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsubsection}{\numberline {2.3.1}Task description}{8}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsection}{\numberline {2.4}Task 4}{8}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsubsection}{\numberline {2.4.1}Task description}{8}{}\protected@file@percent }
\gdef \@abspage@last{8}
\@writefile{toc}{\contentsline {subsubsection}{\numberline {2.3.2}Approach}{8}{}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {5}{\ignorespaces Clustering example}}{8}{}\protected@file@percent }
\newlabel{image:task_3_clustering}{{5}{8}}
\@writefile{toc}{\contentsline {subsubsection}{\numberline {2.3.3}Results}{10}{}\protected@file@percent }
\@writefile{lof}{\contentsline {figure}{\numberline {6}{\ignorespaces Shortest path in maze 4, collecting all treasures}}{10}{}\protected@file@percent }
\newlabel{image:task_1_maze_1}{{6}{10}}
\@writefile{toc}{\contentsline {subsection}{\numberline {2.4}Task 4}{11}{}\protected@file@percent }
\@writefile{toc}{\contentsline {subsubsection}{\numberline {2.4.1}Task description}{11}{}\protected@file@percent }
\gdef \@abspage@last{11}

View File

@ -1,5 +1,5 @@
# Fdb version 3
["pdflatex"] 1668248665 "solution.tex" "solution.pdf" "solution" 1668248665
["pdflatex"] 1668271233 "solution.tex" "solution.pdf" "solution" 1668271233
"/usr/share/texmf-dist/fonts/enc/dvips/cm-super/cm-super-ts1.enc" 1650183167 2900 1537cc8184ad1792082cd229ecc269f4 ""
"/usr/share/texmf-dist/fonts/map/fontname/texfonts.map" 1650183167 3524 cb3e574dea2d1052e39280babc910dc8 ""
"/usr/share/texmf-dist/fonts/tfm/jknappen/ec/tcrm0900.tfm" 1650183167 1536 c4f439db76ef96a9c53bc437f35ffe20 ""
@ -21,6 +21,7 @@
"/usr/share/texmf-dist/fonts/tfm/public/cm/cmsy6.tfm" 1650183167 1116 933a60c408fc0a863a92debe84b2d294 ""
"/usr/share/texmf-dist/fonts/tfm/public/cm/cmsy8.tfm" 1650183167 1120 8b7d695260f3cff42e636090a8002094 ""
"/usr/share/texmf-dist/fonts/tfm/public/cm/cmti10.tfm" 1650183167 1480 aa8e34af0eb6a2941b776984cf1dfdc4 ""
"/usr/share/texmf-dist/fonts/tfm/public/cm/cmti9.tfm" 1650183167 1476 cccc6cc4935c18ec3d5623b77ecb8b74 ""
"/usr/share/texmf-dist/fonts/tfm/public/cm/cmtt10.tfm" 1650183167 768 1321e9409b4137d6fb428ac9dc956269 ""
"/usr/share/texmf-dist/fonts/tfm/public/cm/cmtt9.tfm" 1650183167 764 c98a2af25c99b73a368cf7336e255190 ""
"/usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx10.pfb" 1650183167 34811 78b52f49e893bcba91bd7581cdc144c0 ""
@ -31,6 +32,7 @@
"/usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr17.pfb" 1650183167 32362 179c33bbf43f19adbb3825bb4e36e57a ""
"/usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr9.pfb" 1650183167 33993 9b89b85fd2d9df0482bd47194d1d3bf3 ""
"/usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmti10.pfb" 1650183167 37944 359e864bd06cde3b1cf57bb20757fb06 ""
"/usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmti9.pfb" 1650183167 36310 f5ddc6715cc60deb16d9db5ded6a9391 ""
"/usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmtt10.pfb" 1650183167 31099 c85edf1dd5b9e826d67c9c7293b6786c ""
"/usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmtt9.pfb" 1650183167 29078 718ea4567ceff944262b0f5b0800e1d9 ""
"/usr/share/texmf-dist/fonts/type1/public/cm-super/sfrm0900.pfb" 1650183167 149037 995a6f1e12c1d647b99b1cf55db78699 ""
@ -60,8 +62,10 @@
"images/task_1_maze_1.png" 1668172516 710 43064669273650dfbed9c0cc6fabcd6f ""
"images/task_1_maze_2.png" 1668172594 1008 3c4a6780b53a0d5f210b92134871c99b ""
"images/task_1_maze_4.png" 1668172642 1705 f7a57d75e6d72aea9a0ee3f665d50352 ""
"solution.aux" 1668248665 2559 324baa123d44a542a7394a6f62000bfc "pdflatex"
"solution.tex" 1668248663 13838 6a0310ac335345580487b2cace0bb73b ""
"images/task_3_clustering.png" 1668269576 673735 1e6299d3679c02704d42eb68474b70c7 ""
"images/task_3_maze_4.png" 1668271028 11505 5eab089b4e585db6260f97f5d300aa41 ""
"solution.aux" 1668271233 3131 e6935e2fc13d948c55dc61a71236dc70 "pdflatex"
"solution.tex" 1668271231 19194 66af6e08035b71945db40ea63284b21f ""
(generated)
"solution.aux"
"solution.log"

View File

@ -223,6 +223,17 @@ INPUT ./images/task_1_broken_solution.png
INPUT ./images/task_1_broken_solution.png
INPUT ./images/task_1_broken_solution.png
INPUT ./images/task_1_broken_solution.png
INPUT ./images/task_3_clustering.png
INPUT ./images/task_3_clustering.png
INPUT ./images/task_3_clustering.png
INPUT ./images/task_3_clustering.png
INPUT ./images/task_3_clustering.png
INPUT /usr/share/texmf-dist/fonts/tfm/public/cm/cmti9.tfm
INPUT ./images/task_3_maze_4.png
INPUT ./images/task_3_maze_4.png
INPUT ./images/task_3_maze_4.png
INPUT ./images/task_3_maze_4.png
INPUT ./images/task_3_maze_4.png
INPUT solution.aux
INPUT /usr/share/texmf-dist/fonts/enc/dvips/cm-super/cm-super-ts1.enc
INPUT /usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx10.pfb
@ -233,6 +244,7 @@ INPUT /usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr12.pfb
INPUT /usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr17.pfb
INPUT /usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr9.pfb
INPUT /usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmti10.pfb
INPUT /usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmti9.pfb
INPUT /usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmtt10.pfb
INPUT /usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmtt9.pfb
INPUT /usr/share/texmf-dist/fonts/type1/public/cm-super/sfrm0900.pfb

View File

@ -1,4 +1,4 @@
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022/Arch Linux) (preloaded format=pdflatex 2022.11.9) 12 NOV 2022 11:24
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022/Arch Linux) (preloaded format=pdflatex 2022.11.9) 12 NOV 2022 17:40
entering extended mode
restricted \write18 enabled.
file:line:error style messages enabled.
@ -111,7 +111,11 @@ File: l3backend-pdftex.def 2022-04-14 L3 backend support: PDF output (pdfTeX)
LaTeX Warning: Unused global option(s):
[A4].
(./solution.aux)
(./solution.aux
LaTeX Warning: Label `image:task_1_maze_1' multiply defined.
)
\openout1 = `solution.aux'.
LaTeX Font Info: Checking defaults for OML/cmm/m/it on input line 6.
@ -200,11 +204,6 @@ Overfull \hbox (4.64594pt too wide) in paragraph at lines 238--238
[]
Overfull \hbox (9.37088pt too wide) in paragraph at lines 238--238
[]\OT1/cmtt/m/n/9 size=int(len(no_wall_instances)* random.uniform(0.01, 1.0)), replace=False)[]
[]
Overfull \hbox (61.34528pt too wide) in paragraph at lines 238--238
[] \OT1/cmtt/m/n/9 # Then randomly select random number of the instances where there are no walls[]
[]
@ -214,20 +213,55 @@ Overfull \hbox (9.37088pt too wide) in paragraph at lines 238--238
[]\OT1/cmtt/m/n/9 size=int(len(no_wall_instances)* random.uniform(0.01, 1.0)), replace=False)[]
[]
[7] [8] (./solution.aux) )
Here is how much of TeX's memory you used:
2440 strings out of 478238
37964 string characters out of 5850456
344329 words of memory out of 5000000
20682 multiletter control sequences out of 15000+600000
476294 words of font info for 53 fonts, out of 8000000 for 9000
1141 hyphenation exceptions out of 8191
55i,6n,62p,399b,317s stack positions out of 5000i,500n,10000p,200000b,80000s
{/usr/share/texmf-dist/fonts/enc/dvips/cm-super/cm-super-ts1.enc}</usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx10.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx12.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi10.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr12.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr17.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr9.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmti10.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmtt10.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmtt9.pfb></usr/share/texmf-dist/fonts/type1/public/cm-super/sfrm0900.pfb></usr/share/texmf-dist/fonts/type1/public/cm-super/sfrm1000.pfb>
Output written on solution.pdf (8 pages, 175065 bytes).
PDF statistics:
96 PDF objects out of 1000 (max. 8388607)
57 compressed objects within 1 object stream
0 named destinations out of 1000 (max. 500000)
21 words of extra memory for PDF output out of 10000 (max. 10000000)
[7]
<./images/task_3_clustering.png, id=41, 1340.00626pt x 1537.745pt>
File: ./images/task_3_clustering.png Graphic file (type png)
<use ./images/task_3_clustering.png>
Package pdftex.def Info: ./images/task_3_clustering.png used on input line 278.
(pdftex.def) Requested size: 113.81102pt x 130.601pt.
[8 <./images/task_3_clustering.png>]
Overfull \hbox (132.21945pt too wide) in paragraph at lines 332--332
[] \OT1/cmtt/m/n/9 if maze.shortest_path == [] and path_len > 0 and treasures_found >= len(maze.treasures) // 2:[]
[]
Overfull \hbox (165.29407pt too wide) in paragraph at lines 332--332
[] \OT1/cmtt/m/n/9 elif path_len < len(maze.shortest_path) and treasures_found > maze.treasures_found and path_len > 0:[]
[]
[9]
Overfull \hbox (42.4455pt too wide) in paragraph at lines 354--354
[] \OT1/cmtt/m/n/9 # randomly select random number of the instances where there are clusters[]
[]
Overfull \hbox (344.84198pt too wide) in paragraph at lines 354--354
[] \OT1/cmtt/m/n/9 random_cluster_instances = np.random.choice(cluster_instances, size=int(len(cluster_instances)* random.uniform(0.01, 1.0)), replace=False)[]
[]
<./images/task_3_maze_4.png, id=48, 355.3275pt x 442.65375pt>
File: ./images/task_3_maze_4.png Graphic file (type png)
<use ./images/task_3_maze_4.png>
Package pdftex.def Info: ./images/task_3_maze_4.png used on input line 368.
(pdftex.def) Requested size: 113.81102pt x 141.78041pt.
[10 <./images/task_3_maze_4.png (PNG copy)>] [11] (./solution.aux)
LaTeX Warning: There were multiply-defined labels.
)
Here is how much of TeX's memory you used:
2457 strings out of 478238
38444 string characters out of 5850456
344379 words of memory out of 5000000
20696 multiletter control sequences out of 15000+600000
476639 words of font info for 54 fonts, out of 8000000 for 9000
1141 hyphenation exceptions out of 8191
55i,7n,62p,938b,366s stack positions out of 5000i,500n,10000p,200000b,80000s
{/usr/share/texmf-dist/fonts/enc/dvips/cm-super/cm-super-ts1.enc}</usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx10.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx12.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi10.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr12.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr17.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmr9.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmti10.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmti9.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmtt10.pfb></usr/share/texmf-dist/fonts/type1/public/amsfonts/cm/cmtt9.pfb></usr/share/texmf-dist/fonts/type1/public/cm-super/sfrm0900.pfb></usr/share/texmf-dist/fonts/type1/public/cm-super/sfrm1000.pfb>
Output written on solution.pdf (11 pages, 879285 bytes).
PDF statistics:
112 PDF objects out of 1000 (max. 8388607)
66 compressed objects within 1 object stream
0 named destinations out of 1000 (max. 500000)
31 words of extra memory for PDF output out of 10000 (max. 10000000)

Binary file not shown.

Binary file not shown.

View File

@ -248,7 +248,7 @@ I also generated the initial population using the same function, but firstly I g
\end{center}
\end{small}
The results I got using this approach were suprising! I got a perfect score on all mazes. I think that the reason for this is that the mutation function is not only taking into account the walls, but also the previous solution. The algorithm converges really fast now. In 5 generations we get a shortest path! I even generated a 10000 x 10000 maze and it solved it!
The results I got using this approach were suprising! I got a perfect score on all mazes. I think that the reason for this is that the mutation function is not only taking into account the walls, but also the previous solution. The algorithm converges really fast now. In 5 generations of 400 specimens we get a shortest path! I even generated a 1000 x 1000 maze and it solved it in a few seconds!
\subsection{Task 3}
@ -269,6 +269,107 @@ In Task 3, mazes also contain treasure (marked with T). For example:
Your task is to modify your approach so that the solution returns as short a path as possible that also
collects all the treasure.
\subsubsection{Approach}
For treasures to be found I had to modify my fitness function, initial population generation and mutation function. I introduced clustering of cells which are close to the treasures.
That way the genetic algoritm will also mutate in that way. Clusterization is done using simple alogirthm, which just checks for K valid cells arround the treasure and adds them to
the cluster. The cluster is then used to influence generation of the initial population and mutation of the population.
\begin{figure}[h]
\centering
\includegraphics[width=4cm]{./images/task_3_clustering.png}
\caption{Clustering example}
\label{image:task_3_clustering}
\end{figure}
The fitness function had also be redefined to also take into account the treasures. The fitness function is defined as follows:
\begin{small}
\begin{center}
\begin{verbatim}
def fitness_func(path, solution_idx):
.........................
if path[maze.start_pos] == 1 and path[maze.end_pos] == 1:
fitness += 300
# Check if there is a valid path
# First check if there is a path from start to end
paths = []
complete_path = maze.walk_through_maze(path, maze.end_pos)
paths.extend(complete_path)
# Then for each treasure find a path from start to treasure
treasures_found = 0
if complete_path != []:
for treasure in maze.treasures:
treasure_path = maze.walk_through_maze(path, treasure)
if treasure_path != []:
treasures_found += 1
paths.extend(treasure_path)
# Remove duplicates
path = list(set(paths))
path_len = len(path)
# Set the first path found as the shotest one
if maze.shortest_path == [] and path_len > 0 and treasures_found >= len(maze.treasures) // 2:
fitness += treasures_found * 1000
print('First path found')
maze.shortest_path = path
maze.treasures_found = treasures_found
maze.adjust_weights(complete_path)
#Check if the current path is shorter than the shortest one
elif treasures_found > maze.treasures_found and path_len > 0:
fitness += 1000 * treasures_found
print('Path with more treasures found!')
maze.shortest_path = path
maze.treasures_found = treasures_found
maze.adjust_weights(complete_path)
elif path_len < len(maze.shortest_path) and treasures_found > maze.treasures_found and path_len > 0:
fitness += 1000 * treasures_found
print('Path with less steps found!')
maze.shortest_path = path
maze.treasures_found = treasures_found
maze.adjust_weights(complete_path)
..........................
\end{verbatim}
\end{center}
\end{small}
So now each time there is a treasue in the path or if there is a shorter path, the fitness function will increase the fitness of the specimen. The fitness function also takes into account the number of treasures found. If there is a path with more treasures found, the fitness function will increase the fitness of the specimen.
And the mutation function is same as in task 2, but now it also takes into account the treasures. The mutation function is defined as follows:
\begin{small}
\begin{center}
\begin{verbatim}
def on_mutation(generations, ga_instance):
.........................
cluster_instances = np.reshape(np.array(maze.clusters), -1)
# Loop through the population
for i in range(len(generations)):
# randomly select random number of the instances where there are clusters
random_cluster_instances = np.random.choice(cluster_instances, size=int(len(cluster_instances)* random.uniform(0.01, 1.0)), replace=False)
.........................
generations[i][random_cluster_instances] = 1
.........................
return generations
\end{verbatim}
\end{center}
\end{small}
\subsubsection{Results}
Results are very good! The algorithm finds the shortest path and collects all the treasures on all provided test mazes.
Example of the shortest path found on maze 4:
\begin{small}
\textit{The shortest path is [(12, 4), (4, 9), (5, 1), (3, 13), (5, 10), (10, 6), (7, 1), (1, 15), (18, 1), (16, 13), (18, 10), (7, 10), (9, 1), (3, 15), (17, 14), (13, 1), (1, 8), (6, 4), (18, 3), (7, 12), (14, 8), (17, 16), (1, 10), (15, 9), (18, 5), (7, 5), (7, 14), (3, 1), (14, 1), (3, 10), (13, 5), (1, 3), (16, 1), (1, 12), (16, 10), (18, 7), (14, 3), (3, 12), (1, 5), (6, 1), (1, 14), (16, 12), (18, 9), (14, 5), (4, 4), (3, 14), (10, 1), (1, 7), (18, 2), (1, 16), (16, 14), (7, 11), (12, 1), (14, 7), (5, 4), (4, 6), (3, 16), (8, 6), (10, 3), (1, 9), (18, 4), (12, 3), (4, 8), (10, 5), (1, 2), (2, 1), (1, 11), (6, 10), (12, 5), (4, 1), (3, 11), (4, 10), (8, 1), (19, 10), (1, 4), (1, 13), (14, 4), (17, 15), (1, 6), (15, 8), (6, 5), (7, 13), (14, 6), (4, 5), (8, 5), (11, 1), (17, 17), (2, 16), (15, 1), (15, 10), (18, 6), (4, 7), (17, 1), (10, 4), (9, 6), (11, 3), (1, 1), (16, 11), (18, 8)] }
\end{small}
\begin{figure}[h]
\centering
\includegraphics[width=4cm]{./images/task_3_maze_4.png}
\caption{Shortest path in maze 4, collecting all treasures}
\label{image:task_1_maze_1}
\end{figure}
\subsection{Task 4}
\subsubsection{Task description}