Code covered by the BSD License  

Highlights from
Another Particle Swarm Toolbox

image thumbnail

Another Particle Swarm Toolbox

by

 

01 Dec 2009 (Updated )

Implementation of a PSO algorithm with the same syntax as the Genetic Algorithm Toolbox.

...
function state = ...
    psoboundsreflect(state,Aineq,bineq,Aeq,beq,LB,UB,nonlcon,options)

x = state.Population ;
v = state.Velocities ;

for i = 1:size(state.Population,1)
    lowindex = [] ; highindex = [] ;
    if ~isempty(LB), lowindex = x(i,:) < LB ; end
    if ~isempty(UB), highindex = x(i,:) > UB ; end
    
    x(i,lowindex) = LB(lowindex) ;
    x(i,highindex) = UB(highindex) ;
    v(i,lowindex) = -v(i,lowindex) ;
    v(i,highindex) = -v(i,highindex);
end % for i

state.Population = x ;
state.Velocities = v ;

Contact us