This commit is contained in:
Claudio Maggioni 2020-12-21 16:52:19 +01:00
parent bcce2ac0d5
commit 9c83fe3bbe
7 changed files with 41 additions and 14 deletions

Binary file not shown.

View file

@ -17,11 +17,10 @@ def ant_colony_opt(instance):
"kroA100": (0.9, 8, 0.4, 1000, 750, 100, 30), # 21378 "kroA100": (0.9, 8, 0.4, 1000, 750, 100, 30), # 21378
"lin318": (0.9, 8, 0.4, 1000, 500, 32, 30), # 43171 "lin318": (0.9, 8, 0.4, 1000, 500, 32, 30), # 43171
"pcb442": (0.9, 8, 0.4, 1000, 450, 24, 3), # 52466 "pcb442": (0.9, 8, 0.4, 1000, 450, 24, 3), # 52466
"pr439": (0.9, 8, 0.4, 1000, 450, 24, 2), # 11734 "pr439": (0.9, 8, 0.4, 1000, 1000, 15, 3), # 109721
"rat783": (0.9, 8, 0.4, 1000, 450, 24, 2), # 9232 "rat783": (0.9, 8, 0.4, 1000, 300, 28, 4), # 9218
"u1060": (0.9, 8, 0.4, 1000, 350, 6, 3), # 238025 "u1060": (0.9, 8, 0.4, 1000, 350, 8, 10), # 235506
#"fl1577": (0.9, 8, 0.4, 1000, 50, 9, 3), # 24145 "fl1577": (0.9, 8, 0.4, 1000, 50, 10, 7), # 23020
"fl1577": (0.9, 8, 0.4, 1000, 50, 10, 5), # 24145
} }
alpha, beta, evap, weight, ants, loops, optruns = params[instance.name] alpha, beta, evap, weight, ants, loops, optruns = params[instance.name]

14
approach.md Normal file
View file

@ -0,0 +1,14 @@
# System information
Here is a summary of the system characteristics of the machine used to measure the execution time and
execution results for my AI cup submission:
| Characteristic | Value |
| :------------- | :----------: |
| Machine used | Macbook Pro 2018 15" |
| OS Version | MacOS Catalina 10.15.7 |
| Kernel | Mach 19.6.0 |
| Interpreter used (Python wrapper) | CPython 3.8.3 (default, Jul 2 2020, 11:26:31) |
| Compiler used (C++ companion program) | Apple clang version 12.0.0 (clang-1200.0.32.21) |
| Compiler optimization level (C++ companion program) | `-O2` |
| CPU | Intel i7-8750H (12) @ 2.20GHz |

View file

@ -10,7 +10,7 @@ one must have the following requirements:
acceptable compilers). acceptable compilers).
## Execution ## Execution
`cd` in the `code` directory and execute `python3 ./run.py` from the terminal. `cd` in the `code` directory and execute `python3 ./run.py all` from the terminal.
The script will automatically compile the C++ companion program and start the TSP computation for each problem. The script will automatically compile the C++ companion program and start the TSP computation for each problem.
Results will be saved in `<problemname>.sol` files where `<problemname>` is respectively the name Results will be saved in `<problemname>.sol` files where `<problemname>` is respectively the name
@ -20,6 +20,19 @@ Execution time for each problem will be computed using the same criteria used fo
Times and lengths found will be saved in a file named `results.csv` which will be located in the same directory as Times and lengths found will be saved in a file named `results.csv` which will be located in the same directory as
`run.py`. `run.py`.
Should it be necessary to run the TSP algorithm problem by problem (e.g. if the execution time must be measured by an
external program,
execute first the command:
```bash
c++ -O2 -lpthread --std=c++11 -o c_prob/aco aco.cc opt.cc
```
Then execute `python3 run.py <problem name>` where `<problem name>` is the problem name without extension
(e.g. `rat783`)
The `c++` may not be repeated when running multiple problems in a one-by-one fashion.
## `.sol` file contents ## `.sol` file contents
Solution files are made up of just one line, containing a valid Python expression representing an array. Solution files are made up of just one line, containing a valid Python expression representing an array.
The array in question contains the order in which cities must be visited, representing each city by its number. The array in question contains the order in which cities must be visited, representing each city by its number.

10
run.py
View file

@ -3,13 +3,13 @@ import pandas as pd
from aco.io_tsp import ProblemInstance from aco.io_tsp import ProblemInstance
from aco.TSP_solver import TSPSolver from aco.TSP_solver import TSPSolver
import os import os
import sys
def run(show_plots=False, verbose=False): def run(show_plots=False, verbose=False):
os.system("rm -f " + " ".join(glob.glob("sol/*") + glob.glob("c_prob/*"))) os.system("rm -f " + " ".join(glob.glob("sol/*.sol") + glob.glob("c_prob/*.txt")))
os.system("c++ -O2 -lpthread --std=c++11 -o c_prob/aco aco.cc opt.cc") if sys.argv[1] == "all":
problems = glob.glob('./problems/*.tsp') os.system("c++ -O2 -lpthread --std=c++11 -o c_prob/aco aco.cc opt.cc")
problems = glob.glob('./problems/*.tsp') if sys.argv[1] == "all" else [f"./problems/{sys.argv[1]}.tsp"]
problems = ["./problems/fl1577.tsp"]
results = [] results = []
index = [] index = []

File diff suppressed because one or more lines are too long

View file

@ -5,8 +5,10 @@ execution results for my AI cup submission:
| Characteristic | Value | | Characteristic | Value |
| :------------- | :----------: | | :------------- | :----------: |
| Machine used | Macbook Pro 2018 15" |
| OS Version | MacOS Catalina 10.15.7 | | OS Version | MacOS Catalina 10.15.7 |
| Kernel | Mach 19.6.0 | | Kernel | Mach 19.6.0 |
| Compiler used | Apple clang version 12.0.0 (clang-1200.0.32.21) | | Interpreter used (Python wrapper) | CPython 3.8.3 (default, Jul 2 2020, 11:26:31) |
| Compiler optimization level | `-O2` | | Compiler used (C++ companion program) | Apple clang version 12.0.0 (clang-1200.0.32.21) |
| Compiler optimization level (C++ companion program) | `-O2` |
| CPU | Intel i7-8750H (12) @ 2.20GHz | | CPU | Intel i7-8750H (12) @ 2.20GHz |