forked from donfaq/VRPTW
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
33 lines (28 loc) · 1.4 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
import os
import glob
import argparse
from VRPTW import *
def arguments() -> argparse.Namespace:
parser = argparse.ArgumentParser(description='Solving VRPTW with heuristics')
parser.add_argument('problem_file', type=str, help='Problem file (in Solomon format)')
parser.add_argument('--benchmark', type=bool, default=False, help="Run solvers on all files in instances folder")
return parser.parse_args()
if __name__ == '__main__':
args = arguments()
if not os.path.exists('solutions'):
os.mkdir('solutions')
if args.benchmark:
for file in glob.glob('instances/*.txt'):
problem = SolomonFormatParser(file).get_problem()
solution = IteratedLocalSearch(problem).execute()
with open(f"""solutions/{file.split(os.sep)[1].split(".")[0]}.sol""", 'w') as f:
print(file.split(os.sep)[1].split(".")[0], problem.obj_func(solution))
f.write(problem.print_canonical(solution))
else:
assert os.path.exists(args.problem_file), "Problem file doesn't exist"
problem = SolomonFormatParser(args.problem_file).get_problem()
print(problem)
solution = IteratedLocalSearch(problem).execute()
with open(f"""solutions/{args.problem_file.split(os.sep)[-1].split(".")[0]}.sol""", 'w') as f:
f.write(problem.print_canonical(solution))
# solution = GuidedLocalSearch(problem).execute()