Пример #1
0
def eval_problema(prob_name):
    name, comment, w_type, vertex_list = tsp_load_(prob_name, True)
    dist_matrix = gen_distance_matrix_(vertex_list, w_type)
    n_vertex = len(vertex_list)

    echo('--- Iniciando pruebas ---')
    for i in xrange(NRO_PRUEVAS):
        soluc_a = nearest_vertex(dist_matrix, n_vertex)
        value_a = get_obj_function_value(soluc_a, dist_matrix)
        echo('------------------------------------------------------')
        echo('Problema: ', name)
        echo('Comentarios: ', comment)
        echo('Inicio: ', time.strftime("[%d/%m/%Y-%H:%M:%S]"))
        echo('---------------- Inicio Prueba Nro %d ----------------' % i)
        echo('NRO Vecindades: ', NRO_VECINDADES)
        echo('Iteraciones por vecindad: ', MAX_ITERACIONES)
        echo('Probabilidad: ', PROBABILIDAD)
        echo('------------------------------------------------------', '\n')
        value_a, soluc_a = vns_opt_improved(soluc_a, value_a, NRO_VECINDADES,\
                    MAX_ITERACIONES, PROBABILIDAD, dist_matrix)

        echo('\n', '------------------------------------------------------')
        echo('Fin: ', time.strftime("[%d/%m/%Y-%H:%M:%S]"))
        echo('Mejor Solucion: ', value_a)

        #guardamos la mejor solucion de la instancia
        sol_name = 'mejor_sol_%s_%d.dat' % (name, i)
        save_solucion(sol_name, soluc_a)

        data_name = 'prueva_%s_%d.txt' % (name, i)
        os.rename('stdout.txt', data_name)
Пример #2
0
def eval_problema(prob_name):
    name, comment, w_type, vertex_list = tsp_load_(prob_name, True)
    dist_matrix = gen_distance_matrix_(vertex_list, w_type)
    n_vertex = len(vertex_list)

    echo('--- Iniciando pruebas ---')
    for i in xrange(NRO_PRUEVAS):
        soluc_a = nearest_vertex(dist_matrix, n_vertex)
        value_a = get_obj_function_value(soluc_a, dist_matrix)
        echo('------------------------------------------------------')
        echo('Problema: ',name)
        echo('Comentarios: ',comment)
        echo('Inicio: ',time.strftime("[%d/%m/%Y-%H:%M:%S]"))
        echo('---------------- Inicio Prueba Nro %d ----------------' %i)
        echo('NRO Vecindades: ', NRO_VECINDADES)
        echo('Iteraciones por vecindad: ', MAX_ITERACIONES)
        echo('Probabilidad: ', PROBABILIDAD)
        echo('------------------------------------------------------','\n')
        value_a, soluc_a = vns_opt_improved(soluc_a, value_a, NRO_VECINDADES,\
                    MAX_ITERACIONES, PROBABILIDAD, dist_matrix)

        echo('\n','------------------------------------------------------')
        echo('Fin: ',time.strftime("[%d/%m/%Y-%H:%M:%S]"))
        echo('Mejor Solucion: ', value_a)

        #guardamos la mejor solucion de la instancia
        sol_name = 'mejor_sol_%s_%d.dat' %(name, i)
        save_solucion(sol_name, soluc_a)

        data_name = 'prueva_%s_%d.txt' %(name, i)
        os.rename('stdout.txt', data_name)
Пример #3
0
def mainaaa():
    pygame.init()
    screen = pygame.display.set_mode(RESOLUCION)#, pygame.FULLSCREEN)
    screen.fill(BLANCO)

    #name, comment, vertex_list = tsp_load('eil51.tsp', False, True)
    name, comment, w_type, vertex_list = tsp_load_('eil51.tsp', True)
    dist_matrix = gen_distance_matrix_(vertex_list, w_type)
    n_vertex = len(vertex_list)
    soluc_a = nearest_vertex(dist_matrix, n_vertex)


    x_ini = vertex_list[0][0]
    x_fin = vertex_list[0][0]

    y_ini = vertex_list[0][1]
    y_fin = vertex_list[0][1]

    for vertex in vertex_list:
        if vertex[0] > x_fin:
            x_fin = vertex[0]
        if vertex[0] < x_ini:
            x_ini = vertex[0]

        if vertex[1] > y_fin:
            y_fin = vertex[0]
        if vertex[1] < y_ini:
            y_ini = vertex[0]

    print (x_fin - x_ini), (y_fin - y_ini)

    for vertex in vertex_list:
        x, y = vertex
        x = int(x - x_ini + 10)*4
        y = int(y - y_ini + 10)*4
        pygame.draw.circle(screen, ROJO, (x, y), 2, 0)
    lists = []
    for index in soluc_a:
        x = int((vertex_list[index][0]-x_ini+10)*4)
        y = int((vertex_list[index][1]-y_ini+10)*4)
        lists.append([x,y])
    pygame.draw.circle(screen, ROJO, lists[0], 4, 0)
    pygame.draw.lines(screen,AZUL,True,lists)

    print 'fin'

    loop = True
    while loop:


        pygame.display.flip()

        for evento in pygame.event.get():
            if evento.type == pygame.QUIT:
                loop = False
Пример #4
0
def mainaaa():
    pygame.init()
    screen = pygame.display.set_mode(RESOLUCION)  #, pygame.FULLSCREEN)
    screen.fill(BLANCO)

    #name, comment, vertex_list = tsp_load('eil51.tsp', False, True)
    name, comment, w_type, vertex_list = tsp_load_('eil51.tsp', True)
    dist_matrix = gen_distance_matrix_(vertex_list, w_type)
    n_vertex = len(vertex_list)
    soluc_a = nearest_vertex(dist_matrix, n_vertex)

    x_ini = vertex_list[0][0]
    x_fin = vertex_list[0][0]

    y_ini = vertex_list[0][1]
    y_fin = vertex_list[0][1]

    for vertex in vertex_list:
        if vertex[0] > x_fin:
            x_fin = vertex[0]
        if vertex[0] < x_ini:
            x_ini = vertex[0]

        if vertex[1] > y_fin:
            y_fin = vertex[0]
        if vertex[1] < y_ini:
            y_ini = vertex[0]

    print(x_fin - x_ini), (y_fin - y_ini)

    for vertex in vertex_list:
        x, y = vertex
        x = int(x - x_ini + 10) * 4
        y = int(y - y_ini + 10) * 4
        pygame.draw.circle(screen, ROJO, (x, y), 2, 0)
    lists = []
    for index in soluc_a:
        x = int((vertex_list[index][0] - x_ini + 10) * 4)
        y = int((vertex_list[index][1] - y_ini + 10) * 4)
        lists.append([x, y])
    pygame.draw.circle(screen, ROJO, lists[0], 4, 0)
    pygame.draw.lines(screen, AZUL, True, lists)

    print 'fin'

    loop = True
    while loop:

        pygame.display.flip()

        for evento in pygame.event.get():
            if evento.type == pygame.QUIT:
                loop = False