BlackBoxOptimization

Download zip
Author
Version
0.1.0
License
Apache-2.0
Last updated
15 days ago
Downloads
6

#BlackBoxOptimization

基于 MoonBit 实现的黑盒优化算法框架,支持 75 种经典优化算法,提供统一的接口和基准测试框架。

#算法分类

本框架实现了 75 种黑盒优化算法,按设计灵感和机制分为以下类别:

#🔍 单点搜索算法

最简单的优化策略,从单个初始解出发,通过迭代改进逐步逼近最优值。

算法简称说明
随机搜索Random Search随机采样搜索空间中的点作为基线对比
爬山法Hill Climbing从当前解的邻域中选择更优解进行迭代
模拟退火Simulated Annealing以概率接受劣解,跳出局部最优陷阱

通用参数: 所有算法均包含 max_evals(最大评估次数)、dim(维度)、bounds(搜索边界)三个基础参数。

算法关键参数推荐值
Random Search无需额外参数-
Hill Climbing无需额外参数-
Simulated Annealinginitial_temp(初始温度), cooling_rate(降温速率), step_size(步长)100.0, 0.995, 0.5

#🔧 局部搜索算法

强化局部开发能力,通过记忆或惩罚机制避免陷入循环。

算法简称说明
禁忌搜索Tabu Search使用禁忌表记录近期操作,避免循环
引导局部搜索Guided LS添加惩罚项引导搜索逃出局部最优

算法关键参数推荐值
Tabu Searchtabu_list_size(禁忌表大小), neighborhood_size(邻域大小), step_size(步长)50, 30, 0.5
Guided LSneighborhood_size(邻域大小), step_size(步长), lambda(惩罚系数)30, 0.5, 0.5

#🧬 进化算法

模拟自然选择与遗传过程,基于种群的进化搜索机制。

算法简称说明
差分进化DE通过差分变异和交叉实现种群进化
遗传算法GA选择、交叉、变异三阶段模拟自然选择
帝国主义竞争算法ICA模拟帝国殖民、同化和竞争机制
生物地理学优化BBO基于栖息地适宜度与物种迁移模型
回溯搜索算法BSA基于历史种群记忆的定向交叉变异

算法关键参数推荐值
DEpopulation_size, mutation_factor (F), crossover_probability (CR)30, 0.8, 0.9
GApopulation_size, crossover_rate, mutation_rate30, 0.8, 0.05
ICApopulation_size, imperialist_count, assimilation_rate, revolution_rate25, 3, 0.3, 0.3
BBOpopulation_size, mutation_rate25, 0.01
BSApopulation_size25

#🐝 群体智能算法

本框架最大的算法类别,模拟自然界生物群体行为进行协同搜索。

