-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_example.py
executable file
·42 lines (34 loc) · 1.17 KB
/
run_example.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
39
40
41
42
#!/usr/bin/env python
import json
import click
import time
from pyrallelsa import ParallelSAManager, ProblemClassPath, runner
from pyrallelsa.examples.tsp.cities import cities_120, cities_20, cities_100,\
pd_cities_120_alt, pd_cities_150_alt, pd_cities_200_alt
@click.command()
@click.option('-t', '--type', type=click.Choice(['seq', 'mc']), default='seq')
def main(type):
# cities = cities_100
# problem_data = dict(
# cities=cities,
# start_city="Bakous",
# updates_enabled=True
# )
problem_data = pd_cities_200_alt
cities = pd_cities_200_alt['cities']
pcp = ProblemClassPath("pyrallelsa.examples.tsp", "TSPProblem")
if type == 'mc':
psam = ParallelSAManager(pcp, problem_data)
psam.run(minutes=2.0, cpus=3)
elif type == 'seq':
start = time.time()
args = (0, pcp, json.dumps(cities.keys()), 20.0,
json.dumps(problem_data), None)
winner = runner(args)
print("With an energy of {}; {} was the best.".format(
winner.energy,
winner.state
))
print("Run took {}s".format(time.time() - start))
if __name__ == '__main__':
main()