-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_concorde.py
executable file
·37 lines (28 loc) · 1.08 KB
/
test_concorde.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
import json
import os
import pytest
from pytsp import atsp_tsp, run, dumps_matrix
@pytest.fixture
def matrix():
thisdir = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(thisdir, "matrix.json")) as src:
matrix = json.loads(src.read())
return matrix
def test_tour_concorde(matrix):
matrix_sym = atsp_tsp(matrix, strategy="avg")
outf = "/tmp/myroute_concorde.tsp"
with open(outf, 'w') as dest:
dest.write(dumps_matrix(matrix_sym, name="My Route"))
tour = run(outf, start=10, solver="concorde")
assert tour['solution'] == 102975
assert tour['tour'][0] == 10
# assert tour['tour'] in tours # can't do this, not deterministic
def test_tour_LKH(matrix):
matrix_sym = atsp_tsp(matrix, strategy="avg")
outf = "/tmp/myroute_lkh.tsp"
with open(outf, 'w') as dest:
dest.write(dumps_matrix(matrix_sym, name="My Route"))
tour = run(outf, start=10, solver="lkh")
assert tour['solution'] == 102975
assert tour['tour'][0] == 10
# assert tour['tour'] in tours # can't do this, not deterministic