一、算法主要创新与流程
基于Tent 混沌映射与差分机制改进的狮群优化算法。狮群位置的初始化对算法的收敛速度和求解精度非常重要,在种群位置初始化中引入改进的Tent 混沌映射,增强了初始种群分布的多样性和均匀遍历性,从而提高了初始解的质量;在母狮位置更新方式中引入差分进化机制,增强母狮的局部搜索能力,同时通过引入位置更新扰动因子充分利用群体有效信息,增强了算法跳出局部最优解的能力。
幼狮位置更新中,相同的步长扰动因子和行为方式选择概率会导致算法早熟收敛。为此,通过融合二阶范数与信息熵形成扰动因子,动态调整不同幼狮的移动范围,通过引入包含迭代信息的自适应参数实现了幼狮不同行为方式选择概率的动态调整,解决了 LSO 算法中由于幼狮选择策略较为盲目导致忽略潜在的优质解和步长扰动因子受解空间影响过大而易陷入局部最优的问题,有效抑制算法早熟收敛,提高了算法寻优精度。此外,在采用改进的Tent 混沌映射初始化种群的同时,引入自适应混沌搜索策略调整每次迭代的搜索范围,在增强算法跳出局部最优能力的同时进一步提升了算法的收敛速度和寻优精度,使其在全局和局部寻优能力方面达到了较好的动态均衡。
二、代码与仿真
// 得到一个在闭区间 [min, max] 内的随机整数
int randInt(int min, int max);
// 第一种写法
void shuffle(int[] arr) {
int n = arr.length();
/******** 区别只有这两行 ********/
for (int i = 0 ; i < n; i++) {
// 从 i 到最后随机选一个元素
int rand = randInt(i, n - 1);
/*************************/
swap(arr[i], arr[rand]);
}
}
// 第二种写法
for (int i = 0 ; i < n - 1; i++)
int rand = randInt(i, n - 1);
// 第三种写法
for (int i = n - 1 ; i >= 0; i--)
int rand = randInt(0, i);
// 第四种写法
for (int i = n - 1 ; i > 0; i--)
int rand = randInt(0, i);
// 假设传入这样一个 arr
int[] arr = {1,3,5,7,9};
void shuffle(int[] arr) {
int n = arr.length(); // 5
for (int i = 0 ; i < n; i++) {
int rand = randInt(i, n - 1);
swap(arr[i], arr[rand]);
}
}
void shuffle(int[] arr) {
int n = arr.length();
for (int i = 0 ; i < n; i++) {
// 每次都从闭区间 [0, n-1]
// 中随机选取元素进行交换
int rand = randInt(0, n - 1);
swap(arr[i], arr[rand]);
}
}
种群分割
算法流程图
传统狮群优化算法伪代码如下。其中最大迭代次数用T 表示,当前迭代次数用t 表示,Pbest 表示每只狮子的历史最优位置,fitness(x)表示与每只狮子的位置x 相对应的适应度值,最优适应度值用fbest 表示,全局最优位置用gbest 表示, AC 表示收敛精度。
Algorithm: LSoImput:T,AC, fitmessOoutput: fbest, gbest
1: Initialize related parameters
2:Generate the initial pride of lions according to Eqs.(2.2)
3:Calculate the fitness of each individual lion and the value of nLeaderaccording to nLeader =NB
4:Declare the lion king, 1lionesses and lion cubs.Record Pbest(historical best foreach individual) and gbest
5: While t≤ T and fun(x)>AC do
6: Generate a random number p that obey's the norma1 distribution N(0,1),andcalculate a and a。according to Eqs.(2.6) ,Eqs.(2.8)
7:Update the lion king position using Eqs.(2.4)8: Update the lioness position using Eqs.(2.5)
9:Generate a random number q that obeys uniform distribution U(0,1), and arandom number y that obeys normal distribution N(O,1).Update the lioness positionusing Eqs.(2.7)
If q≤1/3.Then Update the lioness position using Eqs.(2.7a), end ifIf 1/3<q≤2/3,Then Update the lioness position using Eqs.(2.7b), end iflf 2/3<q≤1,Then Update the lioness position using Eqs.(2.7c), end if10: Calculate fitness based on pride of lions position and update Pbest and gbest11:Ift %10=0 Then
12: Reposition the lion king, the lioness and the lion cubs13: end if
14:t= t+1
15: gbest= Xi, fbest -fitmess(Xi)16: end while
17:Output fbest