# [hole sequence planning] dynamic hole sequence planning of three arm rock drilling robot based on MATLAB ant colony algorithm [including Matlab source code 1603]

2022-01-27 03:56:18

## One 、 Introduction to ant colony algorithm

1 Summary
Simulate ant foraging behavior （ Shortest path principle ） Designed algorithm . Talk about the characteristics of ant colony foraging, abstract it and transform it into mathematical description .

• Ant colony algorithm (Ant Colony Algorithm, ACA) from Marco Dorigo On 1992 It was first proposed in his doctoral thesis in .
• When ants are looking for food , Will release a pheromone on its path , And can sense pheromones released by other ants . The size of pheromone concentration indicates the distance of the path , The higher the pheromone concentration , Indicates that the shorter the corresponding path distance .
• Usually , Ants will choose the path with high pheromone concentration with high probability , And release A certain amount of pheromone , To enhance the pheromone concentration on this path , such , Will form a positive feedback . Final , Ants can find the best path from the nest to the food source , That is, the shortest distance .
• Biologists also found that , The pheromone concentration on the path will gradually decay with time .
• The ant colony algorithm is applied to solve the optimization problem , The basic idea is ： The feasible solution of the problem to be optimized is expressed by the walking path of ants , All paths of the whole ant colony constitute the solution space of the problem to be optimized . Ants with shorter paths release more pheromones , Over time , Shorter The pheromone concentration accumulated on the path gradually increased , More and more ants choose this path . Final , The whole ant will focus on the best path under the action of positive feedback , At this time, the corresponding is the optimal solution of the problem to be optimized .
analogy GA（ Genetic algorithm (ga) ） The intersection of 、 choice 、 variation ,PSO（ Particle swarm optimization ） The individual of 、 Group extremum optimization , Ant colony algorithm also has its own optimization strategy ： Positive feedback information mechanism 、 Pheromone concentration update 、 Ants filter the paths that can be accessed .

2 The basic idea
The basic principle of ant colony algorithm comes from the shortest path principle of ant foraging in nature . According to entomologists , It is found that although the vision of ants in nature is not developed , But it can find the shortest path from the food source to the nest without any hint , And can change in the environment ( If there are obstacles on the original path ) after , Adaptively search for the new best path . How do ants do this ?
original , When ants are looking for food , It can put a secretion unique to ants on the path it walks - Information plain , It can also be called pheromone , So that other ants in a certain range can detect and affect their later behavior . When more and more ants pass through some paths , It leaves more and more pheromones , So that the pheromone intensity increases ( Of course , It will gradually weaken over time , Therefore, the higher the probability of ants choosing this path , Thus, the pheromone strength of the path is increased , This selection process is called the autocatalytic behavior of ants . Because its principle is a positive feedback mechanism , therefore , The ant kingdom can also be understood as the so-called reinforcement learning system . Here we use a graph to illustrate the shortest path selection principle of ant foraging , As shown in the figure . In the middle , hypothesis A The point is the nest of ants ,B The order is food ,A、B There is an obstacle between two points , So now from A Point to B spot The ant must decide whether to go left or right , And from B Point to A The ant at the point must also decide which path to take . This decision will be affected by the pheromone concentration left by previous ants on each path ( Residual pheromone concentration ) Influence . If you go The pheromone concentration on the right path is relatively large , Then the path on the right is more likely to be selected by ants . But for the first ants to explore the way , Because there is no pheromone influence or the influence is relatively small , So they are equally likely to choose left or right , As shown in the figure . As the foraging process goes on , Information on all roads The strength of the element began to change , Some lines are strong , yes , we have Weak line . Now from A Point to B Point ants as an example to illustrate ( from B Point to A A little ant , The process is basically the same ) Subsequent process changes . Because the path ADB Comparison path ACB To be short , So choose ADB The first ant in the path is better than the choice ACB The first ant arrived early B spot . here , from B Point to the A Point to see , route BDA A The pheromone concentration on the path is higher than that on the path BCA The pheromone concentration on the . So from the next moment , from B Point to A A little ant , They choose BDA The path is more likely than the choice BCA The path is more likely , So that ABDA The pheromone on the route is further enhanced , So according to D Depending on the pheromone intensity, the ants who choose the path gradually tend to choose the path ADB, As shown in the figure . as time goes on , Almost all ants choose the path ADB( or BDA) Carrying food , And we will also find :ADB The path is actually the shortest path . The principle of ant colony routing can be simply understood as : For a single ant , It has no subjective intention to find the shortest path ; But for the whole ant colony system , They do achieve the effect of finding the shortest path . In nature , The process of finding the path of ant colony is a positive feedback process ,“ Ant colony algorithm ” It's simulation In biology, the principle of ants foraging for the shortest path is derived . for example , We put the work with only simple functions As a unit, it is regarded as “ Ant ”, Then the above process of finding the path can be used to explain the optimization process of artificial ant colony in ant colony algorithm . This is the basic idea of ant colony algorithm .

3 The flow of algorithm design
Here we use TSP The question is , The flow of algorithm design is as follows ：
step 1： Initialize relevant parameters , Including ant colony size 、 Pheromone factor 、 Heuristics factor 、 Pheromone volatilization factor 、 Pheromone constants 、 Maximum number of iterations, etc , And reading data into the program , And pretreatment ： For example, the coordinate information of cities is transformed into the distance matrix between cities .
step 2： Randomly place ants at different starting points , Calculate the next visited city for each ant , Until ants visit all the cities .
step 3： Calculate the path length of each ant Lk, Record the current number of iterations and the optimal solution , At the same time, the pheromone concentration on the path is updated .
step 4： Determine whether the maximum number of iterations is reached , If no , Return steps 2; yes , End procedure .
step 5： Output results , And output the relevant indicators in the optimization process as needed , Such as running time 、 Number of convergence iterations, etc .

4 mathematical model

## Two 、 Partial source code

``````%%  The software is used for off-line hole sequence planning of rock drilling robot
%
function varargout = GuiTest(varargin)
% GUITEST MATLAB code for GuiTest.fig
%      GUITEST, by itself, creates a new GUITEST or raises the existing
%      singleton*.
%
%      H = GUITEST returns the handle to a new GUITEST or the handle to
%      the existing singleton*.
%
%      GUITEST('CALLBACK',hObject,eventDatda,handles,...) calls the local
%      function named CALLBACK in GUITEST.M with the given input arguments.
%
%      GUITEST('Property','Value',...) creates a new GUITEST or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before GuiTest_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to GuiTest_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%

% Edit the above text to modify the response to help GuiTest

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
'gui_Singleton',  gui_Singleton, ...
'gui_OpeningFcn', @GuiTest_OpeningFcn, ...
'gui_OutputFcn',  @GuiTest_OutputFcn, ...
'gui_LayoutFcn',  [] , ...
'gui_Callback',   []);
if nargin && ischar(varargin{
1})
gui_State.gui_Callback = str2func(varargin{
1});
end

