Example #1
0
    def test_alpha_das_qas_less(self):  # alpha = 0.1
        aco_das = aco.ACO('Kempten',
                          'Wuerzburg',
                          ants_num=50,
                          iteration_num=10,
                          type='das',
                          rho=0.4,
                          beta=1,
                          alpha=0.1)  # rho = 0.9
        aco_qas = aco.ACO('Kempten',
                          'Wuerzburg',
                          ants_num=50,
                          iteration_num=10,
                          type='qas',
                          rho=0.4,
                          beta=1,
                          alpha=0.1)
        t1_start = process_time()
        aco_das.aco_run()
        t1_stop = process_time()

        t1 = t1_stop - t1_start

        t2_start = process_time()
        aco_qas.aco_run()
        t2_stop = process_time()

        t2 = t2_stop - t2_start
        self.assertLessEqual(t1, t2)
Example #2
0
    def test_def_das_qas_less(self):  # rho = 0.5
        aco_das = aco.ACO('Kempten',
                          'Wuerzburg',
                          ants_num=50,
                          iteration_num=10,
                          type='das')
        aco_qas = aco.ACO('Kempten',
                          'Wuerzburg',
                          ants_num=50,
                          iteration_num=10,
                          type='qas')

        t1_start = process_time()
        aco_das.aco_run()
        t1_stop = process_time()

        t1 = t1_stop - t1_start

        t2_start = process_time()
        aco_qas.aco_run()
        t2_stop = process_time()

        t2 = t2_stop - t2_start

        self.assertLessEqual(t1, t2)
Example #3
0
def main():
    p, clients = get_data(args.INPUT_FILE)
    p_medians = aco.ACO(p, clients, args.MAXIT, args.ANTN, args.DECAYR,
                        args.ALPHA, args.BETA)

    p_medians.ant_system()
    print(p_medians.best_global)
from plot import Plot
import numpy as np
from matrices import matrices, all_num_optional_nodes

matrices_size = ["Small Graph", "Medium Graph", "Large Graph", "XL Graph"]
i = 0
for matrix, num_optional_nodes in zip(matrices, all_num_optional_nodes):

    whole_matrix_rank = len(matrix)
    classical_matrix_rank = whole_matrix_rank - num_optional_nodes
    m = np.array(matrix)
    classical_matrix = m[0:classical_matrix_rank, 0:classical_matrix_rank]
    optional_nodes = list(range(classical_matrix_rank, whole_matrix_rank))

    g = aco.Graph(classical_matrix)
    alg = aco.ACO(10, 20, 1, 1, 0.5, 1, 0)
    best_solution, best_cost, avg_costs, best_costs, plot_x, plot_y = alg.solve(
        g, True)

    # new_plot=Plot("Regular ACO" ,['r', 'g'],plot_x,"cost")
    # new_plot.plot_lines(plot_y)
    # new_plot.display()

    g0 = aco_max.Graph(classical_matrix)
    alg0 = aco_max.ACO_Max(10, 20, 1, 1, 0.5, 1, 0)
    best_solution0, best_cost0, avg_costs0, best_costs0, plot_x0, plot_y0 = alg0.solve(
        g0, True)

    # new_plot=Plot("Max ACO",['r', 'g'],plot_x0,"cost")
    # new_plot.plot_lines(plot_y0)
    # new_plot.display()
Example #5
0
import aco
import numpy as np
import pandas as pd

dist_mat = pd.read_csv('tc4.csv', header=None).values

g = aco.Graph(dist_mat)

ac = aco.ACO(g, num_colony=10,iter=5,beta=3,rho=0.5)
sol = ac.solve_step()

cost_over_time = []

for i in sol:
    final = i
    cost_over_time.append(i.travel_dist)

thefile = open('cost_over_time4.txt', 'w')
for item in cost_over_time:
  thefile.write("%s\n" % item)
thefile.close()
thefile = open('solution4.txt', 'w')
for item in final.visited_city:
  thefile.write("%s\n" % item)
thefile.close()