[optimization solution] butterfly algorithm based on Cauchy mutation and adaptive weight optimization to solve single objective optimization problems matlab code

Posted by calbolino on Tue, 30 Nov 2021 16:54:56 +0100

1 Introduction

Aiming at the problems of low convergence accuracy and easy to fall into local optimal solution of basic Butterfly Optimization Algorithm (BOA), Cauchy variation and adaptive Weight Butterfly Optimization Algorithm (CWBOA) is proposed. The local search ability of butterfly algorithm is improved by introducing Cauchy distribution function in global position update and adaptive weight factor in local position update; The dynamic switching probability p is introduced to weigh the proportion of global exploration and local development process. The improved algorithm solves multiple single peak, multi peak and fixed test dimension functions. The results show that CWBOA has better accuracy, speed and stability for most test functions.

Inspired by observing the foraging behavior of butterflies, Sankalap Arora and Satvir Singh proposed a new swarm intelligence optimization algorithm Butterfly Optimization Algorithm [6]. The main idea of the algorithm is to simulate the foraging and courtship behavior of butterflies to solve the target problem. The behavior of butterflies can be described as their cooperative movement to the food source. Butterflies receive, perceive and analyze odors in the air to determine the potential direction of food sources or mating partners. BOA algorithm simulates this behavior and finds the optimal solution in the search space. Compared with some existing meta heuristic algorithms, the basic BOA has the advantages of simple operation, less adjusted parameters and good robustness, and has achieved good results in the preliminary application of engineering practice.

The basic butterfly optimization algorithm has some problems, such as relying on the initial population, low convergence accuracy and easy to fall into local optimization. To solve these problems, a multi strategy improved butterfly optimization algorithm is proposed in this paper. The Cauchy distribution function is used to mutate the global position update of the butterfly to improve the global search ability of the algorithm. The adaptive inertia weight factor is introduced at the local position update of the butterfly algorithm to improve the local mining ability of the algorithm. The dynamic switching probability is used to balance the proportion of local search and global search, and improve the optimization performance. The results of 14 benchmark functions show that the improved algorithm has higher convergence accuracy and robustness.

In nature, butterflies can use their senses such as smell, vision, taste, touch and hearing to find food and mate. These senses can help them migrate, avoid hunters and find a suitable place to lay eggs. Among all the senses, the most important is smell. Smell can help butterflies find food (nectar), even far away. In order to find food, butterflies use sensory receptors for smell. These receptors are scattered in butterfly body parts, such as antennae, legs and palms. These receptors are actually nerve cells on the surface of the butterfly's body, called chemoreceptors. These chemoreceptors guide the butterfly to find the best mating partner to continue its strong genetic system. Male butterflies can recognize females through pheromones, which is a specific response caused by the odor secretion of female butterflies. Butterflies will produce some fragrance with intensity related to their adaptability, that is, when butterflies move from one position to another, their adaptability will change accordingly, the fragrance will spread in the distance, and other butterfly individuals can perceive it. This is how butterfly individuals share individual information with other butterflies to form a social knowledge network of a group. When a butterfly can smell the fragrance secreted by other butterflies, it will move towards the direction with the strongest fragrance. This stage is called global search in the algorithm. In another case, when the butterfly cannot perceive the fragrance from its surroundings, it will move randomly. This stage is the local search stage. In view of the above behavior, the following assumptions are put forward: (1) all butterflies should emit some fragrance so that butterflies can attract each other. (2) Each butterfly moves randomly or towards the butterfly that emits the most fragrance. (3) The stimulus intensity of butterflies is affected or determined by the objective function. (4) Global search and local search are controlled by switching probability p. due to physical proximity and various other natural factors such as wind, rain, thunder and electricity, the switching probability p in local search and global search is of great significance.

Part 2 code

<span style="color:#333333"><span style="background-color:#f8f8f8"><span style="color:#Aa5500 ">%% clear environment variables</span>
<span style="color:#3300aa">clear</span> 
<span style="color:#000000">clc</span>

<span style="color:#Aa5500 ">%% parameter setting</span>
<span style="color:#000000">N</span> = <span style="color:#116644">30</span>;             <span style="color:#Aa5500 ">% population size</span>
<span style="color:#000000">Function_name</span> = <span style="color:#aa1111">'F23'</span>;         <span style="color:#Aa5500 ">% names of test functions from F1 to F23 (Tables 1, 2, 3 in this article)</span>
<span style="color:#000000">Max_iteration</span> = <span style="color:#116644">500</span>;           <span style="color:#Aa5500 ">% max iterations</span>
<span style="color:#000000">cnt_max</span> = <span style="color:#116644">30</span>;
<span style="color:#Aa5500 ">% loads the details of the selected benchmark function</span>
[<span style="color:#000000">lb</span>, <span style="color:#000000">ub</span>, <span style="color:#000000">dim</span>, <span style="color:#000000">fobj</span>] = <span style="color:#000000">Get_Functions_details</span>(<span style="color:#000000">Function_name</span>);

<span style="color:#000000">Curve_BOA</span> = <span style="color:#3300aa">zeros</span>(<span style="color:#116644">1</span>, <span style="color:#000000">Max_iteration</span>);
<span style="color:#000000">Curve_WOA</span> = <span style="color:#3300aa">zeros</span>(<span style="color:#116644">1</span>, <span style="color:#000000">Max_iteration</span>);
<span style="color:#000000">Curve_FPA</span> = <span style="color:#3300aa">zeros</span>(<span style="color:#116644">1</span>, <span style="color:#000000">Max_iteration</span>);
<span style="color:#000000">Curve_CWBOA</span> = <span style="color:#3300aa">zeros</span>(<span style="color:#116644">1</span>, <span style="color:#000000">Max_iteration</span>);

<span style="color:#770088">for</span> <span style="color:#000000">cnt</span> = <span style="color:#116644">1</span>:<span style="color:#000000">cnt_max</span>
   <span style="color:#Aa5500 ">% initialize population location</span>
   <span style="color:#000000">X</span> = <span style="color:#000000">initialization</span>(<span style="color:#000000">N</span>, <span style="color:#000000">dim</span>, <span style="color:#000000">ub</span>, <span style="color:#000000">lb</span>);
   
  [<span style="color:#000000">BOA_Best_score</span>(<span style="color:#000000">cnt</span>), <span style="color:#000000">BOA_Best_pos</span>(<span style="color:#000000">cnt</span>, :), <span style="color:#000000">BOA_Curve</span>] = <span style="color:#000000">BOA</span>(<span style="color:#000000">X</span>, <span style="color:#000000">N</span>, <span style="color:#000000">Max_iteration</span>, <span style="color:#000000">lb</span>, <span style="color:#000000">ub</span>, <span style="color:#000000">dim</span>, <span style="color:#000000">fobj</span>);
  [<span style="color:#000000">WOA_Best_score</span>(<span style="color:#000000">cnt</span>), <span style="color:#000000">WOA_Best_pos</span>(<span style="color:#000000">cnt</span>, :), <span style="color:#000000">WOA_Curve</span>] = <span style="color:#000000">WOA</span>(<span style="color:#000000">X</span>, <span style="color:#000000">N</span>, <span style="color:#000000">Max_iteration</span>, <span style="color:#000000">lb</span>, <span style="color:#000000">ub</span>, <span style="color:#000000">dim</span>, <span style="color:#000000">fobj</span>);
  [<span style="color:#000000">FPA_Best_score</span>(<span style="color:#000000">cnt</span>), <span style="color:#000000">FPA_Best_pos</span>(<span style="color:#000000">cnt</span>, :), <span style="color:#000000">FPA_Curve</span>] = <span style="color:#000000">FPA</span>(<span style="color:#000000">X</span>, <span style="color:#000000">N</span>, <span style="color:#000000">Max_iteration</span>, <span style="color:#000000">lb</span>, <span style="color:#000000">ub</span>, <span style="color:#000000">dim</span>, <span style="color:#000000">fobj</span>);
  [<span style="color:#000000">CWBOA_Best_score</span>(<span style="color:#000000">cnt</span>), <span style="color:#000000">CWBOA_Best_pos</span>(<span style="color:#000000">cnt</span>, :), <span style="color:#000000">CWBOA_Curve</span>] = <span style="color:#000000">CWBOA</span>(<span style="color:#000000">X</span>, <span style="color:#000000">N</span>, <span style="color:#000000">Max_iteration</span>, <span style="color:#000000">lb</span>, <span style="color:#000000">ub</span>, <span style="color:#000000">dim</span>, <span style="color:#000000">fobj</span>);
   
    
   <span style="color:#000000">Curve_BOA</span> = <span style="color:#000000">Curve_BOA</span><span style="color:#981a1a">+</span><span style="color:#000000">BOA_Curve</span>;
   <span style="color:#000000">Curve_WOA</span> = <span style="color:#000000">Curve_WOA</span><span style="color:#981a1a">+</span><span style="color:#000000">WOA_Curve</span>;
   <span style="color:#000000">Curve_FPA</span> = <span style="color:#000000">Curve_FPA</span><span style="color:#981a1a">+</span><span style="color:#000000">FPA_Curve</span>;
   <span style="color:#000000">Curve_CWBOA</span> = <span style="color:#000000">Curve_CWBOA</span><span style="color:#981a1a">+</span><span style="color:#000000">CWBOA_Curve</span>;

<span style="color:#770088">end</span>

<span style="color:#000000">Curve_BOA</span> = <span style="color:#000000">Curve_BOA</span><span style="color:#981a1a">/</span><span style="color:#000000">cnt_max</span>;
<span style="color:#000000">Curve_WOA</span> = <span style="color:#000000">Curve_WOA</span><span style="color:#981a1a">/</span><span style="color:#000000">cnt_max</span>;
<span style="color:#000000">Curve_FPA</span> = <span style="color:#000000">Curve_FPA</span><span style="color:#981a1a">/</span><span style="color:#000000">cnt_max</span>;
<span style="color:#000000">Curve_CWBOA</span> = <span style="color:#000000">Curve_CWBOA</span><span style="color:#981a1a">/</span><span style="color:#000000">cnt_max</span>;


<span style="color:#000000">std_BOA</span> = <span style="color:#3300aa">std</span>(<span style="color:#000000">BOA_Best_score</span>);
<span style="color:#000000">std_WOA</span> = <span style="color:#3300aa">std</span>(<span style="color:#000000">WOA_Best_score</span>);
<span style="color:#000000">std_FPA</span> = <span style="color:#3300aa">std</span>(<span style="color:#000000">FPA_Best_score</span>);
<span style="color:#000000">std_CWBOA</span> = <span style="color:#3300aa">std</span>(<span style="color:#000000">CWBOA_Best_score</span>);

<span style="color:#000000">best_BOA</span> = <span style="color:#3300aa">max</span>(<span style="color:#000000">BOA_Best_score</span>);
<span style="color:#000000">best_WOA</span> = <span style="color:#3300aa">max</span>(<span style="color:#000000">WOA_Best_score</span>);
<span style="color:#000000">best_FPA</span> = <span style="color:#3300aa">max</span>(<span style="color:#000000">FPA_Best_score</span>);
<span style="color:#000000">best_CWBOA</span> = <span style="color:#3300aa">max</span>(<span style="color:#000000">CWBOA_Best_score</span>);

<span style="color:#000000">worst_BOA</span> = <span style="color:#3300aa">min</span>(<span style="color:#000000">BOA_Best_score</span>);
<span style="color:#000000">worst_WOA</span> = <span style="color:#3300aa">min</span>(<span style="color:#000000">WOA_Best_score</span>);
<span style="color:#000000">worst_FPA</span> = <span style="color:#3300aa">min</span>(<span style="color:#000000">FPA_Best_score</span>);
<span style="color:#000000">worst_CWBOA</span> = <span style="color:#3300aa">min</span>(<span style="color:#000000">CWBOA_Best_score</span>);

<span style="color:#000000">mean_BOA</span> = <span style="color:#3300aa">mean</span>(<span style="color:#000000">BOA_Best_score</span>);
<span style="color:#000000">mean_WOA</span> = <span style="color:#3300aa">mean</span>(<span style="color:#000000">WOA_Best_score</span>);
<span style="color:#000000">mean_FPA</span> = <span style="color:#3300aa">mean</span>(<span style="color:#000000">FPA_Best_score</span>);
<span style="color:#000000">mean_CWBOA</span> = <span style="color:#3300aa">mean</span>(<span style="color:#000000">CWBOA_Best_score</span>);

<span style="color:#Aa5500 ">%% drawing</span>
<span style="color:#Aa5500 ">% 1. Draw the three-dimensional graph of the selected reference function</span>
<span style="color:#aa5500">% figure;</span>
<span style="color:#aa5500">% func_plot(Function_name);</span>
<span style="color:#aa5500">% title(Function_name)</span>
<span style="color:#aa5500">% xlabel('x_1');</span>
<span style="color:#aa5500">% ylabel('x_2');</span>
<span style="color:#aa5500">% zlabel([Function_name,'( x_1 , x_2 )'])</span>

