コード例 #1
0
# get the instance for the run
index_instance = sys.argv.index("-i") if "-i" in sys.argv else sys.argv.index(
    "--instance")
path = sys.argv[index_instance + 1]
filename = os.path.basename(path)

qap = Reader(path)  # construct the problem

Util.get_configuration()  # get the best configuration of the ant system
runs = [sys.maxsize for i in range(Params.singleton.MAX_RUN)]

for t in range(Params.singleton.MAX_TRY):
    colony = Ants(qap.matrix_A, qap.matrix_B, Params.singleton.nb_ants,
                  qap.size)
    colony.init_pheromone(1 / (Params.singleton.RHO * qap.size))

    run = 0
    start = time.time()
    while not terminal_condition(run, start):
        construct_solutions(colony)  # build the solution for each ant

        if Params.singleton.lcs_flag:
            colony.local_search()  # apply the local search

        update_pheromone(
            colony)  # update the pheromone depending on the ant system

        save_run(run, colony)  # Save the current run

        exit_run(run, colony)  # Print the information about the run