Code Duplication    Length = 18-19 lines in 2 locations

NiaPy/algorithms/basic/pso.py 2 locations

@@ 818-836 (lines=19) @@
815
		kwargs.pop('vMin', None), kwargs.pop('vMax', None)
816
		MutatedCenterParticleSwarmOptimization.setParameters(self, vMin=-np.inf, vMax=np.inf, **kwargs)
817
818
	def updateVelocity(self, V, p, pb, gb, w, vMin, vMax, task, **kwargs):
819
		r"""Update particle velocity.
820
821
		Args:
822
			V (numpy.ndarray): Current velocity of particle.
823
			p (numpy.ndarray): Current position of particle.
824
			pb (numpy.ndarray): Personal best position of particle.
825
			gb (numpy.ndarray): Global best position of particle.
826
			w (numpy.ndarray): Weights for velocity adjustment.
827
			vMin (numpy.ndarray): Minimal velocity allowed.
828
			vMax (numpy.ndarray): Maxmimal velocity allowed.
829
			task (Task): Optimization task.
830
			kwargs: Additional arguments.
831
832
		Returns:
833
			numpy.ndarray: Updated velocity of particle.
834
		"""
835
		r3 = self.rand(task.D)
836
		return self.Repair(w * V + self.C1 * self.rand(task.D) * (pb - p) * r3 + self.C2 * self.rand(task.D) * (gb - p) * (1 - r3), vMin, vMax)
837
838
class ComprehensiveLearningParticleSwarmOptimizer(ParticleSwarmAlgorithm):
839
	r"""Implementation of Mutated Particle Swarm Optimization.
@@ 167-184 (lines=18) @@
164
		d.update({'popb': pop.copy(), 'fpopb': fpop.copy()})
165
		return pop, fpop, d
166
167
	def updateVelocity(self, V, p, pb, gb, w, vMin, vMax, task, **kwargs):
168
		r"""Update particle velocity.
169
170
		Args:
171
			V (numpy.ndarray): Current velocity of particle.
172
			p (numpy.ndarray): Current position of particle.
173
			pb (numpy.ndarray): Personal best position of particle.
174
			gb (numpy.ndarray): Global best position of particle.
175
			w (numpy.ndarray): Weights for velocity adjustment.
176
			vMin (numpy.ndarray): Minimal velocity allowed.
177
			vMax (numpy.ndarray): Maximal velocity allowed.
178
			task (Task): Optimization task.
179
			kwargs: Additional arguments.
180
181
		Returns:
182
			numpy.ndarray: Updated velocity of particle.
183
		"""
184
		return self.Repair(w * V + self.C1 * self.rand(task.D) * (pb - p) + self.C2 * self.rand(task.D) * (gb - p), vMin, vMax)
185
186
	def runIteration(self, task, pop, fpop, xb, fxb, popb, fpopb, w, vMin, vMax, V, **dparams):
187
		r"""Core function of Particle Swarm Optimization algorithm.