File tree Expand file tree Collapse file tree 6 files changed +17
-7
lines changed Expand file tree Collapse file tree 6 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ function operators(obj)
31
31
s = s + stepsize .* randn(size(s ));
32
32
newPop(i ,: ) = s ;
33
33
end
34
- newPop = obj .checkBounds (newPop );
34
+ newPop = obj .checkBoundsToroidal (newPop );
35
35
obj .remplacePopulation(newPop );
36
36
37
37
% A fraction of worse nests are discovered with a probability pa
@@ -41,7 +41,7 @@ function operators(obj)
41
41
stepsize = rand * (obj .population(randperm(obj .sizePopulation ),: )-...
42
42
obj .population(randperm(obj .sizePopulation ),: ));
43
43
newPop = obj .population + stepsize .* K ;
44
- newPop = obj .checkBounds (newPop );
44
+ newPop = obj .checkBoundsToroidal (newPop );
45
45
obj .remplacePopulation(newPop );
46
46
end
47
47
Original file line number Diff line number Diff line change @@ -40,8 +40,7 @@ function operators(obj)
40
40
obj .population(selectedPop(5 ),j ));
41
41
end
42
42
end
43
- solutionBase(solutionBase > 1 ) = 1 ;
44
- solutionBase(solutionBase < 0 ) = 0 ;
43
+ solutionBase = obj .checkBoundsToroidal(solutionBase );
45
44
tempFit = obj .evalPopulation(solutionBase );
46
45
if tempFit < obj .fitness(selectedPop(1 ))
47
46
if obj .plotSpecial
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ function operators(obj)
50
50
end
51
51
% update solutions
52
52
obj.population = obj .population + obj .velocity ;
53
- obj .checkBounds ();
53
+ obj .checkBoundsToroidal ();
54
54
55
55
% eval fitness
56
56
obj .evalPopulation();
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ function operators(obj)
69
69
end
70
70
71
71
obj.population = pobL ;
72
- obj .checkBounds ();
72
+ obj .checkBoundsToroidal ();
73
73
obj.direction = dirL ;
74
74
obj .evalPopulation();
75
75
end
Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ function operators(obj)
48
48
end
49
49
end
50
50
end
51
- obj .checkBounds ();
51
+ obj .checkBoundsToroidal ();
52
52
obj .evalPopulation();
53
53
obj .updateBest();
54
54
end
Original file line number Diff line number Diff line change @@ -161,6 +161,17 @@ function sortPopulation(obj)
161
161
end
162
162
end
163
163
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
+
164
175
function updateBest(obj )
165
176
% update the best know so far solution and it's fitness.
166
177
[bestFitTemp , bestIndex ] = min(obj .fitness );
You can’t perform that action at this time.
0 commit comments