if nargout
[varargout{
1:nargout}] = gui_mainfcn(gui_State, varargin{
:});
else
gui_mainfcn(gui_State, varargin{
:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before GuiTest is made visible.
function GuiTest_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to GuiTest (see VARARGIN)
% Choose default command line output for GuiTest
global undo reundo sequenceflag;
undo=struct('undo1',[],'undo2',[],'undo3',[],'undo4',[],'undo5',[],'undo6',[],'undo7',[],'undoNum',0);
reundo=struct('reundo1',[],'reundo2',[],'reundo3',[],'reundo4',[],'reundo5',[],'reundo6',[],'reundo7',[],'reundoNum',0);
handles.type=0;
sequenceflag = false;
%  Initialize the location of the window
handles.output = hObject;
h = get(gcf,'Position');
h = [5 5 h(3:4)];
set(gcf,'Position',h);

% --------- Set the parent control of the panel
set(handles.panel_changeSize,'Parent',gcf);
set(handles.panel_assignHole,'Parent',gcf);
set(handles.panel_deleteHole,'Parent',gcf);
set(handles.panel_drawTunnel,'Parent',gcf);
set(handles.panel_drillSequence,'Parent',gcf);
% --------- Set add hole as display panel , Others are hidden
set(handles.panel_changeSize,'visible','off');
set(handles.panel_assignHole,'visible','off');
set(handles.panel_deleteHole,'visible','off');
set(handles.panel_drawTunnel,'visible','off');
set(handles.panel_drillSequence,'visible','off');
% ------------ Communication between parent window and child window -----( Test as sub window )
%  Get the handle of the parent window object , And save it in the... Of the current window handles In the structure
%handles.obj=varargin{
1};
%  Get the handle list of all controls in the parent window
%hdl=varargin{
2};
%  Store the handles of all controls of the parent window in the current window structure handles Medium handle In the structure
%handles.handle=hdl;
% Update handles structure
%%  Initialize the function of the hole Task button under the simulation menu Enable
set(handles.simulateSequence,'Enable','off');

% ============================================================
% ---------- As parent window
H=selectTunnelType(hObject,handles);
handles.tunnelType=H;
% set(hObject,'toolbar','figure')
%  Initialize that each arm hole is empty
handles.leftHoles=[];
handles.midHoles=[];
handles.rightHoles=[];
set(hObject,'toolbar','none') ;
guidata(hObject, handles);

% UIWAIT makes GuiTest wait for user response (see UIRESUME)
% uiwait(handles.mainfigure);

% --- Outputs from this function are returned to the command line.
function varargout = GuiTest_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%%
%  Clear the screen first
% h=get(handles.axes1,'children');
% delete(h);
global type;
global tunnel;
global holes;
holes=[];
%  If the user does not select the tunnel type when entering the software , Initialize one
if isempty(type)
type=2;
end
switch type
case 1
tunnel.type=1;
tunnel.size.R=3.31;
tunnel.size.t=5;
tunnel.size.a=2.16;
tunnel.size.l=0;
tunnel.size.r=0;
initTunnelAxes( tunnel,handles );
case 2
tunnel.type=2;
tunnel.size.R=8;
tunnel.size.a=4;
tunnel.size.l=0;
tunnel.size.r=0;
tunnel.size.t=0;
initTunnelAxes( tunnel,handles );
case 3
tunnel.type=3;
tunnel.size.R=8;
tunnel.size.a=4;
tunnel.size.l=0;
tunnel.size.r=0;
tunnel.size.t=0;
initTunnelAxes( tunnel,handles );
end
``````

## Four 、matlab Edition and references

1 matlab edition
2014a

2 reference
[1] Baoziyang , Yu Jizhou , Poplar . Intelligent optimization algorithm and its application MATLAB example （ The first 2 edition ）[M]. Electronic industry press ,2016.
[2] Zhang Yan , Wu Shuigen .MATLAB Optimization algorithm source code [M]. tsinghua university press ,2017.