Beispiel #1
0
def searchers(search, size, number, info, opt, iterations, swap, proc):
    if info:
        logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO)

    average = 0.
    ft_start = time()
    for _ in range(number):
        tsp = generator(size)
        matrix = adjacency_matrix(tsp)

        t_start = time()
        searcher = search_type[search](matrix=matrix, opt=opt, proc=proc)
        searcher.optimize(iterations=iterations, swap=swap)
        average += (time() - t_start)

    click.echo(f'all: {time() - ft_start} s')
    click.echo(f'average: {average / number} s')
Beispiel #2
0
def opts(opt, size, number, info, neighbours, k, mul, sb, ns):
    if info:
        logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO)

    average = 0.
    ft_start = time()
    for _ in range(number):
        tsp = generator(size)
        matrix = adjacency_matrix(tsp)
        length, tour = greedy(matrix)

        t_start = time()
        searcher = opts_type[opt](length, tour, matrix, neighbours=neighbours, k=k, mul=mul, subgradient=sb, non_seq=ns)
        searcher.optimize()
        average += (time() - t_start)

    click.echo(f'all: {time() - ft_start} s')
    click.echo(f'average: {average / number} s')
Beispiel #3
0
def test_greedy_with_two_opt():
    tsp = generator(size)
    matrix = adjacency_matrix(tsp)
    length, tour = two_opt(matrix)
    assert round(get_length(tour, matrix),
                 2) == round(length, 2), 'generated wrong tour'
Beispiel #4
0
def generate_metric_tsp():
    """ Генерируем данные для метрической задачи коммивояжера """
    tsp = generator(size)
    matrix = adjacency_matrix(tsp)
    length, tour = greedy(matrix)
    return length, tour, matrix
Beispiel #5
0
import faulthandler
import logging
from time import time

from lin_kernighan.algorithms.structures.matrix import adjacency_matrix
from lin_kernighan.algorithms.utils.generator import generator
from lin_kernighan.lkh_search import LKHSearch

if __name__ == '__main__':
    size = 500
    logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO)

    faulthandler.enable()
    full = 0.0
    num = 1
    t_start = time()
    for _ in range(num):
        tsp = generator(size)
        matrix = adjacency_matrix(tsp)

        t_start = time()
        opt = LKHSearch(matrix)
        opt.optimize()
        full += (time() - t_start)

    logging.info(f'end: {full / num}')