算法简称说明
粒子群优化PSO模仿鸟群觅食的群体协同行为
萤火虫算法Firefly基于萤火虫发光吸引力模型
蚁群算法ACO基于信息素的蚂蚁路径搜索
蜂群算法Bee Colony模拟蜜蜂觅食与舞蹈交流行为
布谷鸟搜索Cuckoo Search基于巢寄生和Lévy飞行的搜索
灰狼优化GWO模拟灰狼领导的三层狩猎机制
鲸群优化WOA模拟座头鲸气泡网捕食行为
蝙蝠算法Bat Algorithm模拟蝙蝠回声定位行为
和声搜索Harmony Search模拟音乐即兴创作过程
正弦余弦算法SCA利用正弦余弦函数进行振荡搜索
飞蛾火焰优化MFO模拟飞蛾螺旋飞行路径
蚁狮优化ALO模拟蚁狮陷阱捕食行为
麻雀搜索算法SSA模拟麻雀觅食和反捕食行为
哈里斯鹰优化HHO模拟哈里斯鹰协同捕食行为
花粉传播算法FPA模拟花粉全局和局部传播过程
蜻蜓算法DA模拟蜻蜓分离、对齐、聚集行为
乌鸦搜索算法CSA模拟乌鸦记忆和追逐行为
樽海鞘群算法SalpSA模拟樽海鞘链状群体结构
Monarch蝴蝶优化MBO模拟蝴蝶迁徙和调整行为
人工生态系统优化AEO模拟生态系统生产者-消费者-分解者
入侵杂草优化IWO模拟杂草生长扩散与竞争
细菌觅食优化BFO模拟大肠杆菌觅食行为
混合蛙跳算法SFLA模拟青蛙群体觅食与信息共享
萤火虫群优化GSO模拟萤火虫发光吸引行为
动物迁徙优化AMO模拟动物群体迁徙跟随行为
磷虾群算法KH模拟磷虾诱导运动、觅食和扩散
共生生物搜索SOS模拟生物间互利共生/偏利共生/寄生关系
大象牧群优化EHO模拟大象族群分离与母系领导机制
高斯骨干粒子群优化GBPSO基于高斯分布的简化粒子群算法
飞蛾搜索算法MSA基于飞蛾 Lévy 飞行和螺旋搜索
路径finder算法PFA基于领导者-跟随者层级移动
菌落捕食算法CPA模拟捕食-逃跑概率行为
细菌菌落优化BCO基于细菌趋化聚集行为
飞狐优化算法FFOA带惯性权重的群体飞行搜索
人工鱼群算法AFSA模拟鱼群觅食、聚群和追尾行为
烟花算法FWA模拟烟花爆炸及火花分布机制
鸽群优化PIO模拟信鸽导航的地图指南针与地标两阶段
蜜獾算法HBA模拟蜜獾挖洞与觅食的密度因子搜索
鹈鹕优化算法POA模拟鹈鹕捕猎的两阶段策略
金枪鱼群优化TSA基于螺旋运动和觅食行为的群体搜索
金豺优化GJO模拟雄雌金豺协同捕猎的双引导搜索
蝗虫优化算法GOA模拟蝗虫群体觅食的吸引-排斥机制
海鸥优化算法SOA模拟海鸥迁徙和螺旋攻击行为
猫群优化CSO模拟猫的追踪和搜寻两种模式切换
大猩猩部队优化GTO模拟大猩猩群体社会等级与领导机制
黏菌算法SMA模拟黏菌觅食行为的群体路径搜索
苍鹰优化器AO模拟苍鹰捕猎的四个阶段策略
黑猩猩优化算法ChOA模拟黑猩猩狩猎的驱动-追逐-竞争行为
蒲公英优化器DO模拟蒲公英种子风力传播的上升-下降搜索
斑马优化算法ZOA模拟斑马群体探索-开发机制

通用群体智能参数: 大部分算法默认 population_size = 25。下表列出各算法的特有参数。

算法特有参数推荐值
PSOinertia_weight, cognitive_coeff, social_coeff0.7, 1.5, 1.5
Fireflyinitial_attractiveness (β₀), light_absorption (γ), step_size (α)1.0, 1.0, 0.2
ACOant_count, evaporation_rate (ρ), pheromone_weight (α), heuristic_weight (β)20, 0.1, 1.0, 10.0
Bee Colonyscout_bee_count, max_trials25, 100
Cuckoo Searchnest_count, abandon_probability (p_a), levy_parameter (β)25, 0.25, 1.5
Bat Algorithmfreq_min, freq_max, loudness, pulse_rate0.0, 1.0, 0.5, 1.0
Harmony Searchmemory_size, hmcr, par, fretwidth20, 0.9, 0.3, 0.05
SSAdiscoverer_ratio, warning_threshold0.2, 0.8
FPAswitch_probability0.8
DAseparation_weight, alignment_weight, cohesion_weight1.0, 1.0, 1.0
CSAflight_length, awareness_prob2.0, 0.1
MBOmigration_period, adjustment_rate5, 1.0
IWOinitial_pop, max_pop, min_seeds, max_seeds, initial_sigma, final_sigma10, 40, 1, 5, 2.0, 0.1
BFOchemotactic_steps, reproduction_steps, step_size5, 3, 0.2
SFLAmemeplex_count, iterations_per_group5, 10
GSOluciferin_decay, luciferin_enhancement, neighbor_count, sensing_radius, step_size0.4, 0.6, 5, 5.0, 1.0
AMOmigration_interval5
KHmax_speed, foraging_speed0.01, 0.02
EHOclan_count, alpha5, 0.5
AFSAvisual, step, crowd_factor2.0, 0.5, 0.5
CSOmixture_ratio0.3
WCAnum_rivers4
MFOspiral_constant1.0
WOAspiral_constant1.0
其余算法 (GWO, SCA, ALO, HHO, SalpSA, AEO, SOS, GBPSO, MSA, PFA, CPA, BCO, FFOA, FWA, PIO, HBA, POA, TSA, GJO, GOA, SOA, GTO, SMA, AO, ChOA, DO, ZOA)仅需 population_size25

#📐 确定性直接搜索

无需梯度信息,通过几何模式进行直接搜索,适合不可导函数。

