[Fault analysis] fault diagnosis based on matlab GUI ant colony algorithm [including Matlab source code 931]

[Fault analysis] fault diagnosis based on matlab GUI ant colony algorithm [including Matlab source code 931]

1. Introduction

1 The origin and development of ant colony algorithm (ACA)
. In the process of researching new algorithms, Marco Dorigo and others found that when ant colonies are looking for food, they exchange foraging information by secreting a biological hormone called pheromone. So that the target can be found quickly, so in his doctoral thesis in 1991, he first systematically proposed a new intelligent optimization algorithm based on ant population "Ant system (AS)". Later, the proponent and many researchers Various improvements have been made to the algorithm and applied to a wider range of fields, such as coloring problems, secondary allocation problems, workpiece sequencing problems, vehicle routing problems, job shop scheduling problems, network routing problems, and large-scale integrated circuits. Design etc. In recent years, M.Dorigo and others have further developed the ant algorithm into a general optimization technology "Ant Colony Optimization (ACO)", and called all algorithms that conform to the ACO framework "Ant Colony Optimization Algorithm" ACO algorithm)".


Specifically, each ant started looking for food without telling where the food was in advance. When a person finds food, it releases a volatile secretion pheromone (called pheromone, which will gradually evaporate and disappear over time. The concentration of pheromone indicates the distance of the path). Let other ants perceive and play a guiding role. Generally, when there are pheromone on multiple paths, the ants will preferentially select the path with high pheromone concentration, so that the path with high concentration has higher pheromone concentration, forming a positive feedback. Some ants do not always repeat the same path like other ants. They will find another way. If the new road is shorter than the original other roads, then gradually, more ants will be attracted to this shorter road. . Finally, after running for a period of time, there may be a shortest path repeated by most ants. In the end, the path with the highest pheromone concentration is the optimal path ultimately selected by the ants.
Compared with other algorithms, ant colony algorithm is a relatively young algorithm. It has the characteristics of distributed computing, no central control, asynchronous and indirect communication between individuals, and is easy to combine with other optimization algorithms. Exploring, a variety of improved ant colony algorithms have been developed to this day, but the principle of ant colony algorithm is still the backbone.

2 The solution principle of the ant colony algorithm
Based on the above description of the foraging behavior of the ant colony, the algorithm mainly simulates the foraging behavior in the following aspects:
(1) The simulated picture scene contains two kinds of pheromone, one is a representation Home, a place that represents food, and both pheromones are evaporating at a certain rate.
(2) Each ant can only perceive information in a small part of its surroundings. When ants are looking for food, if they are within the range of perception, they can go directly. If they are not within the range of perception, they have to move towards a place with a lot of pheromone. There is a small probability that the ant will not go to a place with a lot of pheromones. Taking another approach, this small probability event is very important, represents a way-finding innovation, and is important for finding a better solution.
(3) The rules for ants returning to their nest are the same as those for finding food.
(4) When the ant moves, it will first follow the guidance of the pheromone. If there is no guidance of the pheromone, it will go inertially according to its own moving direction, but there is a certain chance to change its direction. The ant can also remember the way it has traveled. , To avoid repeating one place.
(5) Ants leave the most pheromones when they find food, and then the farther away the food is, the less pheromones are left. The rules for finding the amount of pheromone left in the nest are the same as food. Ant colony algorithm has the following characteristics: positive feedback algorithm, concurrency algorithm, strong robustness, probabilistic global search, not relying on strict mathematical properties, long search time, and easy to stop.
Ant transfer probability formula: In the

formula: is the probability of ant k transferring from city i to j; and are the relative importance of pheromone and heuristic factor respectively; is the amount of pheromone on edge (i, j); is Heuristic factor; is the city that ant k is allowed to choose in the next step. The above formula is the pheromone update formula in the ant system, which is the amount of pheromone on the edge (i, j); is the pheromone evaporation coefficient, 0< <1; is the kth ant staying in this iteration The amount of pheromone on the edge (i, j); Q is a normal coefficient; is the path length of the k-th ant in this trip.
In the ant system, the pheromone update formula is:

