-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
38 lines (31 loc) · 1.41 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import argparse
from utils.aco import Environment
from utils.data import plot_length, plot_path, save_path
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('--input', type=str,
default="data/a280.tsp", help="Input file")
parser.add_argument('--num-ants', type=int,
default=50, help="Num of ants of the colony")
parser.add_argument('--alpha', type=float, nargs='+',
default=[1.6, 1.6], help="Pheromone power constant")
parser.add_argument('--beta', type=float, nargs='+',
default=[1, 1], help="Visibility power constant")
parser.add_argument('--evap-rate', type=float,
default=0.15, help="Pheromone evaporation rate")
parser.add_argument('--est-len', type=float,
default=1.0, help="Estimated tour length")
parser.add_argument('--num-iters', type=int,
default=30, help="Number of iterations")
args = parser.parse_args()
return args
def main():
args = parse_arguments()
env = Environment(args.input, args.num_ants, args.alpha, args.beta,
args.evap_rate, args.est_len, args.num_iters)
env.run()
print(env.best_path_length)
# plot_length(env.best_path_length_history)
# plot_path(env.best_path, env.vertices)
if __name__ == "__main__":
main()