0% found this document useful (0 votes)
175 views13 pages

2013 Bookmatter OptimizationOfPIDControllersUs

This document provides Matlab code and documentation for using Ant Colony Optimization (ACO) to optimize PID controller parameters. It includes: 1) An ACO solver function that performs the optimization using various ACO parameters and options. 2) A cost function that evaluates candidate PID parameters in a Simulink model of a pressure control process. 3) Documentation and code to run the ACO algorithm to optimize PID controller gains for the pressure control process model.

Uploaded by

Dadi Aziz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
175 views13 pages

2013 Bookmatter OptimizationOfPIDControllersUs

This document provides Matlab code and documentation for using Ant Colony Optimization (ACO) to optimize PID controller parameters. It includes: 1) An ACO solver function that performs the optimization using various ACO parameters and options. 2) A cost function that evaluates candidate PID parameters in a Simulink model of a pressure control process. 3) Documentation and code to run the ACO algorithm to optimize PID controller gains for the pressure control process model.

Uploaded by

Dadi Aziz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Appendix

A.1 Matlab Codes for ACO

A.1.1 Ant Colony Optimization Solver

function [x,cval,time,assign]=ant(nvars,LB,UB,options)

%x : independent variables for the cost function


% cval : cost value
% time : optimization time
% assign : number of last tour
% nvars : number of independent variables for the cost function
% LB : lower bounds on the variables
(Lower specifies lower bounds as a vector)
% UB : upper bounds on the variables
(Upper specifies lower bounds as a vector)
% options : specify options for the Ant Colony Optimization Algorithm solver

%% Default options
defaultopt = struct('CostFcn',@ant_cost,...
'NumOfAnts', 20, ...
'Pheromone', 0.06, ...
'EvaporationParameter', 0.95, ...
'Positive Pheremone',0.2,...
'NegativePheremone',0.3,...
'MinValue', 0,...
'MaxValue',20,...
'Piece',101,...
'Figure','On',...
'MaxTour', 100);

%% Check input arguments and initialize them


% Check number of input arguments
errmsg = nargchk(1,4,nargin);
if ~isempty(errmsg)
error([errmsg,' ANT requires at least 1 input argument.']);
end
if nargin< 4, options = [];
if nargin< 3, UB = ones(1,nvars);
if nargin< 2, LB = zeros(1,nvars);
end
74 Appendix

end
end

% Use default options if empty


if ~isempty(options) && ~isa(options,'struct')
error('Options must be a valid structure.');
elseif isempty(options)
options = defaultopt;
end
user_options = options;

% All inputs should be double


try
dataType = superiorfloat(LB,UB);
if ~isequal('double', dataType)
error('ANT only accepts inputs of data type double.')
end
catch
error('ANT only accepts inputs of data type double.')
end
%% Start Ant Colony Optimization
clc % clear command window
tic % run chronometer
%% Initialize options
cost = user_options.CostFcn; % Cost function
ants = user_options.NumOfAnts % Number of ants
ph = user_options.Pheromone % Weight of pheromone
poz_ph = user_options.PozitivePheremone
% Value of positivepheromone constant
neg_ph = user_options.NegativePheremone
% Value of negative pheromone constant
lambda = user_options.EvaporationParameter ;
% Evaporation Parameter
max_assign =user_options.MaxTour % Number of tour
piece = user_options.Piece % How many piece of design
variable matrices

%% Initialize variables
pher = ones(piece,nvars);
indis = zeros (ants,nvars);
costs = zeros(ants,1);
cost_general = zeros(max_assign,(nvars+1));

deger=zeros(piece,nvars);
deger(1,:)=LB;
for i=2:piece
Appendix 75

for j=1:nvars
deger(i,j)=deger(i-1,j)+ (UB(j)-LB(j))/(piece-1);
end
end
%%
assign=0;
while (assign <max_assign)
for i=1:ants
% FINDING THE PARAMETERS OF VALUE
prob = pher.*rand(piece,nvars);
for j=1:nvars
indis(i,j) = find(prob(:,j) == max(prob(:,j))) ;
end

