PSO doesn't restrict the solution within the inf and sup bounds when supplied
PSO doesn't restrict solutions within the inf and sup bounds. Looking in the code, it is not verified that the next iteration guess from the speed parameters is actually within the bounds and this is not safe with regard to the cost function evaluation. ``` //--------------------------------------------------- // Speed and location computation for next iteration //--------------------------------------------------- T=[]; for i=1:D t = grand(2*N, 1,'def'); T=[T t]; end v1 = T(1:N,:) .* (pbest(:, :, j) - x(:, :, j)); v2 = T(N+1:2*N,:) .* (G(:, :, j) - x(:, :, j)); v(:, :, j + 1) = W(j) * v(:, :, j) + c1 * v1 + c2 * v2;// speed x(:, :, j + 1) = x(:, :, j) + v(:, :, j + 1);// location ``` This is causing cost function evaluation error in such practical cases. Thus I inserted in the source code of **PSO_inertial()** after next location assumption **x** : ``` for k=1:D // force location within the bounds x(x(:, k, j + 1)<borne_inf(k), k, j+1)= borne_inf(k) x(x(:, k, j + 1)>borne_sup(k), k, j+1)= borne_sup(k) end ``` It actually manages to keep the solution within the bounds. However I don't master the PSO core algorithm to be sure it doesn't disturb it: would be nice to have another point of view about this workaround. David
issue