
clear all
close all
clc
NP=20;
FoodNumber=NP/2;
limit=100;
maxCycle=2500;
objfun='Sphere';
D=100;
ub=ones(1,D)*100;
lb=ones(1,D)*(-100);
runtime=1;
GlobalMins=zeros(1,runtime);
for r=1:runtime
Range = repmat((ub-lb),[FoodNumber 1]);
Lower = repmat(lb, [FoodNumber 1]);
Foods = rand(FoodNumber,D) .* Range + Lower;
ObjVal=feval(objfun,Foods);
Fitness=calculateFitness(ObjVal);
trial=zeros(1,FoodNumber);
BestInd=find(ObjVal==min(ObjVal));
BestInd=BestInd(end);
GlobalMin=ObjVal(BestInd);
GlobalParams=Foods(BestInd,:);
iter=1;
while ((iter <= maxCycle)),
for i=1:(FoodNumber)
Param2Change=fix(rand*D)+1;
neighbour=fix(rand*(FoodNumber))+1;
while(neighbour==i)
neighbour=fix(rand*(FoodNumber))+1;
end;
sol=Foods(i,:);
sol(Param2Change)=Foods(i,Param2Change)+(Foods(i,Param2Change)-Foods(
neighbour,Param2Change))*(rand-0.5)*2;
ind=find(sol<lb);
sol(ind)=lb(ind);
ind=find(sol>ub);