temp=zeros(1,nvars);
for j=1:nvars
temp(j)=deger(indis(i,j),j);
end
costs(i) = cost(temp);
% LOCAL UPDATING
deltalocal = zeros(piece,nvars);
% CREATES THE MATRIX THAT WILL CONTAIN THE PHEREMONES
DEPOSITED FOR LOCAL UPDATING
for j=1:nvars
deltalocal(indis(i,j),j)= (poz_ph *ph / (costs(i)));
end
pher = pher + deltalocal;
end
76 Appendix

% FIND THE BEST ANT AND UPDATE THE PHEROMONE OF THE BEST
ANT'S PARAMETERS
best_ant= min(find(costs==min(costs)));
worst_ant = min(find(costs==max(costs)));

deltapos = zeros(piece,nvars);
deltaneg = zeros(piece,nvars);

for j=1:nvars
deltapos( indis(best_ant,j),j) = (ph /(costs(best_ant))) ;
%UPDATING PHER OF nvars
deltaneg( indis(worst_ant,j),j) = -(neg_ph * ph /(costs(worst_ant))) ;
% NEGATIVE UPDATING PHER OF worst path
end

delta = deltapos + deltaneg;


pher = pher.^lambda + delta ;

assign=assign + 1;

% Update general cost matrix


for j=1:nvars
cost_general (assign,j)=deger(indis(best_ant,j),j);
end
cost_general (assign,nvars+1)=costs(best_ant);
%%
if strcmp(options.Figure,'On')
set(gca,'xlim',[1,options.MaxTour],'Yscale','log');
xlabelTour
title('Change in Cost Value. Red: Means, Blue: Best')
holdon
plot(assign, mean(costs), '.r');
plot(assign, costs(best_ant), '.b');
end
end
%%
list_cost =sortrows(cost_general,nvars+1);
for j=1:nvars
x(j)=list_cost(1,j);
end
cval = ant_cost(x);
time = toc;
end
Appendix 77

A.1.2 ACO Cost Function


function cval = ant_cost(x)
% Assign Kp, Ki and Kd
Kp = num2str(x(1));
Ki = num2str(x(2));
Kd = num2str(x(3));
% Run Close Loop Model with PID Controller
set_param('antz/PID','P', Kp ,'I', Ki, 'D', Kd);
sim('antz');
% Calculating the Cost Value
cval = mean(sqrt(power(reference - output,2)));
end
78 Appendix

A.1.3 Run ACO


Simulink block diagram in Fig. A.1 is constituted to optimize the PID control with
ACO. Process block represents the ANN model of the pressure process. Saturation
object of 10V and a rate limiter to prevent sudden change of the proportional valve
is placed to the PID controller output. Thus, the simulation is run with adjusting
Kp, Ki and Kd values as the parameters of the controller while PID controller
optimizing with ACO. The output and reference values obtained from program are
sent to Workspace and used to calculate the cost value.

Reference
To Workspace

+_ GUNT RT 532
PID Output
(NARX Model)
Step PID Controller Saturation Rate Limiter To Workspace

Fig. A.1 Close loop model with PID Controller for pressure process

clearall
clc
options = struct( 'CostFcn',@ant_cost,...
'NumOfAnts', 100, ...
'Pheromone', 0.06, ...
'EvaporationParameter', 0.95, ...
'PozitivePheremone',0.2,...
'NegativePheremone',0.3,...
'MaxTour', 100, ...
'MinValue', -10, ...
'MaxValue',10,...
'Figure','On',...
'Piece',501);
LB = [0 0 0];
UB = [20 1 10];
nvars=size(LB,2);
% Run ACO
[x,cval]=ant(nvars,LB,UB,options)
% Set PID Controller
Kp = num2str(x(1));
Ki = num2str(x(2));
Kd = num2str(x(3));
% Run Close Loop Model with PID Controller
set_param('close_loop_model/PID','P', Kp ,'I', Ki, 'D', Kd);
sim('close_loop_model');
References