算法简称说明
Nelder-Mead 单纯形法NM无导数的单纯形几何变形方法
Hooke-Jeeves 模式搜索HJ无导数的直接搜索方法

算法关键参数推荐值
Nelder-Meadreflection_coeff (α), expansion_coeff (γ), contraction_coeff (ρ), shrink_coeff (σ)1.0, 2.0, 0.5, 0.5
Hooke-Jeevesinitial_step, step_reduction, min_step0.5, 0.5, 1e-6

#🧮 进化策略

基于概率分布的参数自适应优化,适合复杂病态问题。

算法简称说明
协方差矩阵自适应进化策略CMA-ES协方差矩阵自适应调整,适合病态问题

算法关键参数推荐值
CMA-ESsigma (初始标准差), lambda (种群大小), mu (父代数量)0.5, 20, 10

#📊 估计分布算法

基于概率分布估计的迭代优化方法。

算法简称说明
交叉熵方法CEM基于高斯分布的迭代估计
随机分形搜索SFS基于分形发现和学习两阶段搜索

算法关键参数推荐值
CEMsample_size, elite_fraction, smoothing100, 0.1, 0.7
SFSpopulation_size, discovery_iterations, learning_iterations25, 3, 2

#⚛️ 物理启发算法

基于物理定律和自然现象的搜索机制。

算法简称说明
引力搜索算法GSA基于牛顿万有引力定律的搜索
多宇宙优化MVO基于白洞/黑洞/虫洞的宇宙机制
均衡优化EO基于控制理论均衡池与指数衰减策略
风驱动优化WDO模拟大气风速更新与科里奥利力
水循环算法WCA基于水循环和河流流动过程

算法关键参数推荐值
GSAgravity_constant (G₀), decay_alpha (α)100.0, 0.99
MVOwormhole_exploitation, travelling_distance_rate1.0, 0.6
EO仅需 population_size25
WDO仅需 population_size25
WCApopulation_size, num_rivers25, 4

#🎓 教学模型算法

模拟教学与学习过程的优化方法。

算法简称说明
教与学优化TLBO模拟班级教学和学习过程,无需额外参数

算法关键参数推荐值
TLBO仅需 population_size30

#🔢 数学启发算法

基于数学原理和运算规则的搜索机制。

算法简称说明
Jaya算法Jaya基于最优-最差个体更新策略
算术优化算法AOA基于算术运算符(除/乘/减/加)的搜索

算法关键参数推荐值
Jaya仅需 population_size25
AOA仅需 population_size25

#👥 人类行为算法

模拟人类社会活动和思维过程的优化方法。

算法简称说明
头脑风暴优化BSO模拟人类头脑风暴聚类的创意生成过程
足球联赛竞争算法SLC模拟足球联赛团队竞争与球员交换

算法关键参数推荐值
BSO仅需 population_size25
SLC仅需 population_size25

#项目结构

BlackBoxOptimization/ ├── lib/ # 核心库包 │ ├── moon.pkg.json # 包配置 │ └── lib.mbt # 所有优化算法实现 ├── main/ # 主程序入口 │ ├── moon.pkg.json # 包配置 │ └── main.mbt # 基准测试入口 ├── test/ # 测试包 │ ├── moon.pkg.json # 包配置 │ └── lib_test.mbt # 单元测试(140 个测试用例) ├── example/ # 示例包 │ ├── moon.pkg.json # 包配置 │ └── simple_usage.mbt # 使用示例(61 个示例) ├── .github/workflows/ # CI 配置 │ └── ci.yml # GitHub Actions ├── moon.mod.json # 模块配置 └── README.md

#快速开始

#环境要求

#安装

# 克隆项目 git clone https://github.com/your-username/BlackBoxOptimization.git cd BlackBoxOptimization

#运行示例

# 运行简单示例 moon run example # 运行基准测试 moon run main

#运行测试

# 运行所有测试(140 个测试用例) moon test # 代码检查 moon check

#使用方法

#基本用法

import lib

fn main {
// 1. 定义问题
let dim = 3
let bounds = @lib.make_bounds(-5.0, 5.0)
let rng = @lib.make_rng(123.0)

// 2. 选择目标函数(Sphere 函数)
// f(x) = sum(x_i^2),最优值为 0

// 3. 配置并运行算法
let config = @lib.make_pso_config(
1000, // max_evaluations
dim, // dimension
bounds, // bounds
30, // population_size
0.7, // inertia_weight
1.5, // cognitive_coeff
1.5 // social_coeff
)
let result = @lib.pso(config, @lib.sphere_function, rng)

// 4. 获取结果
println("最优值: \{result.best_value}")
println("评估次数: \{result.evaluations}")
}

