Пример #1
0
def run_gmctp1(input_file, output_file):
    time1 = datetime.datetime.now()
    file = join(data_dir, data_mgctp1, input_file)
    problem = GMCTPProblem(data_path=file)

    problem.max_nodes_per_route = 1000
    #    problem.max_tour_length = MAX_VALUE

    #    print problem.max_tour_length

    best_solution = None
    best_cost = MAX_VALUE

    best_runs = []
    lines = []
    for job in xrange(JOBS):
        ga = GA_MCTP(problem, job)
        cost, tours = ga.run()

        best_runs.append(cost)

        if cost < best_cost:
            best_cost = cost
            best_solution = deepcopy(tours)

        lines.append('%s %.2f %.2f %d [%s] %s\n' % (
            input_file,
            problem.best_cost,
            best_cost,
            len(best_solution),
            #                                                  d.seconds,
            ' '.join([str(v) for v in best_runs]),
            str(best_solution),
            #                                                  str(best_solution.tours)
        ))


#         print best_cost, best_solution
    time2 = datetime.datetime.now()
    duration = time2 - time1

    lines.append(str(duration))

    f = open(join('mgctp1_out', output_file), 'w')
    f.writelines(lines)
Пример #2
0
def run_gmctp2(input_file, output_file):
    time1 = datetime.datetime.now()
    file = join(data_dir, data_gmctp2, input_file)
    problem = GMCTPProblem(data_path=file)

#     problem.max_nodes_per_route = 1000
    problem.max_tour_length = MAX_VALUE

    print problem.max_tour_length

    best_solution = None
    best_cost = MAX_VALUE

    best_runs =[]
    lines = []
    for job in xrange(JOBS):
        ga = GA_MCTP(problem, job)
        cost, tours = ga.run()

        best_runs.append(cost)

        if cost < best_cost:
            best_cost = cost
            best_solution = deepcopy(tours)

        lines.append('%s %.2f %.2f %d [%s] %s\n' %(input_file,
                                               problem.best_cost,
                                               best_cost,
                                               len(best_solution),
#                                                  d.seconds,
                                               ' '.join([str(v) for v in best_runs]),
                                               str(best_solution),
#                                                  str(best_solution.tours)
                                               ))

#         print best_cost, best_solution
    time2 = datetime.datetime.now()
    duration = time2-time1

    lines.append(str(duration))

    f = open(join('gmctp2_out', output_file), 'w')
    f.writelines(lines)
Пример #3
0
            ]
#     files = [os.path.join(data_dir, 'A-50-50-6.ctp')]
#     files = glob.glob(data_dir + '*.ctp')

    moves_freq = {}
#     lengths = [250,500,250,500]
#     lengths = [250]
    ro = 500

    for file in files:
        time1 = datetime.datetime.now()
        file_name = os.path.basename(file)
        print file_name,

        # convert gmctp visit moi node nhieu lan sang visit moi node 1 lan
        problem = GMCTPProblem(data_path=file)
#         problem.convert_to_gmctp1()

        # generate gmctp problem
#        problem = MCTPProblem(data_path=file)
#        problem.export_gmctp()

        # export gmctp voi rang buoc do dai moi route
#         n = problem.num_of_nodes + len(problem.obligatory_nodes) + 1
#
#         cost_from_depot = [problem.nodes[0].cost_dict[node] for node in range(1, n)]
#         max_cost_from_depot = max(cost_from_depot)
#
#         problem.max_tour_length = 2*max_cost_from_depot + ro
#         problem.max_nodes_per_route = 1000
#