|
| 1 | +from argparse import ArgumentParser |
| 2 | +from os.path import split |
| 3 | +from time import time |
| 4 | + |
1 | 5 | from algorithm.algorithm import Algorithm |
2 | 6 | from parsers.input_parser import parse_input |
3 | | -from utils.solution_checker import check_solution |
4 | | -from parsers.output_builder import save_solution |
5 | | -import time |
| 7 | +from parsers.output_builder import save_solution, save_execution_parameters |
| 8 | +from utils.argument_parser_util import add_parser_arguments, str2bool |
| 9 | +from utils.solution_checker import check_solution, calculate_score |
6 | 10 |
|
7 | 11 |
|
8 | 12 | def main(): |
9 | | - input_file = "files/videos_worth_spreading.in" |
10 | | - # input_file = "files/kittens.in" |
11 | | - # input_file = "files/example1.in" |
12 | | - input_file = "files/me_at_the_zoo.in" |
13 | | - # input_file = "files/trending_today.in" |
14 | | - |
15 | | - # solution_file = "files/example1.out" |
16 | | - # solution = check_solution(input_file, solution_file) |
17 | | - # print(solution) |
| 13 | + input_file, output_file = args.i, args.o |
| 14 | + n, m, e = args.n, args.m, args.e |
| 15 | + nep, nsp, ngh = args.nep, args.nsp, args.ngh |
| 16 | + iterations = args.max |
| 17 | + should_save = str2bool(args.s) |
18 | 18 |
|
19 | | - before = time.time() |
20 | | - best_solution = Algorithm.execute(parse_input(input_file)) |
21 | | - save_solution(best_solution, "files/out1.out") |
22 | | - score = check_solution(input_file, "files/out1.out") |
23 | | - after = time.time() |
| 19 | + before = time() |
| 20 | + data = parse_input(input_file) |
| 21 | + best_solution = Algorithm.execute(data, n, m, e, nep, nsp, ngh, iterations) |
| 22 | + if should_save: |
| 23 | + save_solution(best_solution, output_file) |
| 24 | + score = check_solution(input_file, output_file) |
| 25 | + else: |
| 26 | + score = calculate_score(data, best_solution) |
| 27 | + filename = split(input_file)[1] |
| 28 | + save_execution_parameters(";", filename, n, m, e, nep, nsp, ngh, iterations, score, output_file) |
| 29 | + after = time() |
24 | 30 |
|
25 | 31 | print(best_solution) |
26 | 32 | print("-----------------------------") |
27 | | - print("Algorithm took: " + str(round(after-before, 2)) + " s") |
| 33 | + print("Algorithm took: " + str(round(after - before, 2)) + " s") |
28 | 34 | print("-----------------------------") |
29 | 35 | print("Saved time: " + str(round(score / 1000, 2)) + " s (score: " + str(score) + ")") |
30 | 36 |
|
31 | | -if __name__ == '__main__': |
| 37 | + |
| 38 | +if __name__ == "__main__": |
| 39 | + parser = ArgumentParser(description="Distributed cache problem solver.") |
| 40 | + add_parser_arguments(parser) |
| 41 | + args = parser.parse_args() |
32 | 42 | main() |
0 commit comments