[1] Ünal, M.: Optimization of PID Controller Using Ant Colony / Genetic Algorithms
and Control of The Gunt RT 532 Pressure Process, Master Master, Institue for
Graduate Studies in Pure and Applied Sciences, Marmara University, İstanbul,
Turkey (2008)
[2] Mok, H.S., Kim, G.T., Park, M.H., Rhew, H.W.: PI Controller Gains Tuning of The
Pressure Control System By Open-Loop Frequency Response. IEEE (1988)
[3] Namba, R., Yamamoto, T., Kaneda, M.: Robust PID Controller and Its Application.
IEEE (1997)
[4] Guo, C., Song, Q., Cai, W.: Real-time control of AHU based on a neural network
assisted cascade control system. In: Robotics, Automation and Mechatronics, pp.
964–969 (2004)
[5] Jian, W., Wenjian, C.: Development of an Adaptive Neuro-Fuzzy Method For
Supply Air Ressure Contro. In: Hvac System. IEEE (2000)
[6] Ünal, M., Erdal, H., Topuz, V., Ergüzel, T.T.: Isac Robot Kolunun Yörünge Takibi
İçin PID Kontrolörün Genetik Algoritma ile Optimizasyonu. In: UMES, İzmit,
Kocaeli (2007)
[7] Salami, M., Cain, G.: An Adaptive PID Controller Based on Genetic Algorithm
Processor. In: Genetic Algorithms in Engineering Systems: Innovations and
Applications (1995)
[8] Jones, A.H., DeMouraOliveira, P.B.: Genetic Auto-Tuning of PID Controllers. In:
Genetic Algorithms in Engineering Systems: Innovations and Applications (1995)
[9] Gündoğdu, Ö.: Optimal-Tuning of PID Controller Gains Using Genetic Algorithms,
Pamukkale Üniversitesi Mühendislik Fakültesi Mühendislik Bilimleri Dergisi, vol.
1 (2005)
[10] Dandıl, B., Gökbulut, M., Ata, F.: Genetik Algoritma ile Model Referans-PID
Denetleyici Tasarımı. Fırat Üniversitesi Fen ve Mühendislik Bilimleri Dergisi 14,
33–43 (2002)
[11] Alli, H., Kaya, M.: Genetik Algoritma Kullanarak PID Kontrol Parametrelerinin
Bulunması. Fırat Üniversitesi Fen ve Mühendislik Bilimleri Dergisi 13, 1–8 (2001)
[12] Mitsukura, Y., Yamamoto, T., Kaneda, M.: A Design of Self-Tuning PID Controllers
Using a Genetic Algorithm. In: American Control Conference, pp. 1361–1365 (1999)
[13] Duan, H.-B., Wang, D.-B., Yu, X.-F.: Novel Approach to Nonlinear PID Parameter
Optimization Using Ant Colony Optimization Algorithm. Journal of Bionic
Engineering 3, 73–78 (2006)
[14] Ergüzel, T.T., Akbay, E.: ACO (Ant Colony Optimization) Algoritması ile Yörünge
Takibi. In: UMES, İzmit, Kocaeli (2007)
[15] Varol, H.A., Bingul, Z.: A New PID Tuning Technique Using Ant Algorithm. In:
American Control Conference, Boston, Massachusetts (2004)
80 References

