Skip to content

Commit 3397f9b

Browse files
committed
add checkBoundsToroidal
1 parent 1479ce3 commit 3397f9b

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed

CS.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function operators(obj)
3131
s = s + stepsize .* randn(size(s));
3232
newPop(i,:) = s;
3333
end
34-
newPop = obj.checkBounds(newPop);
34+
newPop = obj.checkBoundsToroidal(newPop);
3535
obj.remplacePopulation(newPop);
3636

3737
% A fraction of worse nests are discovered with a probability pa
@@ -41,7 +41,7 @@ function operators(obj)
4141
stepsize = rand * (obj.population(randperm(obj.sizePopulation),:)-...
4242
obj.population(randperm(obj.sizePopulation),:));
4343
newPop = obj.population + stepsize.*K;
44-
newPop = obj.checkBounds(newPop);
44+
newPop = obj.checkBoundsToroidal(newPop);
4545
obj.remplacePopulation(newPop);
4646
end
4747

DE.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ function operators(obj)
4040
obj.population(selectedPop(5),j));
4141
end
4242
end
43-
solutionBase(solutionBase > 1) = 1;
44-
solutionBase(solutionBase < 0) = 0;
43+
solutionBase = obj.checkBoundsToroidal(solutionBase);
4544
tempFit = obj.evalPopulation(solutionBase);
4645
if tempFit < obj.fitness(selectedPop(1))
4746
if obj.plotSpecial

PSO.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function operators(obj)
5050
end
5151
% update solutions
5252
obj.population = obj.population + obj.velocity;
53-
obj.checkBounds();
53+
obj.checkBoundsToroidal();
5454

5555
% eval fitness
5656
obj.evalPopulation();

SMS.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function operators(obj)
6969
end
7070

7171
obj.population = pobL;
72-
obj.checkBounds();
72+
obj.checkBoundsToroidal();
7373
obj.direction = dirL;
7474
obj.evalPopulation();
7575
end

WOA.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function operators(obj)
4848
end
4949
end
5050
end
51-
obj.checkBounds();
51+
obj.checkBoundsToroidal();
5252
obj.evalPopulation();
5353
obj.updateBest();
5454
end

metaheuristic.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ function sortPopulation(obj)
161161
end
162162
end
163163

164+
function solutions = checkBoundsToroidal(obj, solutions)
165+
if nargin == 1
166+
solutions = obj.population;
167+
end
168+
solutions(solutions>1)=solutions(solutions>1)-1;
169+
solutions(solutions<0)=solutions(solutions<0)+1;
170+
if nargin == 1
171+
obj.population = solutions;
172+
end
173+
end
174+
164175
function updateBest(obj)
165176
% update the best know so far solution and it's fitness.
166177
[bestFitTemp, bestIndex] = min(obj.fitness);

0 commit comments

Comments
 (0)