Пример #1
0
def tsplib(content, f=1, r=None, learning_plot=False):
    idx = content.index('DIMENSION:') + 1
    n = int(content[idx])
    idx = content.index('EDGE_WEIGHT_FORMAT:') + 1
    if content[idx] != 'FULL_MATRIX':
        return [], 0
    idx = content.index('EDGE_WEIGHT_SECTION') + 1
    inf = int(content[idx])
    data = []
    for i in range(n):
        if len(content) > idx + n:
            data.append(list(map(int, content[idx:idx + n])))
        else:
            return [], 0
        idx += n

    for j in range(len(data)):
        print(data[j])
        print('\n')

    _atsp = atsp.SA(data,
                    initial_fitness=f,
                    infinity=inf,
                    regularization_bound=r,
                    learning_plot=learning_plot)
    return _atsp.solve()
Пример #2
0
def atsp_array(array):
    _atsp = atsp.SA(list(map(int, array)),
                    regularization_bound=(0.3, 3),
                    silent_mode=True)
    output.put(_atsp.solve())
Пример #3
0
import atsp, sys

if len(sys.argv) == 2:
    with open(sys.argv[1], 'r') as fp:
        content = fp.read().split()
        atsp = atsp.SA(list(map(int, content)),
                       regularization_bound=(0.3, 3),
                       learning_plot=True)
        res = atsp.solve()
        if res[1]:
            print('OPTIMIZED COST:', res[1])
            print(' '.join(map(str, res[0])))
        else:
            print('NO SOLUTION')