• (SCA)正弦余弦算法SCA: A Sine Cosine Algorithm(代码可复制粘贴)


    【优化算法】正弦余弦算法(SCA):SCA: A Sine Cosine Algorithm

    论文题目:SCA is a novel algorithm for solving single-objective optimization problems

    这个算法是澳大利亚学者Mirjalili提出的。这个人在这类优化算法中真的是很厉害,像鲸鱼优化算法,多元宇宙算法,包括这个正弦余弦算法,都是他提出的。给我的感觉就是,这类算法大部分在寻优的时候,分为两部分,也就是局部挖掘和全局搜索。这两个部分相互促进又相互矛盾,全局搜索用于快速定位最优解的范围,而局部挖掘用于寻找最优解,这两者必须达到一种动态平衡的状态。全局搜索过多的时候,运行会特别慢,尤其是用MATLAB这种不擅长循环的软件;局部挖掘过多的时候,就容易陷入局部最优解,当然实际工程里,全局最优解可能真的不容易找到,尤其在一些非凸问题里,局部最优解也凑合。
     

    引用格式:

    Seyedali Mirjalili (2022). SCA: A Sine Cosine Algorithm (https://www.mathworks.com/matlabcentral/fileexchange/54948-sca-a-sine-cosine-algorithm), MATLAB Central File Exchange. 检索来源 2022/7/28.

     

    少废话,直接上算法源码

    1. % Sine Cosine Algorithm (SCA)
    2. %
    3. % Source codes demo version 1.0
    4. %
    5. % Developed in MATLAB R2011b(7.13)
    6. %
    7. % Author and programmer: Seyedali Mirjalili
    8. %
    9. % e-Mail: ali.mirjalili@gmail.com
    10. % seyedali.mirjalili@griffithuni.edu.au
    11. %
    12. % Homepage: http://www.alimirjalili.com
    13. %
    14. % Main paper:
    15. % S. Mirjalili, SCA: A Sine Cosine Algorithm for solving optimization problems
    16. % Knowledge-Based Systems, DOI: http://dx.doi.org/10.1016/j.knosys.2015.12.022
    17. %_______________________________________________________________________________________________
    18. % You can simply define your cost function in a seperate file and load its handle to fobj
    19. % The initial parameters that you need are:
    20. %__________________________________________
    21. % fobj = @YourCostFunction
    22. % dim = number of your variables
    23. % Max_iteration = maximum number of iterations
    24. % SearchAgents_no = number of search agents
    25. % lb=[lb1,lb2,...,lbn] where lbn is the lower bound of variable n
    26. % ub=[ub1,ub2,...,ubn] where ubn is the upper bound of variable n
    27. % If all the variables have equal lower bound you can just
    28. % define lb and ub as two single numbers
    29. % To run SCA: [Best_score,Best_pos,cg_curve]=SCA(SearchAgents_no,Max_iteration,lb,ub,dim,fobj)
    30. %______________________________________________________________________________________________
    31. function [Destination_fitness,Destination_position,Convergence_curve]=SCA(N,Max_iteration,lb,ub,dim,fobj)
    32. display('SCA is optimizing your problem');
    33. %Initialize the set of random solutions
    34. X=initialization(N,dim,ub,lb);
    35. Destination_position=zeros(1,dim);
    36. Destination_fitness=inf;
    37. Convergence_curve=zeros(1,Max_iteration);
    38. Objective_values = zeros(1,size(X,1));
    39. % Calculate the fitness of the first set and find the best one
    40. for i=1:size(X,1)
    41. Objective_values(1,i)=fobj(X(i,:));
    42. if i==1
    43. Destination_position=X(i,:);
    44. Destination_fitness=Objective_values(1,i);
    45. elseif Objective_values(1,i)
    46. Destination_position=X(i,:);
    47. Destination_fitness=Objective_values(1,i);
    48. end
    49. All_objective_values(1,i)=Objective_values(1,i);
    50. end
    51. %Main loop
    52. t=2; % start from the second iteration since the first iteration was dedicated to calculating the fitness
    53. while t<=Max_iteration
    54. % Eq. (3.4)
    55. a = 2;
    56. Max_iteration = Max_iteration;
    57. r1=a-t*((a)/Max_iteration); % r1 decreases linearly from a to 0
    58. % Update the position of solutions with respect to destination
    59. for i=1:size(X,1) % in i-th solution
    60. for j=1:size(X,2) % in j-th dimension
    61. % Update r2, r3, and r4 for Eq. (3.3)
    62. r2=(2*pi)*rand();
    63. r3=2*rand;
    64. r4=rand();
    65. % Eq. (3.3)
    66. if r4<0.5
    67. % Eq. (3.1)
    68. X(i,j)= X(i,j)+(r1*sin(r2)*abs(r3*Destination_position(j)-X(i,j)));
    69. else
    70. % Eq. (3.2)
    71. X(i,j)= X(i,j)+(r1*cos(r2)*abs(r3*Destination_position(j)-X(i,j)));
    72. end
    73. end
    74. end
    75. for i=1:size(X,1)
    76. % Check if solutions go outside the search spaceand bring them back
    77. Flag4ub=X(i,:)>ub;
    78. Flag4lb=X(i,:)
    79. X(i,:)=(X(i,:).*(~(Flag4ub+Flag4lb)))+ub.*Flag4ub+lb.*Flag4lb;
    80. % Calculate the objective values
    81. Objective_values(1,i)=fobj(X(i,:));
    82. % Update the destination if there is a better solution
    83. if Objective_values(1,i)
    84. Destination_position=X(i,:);
    85. Destination_fitness=Objective_values(1,i);
    86. end
    87. end
    88. Convergence_curve(t)=Destination_fitness;
    89. % Display the iteration and best optimum obtained so far
    90. if mod(t,50)==0
    91. display(['At iteration ', num2str(t), ' the optimum is ', num2str(Destination_fitness)]);
    92. end
    93. % Increase the iteration counter
    94. t=t+1;
    95. end

    The SCA creates multiple initial random candidate solutions and requires them to fluctuate outwards or towards the best solution using a mathematical model based on sine and cosine functions. Several random and adaptive variables also are integrated to this algorithm to emphasize exploration and exploitation of the search space in different milestones of optimization.
    This is the source codes of the paper:

    S. Mirjalili, SCA: A Sine Cosine Algorithm for solving optimization problems, Knowledge-Based Systems, in press, 2015, DOI: Redirecting

    Link: http://www.sciencedirect.com/science/article/pii/S0950705115005043

    A Matlab toolbox for this algorithm can be found here: Sine Cosine Algorithm Toolbox - File Exchange - MATLAB Central

    If you have no access to the paper, please drop me an email at ali.mirjalili@gmail.com and I will send you the paper.

    All of the source codes and extra information as well as more optimization techniques can be found in my personal website at http://www.alimirjalili.com

    I have a number of relevant courses in this area. You can enrol via the following links with 95% discount:

    *******************************************************************************************************************************************
    A course on “Optimization Problems and Algorithms: how to understand, formulation, and solve optimization problems”:
    https://www.udemy.com/optimisation/?couponCode=MATHWORKSREF

    A course on “Introduction to Genetic Algorithms: Theory and Applications”
    https://www.udemy.com/geneticalgorithm/?couponCode=MATHWORKSREF
    *******************************************************************************************************************************************

  • 相关阅读:
    C++常用stl
    【数据分享】2022年全国各城市公交线路与站点数据
    双十一报告:服饰企业借助团队管理工具飞项高效协作
    [操作系统笔记]内存管理1
    前端培训丁鹿学堂:vue2和vue3的响应式原理对比
    SQL CASE WHEN语句的使用技巧
    VMware安装Debian,Debian分区,虚拟机使用NAT模式联网,Linux设置静态IP
    [多线程] | 实例演示三种创建多线程的方式,初识线程同步以及解决线程安全问题(超卖)
    EAV模型(实体-属性-值)的设计和低代码的处理方案(2)--数据的查询处理
    eclipse启动一个Springboot项目
  • 原文地址:https://blog.csdn.net/Vertira/article/details/126031198