#使用不同算法

// 随机搜索
let rs_config = @lib.make_random_search_config(1000, dim, bounds)
let rs_result = @lib.random_search(rs_config, f, rng)

// 爬山法
let hc_config = @lib.make_hill_climbing_config(1000, dim, bounds, 0.5, 10)
let hc_result = @lib.hill_climbing(hc_config, f, rng)

// 模拟退火
let sa_config = @lib.make_simulated_annealing_config(1000, dim, bounds, 100.0, 0.995, 0.5)
let sa_result = @lib.simulated_annealing(sa_config, f, rng)

// 粒子群优化
let pso_config = @lib.make_pso_config(1000, dim, bounds, 30, 0.7, 1.5, 1.5)
let pso_result = @lib.pso(pso_config, f, rng)

// 差分进化
let de_config = @lib.make_de_config(1000, dim, bounds, 30, 0.8, 0.9)
let de_result = @lib.differential_evolution(de_config, f, rng)

// 遗传算法
let ga_config = @lib.make_ga_config(1000, dim, bounds, 30, 0.8, 0.05)
let ga_result = @lib.genetic_algorithm(ga_config, f, rng)

// Nelder-Mead
let nm_config = @lib.make_nm_config(1000, dim, bounds, 1.0, 2.0, 0.5, 0.5)
let nm_result = @lib.nelder_mead(nm_config, f, rng)

// 萤火虫算法
let ff_config = @lib.make_firefly_config(1000, dim, bounds, 30, 1.0, 1.0, 0.2)
let ff_result = @lib.firefly_algorithm(ff_config, f, rng)

// 蚁群算法 (ACO)
let aco_config = @lib.make_aco_config(1000, dim, bounds, 20, 0.1, 1.0, 10.0)
let aco_result = @lib.aco(aco_config, f, rng)

// 蜂群算法 (Bee Colony)
let bc_config = @lib.make_bee_colony_config(1000, dim, bounds, 25, 100)
let bc_result = @lib.bee_colony(bc_config, f, rng)

// 禁忌搜索 (Tabu Search)
let ts_config = @lib.make_tabu_search_config(1000, dim, bounds, 50, 30, 0.5)
let ts_result = @lib.tabu_search(ts_config, f, rng)

// 引导局部搜索 (Guided LS)
let ls_config = @lib.make_local_search_config(1000, dim, bounds, 30, 0.5, 0.5)
let ls_result = @lib.local_search(ls_config, f, rng)

// CMA-ES
let cma_config = @lib.make_cmaes_config(1000, dim, bounds, 0.5, 20, 10)
let cma_result = @lib.cma_es(cma_config, f, rng)

// 交叉熵方法 (CEM)
let cem_config = @lib.make_cem_config(1000, dim, bounds, 100, 0.1, 0.7)
let cem_result = @lib.cross_entropy_method(cem_config, f, rng)

// 布谷鸟搜索 (Cuckoo Search)
let cs_config = @lib.make_cuckoo_config(1000, dim, bounds, 25, 0.25, 1.5)
let cs_result = @lib.cuckoo_search(cs_config, f, rng)

// 灰狼优化 (GWO)
let gwo_config = @lib.make_gwo_config(1000, dim, bounds, 25)
let gwo_result = @lib.grey_wolf_optimizer(gwo_config, f, rng)

// Hooke-Jeeves 模式搜索
let hj_config = @lib.make_hooke_jeeves_config(1000, dim, bounds, 0.5, 0.5, 1.0e-6)
let hj_result = @lib.hooke_jeeves(hj_config, f, rng)

// 鲸群优化 (WOA)
let woa_config = @lib.make_woa_config(1000, dim, bounds, 25, 1.0)
let woa_result = @lib.whale_optimization(woa_config, f, rng)

// 蝙蝠算法 (Bat Algorithm)
let bat_config = @lib.make_bat_config(1000, dim, bounds, 25, 0.0, 1.0, 0.5, 1.0)
let bat_result = @lib.bat_algorithm(bat_config, f, rng)

// 和声搜索 (Harmony Search)
let hs_config = @lib.make_hs_config(1000, dim, bounds, 20, 0.9, 0.3, 0.05)
let hs_result = @lib.harmony_search(hs_config, f, rng)

