Exemple #1
0
 def solve(self, options: dict):
     solver = aco.Solver(rho=options.get("rho", 0.03),
                         q=options.get("q", 1))
     timeLimit_plugin = aco.plugins.TimeLimit(options.get("timeLimit", 10))
     solver.add_plugin(timeLimit_plugin)
     colony = aco.Colony(alpha=options.get("alpha", 1),
                         beta=options.get("beta", 3))
     problem = self.instance.to_tsplib95()
     G = problem.get_graph()
     tour = solver.solve(G, colony, limit=100)
     solution = TupList(
         dict(pos=pos, node=el) for pos, el in enumerate(tour.nodes))
     self.solution = Solution(dict(route=solution))
     return dict(status_sol=SOLUTION_STATUS_FEASIBLE,
                 status=STATUS_UNDEFINED)
Exemple #2
0
 def Ant_Colony_solver(self, G_prime, start_index, cluster_center_drop_off):
     # alpha = how much pheromone matters
     # beta = how much distance matters
     colony = acopy.Colony(alpha=0.6, beta=6)
     solver = acopy.Solver(rho=.6, q=1)
     ant_tour = solver.solve(G_prime, colony, limit=10)
     ant_tour_nodes = ant_tour.nodes
     cost = ant_tour.cost
     if (ant_tour_nodes.count(start_index) == 1):
         ant_start = ant_tour_nodes.index(start_index)
         ant_tour_nodes = ant_tour_nodes[
             ant_start:] + ant_tour_nodes[:ant_start] + [start_index]
     tour_ant = [(ant_tour_nodes[i], ant_tour_nodes[i + 1])
                 for i in range(len(ant_tour_nodes) - 1)]
     rao_tour_2 = compute_tour_paths(self.G, tour_ant)
     rao_tour_2 = [
         rao_tour_2[i] for i in range(len(rao_tour_2) - 1)
         if rao_tour_2[i] != rao_tour_2[i + 1]
     ] + [start_index]
     cost = self.faster_cost_solution(rao_tour_2, cluster_center_drop_off)
     return rao_tour_2, cost
Exemple #3
0
import acopy
import tsplib95

a = 20
coste = []
it_alpha = []

#for i in range (30):
#    it_alpha.append(a)

solver = acopy.Solver(rho=0.55, q=0.7)
colony = acopy.Colony(alpha=0.7, beta=4)
threshold = acopy.plugins.Threshold(threshold=95345)

problem = tsplib95.load_problem(
    'C://Users//Vicente//PycharmProjects//TSPproblem//venv//datasetcorto')
G = problem.get_graph()
tour = solver.solve(G, colony, limit=90)

#    a = a + 10

print(tour.cost)
print(tour.nodes)
#coste.append(tour.cost)
'''import matplotlib.pyplot as plt

plt.plot(it_alpha, coste)
plt.show()'''