[16] Fausett, L.: Fundamentals of neural networks. Prentice Hall Publishing, New York
(1994)
[17] Zurada, J.M.: Introduction to Artificial Neural Systems. West Publishing Company,
Minnesota (1992)
[18] Cavuto, D.J.: An Exploration and Development of Current Artificial Neural
Network Theory and Applications with Emphasis of Artificial Life. Master Thesis,
Citeseer (1997)
[19] Hagan, M.T., Demuth, H.B., Beale, M.: Neural Network Design. PWS, Boston
(1997)
[20] Tsypkin, Y.Z., Nikolic, Z.J.: Foundations of the theory of learning systems.
Academic Press, New York (1973)
[21] Onat, A., Kita, H., Nishikawa, Y.: Recurrent Neural Networks for Reinforcement
Learning: Architecture, Learning Algorithms and Internal Representation. In: IEEE
World Congress on Computational Intelligence (1998)
[22] Kecman, V.: Learning and Soft Computing: Support Vector Machines. In: Neural
Networks, and Fuzzy Logic Models, pp. 121–191. MIT Press, Cambridge (2001)
[23] Ronco, E., Gawthrop, P.J.: Neural Networks for Modelling and Control. Centre for
System and Control Department of Mechanical Engineering University of Glasgow
(1997)
[24] Narendra, K.S., Parthasarathy, K.: Identification and Control of Dynamical Systems
Using Neural Networks. IEEE Transactions on Neural Networks 1 (1990)
[25] Özçalık, H.R., Küçüktüfekçi, A.: Dinamik Sistemlerin Yapay Sinir Ağları ile Düz
ve Ters Modellenmesi. KSÜ Fen ve Mühendislik Dergisi 6, 26–35 (2003)
[26] Şafak, K.K.: Identification of a Universal DC Motor Dynamics Using Feedforward
Neural Networks. MS, Fen Bilimleri Enstitüsü, Boğaziçi Üniversitesi, İstanbul
(1997)
[27] Coley, D.A.: An introduction to genetic algorithms for scientists and engineers.
World Scientific Pub. Co. Inc. (1999)
[28] Quagliarella, D., Periaux, J., Poloni, C., Winter, G.: Genetic Algorithms and
Evolution Strategy in Engineering Computer Science. John Wiley, NY (1998)
[29] Michalewicz, Z.: Genetic algorithms+ data structures = Evolution Programs.
Springer, USA (1996)
[30] Goldberg, D.E.: Genetic algorithms in search, optimization, and machine learning.
Addison-wesley (1989)
[31] Bäck, T.: Optimal Mutation Rates in Genetic Search. In: Proceeding of the Fifth
International Conference on Genetic Algorithms, CL, USA (1993)
[32] Mitchell, M.: An introduction to genetic algorithms. The MIT Press (1998)
[33] Robertson, G.G.: Population Size in Classifier Systems. In: Proceeding of Fifth
International Conference on Machine Learning, MA, USA (1988)
[34] Goldberg, D.E.: Sizing Populations for Serial and Parallel Genetic Algorithms. In:
Proceeding of The Third International Conference on Genetic Algorithms, CL, USA
(1989)
[35] Schaffer, D.J., Caruana, R., Eshelman, L., Das, R.: A Study of Control Parameters
Affecting Online Perfpormance of Genetic Algorithms for Function Optimization.
In: Proceeding of The Third International Conference on Genetic Algorithms, NJ,
USA (1988)
[36] Janikow, C.Z., Michalewicz, Z.: An Experimental Comparison of Binary and
Floating Point Representation in Genetic Algorithms. In: Proceeding of The Fourth
International Conference on Genetic Algorithms, CL, USA (1991)
References 81