// 正弦余弦算法 (SCA)
let sca_config = @lib.make_sca_config(1000, dim, bounds, 25)
let sca_result = @lib.sine_cosine_algorithm(sca_config, f, rng)

// 飞蛾火焰优化 (MFO)
let mfo_config = @lib.make_mfo_config(1000, dim, bounds, 25, 1.0)
let mfo_result = @lib.moth_flame_optimization(mfo_config, f, rng)

// 蚁狮优化 (ALO)
let alo_config = @lib.make_alo_config(1000, dim, bounds, 25)
let alo_result = @lib.antlion_optimizer(alo_config, f, rng)

// 麻雀搜索算法 (SSA)
let ssa_config = @lib.make_ssa_config(1000, dim, bounds, 25)
let ssa_result = @lib.sparrow_search_algorithm(ssa_config, f, rng)

// 哈里斯鹰优化 (HHO)
let hho_config = @lib.make_hho_config(1000, dim, bounds, 25)
let hho_result = @lib.harris_hawks_optimization(hho_config, f, rng)

// 花粉传播算法 (FPA)
let fpa_config = @lib.make_fpa_config(1000, dim, bounds, 25)
let fpa_result = @lib.flower_pollination_algorithm(fpa_config, f, rng)

// 蜻蜓算法 (DA)
let da_config = @lib.make_da_config(1000, dim, bounds, 25)
let da_result = @lib.dragonfly_algorithm(da_config, f, rng)

// 乌鸦搜索算法 (CSA)
let csa_config = @lib.make_csa_config(1000, dim, bounds, 25)
let csa_result = @lib.crow_search_algorithm(csa_config, f, rng)

// 樽海鞘群算法 (SalpSA)
let salp_config = @lib.make_salp_sa_config(1000, dim, bounds, 25)
let salp_result = @lib.salp_swarm_algorithm(salp_config, f, rng)

// Monarch蝴蝶优化 (MBO)
let mbo_config = @lib.make_mbo_config(1000, dim, bounds, 25)
let mbo_result = @lib.monarch_butterfly_optimization(mbo_config, f, rng)

// 人工生态系统优化 (AEO)
let aeo_config = @lib.make_aeo_config(1000, dim, bounds, 25)
let aeo_result = @lib.artificial_ecosystem_optimization(aeo_config, f, rng)

// 入侵杂草优化 (IWO)
let iwo_config = @lib.make_iwo_config(1000, dim, bounds, 10, 40, 1, 5, 2.0, 0.1, 3.0)
let iwo_result = @lib.invasive_weed_optimization(iwo_config, f, rng)

// 细菌觅食优化 (BFO)
let bfo_config = @lib.make_bfo_config(1000, dim, bounds, 25, 5, 3, 0.2)
let bfo_result = @lib.bacteria_foraging_optimization(bfo_config, f, rng)

// 混合蛙跳算法 (SFLA)
let sfla_config = @lib.make_sfla_config(1000, dim, bounds, 30, 5, 10)
let sfla_result = @lib.shuffled_frog_leaping_algorithm(sfla_config, f, rng)

// 萤火虫群优化 (GSO)
let gso_config = @lib.make_gso_config(1000, dim, bounds, 25, 0.4, 0.6, 5, 5.0, 1.0)
let gso_result = @lib.glowworm_swarm_optimization(gso_config, f, rng)

// 引力搜索算法 (GSA)
let gsa_config = @lib.make_gsa_config(1000, dim, bounds, 25, 100.0, 0.99)
let gsa_result = @lib.gravitational_search_algorithm(gsa_config, f, rng)

// 教与学优化 (TLBO)
let tlbo_config = @lib.make_tlbo_config(1000, dim, bounds, 30)
let tlbo_result = @lib.teaching_learning_based_optimization(tlbo_config, f, rng)

// 动物迁徙优化 (AMO)
let amo_config = @lib.make_amo_config(1000, dim, bounds, 25, 5)
let amo_result = @lib.animal_migration_optimization(amo_config, f, rng)

// 多宇宙优化 (MVO)
let mvo_config = @lib.make_mvo_config(1000, dim, bounds, 25)
let mvo_result = @lib.multi_verse_optimizer(mvo_config, f, rng)

// 磷虾群算法 (KH)
let kh_config = @lib.make_kh_config(1000, dim, bounds, 25)
let kh_result = @lib.krill_herd(kh_config, f, rng)

