""" JAYA Algorithm """
import random
import numpy
import math
from solution import solution
import time
def JAYA(objf, lb, ub, dim, SearchAgents_no, Max_iter):
# Best and Worst position initialization
Best_pos = numpy.zeros(dim)
Best_score = float("inf")
Worst_pos = numpy.zeros(dim)
Worst_score = float(0)
fitness_matrix = numpy.zeros((SearchAgents_no))
if not isinstance(lb, list):
lb = [lb] * dim
if not isinstance(ub, list):
ub = [ub] * dim
# Initialize the positions of search agents
Positions = numpy.zeros((SearchAgents_no, dim))
for i in range(dim):
Positions[:, i] = (
numpy.random.uniform(0, 1, SearchAgents_no) * (ub[i] - lb[i]) + lb[i]
)
for i in range(0, SearchAgents_no):
# Return back the search agents that go beyond the boundaries of the search space
for j in range(dim):
Positions[i, j] = numpy.clip(Positions[i, j], lb[j], ub[j])
# Calculate objective function for each search agent
fitness = objf(Positions[i])
fitness_matrix[i] = fitness
if fitness < Best_score:
Best_score = fitness # Update Best_Score
Best_pos = Positions[i]
if fitness > Worst_score:
Worst_score = fitness # Update Worst_Score
Worst_pos = Positions[i]
Convergence_curve = numpy.zeros(Max_iter)
s = solution()
# Loop counter
print('JAYA is optimizing "' + objf.__name__ + '"')
timerStart = time.time()
s.startTime = time.strftime("%Y-%m-%d-%H-%M-%S")
# Main loop
for l in range(0, Max_iter):
# Update the Position of search agents
for i in range(0, SearchAgents_no):
New_Position = numpy.zeros(dim)
for j in range(0, dim):
# Update r1, r2
r1 = random.random()
r2 = random.random()
# JAYA Equation
New_Position[j] = (
Positions[i][j]
+ r1 * (Best_pos[j] - abs(Positions[i, j]))
- r2 * (Worst_pos[j] - abs(Positions[i, j]))
)
# checking if New_Position[j] lies in search space
if New_Position[j] > ub[j]:
New_Position[j] = ub[j]
if New_Position[j] < lb[j]:
New_Position[j] = lb[j]
new_fitness = objf(New_Position)
current_fit = fitness_matrix[i]
# replacing current element with new element if it has better fitness
if new_fitness < current_fit:
Positions[i] = New_Position
fitness_matrix[i] = new_fitness
# finding the best and worst element
for i in range(SearchAgents_no):
if fitness_matrix[i] < Best_score:
Best_score = fitness_matrix[i]
Best_pos = Positions[i, :].copy()
if fitness_matrix[i] > Worst_score:
Worst_score = fitness_matrix[i]
Worst_pos = Positions[i, :].copy()
Convergence_curve[l] = Best_score
if l % 1 == 0:
print(
["At iteration " + str(l) + " the best fitness is " + str(Best_score)]
)
timerEnd = time.time()
s.endTime = time.strftime("%Y-%m-%d-%H-%M-%S")
s.executionTime = timerEnd - timerStart
s.convergence = Convergence_curve
s.optimizer = "JAYA"
s.objfname = objf.__name__
return s
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
JAYA.zip (2个子文件)
JAYA.py 3KB
solution.py 434B
共 2 条
- 1
资源评论
sjx_alo
- 粉丝: 1w+
- 资源: 1206
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- LS416 高性能DSP的声控处理芯片语音识别模块AD设计硬件(原理图+PCB)+L2416-M-26P模块封装库+器件手册
- 基于tensorflow实现LSTM, CNN, SVM, MLP语音情感识别源码.zip
- 基于JSP在线学生选课管理系统源码.zip
- 基于JSP在线学生信息管理系统源码.zip
- 常用DHT11 MIC SHT11 VS1838B CHT8305 MQ-3 温湿度气体等传感元件2D3D封装库.PcbLib
- 基于JSP在线新闻管理系统包含前后台源码.zip
- 基于JSP在线文具销售平台商城源码.zip
- tiamo软件教程.doc
- nvm管理Nodejs多版本工具
- Unit1Howcanwebecomegoodlearners知识点整理(良心出品必属精品).doc
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功