3 Solving steps of the ant colony algorithm:
(1) Initialization parameters At the beginning of calculation, relevant parameters need to be initialized, such as ant colony size (number of ants) m, pheromone importance factor , heuristic function importance factor , pheromone will send silver , pheromone Release the total amount Q, the maximum number of iterations iter_max, and the initial value of the number of iterations iter=1.
(2) Construct a solution space and place each ant randomly at a different starting point. For each ant k (k=1,2,3...m), calculate the next city to be visited according to (2-1) until all ants are The ants have visited all the cities.
(3) Update information Su calculate the length of each ant's path Lk (k=1,2,...,m), and record the optimal solution (shortest path) in the current iteration times. At the same time, according to formula (2-2) and (2-3), the pheromone concentration on the connection path of each city is updated.
(4) Determine whether to terminate. If iter<iter_max, set iter=iter+1, clear the record table of the ant's path, and return to step 2; otherwise, terminate the calculation and output the optimal solution.
(5) Determine whether to terminate. If iter<iter_max, set iter=iter+1, clear the record table of the ant's path, and return to step 2; otherwise, terminate the calculation and output the optimal solution. 3. Determine whether to terminate. If iter<iter_max, set iter=iter+1, clear the record table of the ant's path, and return to step 2; otherwise, terminate the calculation and output the optimal solution.

2. the source code