// 帝国主义竞争算法 (ICA)
let ica_config = @lib.make_ica_config(1000, dim, bounds, 25)
let ica_result = @lib.imperialist_competitive_algorithm(ica_config, f, rng)

// 随机分形搜索 (SFS)
let sfs_config = @lib.make_sfs_config(1000, dim, bounds, 25)
let sfs_result = @lib.stochastic_fractal_search(sfs_config, f, rng)

// 共生生物搜索 (SOS)
let sos_config = @lib.make_sos_config(1000, dim, bounds, 25)
let sos_result = @lib.symbiotic_organisms_search(sos_config, f, rng)

// 生物地理学优化 (BBO)
let bbo_config = @lib.make_bbo_config(1000, dim, bounds, 25, 0.01)
let bbo_result = @lib.biogeography_based_optimization(bbo_config, f, rng)

// 大象牧群优化 (EHO)
let eho_config = @lib.make_eho_config(1000, dim, bounds, 25, 5, 0.5)
let eho_result = @lib.elephant_herding_optimization(eho_config, f, rng)

// 均衡优化 (EO)
let eo_config = @lib.make_eo_config(1000, dim, bounds, 25)
let eo_result = @lib.equilibrium_optimizer(eo_config, f, rng)

// 风驱动优化 (WDO)
let wdo_config = @lib.make_wdo_config(1000, dim, bounds, 25)
let wdo_result = @lib.wind_driven_optimization(wdo_config, f, rng)

// Jaya算法
let jaya_config = @lib.make_jaya_config(1000, dim, bounds, 25)
let jaya_result = @lib.jaya_optimization(jaya_config, f, rng)

// 足球联赛竞争算法 (SLC)
let slc_config = @lib.make_slc_config(1000, dim, bounds, 25)
let slc_result = @lib.soccer_league_competition(slc_config, f, rng)

// 高斯骨干粒子群优化 (GBPSO)
let gbpso_config = @lib.make_gbpso_config(1000, dim, bounds, 25)
let gbpso_result = @lib.gaussian_bare_bones_pso(gbpso_config, f, rng)

// 飞蛾搜索算法 (MSA)
let msa_config = @lib.make_msa_config(1000, dim, bounds, 25)
let msa_result = @lib.moth_search_algorithm(msa_config, f, rng)

// 路径finder算法 (PFA)
let pfa_config = @lib.make_pfa_config(1000, dim, bounds, 25)
let pfa_result = @lib.pathfinder_algorithm(pfa_config, f, rng)

// 菌落捕食算法 (CPA)
let cpa_config = @lib.make_cpa_config(1000, dim, bounds, 25)
let cpa_result = @lib.colony_predation_algorithm(cpa_config, f, rng)

// 细菌菌落优化 (BCO)
let bco_config = @lib.make_bco_config(1000, dim, bounds, 25)
let bco_result = @lib.bacteria_colony_optimization(bco_config, f, rng)

// 飞狐优化算法 (FFOA)
let ffoa_config = @lib.make_ffoa_config(1000, dim, bounds, 25)
let ffoa_result = @lib.flying_fox_optimization(ffoa_config, f, rng)

// 人工鱼群算法 (AFSA)
let afsa_config = @lib.make_afsa_config(1000, dim, bounds, 25, 2.0, 0.5, 0.5)
let afsa_result = @lib.artificial_fish_swarm(afsa_config, f, rng)

// 烟花算法 (FWA)
let fwa_config = @lib.make_fwa_config(1000, dim, bounds, 25)
let fwa_result = @lib.fireworks_algorithm(fwa_config, f, rng)

// 头脑风暴优化 (BSO)
let bso_config = @lib.make_bso_config(1000, dim, bounds, 25)
let bso_result = @lib.brain_storm_optimization(bso_config, f, rng)

// 回溯搜索算法 (BSA)
let bsa_config = @lib.make_bsa_config(1000, dim, bounds, 25)
let bsa_result = @lib.backtracking_search_algorithm(bsa_config, f, rng)

// 鸽群优化 (PIO)
let pio_config = @lib.make_pio_config(1000, dim, bounds, 25)
let pio_result = @lib.pigeon_inspired_optimization(pio_config, f, rng)

// 算术优化算法 (AOA)
let aoa_config = @lib.make_aoa_config(1000, dim, bounds, 25)
let aoa_result = @lib.arithmetic_optimization_algorithm(aoa_config, f, rng)

// 蜜獾算法 (HBA)
let hba_config = @lib.make_hba_config(1000, dim, bounds, 25)
let hba_result = @lib.honey_badger_algorithm(hba_config, f, rng)

