[Optimization solution] Function optimization analysis based on matlab ant colony algorithm [including Matlab source code 219]

1. Introduction

1 Overview of the
ant colony algorithm The ant colony algorithm ACO is a new type of simulated evolutionary algorithm. The algorithm uses the ability of the ant colony to search for food sources to solve some difficult problems in the optimization of discrete systems. Should be used to solve the traveling salesman problem (TSP problem), assignment problem, scheduling problem, etc., a series of good experimental results have been obtained.
The behavior of a single ant is extremely simple, but the ant colony composed of such a single individual exhibits extremely complex behavior. The reason is that the individual ants pass through a kind of pheromone called pheromone. The substance transmits information. During the movement of the ant, it can leave the substance on the path it travels and guide its movement direction. Ants tend to move in the direction where the substance is strong. If an obstacle is encountered in the direction of movement of the ant colony, the ants are evenly distributed at first, so regardless of the length of the path, the ants always choose various paths with equal probability. Ants can leave pheromone on the route of their movement. There will be more ants where the concentration of pheromone is high. The concentration of pheromone is higher in the shorter path in the same time, so the number of ants who choose the shorter path will increase accordingly. The more ants that travel on a certain path, the greater the probability that the ants that follow will choose this path, resulting in more and more ants choosing short paths while ants choosing other paths (longer paths) slowly disappear. Individuals in the ant colony search for food through this pheromone exchange and finally choose the optimal path. This is the biological background and basic principle of the ant colony algorithm.
2 Performance analysis of ant colony algorithm
It has the following advantages:
(1) Strong robustness: A slight modification to the basic ant colony algorithm model can be applied to other problems.
(2) Distributed computing: Ant colony algorithm is an evolutionary algorithm based on population, which is inherently parallel and easy to implement in parallel.
(3) Easy to combine with other intelligent algorithms: Ant colony algorithm is easy to combine with a variety of heuristic algorithms (particle swarm algorithm, genetic algorithm, etc.) to improve the performance of the algorithm.
The ant colony algorithm also has some shortcomings:
(1) Long search time: Since the movement of multiple individuals in the ant colony is random, although the communication of information can evolve towards the optimal path, when the colony is large, it is difficult to move from complex to nothing in a short time. Find a better path among chapter paths.
(2) Stagnation behavior is prone to occur: that is, after the search has progressed to a certain level, the solutions found by all individuals are exactly the same, and the solution space cannot be further searched, which is not conducive to finding better solutions, so that they fall into local Optimal.
(3) It is difficult to deal with the optimization problem of continuous space: Since the choices made by each ant at each stage are always limited, it requires a discrete solution space, so it is very suitable for discrete optimization problems such as combinatorial optimization, but for linear programming The solution of continuous space optimization problems cannot be directly applied.

Second, the source code

%% 基于蚁群算法ACO的函数优化分析
% Designed by Yu Shengwei, From SWJTU University, 2014 08 12
clc         % 清屏
clear all;  % 删除workplace变量
close all;  % 关掉显示图形窗口
warning off
tic;        % 计时开始

%% 取值范围
popmax = 5;                 % 待寻优阈值最大取值初始化
popmin = -5;                % 待寻优阈值最小取值初始化

%% 蚁群算法ACO参数初始化
Ant = 100;    % 蚂蚁数量
Times = 100; % 蚂蚁移动次数
Rou = 0.8;   % 信息素挥发系数
P0 = 0.2;    % 转移概率常数

%% 产生初始粒子和速度
for i=1:Ant
    % 随机产生一个种群
    for j = 1: 2
        pop(i,j) = (rand(1,1) * ( popmax-popmin ) + popmin );  % 初始种群个体
    end
    % 计算适应度
    fitness(i) = Fitness_ACO( pop(i,:), 'aco');   % 染色体的适应度
end

% 找最好的染色体
[bestfitness bestindex]=min(fitness); % 最大适应度值
zbest = pop(bestindex,:);             % 全局最佳
gbest = pop;                          % 个体最佳
fitnessgbest = fitness;               % 个体最佳适应度值
fitnesszbest = bestfitness;           % 全局最佳适应度值

%% 迭代寻优
for T = 1:Times   
     disp(['迭代次数:   ',num2str(T)])        % 迭代次数

    lamda = 1/T;                               % 随着迭代次数进行,蚂蚁信息素挥发参数
    [bestfitness, bestindex]=min(fitness);     % 找最好的适应度值
    ysw(T) = bestfitness;                      % 存储最好的适应度值
    for i=1:Ant
        P(T,i)=(fitness(bestindex)-fitness(i))/fitness(bestindex);  % 计算状态转移概率
    end
    % 蚂蚁个体更新
    for i=1:Ant
        if P(T,i)<P0  % 局部搜索
            temp(i,:) = pop(i,:)+(2*rand-1)*lamda;
        else          % 全局搜索
            temp(i,:) = pop(i,:)+(popmax-popmin)*(rand-0.5);
        end
        % 越界处理
        temp(i,find(temp(i,:)>popmax))=popmax;
        temp(i,find(temp(i,:)<popmin))=popmin;
        % 判断蚂蚁是否移动
        if Fitness_ACO( temp(i,:), 'aco') < Fitness_ACO(pop(i,:), 'aco')  % 判断蚂蚁是否移动
            pop(i,:) = temp(i,:);
        end

Three, running results

Insert picture description here

Four, remarks

Complete code or writing to 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]
[Optimization solution] Function optimization analysis based on matlab gravity search algorithm [including Matlab source code 218]

Guess you like

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