python:基于竞争学习的鳟海鞘算法(Competitive Learning-Based Salp Swarm Algorithm,CLSSA)求解23个测试函数(提供python代码及参考文献)

一、基于竞争学习的鳟海鞘算法

基于竞争学习的鳟海鞘算法(Competitive Learning-Based Salp Swarm Algorithm,CLSSA)由Mohammed Qaraad等人于2023年提出。

参考文献:

Qaraad M, Aljadania A, Elhosseini M. Large-Scale Competitive Learning-Based Salp Swarm for Global Optimization and Solving Constrained Mechanical and Engineering Design Problems. Mathematics. 2023; 11(6):1362. Mathematics | Free Full-Text | Large-Scale Competitive Learning-Based Salp Swarm for Global Optimization and Solving Constrained Mechanical and Engineering Design Problems

二、CLSSA求解23个测试函数

23个测试函数简介

测试集:23组基本测试函数简介及图像(提供python代码)_IT猿手的博客-CSDN博客

部分代码

from FunInfo import Get_Functions_details
from CLSSA import CLSSA
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['Microsoft YaHei']
#主程序
function_name =5 #测试函数1-23
SearchAgents_no = 50#种群大小
Max_iter = 100#迭代次数
lb,ub,dim,fobj=Get_Functions_details(function_name)#获取问题信息
BestX,BestF,curve = CLSSA(SearchAgents_no, Max_iter,lb,ub,dim,fobj)#问题求解

#画收敛曲线图
if BestF>0:
    plt.semilogy(curve,color='r',linewidth=2,label='CLSSA')
else:
    plt.plot(curve,color='r',linewidth=2,label='CLSSA')
plt.xlabel("Iteration")
plt.ylabel("Fitness")
plt.xlim(0,Max_iter)
plt.title("F"+str(function_name))
plt.legend()
plt.savefig(str(function_name)+'.png')
plt.show()
print('\nThe best solution is:\n'+str(BestX))
print('\nThe best optimal value of the objective funciton is:\n'+str(BestF))

部分结果

三、完整python代码

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当然可以,以下是一个简单的樽海鞘算法Python实现代码,供您参考: ```python import numpy as np # 定义问题 def objective_function(x): return np.sum(x ** 2) # 初始化种群 def initialize_population(pop_size, problem_size): return np.random.uniform(low=-5.12, high=5.12, size=(pop_size, problem_size)) # 计算适应度值 def calculate_fitness(population): fitness = np.zeros(population.shape[0]) for i in range(population.shape[0]): fitness[i] = objective_function(population[i]) return fitness # 樽海鞘算法 def tunicate_swarm_algorithm(pop_size, problem_size, max_iter): # 初始化种群 population = initialize_population(pop_size, problem_size) # 初始化最优解 best_solution = None best_fitness = float('inf') # 迭代 for i in range(max_iter): # 计算适应度值 fitness = calculate_fitness(population) # 更新最优解 if np.min(fitness) < best_fitness: best_fitness = np.min(fitness) best_solution = population[np.argmin(fitness)] # 计算化学物质浓度值 concentration = np.zeros(pop_size) for j in range(pop_size): for k in range(pop_size): concentration[j] += np.exp(-objective_function(population[k] - population[j])) concentration = concentration / np.sum(concentration) # 移动樽海鞘 for j in range(pop_size): move_direction = np.zeros(problem_size) for k in range(pop_size): move_direction += (population[k] - population[j]) * concentration[k] population[j] += move_direction return best_solution, best_fitness ``` 注:此代码仅供参考,具体实现可能会因问题细节而有所不同,需要根据实际情况进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值