function varargout = untitled(varargin) % UNTITLED M-file for untitled.fig % UNTITLED, by itself, creates a new UNTITLED or raises the existing % singleton*. % % H = UNTITLED returns the handle to a new UNTITLED or the handle to % the existing singleton*. % % UNTITLED( 'CALLBACK' ,hObject,eventData,handles,...) calls the local % function named CALLBACK in UNTITLED.M with the given input arguments. % % UNTITLED( 'Property' , 'Value' ,...) creates a new UNTITLED or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before untitled_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to untitled_OpeningFcn via varargin. % % *See GUI Options on GUIDE ' s Tools menu. Choose "GUI allows only one % instance to run (singleton)" . % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help untitled % Last Modified by GUIDE v2 .5 23 -May -2021 10 : 03 : 35 % Begin initialization code-DO NOT EDIT gui_Singleton = 1 ; gui_State = struct( 'gui_Name' , mfilename, ... 'gui_Singleton' , gui_Singleton, ... 'gui_OpeningFcn' , @untitled_OpeningFcn, ... 'gui_OutputFcn' , @untitled_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 untitled is made visible. function untitled_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 untitled (see VARARGIN) % Choose default command line output for untitled handles.output = hObject; % Update handles structure guidata (hObject, handles) ; % UIWAIT makes untitled wait for user response (see UIRESUME) % uiwait ( handles.figure1 ) ; % --- Outputs from this function are returned to the command line. function varargout = untitled_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) % Get default command line output from handles structure varargout { 1 } = handles.output ; function edit1_Callback (hObject, eventdata , handles) % hObject handle to edit1 (see GCBO) % eventdata reserved-to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get (hObject, 'String' ) returns contents of edit1 as text % str2double (get(hObject, 'String' )) returns contents of edit1 as a double % --- Executes during object creation, after setting all properties. function edit1_CreateFcn (hObject, eventdata , handles) % hObject handle to edit1 (see GCBO) % eventdata reserved-to be defined in a future version of MATLAB % handles empty-handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal (get(hObject, 'BackgroundColor' ), get( 0 , 'defaultUicontrolBackgroundColor' )) set (hObject, 'BackgroundColor' , 'white' ) ; end % --- Executes on button press in pushbutton1. function pushbutton1_Callback (hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved-to be defined in a future version of MATLAB Structure with Handles Handles% and User Data (See guidata) X = [ .054162803 3.278279079 1.269967423 5.161372814 6.554775334 7.802945518 89.91596827 169.1776572 143.304565 0.074421113 3.316697348 1.270329881 5.970864604 7.584967721 9.022343602 89.85758218 169.1213613 143.2747353 0.053348632 3.304197238 1.267854133 5.735004473 7.271149126 8.6360041 89.99066115 169.2467539 143.3392641 % 0.051720081 3.339632945 158.99294421.271724127 6.229903633 7.922718759 9.441330731 89.55978521 168.8424101 143.1321219 % 0.051864712 3.32076324 1.270382991 5.085988065 6.461152729 7.684102897 89.82998427 169.0964666 143.2626572 1.592002536 122.290451 1.734621006 28.65370822 49.70332419 64.63137481 151.3340327 219.4791589 158.962611 1.19861478 105.0456268 1.699966023 25.99113342 44.1840437 56.97791422 151.9810149 219.9476874 0.313453805 103.56017 1.74601649 25.72328554 44.91328074 58.52352399 152.2544307 220.1452556 159.0047857 % 1.74620714 104.5750915 1.722814423 26.09465184 44.95624257 58.40710523 155.5112779 222.4873381 159.1127213 % 0.800414929 115.6703271 1.75275249 25.50893937 44.71085699 58.1797557 154.2472348 221.5812885 159.0787792 -1.139654266 327.4563137 3.296710797 32.35697041 106.6715737 168.3318025 170.8728098 233.2175981 158.7228117 -3.177948091 401.7915242 3.349843446 34.95480454 117.0931229 184.2414168 177.5168284 237.7084602 158.0920229 0.10537445 358.1021167 3.403456107 33.08520829 112.6040542 179.1685128 177.1584012 237.4684609 158.1333957 % 1.345927915 346.0074742 3.277585069 34.71886501 113.7940336 178.5752461 177.8978973 237.9635592 158.0474411 % 0.98680132 352.4758738 3.226268588 35.43208236 114.3134143 178.6895352 174.8682892 235.9285934 158.3773425 -11.91636275 763.3694263 2.163303163 66.74137606 144.3818299 197.3606479 178.1653349 238.1423511 158.0154829 -10.83476732 642.6532934 2.224536056 59.143315 131.5664367 180.4907521 178.1435308 238.1277955 158.0181301 -11.03075139 711.5078011 2.133406233 64.65685363 137.9393345 187.861062 175.3695323 236.2664234 158.326719 % -10.62874379 592.6236111 2.245205144 59.07819077 132.6426578 181.8505502 180.9528024 239.997917 157.6549507 % -15.28771972 792.6990829 2.333439781 55.9847639 130.6370752 180.1123338 182.4871818 241.0134313 157.4353917 % 0.051720081 3.339632945 1.271724127 6.229903633 7.922718759 9.441330731 89.55978521 168.8424101 143.1321219 ]; a = get(handles.edit2, 'String' ); [c,flag]=str2num(a); X=zeros( 13 , 9 ); X( 1 : 12 ,:)=x( 1 : 12 ,:); X( 13 ,:)=c( 1 ,:); R=get(handles.edit4, 'String' ); R=str2num(R); t_max=get(handles.edit5, 'String' ); t_max=str2num(t_max); b=myant(X,R,t_max); unction edit2_Callback (hObject, eventdata , handles) % hObject handle to edit2 (see GCBO) % eventdata reserved-to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get (hObject, 'String' ) returns contents of edit2 as text % str2double (get(hObject, 'String' )) returns contents of edit2 as a double % --- Executes during object creation, after setting all properties. function edit2_CreateFcn (hObject, eventdata , handles) % hObject handle to edit2 (see GCBO) % eventdata reserved-to be defined in a future version of MATLAB % handles empty-handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal (get(hObject, 'BackgroundColor' ), get( 0 , 'defaultUicontrolBackgroundColor' )) set (hObject, 'BackgroundColor' , 'white' ) ; end % --- Executes on button press in pushbutton 2. function pushbutton2_Callback (hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved-to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) a = get( handles.edit3 , 'String' ); a=str2num(a); switch a case 1 b=canshu( '1.txt' ); case 2 b=canshu( '2.txt' ); case 3 b=canshu( '3.txt' ); case 4 b=canshu( '4. TXT' ); end b=b ' ; c=num2str(b); % ct=get(handles.edit2, 'string' ); % empty(ct); set (handles.edit2, 'String' ,c); guidata(hObject, handles); function edit3_Callback (hObject, eventdata , handles) % hObject handle to edit3 (see GCBO) % eventdata reserved-to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get (hObject, 'String' ) returns contents of edit3 as text % str2double (get(hObject, 'String' )) returns contents of edit3 as a double % --- Executes during object creation, after setting all properties. function edit3_CreateFcn (hObject, eventdata , handles) % hObject handle to edit3 (see GCBO) % eventdata reserved-to be defined in a future version of MATLAB % handles empty-handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal (get(hObject, 'BackgroundColor' ), get( 0 , 'defaultUicontrolBackgroundColor' )) set (hObject, 'BackgroundColor' , 'white' ) ; end Copy code

3. running results




4. remarks

Version: 2014a