// 鹈鹕优化算法 (POA)
let poa_config = @lib.make_poa_config(1000, dim, bounds, 25)
let poa_result = @lib.pelican_optimization_algorithm(poa_config, f, rng)

// 金枪鱼群优化 (TSA)
let tsa_config = @lib.make_tsa_config(1000, dim, bounds, 25)
let tsa_result = @lib.tuna_swarm_optimization(tsa_config, f, rng)

// 金豺优化 (GJO)
let gjo_config = @lib.make_gjo_config(1000, dim, bounds, 25)
let gjo_result = @lib.golden_jackal_optimization(gjo_config, f, rng)

// 蝗虫优化算法 (GOA)
let goa_config = @lib.make_goa_config(1000, dim, bounds, 25)
let goa_result = @lib.grasshopper_optimization_algorithm(goa_config, f, rng)

// 海鸥优化算法 (SOA)
let soa_config = @lib.make_soa_config(1000, dim, bounds, 25)
let soa_result = @lib.seagull_optimization_algorithm(soa_config, f, rng)

// 猫群优化 (CSO)
let cso_config = @lib.make_cso_config(1000, dim, bounds, 25)
let cso_result = @lib.cat_swarm_optimization(cso_config, f, rng)

// 大猩猩部队优化 (GTO)
let gto_config = @lib.make_gto_config(1000, dim, bounds, 25)
let gto_result = @lib.gorilla_troops_optimizer(gto_config, f, rng)

// 水循环算法 (WCA)
let wca_config = @lib.make_wca_config(1000, dim, bounds, 25, 4)
let wca_result = @lib.water_cycle_algorithm(wca_config, f, rng)

#内置测试函数

// Sphere 函数: f(x) = sum(x_i^2),最优值: 0
let f1 = @lib.sphere_function

// Rastrigin 函数: f(x) = 10n + sum(x_i^2 - 10*cos(2*pi*x_i)),最优值: 0
let f2 = @lib.rastrigin_function

// Rosenbrock 函数: f(x) = sum(100*(x_{i+1} - x_i^2)^2 + (1 - x_i)^2),最优值: 0
let f3 = @lib.rosenbrock_function

#基准测试

// 运行单轮基准测试
let results = @lib.run_benchmark_at_evals(f, "Sphere", dim, bounds, 0.0, 5000, rng)
@lib.print_benchmark_table(results, "Sphere", 5000)

// 运行多次试验统计分析
@lib.run_multiple_trials(f, "Sphere", dim, bounds, 0.0, 10000, 20, 100.0)

#性能对比

#基准函数性能对比(5维,10次试验平均值)