[37] Reeves, C.R.: Using Genetic Algorithms with Small Populations. In: Fifth
International Conference on Genetic Algorithms, CL, USA (1993)
[38] Syswerda, G.: Uniform Crossover in Genetic Algorithms. In: Proceeding of the
Third International Conference on Genetic Algorithms, NJ, USA (1989)
[39] Fogarty, T.C.: Varying the probability of Mutation in the Genetic Algorithm. In:
Proceeding of The Third International Conference on Genetic Algorithms, NJ, USA
(1989)
[40] Man, K.F., Tang, K.S., Kwong, S., Halang, W.A.: Genetic Algorithms for Control
and Signal Processing (Advances in Industrial Control). Springer, England (1997)
[41] Goldberg, D.E., Deb, K., Korb, B.: Don’t Worry be Messy. In: Proceeding of The
Fourth International Conference on Genetic Algorithms. University of California,
San Diego (1991)
[42] Kallel, L.S.: Alternative Random Initialization in Genetic Algorithm. In: Proceeding
of The Seventh international Conference on Genetic Algorithms, MI, USA (1997)
[43] Buckles, B.P., Petry, E.F.: Genetic Algorithms. IEEE Computer Society Press, CL
(1994)
[44] Michalewicz, Z.: Genetic algorithms + data structures = Evolution Programs.
Springer, USA (1996)
[45] Grefenstette, J.J.: Optimization of Control Parameters for Genetic Algorithms. IEEE
Transactions on Systems, Man and Cybernetics 16, 122–128 (1986)
[46] Goldberg, D.E., Sastry, K.: A practical schema theorem for genetic algorithm design
and tuning. University of Illinois at Urbana IL, USA IlliGAL Report No 2001017
(2001)
[47] Yun, Y., Gen, M.: Performance Analysis of Adaptive Genetic Algorithms with
Fuzzy Logic and Heuristics. Fuzzy Optimization and Decision Making 2, 161–175
(2003)
[48] Chambers, L.: Practical handbook of genetic algorithms, vol. 1-2. CRC Press, FL
(1995)
[49] Dorigo, M.: Optimization, Learning and Natural Algorithms, PhD., Politecnico di
Milano, Italie (1992)
[50] Colorni, A., Dorigo, M., Maniezzo, V.: Distributed Optimization by Ant Colonies.
In: The First European Conference on Artificial Life, Paris, France (1992)
[51] Dorigo, M.: Ant Algorithms for Discrete Optimization. Artificial Life 5, 137 (1999)
[52] Hsiao, Y.-T., Chuang, C.-L., Chien, C.-C.: Ant Colony Optimization for Designing
of PID Controllers. In: lntemational Symposium on Computer Aided Control
Systems Design, Taiwan (2004)
[53] Bonabeau, E., Dorigo, M., Theraulaz, G.: Inspiration for Optimization From Social
Insect Behaviour. Nature 406 (2000)
[54] Gambardella, L.M., Dorigo, M.: Ant-Q: A Reinforcement Learning approach to the
traveling salesman problem. In: Twelfth Intern. Conf. on Machine Learning, ML
1995, pp. 252–260 (1995)
[55] Alaykıran, K., Engin, O.: Karınca Kolonileri Metasezgiseli ve Gezgin Satıcı
Problemleri Üzerinde Bir Uygulaması. Gazi Üniv. Müh. Mim. Fak. Der. 20, 69–76
(2005)
[56] Can, B.: The optimal control of ITU Triga Mark II Reactor. Presented at the The
Twelfth European Triga User’s Conference, NRI Bucuresti-Pitesti, Romania (1992)
[57] Advantech PCI 1711 DAQ Card (December 30, 2009),
http://www.advantech.com/products/100-kS-s-12-bit-16-
ch-SE-Input-PCI-Multifunction-Cards/mod_1-2MLGWA.aspx
82 References

[58] Sanchez, E., Shibata, T., Zadeh, L.A.: Genetic Algorithms and Fuzzy Logic
Systems: Soft Computing Perspectives (1997)
[59] Topuz, V.: Fuzzy Genetic Process Control. Ph.D, Institue for Graduate Studies in
Pure and Applied Sciences, Marmara University, Istanbul, Turkey (2002)
[60] Yeniay, Ö.: An Overview of Genetic Algorithms. Anadolu Üniversitesi Bilim ve
Teknoloji Dergisi 2, 37–49 (2001)
[61] Altiparmak, F., Dengiz, B., Smith, A.E.: An Evolutionary Approach For Reliability
Optimization in Fixed Topology Computer Networks. Transactions on Operational
Research 12, 57–75 (2000)
[62] Oliveira, P., Sequeira, J., Sentieiro, J.: Selection of Controller Parameters using
Genetic Algorithms. Kluwer Academic Publishers, Dordrecht (1991)
[63] Ogata, K.: Modern Control Engineering, 3rd edn. Prentice Hall, New Jersey (1997)
Index

A E

activation functions 6, 11 elistic model 24, 47


adaptation function 47 error backpropagation algorithm 12
adaptation value 2, 47 evolution strategies 19
advanced modeling (series-parallel evolutionary algorithms 19
modeling) 15
air pressure control 39
F
ant colony optimization 3, 31, 73, 74
ant-based algorithms 33
feedforward network 7
artificial ants 33
fitness function 19, 28, 47
artificial neural network 5, 7, 15
fitness value 21, 25, 26, 28, 29
fitness value scaling 28
B

