Skip to content

Commit 9624560

Browse files
authored
Merge pull request #124 from jmejia8/add-rdex-algorithm
Add RDEx algorithm
2 parents 1411062 + e369a0b commit 9624560

13 files changed

Lines changed: 1050 additions & 6 deletions

File tree

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
version:
16-
- 1.7
16+
- 1.10.10
1717
os:
1818
- ubuntu-latest
1919
arch:

Project.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name = "Metaheuristics"
22
uuid = "bcdb8e00-2c21-11e9-3065-2b553b22f898"
3-
authors = ["Jesus Mejia <jesusmejded@gmail.com>"]
43
version = "3.4.2"
4+
authors = ["Jesus Mejia <jesusmejded@gmail.com>"]
55

66
[deps]
77
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
8+
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
89
JMcDM = "358108f5-d052-4d0a-8344-d5384e00c0e5"
910
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1011
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
@@ -18,19 +19,19 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1819
[compat]
1920
Aqua = "^0.8"
2021
Distances = "^0.10.7"
22+
Distributions = "^0.25"
2123
JMcDM = "^0.7.1"
2224
LinearAlgebra = "1"
2325
Printf = "1"
2426
Random = "1"
2527
Reexport = "^1"
2628
Requires = "1"
27-
Statistics = "1"
2829
SearchSpaces = "^0.2"
2930
SnoopPrecompile = "1"
31+
Statistics = "1"
3032
Test = "1"
31-
UnicodePlots = "2.6, 3"
32-
33-
julia = "^1.7"
33+
UnicodePlots = "^2.6, ^3"
34+
julia = "^1.10"
3435

3536
[extras]
3637
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"

src/Metaheuristics.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export optimize!
3030
export set_user_solutions!
3131
export boxconstraints
3232
export SHADE, CSO
33+
export RDEx
3334

3435
include("externals.jl")
3536

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
RDEx: An effectiveness-driven hybrid Single-Objective optimizer
3+
4+
Julia implementation of the adaptive differential evolution algorithm.
5+
6+
"""
7+
module RDExModule
8+
9+
# Standard library dependencies
10+
using Random
11+
using Statistics
12+
using Distributions
13+
14+
# Submodules
15+
include("RDEx/constants.jl")
16+
include("RDEx/random.jl")
17+
include("RDEx/selection.jl")
18+
include("RDEx/types.jl")
19+
include("RDEx/mutation.jl")
20+
include("RDEx/adaptation.jl")
21+
include("RDEx/metaheuristics.jl")
22+
23+
24+
# Export public API
25+
export RDEx
26+
27+
28+
29+
# Import Metaheuristics API (avoid conflict by importing functions directly)
30+
import .MetaheuristicsAPI: RDEx
31+
# Note: RDExAlgorithm is the Metaheuristics-compatible algorithm constructor
32+
# Users can do: using RDEx: RDExAlgorithm; algo = RDExAlgorithm()
33+
# Or: import RDEx: RDExAlgorithm as RDEx; algo = RDEx()
34+
35+
end # module RDExModule
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
"""
2+
Parameter adaptation mechanisms for RDEx optimizer.
3+
4+
Handles adaptation of F, Cr, and hybrid strategy parameters.
5+
"""
6+
module AdaptationUtils
7+
8+
import ..Constants
9+
10+
"""
11+
weighted_mean(values::Vector{Float64}, weights::Vector{Float64}, success_filled::Int, weights_storage::Vector{Float64}) -> Float64
12+
13+
Compute weighted mean of values using weights.
14+
"""
15+
function weighted_mean(
16+
values::Vector{Float64},
17+
weights::Vector{Float64},
18+
success_filled::Int,
19+
weights_storage::Vector{Float64}
20+
)::Float64
21+
sum_weight = sum(weights[1:success_filled])
22+
if sum_weight == 0.0
23+
return 1.0
24+
end
25+
26+
weights_storage[1:success_filled] = weights[1:success_filled] / sum_weight
27+
28+
sum_square = sum(weights_storage[i] * values[i] * values[i] for i = 1:success_filled)
29+
sum_val = sum(weights_storage[i] * values[i] for i = 1:success_filled)
30+
31+
if abs(sum_val) > 1e-8
32+
return sum_square / sum_val
33+
else
34+
return 1.0
35+
end
36+
end
37+
38+
"""
39+
update_memory!(
40+
parameters,
41+
temp_success_cr::Vector{Float64},
42+
temp_success_f::Vector{Float64},
43+
fit_delta::Vector{Float64}
44+
)
45+
46+
Update memory for Cr and F parameters based on successful trials.
47+
"""
48+
function update_memory!(
49+
parameters,
50+
temp_success_cr::Vector{Float64},
51+
temp_success_f::Vector{Float64},
52+
fit_delta::Vector{Float64}
53+
)::Nothing
54+
if parameters.success_filled != 0
55+
parameters.memory_cr[parameters.memory_iter+1] = 0.5 * (
56+
weighted_mean(temp_success_cr, fit_delta, parameters.success_filled, parameters.weights) +
57+
parameters.memory_cr[parameters.memory_iter+1]
58+
)
59+
parameters.memory_f[parameters.memory_iter+1] = weighted_mean(
60+
temp_success_f, fit_delta, parameters.success_filled, parameters.weights
61+
)
62+
parameters.memory_iter = (parameters.memory_iter + 1) % parameters.memory_size
63+
end
64+
return nothing
65+
end
66+
67+
"""
68+
update_eb_hybrid_param!(
69+
parameters,
70+
eb_hybrid_flag::Vector{Float64},
71+
fit_arr_front::Vector{Float64},
72+
fit_temp::Vector{Float64},
73+
n_inds_front::Int
74+
)
75+
76+
Update the elite-based hybrid rate parameter based on performance.
77+
"""
78+
function update_eb_hybrid_param!(
79+
parameters,
80+
eb_hybrid_flag::Vector{Float64},
81+
fit_arr_front::Vector{Float64},
82+
fit_temp::Vector{Float64},
83+
n_inds_front::Int
84+
)::Nothing
85+
sum_eb_delta_fit = 0.0
86+
sum_origin_delta_fit = 0.0
87+
88+
for chosen_one = 1:n_inds_front
89+
if eb_hybrid_flag[chosen_one] == 1.0
90+
if fit_temp[chosen_one] <= fit_arr_front[chosen_one]
91+
sum_eb_delta_fit += fit_arr_front[chosen_one] - fit_temp[chosen_one]
92+
end
93+
else
94+
if fit_temp[chosen_one] <= fit_arr_front[chosen_one]
95+
sum_origin_delta_fit += fit_arr_front[chosen_one] - fit_temp[chosen_one]
96+
end
97+
end
98+
end
99+
100+
if sum_eb_delta_fit != 0.0 && sum_origin_delta_fit != 0.0
101+
parameters.eb_hybrid_rate = sum_eb_delta_fit / (sum_eb_delta_fit + sum_origin_delta_fit)
102+
parameters.eb_hybrid_rate = clamp(parameters.eb_hybrid_rate, 0.0, 1.0)
103+
else
104+
parameters.eb_hybrid_rate = Constants.EB_HYBRID_RATE_INIT
105+
end
106+
107+
return nothing
108+
end
109+
110+
end # module AdaptationUtils
111+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
Constants used throughout the RDEx optimizer.
3+
"""
4+
module Constants
5+
6+
# Algorithm constants
7+
const EB_HYBRID_RATE_INIT = 0.7
8+
const MEMORY_SIZE = 5
9+
10+
end # module Constants
11+

0 commit comments

Comments
 (0)