算法Sphere 1000Sphere 5000Sphere 10000Rastrigin 5000Rastrigin 10000Rosenbrock 5000Rosenbrock 10000
随机搜索3.170.920.9221.8417.38108.8422.78
爬山法0.00940.00940.009453.5352.757.065.63
模拟退火0.570.00590.005923.4123.414.982.74
PSO8.56e-42.28e-153.38e-292.992.984.354.09
DE0.1561.02e-88.65e-188.291.350.06763.98e-8
GA0.6980.05590.01119.761.6628.9217.26
Nelder-Mead49.3849.3849.3861.3961.3943504.8843504.88
萤火虫4.250.920.9222.9917.7891.2191.21
蚁群算法2.432.432.129.499.4914.267.47
蜂群算法0.2733.33e-46.23e-103.921.111.360.265
禁忌搜索0.01720.01510.01516.916.911.951.95
引导局部搜索0.01720.01720.017223.3115.643.673.67
CMA-ES0.02363.56e-49.22e-722.9922.883.221.25
CEM0.3103.52e-71.04e-70.5932.30e-52.382.35
布谷鸟搜索0.7440.06360.063611.7411.7417.8015.13
GWO0.001631.00e-96.61e-165.020.00255.900.0392
Hooke-Jeeves1.71e-121.71e-121.71e-1245.7745.770.4400.288
WOA0.00209.70e-109.03e-160.9951.27e-112.100.00221
蝙蝠算法0.006256.49e-56.49e-513.3713.20130.18130.18
和声搜索0.002843.39e-52.31e-52.030.6070.6990.679
SCA1.14e-149.11e-471.60e-99000.01930.00461
MFO0.1401.63e-82.02e-173.991.994.342.49
ALO1.451.410.38511.4511.4534.0634.06
SSA1.24e-46.28e-131.95e-178.958.952.091.31
HHO~000000.002270.00227
FPA0.5960.07280.05429.435.093.060.346
DA1.5892.6672.63549.1249.751025.52976.07
CSA0.003651.70e-71.38e-79.06e-58.92e-51.06e-45.25e-5
SalpSA0.7310.05910.0050625.5625.589.622.27
MBO5.73e-52.53e-52.47e-50.005250.005150.02390.00623
AEO0.03550.003940.01052.825.385.622.95
IWO3.580.002420.001062.691.231.421.48
BFO1.680.007350.007353.023.022.411.87
SFLA9.86e-43.48e-57.36e-91.991.9917.784.69
GSO7.616.396.3922.2322.231856.04451.42
GSA18.1118.1118.1165.3265.324343.624343.62
TLBO1.41e-44.26e-249.02e-470.033301.721.57
AMO0.01715.02e-78.41e-126.976.963.913.60
MVO13.4713.4713.4748.8648.864875.104875.10
KH0.1930.1930.1936.307.869.5913.22
ICA0.9060.9060.90617.9717.979.5732.58
SFS1.82e-45.63e-53.36e-60.4540.01130.01230.0128
SOS3.17e-4~0~02.982.984.514.16
BBO13.468.474.1037.3237.322373.73636.06
EHO0.01127.69e-42.37e-45.115.041.540.394
EO6.880.5980.0065550.3045.774.900.160
WDO3.9610.780.142125.66101.0855358.40559.77
Jaya0.0133~0~07.826.710.7060.0925
SLC2.87e-52.70e-52.70e-52.012.0162.5962.59
GBPSO~0~0~09.959.950.001100.000123
MSA13.472.770.41331.6535.67544.40173.63
PFA0.2260.1090.35321.9524.167.1911.27
CPA1.900.5922.7325.9923.1316.3082.19
BCO0.2450.001570.002702.291.583.221.89
FFOA0.7010.7590.34624.1725.0686.24316.22
AFSA0.1340.01830.018314.887.537.876.79
FWA7.284.214.2127.7927.79522.59121.52
BSO0.003210.00002900.00002082.9981.9932.390.407
BSA1.570.1820.0017029.9922.3631.706.59
PIO0.006761.83e-101.88e-185.975.973.471.72
AOA0.002805.27e-52.86e-40.5520.06800.04240.0327
HBA0.009490.01836.31e-47.466.364.380.263
POA0.008887.24e-106.18e-171.120.002540.9990.966
TSA000003.773.77
GJO1.87e-71.07e-263.75e-561.9914.920.8980.775
GOA0.05530.004141.65e-44.257.040.9223.65
SOA4.89e-5~0~02.981.991.490.0162
CSO0.02182.57e-5~06.115.971.580.618
GTO0.05737.99e-69.28e-61.301.173.000.0833
WCA0.03430.01290.01173.194.323.552.74
SMA0.03900.03600.036017.0417.0438.6738.24
AO0.1170.003310.0005368.484.824.353.44
ChOA1.18e-10~0~09.659.652.071.99
DO0.2790.3960.36614.9913.64128.57127.91
ZOA0.01130.0002510.00003288.425.071.370.821

#算法分类特点总结

类别代表算法特点
🔍 单点搜索随机搜索、爬山法、模拟退火简单、易于实现,适合低维问题
🔧 局部搜索禁忌搜索、引导局部搜索强化局部开发,避免陷入局部最优
🧬 进化算法DE、GA、ICA、BBO、BSA基于种群进化,鲁棒性好
🐝 群体智能PSO、萤火虫、蚁群、蜂群、灰狼、鲸群、蝙蝠、和声、麻雀搜索、哈里斯鹰、GOA、SOA、CSO、GTO、SMA、AO、ChOA、DO、ZOA 等基于群体行为,全局搜索能力强
📐 确定性直接搜索Nelder-Mead、Hooke-Jeeves无需梯度,适合不可导函数
🧮 进化策略CMA-ES协方差自适应,适合病态问题
📊 估计分布CEM、SFS基于概率分布估计,适合连续优化
⚛️ 物理启发GSA、MVO、EO、WDO、WCA基于物理规律,自适应搜索
🎓 教学模型TLBO无需算法特定参数,收敛速度快
🔢 数学启发Jaya、AOA基于数学原理的搜索机制
👥 人类行为BSO、SLC模拟人类社会行为过程

#许可证

本项目基于 Apache-2.0 license 开源。