@@ 111-126 (lines=16) @@ | ||
108 | }) |
|
109 | return d |
|
110 | ||
111 | def repair(self, x, lower, upper): |
|
112 | r"""Truncate exceeded dimensions to the limits. |
|
113 | ||
114 | Args: |
|
115 | x (numpy.ndarray): Individual to repair. |
|
116 | lower (numpy.ndarray): Lower limits for dimensions. |
|
117 | upper (numpy.ndarray): Upper limits for dimensions. |
|
118 | ||
119 | Returns: |
|
120 | numpy.ndarray: Repaired individual. |
|
121 | """ |
|
122 | ir = where(x < lower) |
|
123 | x[ir] = lower[ir] |
|
124 | ir = where(x > upper) |
|
125 | x[ir] = upper[ir] |
|
126 | return x |
|
127 | ||
128 | def levy(self, step_size, D): |
|
129 | r"""Calculate levy flight. |
@@ 164-179 (lines=16) @@ | ||
161 | ||
162 | return BeesPosition, BeesCost, {'ngh': self.ngh} |
|
163 | ||
164 | def repair(self, x, lower, upper): |
|
165 | r"""Truncate exceeded dimensions to the limits. |
|
166 | ||
167 | Args: |
|
168 | x (numpy.ndarray): Individual to repair. |
|
169 | lower (numpy.ndarray): Lower limits for dimensions. |
|
170 | upper (numpy.ndarray): Upper limits for dimensions. |
|
171 | ||
172 | Returns: |
|
173 | numpy.ndarray: Repaired individual. |
|
174 | """ |
|
175 | ir = where(x < lower) |
|
176 | x[ir] = lower[ir] |
|
177 | ir = where(x > upper) |
|
178 | x[ir] = upper[ir] |
|
179 | return x |
|
180 | ||
181 | def runIteration(self, task, BeesPosition, BeesCost, xb, fxb, ngh, **dparams): |
|
182 | r"""Core function of Forest Optimization Algorithm. |