def _update_particles(self): """ Update the velocities and positions for all particles. This does not update the fitness for each particle. """ # Random values between zero and one. One random value per particle. rand_g = tools.rand_uniform(size=self.num_particles) # Update velocity for all particles using numpy operations. # For an explanation of this formula, see the research papers referenced above. # Note that self.best is the swarm's best-known position aka. global-best. self.velocity = (self.omega * self.velocity.T \ + self.phi_g * rand_g * (self.best - self.particle).T).T # Fix de-normalized floating point values which can make the execution very slow. self.velocity = tools.denormalize_trunc(self.velocity) # Bound velocity. self.velocity = tools.bound(self.velocity, self.velocity_lower_bound, self.velocity_upper_bound) # Update particle positions in the search-space by adding the velocity. self.particle = self.particle + self.velocity # Bound particle position to search-space. self.particle = tools.bound(self.particle, self.problem.lower_bound, self.problem.upper_bound)