30 lines
1.5 KiB
Markdown
30 lines
1.5 KiB
Markdown
<!-- vim: set ts=2 sw=2 et tw=80: -->
|
|
|
|
# Approach used to solve the AI cup
|
|
|
|
My submission for the AI cup uses a _Ant Colony Optimization_ algorithm
|
|
implementation paired with a 3-opt optimizer.
|
|
|
|
For efficiency's sake, both the
|
|
algorithm and the optimizer were implemented in C++. However, solution checking
|
|
and the calculation of the euclid distance matrix are still computed in a
|
|
modified version of the Python 3 code of the `AI2020BsC` repository from Mr.
|
|
Montegazza.
|
|
|
|
The Python code first compiles the C++ portion of the code in an executable.
|
|
Then, a Python wrapper is used to call said executable. The distance matrix is
|
|
computed by the Python implementation and then saved in a .txt file. The C++
|
|
executable reads said file and, after executing the algorithm and the optimizer,
|
|
the program writes on the standard output a python expression containing the
|
|
solution array. This expression is then read by the Python wrapper and evaluated
|
|
using `eval(...)`, and then is is checked and displayed thanks to the original
|
|
`AI2020BsC` code.
|
|
|
|
More details on how to compile and run the program can be found in `execute.md`.
|
|
|
|
The C++ implementation is by default non-parallel, as I interpreted the
|
|
"Single CPU" restriction described in the cup introductory PDF as meaning that
|
|
the code must run on a single core. The implementation can however be easily
|
|
converted in a multi-core one ant per thread implentation by changing the
|
|
`#define SINGLE_CORE` flag in `aco.cc` to `0`. Note that the 3 minute limit is
|
|
of course never reached even when using the single core implementation.
|