Skip to content

Commit a6e1c36

Browse files
committed
modified: docs/src/example.md
modified: src/benchmark/CEC2005.jl modified: test/benchfunctions.jl
1 parent d465855 commit a6e1c36

File tree

3 files changed

+39
-33
lines changed

3 files changed

+39
-33
lines changed

docs/src/example.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,11 @@ with ``a = 20``, ``b = 0.2``, ``c = 2π``, and global minimum at ``x=0``.
99

1010
```@example
1111
using MetaheuristicsAlgorithms
12-
using Statistics: mean
13-
14-
function Ackley(x::Vector{Float64})::Float64
15-
a = 20.0
16-
b = 0.2
17-
c = 2π
18-
19-
term1 = -a * exp(-b * sqrt(mean(x.^2)))
20-
term2 = -exp(mean(cos.(c * x)))
21-
22-
return term1 + term2 + a + exp(1)
23-
end
12+
import MetaheuristicsAlgorithms as MA
2413
2514
lb = [-32.768 for _ = 1:5]
2615
ub = [ 32.768 for _ = 1:5]
27-
result = AEO(Ackley, lb, ub, 100, 1000)
16+
result = AEO(MA.Ackley, lb, ub, 100, 1000)
2817
convergence_curve(result)
2918
```
3019

src/benchmark/CEC2005.jl

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,42 @@ function F9(x)
159159
return sum(x.^2 .- 10 .* cos.(2π .* x)) + 10 * dim
160160
end
161161

162+
"""
163+
Ackley(x)
164+
165+
Ackley function.
166+
167+
A popular multimodal benchmark with a nearly flat outer region and many local minima.
168+
Commonly used to test global optimization algorithms.
169+
170+
Equation (with a = 20, b = 0.2, c = 2π):
171+
172+
```math
173+
f(\\mathbf{x}) = -a\\,\\exp\\left(-b\\,\\sqrt{\\tfrac{1}{n}\\sum_{i=1}^n x_i^2}\\right)
174+
- \\exp\\left(\\tfrac{1}{n}\\sum_{i=1}^n \\cos(c\\,x_i)\\right)
175+
+ a + e
176+
```
177+
178+
Properties:
179+
- Domain: any dimension `n`; typical bounds `x_i ∈ [-32.768, 32.768]` (sometimes `[-5, 5]`).
180+
- Global minimum: `f(0,…,0) = 0` at `x = 0`.
181+
- Output: `Float64` scalar value of the function at `x`.
182+
"""
183+
function Ackley(x::AbstractVector{<:Real})::Float64
184+
n = length(x)
185+
a = 20.0
186+
b = 0.2
187+
c = 2π
188+
189+
sum1 = sum(xi^2 for xi in x)
190+
sum2 = sum(cos(c * xi) for xi in x)
191+
192+
term1 = -a * exp(-b * sqrt(sum1 / n))
193+
term2 = -exp(sum2 / n)
194+
195+
return term1 + term2 + a + exp(1)
196+
end
197+
162198
"""
163199
F10(x)
164200
@@ -175,11 +211,7 @@ f(\\mathbf{x}) = -20 \\exp\\left(-0.2 \\sqrt{\\frac{1}{n} \\sum_{i=1}^n x_i^2}\\
175211
+ 20 + e
176212
```
177213
"""
178-
function F10(x)
179-
dim = length(x)
180-
return -20 * exp(-0.2 * sqrt(sum(x.^2) / dim)) -
181-
exp(sum(cos.(2π .* x)) / dim) + 20 + exp(1)
182-
end
214+
F10 = Ackley
183215

184216
"""
185217
F11(x)

test/benchfunctions.jl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
function Ackley(x::AbstractVector{<:Real})::Float64
2-
n = length(x)
3-
a = 20.0
4-
b = 0.2
5-
c = 2 * π
6-
7-
sum1 = sum(xi^2 for xi in x)
8-
sum2 = sum(cos(c * xi) for xi in x)
9-
10-
term1 = -a * exp(-b * sqrt(sum1 / n))
11-
term2 = -exp(sum2 / n)
12-
13-
return term1 + term2 + a + exp(1)
14-
end
15-
161
function Griewank(x::AbstractVector{<:Real})::Float64
172
sum_term = sum(xi^2 / 4000 for xi in x)
183
prod_term = prod(cos(xi / sqrt(i + 1)) for (i, xi) in enumerate(x))

0 commit comments

Comments
 (0)