Example #1
0
def main():
    #f_name ,s_exa = tsp_sol_load('pr76.opt.tour', False, True)
    name, comment, vertex_list = tsp_load('p654.tsp', False, True)

    print 'Problema:', name
    print 'Comentarios:', comment
    m = gen_distance_matrix(vertex_list)

    #s1 = gen_random_sol(vertex_list)
    #print 'rand', get_obj_function_value(s1, m)

    #anda para el ojete
    #t = type_moon(vertex_list, m)
    #print 'type_moon', get_obj_function_value(t, m)

    s0 = greedy(vertex_list, m, 502)
    l = len(s0)
    print 'greedy', get_obj_function_value(s0, m)

    s1 = vns_opt2(s0, m)
    print 'vns', get_obj_function_value(s1, m)
    if l != len(s1):
        print 'mankeada'

    s2 = opt3_(s1, m)
    print 'opt3', get_obj_function_value(s2, m)
    if l != len(s2):
        print 'mankeada'
Example #2
0
def main():
    #f_name ,s_exa = tsp_sol_load('pr76.opt.tour', False, True)
    name, comment, vertex_list = tsp_load('p654.tsp', False, True)

    print 'Problema:', name
    print 'Comentarios:', comment
    m = gen_distance_matrix(vertex_list)

    #s1 = gen_random_sol(vertex_list)
    #print 'rand', get_obj_function_value(s1, m)

    #anda para el ojete
    #t = type_moon(vertex_list, m)
    #print 'type_moon', get_obj_function_value(t, m)

    s0 = greedy(vertex_list, m, 502)
    l = len(s0)
    print 'greedy', get_obj_function_value(s0, m)

    s1 = vns_opt2(s0, m)
    print 'vns', get_obj_function_value(s1, m)
    if l != len(s1):
        print 'mankeada'

    s2 = opt3_(s1, m)
    print 'opt3', get_obj_function_value(s2, m)
    if l != len(s2):
        print 'mankeada'
Example #3
0
def main():
    #505
    opc = menu()
    if opc != '0':
        #file_name = raw_input('Nombre del fichero: ')
        name, comment, vertex_list = tsp_load('eil51.tsp', False, True)
        print 'Problema:', name
        print 'Comentarios:', comment
        sol = 999999999 #valor muy alto para una solucion inicial base
        dist_matrix = gen_distance_matrix(vertex_list)

        for i in xrange(len(vertex_list)):
            s0 = greedy(vertex_list, dist_matrix, i)
            s1 = opt2(s0, dist_matrix)
            s2 = vns_opt2(s1, dist_matrix)
            nsol = get_obj_function_value(s2, dist_matrix)
            if nsol < sol:
                sol = nsol
                ms = s1[:]
                print 'nueva mejor sol :P'
            print 'greedy',i, 'sol: 2opt+vns', nsol, 'mejor:', sol

        s3 = opt3_(ms, dist_matrix)
        print 'opt3', get_obj_function_value(s3, dist_matrix)
        s4 = vns_opt2(ms, dist_matrix)
        print 'vns_2opt', get_obj_function_value(s4, dist_matrix)
Example #4
0
def main():
    #505
    opc = menu()
    if opc != '0':
        #file_name = raw_input('Nombre del fichero: ')
        name, comment, vertex_list = tsp_load('eil51.tsp', False, True)
        print 'Problema:', name
        print 'Comentarios:', comment
        sol = 999999999  #valor muy alto para una solucion inicial base
        dist_matrix = gen_distance_matrix(vertex_list)

        for i in xrange(len(vertex_list)):
            s0 = greedy(vertex_list, dist_matrix, i)
            s1 = opt2(s0, dist_matrix)
            s2 = vns_opt2(s1, dist_matrix)
            nsol = get_obj_function_value(s2, dist_matrix)
            if nsol < sol:
                sol = nsol
                ms = s1[:]
                print 'nueva mejor sol :P'
            print 'greedy', i, 'sol: 2opt+vns', nsol, 'mejor:', sol

        s3 = opt3_(ms, dist_matrix)
        print 'opt3', get_obj_function_value(s3, dist_matrix)
        s4 = vns_opt2(ms, dist_matrix)
        print 'vns_2opt', get_obj_function_value(s4, dist_matrix)
