Skip to content
Snippets Groups Projects
Commit 553fb84f authored by Matthieu Oberon's avatar Matthieu Oberon
Browse files

fix MMAS

parent 25e82dad
No related branches found
No related tags found
No related merge requests found
...@@ -103,8 +103,9 @@ def ACO(Me, NbP, comm, alpha, rho, Q, nb_ants, tau_0, n_iter, n1_max=256, n2_max ...@@ -103,8 +103,9 @@ def ACO(Me, NbP, comm, alpha, rho, Q, nb_ants, tau_0, n_iter, n1_max=256, n2_max
best_p = paths[np.argmin(costs), :] best_p = paths[np.argmin(costs), :]
#we compare the best paths of all process and we save only the best one #we compare the best paths of all process and we save only the best one
recv_table = np.empty(2) recv_table = (0., 0)
comm.Allreduce(np.array([best_cost, Me]), recv_table, OP=MPI.MINLOC) send_table = (best_cost, Me)
recv_table = comm.allreduce(send_table, op=MPI.MINLOC)
best_cost = recv_table[0] best_cost = recv_table[0]
best_p = comm.bcast(best_p, root=recv_table[1]) best_p = comm.bcast(best_p, root=recv_table[1])
...@@ -113,13 +114,7 @@ def ACO(Me, NbP, comm, alpha, rho, Q, nb_ants, tau_0, n_iter, n1_max=256, n2_max ...@@ -113,13 +114,7 @@ def ACO(Me, NbP, comm, alpha, rho, Q, nb_ants, tau_0, n_iter, n1_max=256, n2_max
tau = tools.add_pheromones(tau, np.array([best_p]), np.array([[best_cost]]), Q, n1_size, n2_size, n3_size, n_cbx, n_cby) tau = tools.add_pheromones(tau, np.array([best_p]), np.array([[best_cost]]), Q, n1_size, n2_size, n3_size, n_cbx, n_cby)
#verification of the threshold constraint #verification of the threshold constraint
size = np.size(tau) np.clip(tau, sub_threshold, sup_threshold)
for i in range(size[0]):
for j in range(size[1]):
if tau[i][j] < sub_threshold:
tau[i][j] = sub_threshold
if tau[i][j] > sup_threshold:
tau[i][j] = sup_threshold
#we update the best path on all iteration #we update the best path on all iteration
if best_cost < cost_opti: if best_cost < cost_opti:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment