[Optimization solution] Function optimization analysis based on matlab gravitational search algorithm [Contains Matlab source code 218]

1. Introduction

Gravitational Search Algorithm (Gravitational Search Algorithm, GSA) is a new heuristic optimization algorithm proposed by Esmat Rashedi et al. of Kerman University in Iran in 2009. It is derived from the population generated by simulating the gravitation in physics. Intelligent optimization algorithm. The principle of the gravitational search algorithm GSA is to treat the search particles as a group of objects moving in space. The objects are attracted by the gravitational interaction, and the movement of the objects follows the law of dynamics. A particle with a moderately large value has a larger inertial mass, so the universal gravitation will cause the objects to move toward the most massive object, thereby gradually approaching the optimal solution of the optimization problem. The universal gravitation search algorithm GSA has a strong global search capability and convergence speed. With the progress of GSA theoretical research, its application has become more and more extensive, gradually attracting the attention of domestic and foreign scholars. However, the universal gravitation search algorithm GSA, like other global algorithms, has problems such as being easy to fall into local solutions and the solution accuracy is not quotient. There are many things to be improved. This chapter will focus on introducing the most basic gravitational algorithm to the majority of programming enthusiasts. Each programming researcher can improve on the algorithm in this chapter and apply it to actual cases.
Insert picture description here
1 Inertial mass calculation
Insert picture description here
2 Gravitation calculation
Insert picture description here
3 Position update
Insert picture description here
4 Parameter analysis
Insert picture description here
5 Universal gravitation algorithm implementation process
Insert picture description here

Second, the source code

% 万有引力搜索算法
clc,clear,close all
warning off
feature jit off
 N=50;           % 粒子数量(智能个体)
 max_it=1000;    % 最大迭代次数
 ElitistCheck=1; % ElitistCheck: 算法执行次数选择
 Rpower=1;       % Rpower: 'R'的次方
 min_flag=1;     % 1: 求函数最小值,0:求函数最大值
 F_index=1;      % 带求解函数选择
 [Fbest,Lbest,BestChart,MeanChart]=GSA(F_index,N,max_it,ElitistCheck,min_flag,Rpower);
 %  输出:
% Fbest: 最优适应度值.
% Lbest: 最优解向量
% BestChart: 适应度变化值.
% MeanChart: 平均适应度变化值
 Fbest,  % 最优适应度值
 Lbest,  % 最优解
%% 绘制适应度曲线
figure('color',[1,1,1])
plot(BestChart,'linewidth',2),
xlabel('\fontsize{12}\bf Iteration');ylabel('\fontsize{12}\bf 最优适应度值');
legend('\fontsize{10}\bf GSA',1);
grid on
% 万有引力搜索算法
function [Fbest,Lbest,BestChart,MeanChart]=GSA(F_index,N,max_it,ElitistCheck,min_flag,Rpower)
%V:   速度
%a:   加速度
%M:   质量.  Ma=Mp=Mi=M;
%dim: 待求解未知量维数
%N:   智能粒子个数
%X:   种群个体位置. dim-by-N matrix.
%R:   种群之间的距离
%[low-up]: 取值范围
%Rnorm:  范数
%Rpower: Power of R 
Rnorm=2;  % 2阶范数,即欧氏距离
% 获取待求解目标方程的未知数个体以及取值范围
[low,up,dim]=test_functions_range(F_index); 
% 随机的初始化个体
X=initialization(dim,N,up,low); 
% 适应度值数组初始化
BestChart=[];
MeanChart=[];
V=zeros(N,dim); % 速度初始化
for iteration=1:max_it  % 迭代开始
%     iteration
    
    % 检查x个体是否在取值范围内
    X=space_bound(X,up,low); 
    % 计算适应度值
    fitness=evaluateF(X,F_index); 
    
    if min_flag==1
        [best best_X]=min(fitness); %minimization.
    else
        [best best_X]=max(fitness); %maximization.
    end        
    
    if iteration==1
       Fbest=best;Lbest=X(best_X,:);
    end
    if min_flag==1
      if best<Fbest  % 极小值求解
       Fbest=best;Lbest=X(best_X,:);
      end
    else 
      if best>Fbest  % 极大值求解
       Fbest=best;Lbest=X(best_X,:);
      end

Three, running results

Insert picture description here
Insert picture description here

Four, remarks

Complete code or writing add QQ1564658423 past review
>>>>>>
[Optimization] based on matlab particle swarm optimization gray wolf algorithm [including Matlab source code 006]
[Optimization] based on matlab multi-objective gray wolf optimization algorithm MOGWO [including Matlab source code issue 007]
[optimized solution] optimal layout of charging stations based on matlab particle swarm algorithm [including Matlab source code 012]
[optimized solution] multi-traveling salesman problem based on matlab genetic algorithm [including Matlab source code 016]
[optimized solution 】Find the shortest path based on matlab genetic algorithm [including Matlab source code 023]
[Optimization solution] 3D packing problem based on matlab genetic and simulated annealing [including Matlab source code 031]
[Optimization solution] Solve the optimization of vehicle departure interval based on matlab genetic algorithm Problem [Including Matlab source code 132]
[Optimizing solution] Krill swarm algorithm [Including matlab source code 133]
[Optimizing solution] Differential evolution algorithm [Including Matlab source code 134]
[Optimizing solution] Penalty function method based on matlab constraint optimization [ Include Matlab source code 163 period]
[Optimization solution] Based on matlab improved gray wolf algorithm to solve the heavy oil pyrolysis model [Include Matlab source code 164 period]
[Optimized solution] Based on matlab ant colony algorithm distribution network fault location [Include Matlab source code 165 period]
[ Optimization solution based on matalb genetic algorithm to solve the island material replenishment optimization problem [including Matlab source code 172]
[Optimization solution] Coronavirus population immune optimization algorithm (CHIO) [including Matlab source code 186]
[Optimization solution] Golden Eagle optimization algorithm (GEO) )【Include Matlab source code 187 period】
[Multi-objective optimization solution] Multi-objective optimization solution based on matlab golden eagle algorithm (MOGEO) [including Matlab source code 188]
[Optimization solution] BP neural network optimization solution based on matlab GUI interface [Matlab source code 208]
[Optimization solution] Genetic algorithm optimization solution based on matlab GUI interface [including Matlab source code 209]
[Optimization solution] Numerical approximation optimization analysis based on matlab immune algorithm [including Matlab source code 211]
[Optimization solution] Function optimization analysis based on matlab heuristic algorithm [ Include Matlab source code 212]
[Optimization solution] Urban traffic signal optimization based on matalb improved genetic algorithm (GA+IGA) [Include Matlab source code 213 period]
[Optimization solution] Urban traffic signal optimization based on matalb improved genetic algorithm GA [ Including Matlab source code 214 period]

[Optimization solution] Urban traffic signal optimization based on matalb improved genetic algorithm IGA [including Matlab source code 215]
[Optimization solution] Function optimization of particle swarm algorithm based on matlab penalty function [including Matlab source code 216]
[Optimization solution] Function optimization analysis based on matlab bacterial foraging algorithm [including Matlab source code 217]

Guess you like

Origin blog.csdn.net/TIQCmatlab/article/details/113642950