Example #5
0
def main():
    name, comment, vertex_list = tsp_load('p654.tsp', False, True)
    dist_matrix = gen_distance_matrix(vertex_list)

    #mejor valor encontrado, sacado de la tabla
    optimo = 34643

    #fichero con la solucion a cargar
    soluc_a = load_solucion('mejor_sol_p654_1.dat')
    value_a = get_obj_function_value(soluc_a, dist_matrix)
    percent = (value_a - optimo) * 100 / optimo

    print '\n----- Resultados -----'
    print 'Optimo Tabla: ', optimo
    print 'Mi Optimo', value_a
    print 'Porcentaje de Error', percent
Example #6
0
def main():
    name, comment, vertex_list = tsp_load('p654.tsp', False, True)
    dist_matrix = gen_distance_matrix(vertex_list)

    #mejor valor encontrado, sacado de la tabla
    optimo = 34643

    #fichero con la solucion a cargar
    soluc_a = load_solucion('mejor_sol_p654_1.dat')
    value_a = get_obj_function_value(soluc_a, dist_matrix)
    percent = (value_a - optimo) * 100 / optimo

    print '\n----- Resultados -----'
    print 'Optimo Tabla: ', optimo
    print 'Mi Optimo', value_a
    print 'Porcentaje de Error', percent
Example #7
0
def main():
    #opc = menu()
    #if opc != '0':
    #file_name = raw_input('Nombre del fichero: ')
    #name, comment, vertex_list = tsp_load('ch130.tsp', False, True)
    name, comment, vertex_list = tsp_load('rat575.tsp', False, True)
    print 'Problema:', name
    print 'Comentarios:', comment
    dist_matrix = gen_distance_matrix(vertex_list)
    a = nearest_vertex(dist_matrix, len(vertex_list))
    solution_validator(a, len(vertex_list))
    value_a = get_obj_function_value(a, dist_matrix)

    for i in range(1):
        vns_opt_improved(a, value_a, 20, 30, 0.98, dist_matrix)
    for i in range(1):
        vns_opt(a, value_a, 20, 30, dist_matrix)
Example #8
0
def main():
    #opc = menu()
    #if opc != '0':
        #file_name = raw_input('Nombre del fichero: ')
        #name, comment, vertex_list = tsp_load('ch130.tsp', False, True)
        name, comment, vertex_list = tsp_load('rat575.tsp', False, True)
        print 'Problema:', name
        print 'Comentarios:', comment
        dist_matrix = gen_distance_matrix(vertex_list)
        a = nearest_vertex(dist_matrix,len(vertex_list))
        solution_validator(a,len(vertex_list))
        value_a = get_obj_function_value(a, dist_matrix)
        
        for i in range(1):
            vns_opt_improved(a,value_a,20,30,0.98,dist_matrix)
        for i in range(1):
            vns_opt(a,value_a,20,30,dist_matrix)
Example #9
0
def main():
    #opc = menu()
    #if opc != '0':
        #file_name = raw_input('Nombre del fichero: ')
        name, comment, vertex_list = tsp_load('ch130.tsp', False, True)
        print 'Problema:', name
        print 'Comentarios:', comment
        # falta revisar como me muevo entre vecindarios
        # y cuantos vecindarios uso
        problem_lenght = len(vertex_list)
        dist_matrix = gen_distance_matrix(vertex_list)
        #creo una solucion inicial 
        a = nearest_vertex(dist_matrix,problem_lenght)
        solution_validator(a,problem_lenght)
        value_a = get_obj_function_value(a, dist_matrix)
        best_solution =value_a
        solution = a
        a2 = a[:]
        print "Primera Solucion", value_a
        local_optima = 0
                #aplico busqueda local hasta que me encuentro con un 
                #optimo local
        while not local_optima:
            temp_solution = opt2(a,dist_matrix)
            value_temp = get_obj_function_value(temp_solution, dist_matrix)
            if value_a == value_temp:
                local_optima = 1
            if value_temp < value_a:
                a = temp_solution
                value_a = value_temp
        print "partial solution",value_temp,"best solution",best_solution#,"neig",neigborhood
        vns_opt = opt2(a2,dist_matrix)
        vns_opt = vns_opt2(vns_opt,dist_matrix)
        vns_opt = vns_opt2(vns_opt,dist_matrix)
        vns_opt_v = get_obj_function_value(vns_opt,dist_matrix)
        vopt3 = opt3_(a2,dist_matrix)
        vvopt3 = get_obj_function_value(vopt3,dist_matrix)
        print "opt_vns", vns_opt_v, "2-opt-iter", value_a, "3opt", vvopt3