<span style="color:#Aa5500 ">% 2. Draw the change curve of objective function value</span>
<span style="color:#000000">figure</span>;
<span style="color:#000000">t</span> = <span style="color:#116644">1</span>:<span style="color:#000000">Max_iteration</span>;
<span style="color:#000000">semilogy</span>(<span style="color:#000000">t</span>, <span style="color:#000000">Curve_BOA</span>, <span style="color:#aa1111">'k^-'</span>, <span style="color:#000000">t</span>, <span style="color:#000000">Curve_WOA</span>, <span style="color:#aa1111">'bo-'</span>, <span style="color:#000000">t</span>, <span style="color:#000000">Curve_FPA</span>, <span style="color:#aa1111">'mv-'</span>, <span style="color:#000000">t</span>, <span style="color:#000000">Curve_CWBOA</span>, <span style="color:#aa1111">'rd-'</span>, <span style="color:red">...</span>
   <span style="color:#aa1111">'linewidth'</span>, <span style="color:#116644">1.5</span>, <span style="color:#aa1111">'MarkerSize'</span>, <span style="color:#116644">8</span>, <span style="color:#aa1111">'MarkerIndices'</span>, <span style="color:#116644">1</span>:<span style="color:#116644">50</span>:<span style="color:#000000">Max_iteration</span>);
<span style="color:#3300aa">title</span>(<span style="color:#000000">Function_name</span>)
<span style="color:#3300aa">xlabel</span>(<span style="color:#aa1111">'Iteration'</span>);
<span style="color:#3300aa">ylabel</span>(<span style="color:#aa1111">'Fitness'</span>);
<span style="color:#000000">axis</span> <span style="color:#000000">fill</span>
<span style="color:#3300aa">grid</span> <span style="color:#000000">on</span>
<span style="color:#000000">box</span> <span style="color:#000000">on</span>
<span style="color:#3300aa">legend</span>(<span style="color:#aa1111">'BOA'</span>, <span style="color:#aa1111">'WOA'</span>, <span style="color:#aa1111">'FPA'</span>, <span style="color:#aa1111">'CWBOA'</span>);

<span style="color:#Aa5500 ">%% display results</span>
<span style="color:#770088">disp</span>([<span style="color:#aa1111">'Function:'</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">Function_name</span>)]);
<span style="color:#770088">disp</span>([<span style="color:#aa1111">'BOA: Maximum: '</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">best_BOA</span>), <span style="color:#aa1111">',minimum value:'</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">worst_BOA</span>), <span style="color:#aa1111">',average value:'</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">mean_BOA</span>), <span style="color:#aa1111">',standard deviation:'</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">std_BOA</span>)]);
<span style="color:#770088">disp</span>([<span style="color:#aa1111">'WOA: Maximum: '</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">best_WOA</span>), <span style="color:#aa1111">',minimum value:'</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">worst_WOA</span>), <span style="color:#aa1111">',average value:'</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">mean_WOA</span>), <span style="color:#aa1111">',standard deviation:'</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">std_WOA</span>)]);
<span style="color:#770088">disp</span>([<span style="color:#aa1111">'FPA: Maximum: '</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">best_FPA</span>), <span style="color:#aa1111">',minimum value:'</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">worst_FPA</span>), <span style="color:#aa1111">',average value:'</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">mean_FPA</span>), <span style="color:#aa1111">',standard deviation:'</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">std_FPA</span>)]);
<span style="color:#770088">disp</span>([<span style="color:#aa1111">'CWBOA: Maximum: '</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">best_CWBOA</span>), <span style="color:#aa1111">',minimum value:'</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">worst_CWBOA</span>), <span style="color:#aa1111">',average value:'</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">mean_CWBOA</span>), <span style="color:#aa1111">',standard deviation:'</span>, <span style="color:#3300aa">num2str</span>(<span style="color:#000000">std_CWBOA</span>)]);
</span></span>

3 simulation results

4 references

[1] Gao Wenxin et al. "Butterfly algorithm for Cauchy mutation and adaptive weight optimization." Computer Engineering and application 56.15 (2020): 8

Topics: MATLAB Algorithm