backpropagation 12, 14 G
binary coding 20, 23
binary coding method 23 generalization property 39, 40
block diagram 10, 16, 38, 45, 78 generation 19, 20–22, 24–26, 28, 46,
47
C generation gap 21, 24
genetic algorithm 1, 3, 21, 22
chromosomes 19, 20–22, 26, 27, 47 genetic operator 19, 22, 47, 71
coding 20, 23, 46, 47 genetic programming 19
coding function 19 genotype 19
control signals 48, 58, 64 graph representation 31, 54
crossover 26–28, 47 gray coding method 23
crossover operator 20, 21, 47
crossover probability 21, 28, 46
H
D hard combinatorial optimization 31
data normalization 42 hierarchic genetic algorithm 21
delay time 62 hyperbolic tangent 39, 40
derivative 44, 46
deterministic 10, 26 I
digital controller 38
discrete-time recurrent network 9 initialization function 19
distortion 50, 51, 59, 60, 66 integral 44, 46
dynamic mutation 21 iteration 34, 42, 55
84 Index

L power scaling 29
pressure 1, 3, 28, 37–40, 44, 50, 57, 63,
learning rules 9 66, 69, 72, 78
linear activation function 39, 40 pressure process control system 3
linear scaling 28 process 2, 3, 7, 14, 15, 19, 33, 37, 39,
40, 42, 45, 69, 72, 78
M proportional 6, 23, 26, 27, 39, 44, 46,
50, 51, 60, 66, 78
Messy Genetic Algorithm 21
Micro Genetic Algorithm 21 R
minimum cost path 31
multilayer perceptron 11 real ants 31
multimodal optimizations problems 19 real time performances 48
mutation operator 20, 21, 27, 47 realized system 38
mutation probability 21, 22, 46 recurrent networks 9
reel number coding 20
N reinforcement (or graded) learning 10
replacement methods 21
natural ants 31 replacement policy 20
normalization process 42 rise time 70
robust 1, 19
O root mean square 2, 13
roulette wheel 21, 25
obstacle 32, 33
offsprings 24, 25, 26 S
optimization problems 19, 20, 21, 23,
31 sampling time 16, 47
overshoot 2, 37, 70 scheme theorem 26
search space 2, 19, 20, 23, 71
P selection 16, 19, 21, 24, 25, 26, 28, 32,
46, 47, 48
parallel systems 34 selection methods 21, 26
parallel working 34 settling time 70
parents 21, 24, 25, 26, 27 shortest path problems 31
perceptron 5, 11, 12 sigma scaling 29
pheromone 32, 33, 34, 35, 54, 55, 57, steady state Genetic Algorithm 21
74 steady-state 21, 48, 58, 64
Pheromone Vaporization 35 step inputs 40, 49, 58, 69, 70
PID Controller 1, 3, 44, 47, 48, 54, 56, stochastic sampling with replacement
58, 66, 69, 77, 78 selection 21
PID parameters 2, 45, 46 stochastic universal sampling 21, 25
pneumatic 38, 45, 50, 66 suboptimal solution 19, 21
pneumatic valve 38, 45 supervised learning 9, 10
population size 19, 20, 21, 23, 25, 28, symbolic alphabets coding 20
46, 47 system response 48, 58, 64
Index 85

T traveling salesman problem 31


tree coding 20
termination criterion 20
the Nonlinear Autoregressive Network U
with Exogenous Inputs (NARX) 13
uniform crossover 21
time constant 62, 63
universal approximator 11
time delay 1, 9, 14, 16, 40, 63
unsupervised learning 10, 11
time delay unit 40
tournament selection 21
trace 31, 34, 35, 47 V
training data 40 virtual ants 31
trajectory coefficients 37
trajectory function 37, 52, 60, 66, 69 Z
trajectory slope 37, 69, 72
trajectory tracking 52, 60 Ziegler-Nichols 1, 63

You might also like