Hi, I have a question about how you implemented particle swarm optimization. In pso.py, the section of code that updates the new routes has a bit of code that I'm not sure of the function of.
for i in range(len(self.cities)):
if new_route[i] != particle.pbest[i]:
swap = (i, particle.pbest.index(new_route[i]), self.pbest_probability)
temp_velocity.append(swap)
new_route[swap[0]], new_route[swap[1]] = \
new_route[swap[1]], new_route[swap[0]]
for i in range(len(self.cities)):
if new_route[i] != gbest[i]:
swap = (i, gbest.index(new_route[i]), self.gbest_probability)
temp_velocity.append(swap)
gbest[swap[0]], gbest[swap[1]] = gbest[swap[1]], gbest[swap[0]]
particle.velocity = temp_velocity
for swap in temp_velocity:
if random.random() <= swap[2]:
new_route[swap[0]], new_route[swap[1]] = \
new_route[swap[1]], new_route[swap[0]]
particle.route = new_route
particle.update_costs_and_pbest()`