コード例 #1
0
def test_tsp():
    """
    Shortest Path: 1 3 2 5 6 4 1
    """
    coordinates = [
        dp.Coordinate(*x) for x in [(2, 1), (4, 0), (2, 0), (0, 0), (4, 3), (0, 3)]
    ]
    actual = hs.tsp(coordinates)
    assert round(actual, 4) == 15.2361
コード例 #2
0
def test_tsp():
    coordinates = [dp.Coordinate(*x) for x in ((0, 0), (4, 3), (4, 0), (0, 3))]
    actual = dp.tsp(coordinates)
    assert actual == 14.0
コード例 #3
0
def test_distance(x, y, distance):
    c1 = dp.Coordinate(x=0, y=0)
    c2 = dp.Coordinate(x=x, y=y)
    assert dp.distance(c1, c2) == distance
コード例 #4
0
def test_tsp(file, expected):
    coordinates = util.get_tuples(file, skip_first=True, num_type=float)
    coordinates = [dp.Coordinate(*x) for x in coordinates]
    actual = dp.tsp(coordinates)
    assert round(actual, 2) == expected
コード例 #5
0
def test_tsp(file, expected):
    coordinates = util.get_tuples(file, skip_first=True, num_type=float)
    coordinates = [dp.Coordinate(x[1], x[2]) for x in coordinates]
    actual = heuristics.tsp(coordinates)
    assert int(actual) == expected