Professional Documents
Culture Documents
Optimal Dispatch Ot Genrating Units
Optimal Dispatch Ot Genrating Units
Optimal Dispatch Ot Genrating Units
FACULTY OF ENGINEERING
DEPARTMENT OF ELECTRICAL AND INFORMATION
ENGINEEERING
i
DECLARATION OF ORIGINALITY
1) I understand what plagiarism is and I am aware of the university policy on this regard.
2) I declare that this final year project is my original work and has not been submitted elsewhere
for examination, award degree or publication. Where other people’s work or my own work
has been used, this has been properly acknowledged and referenced in accordance with the
University of Nairobi’s requirements.
3) I have not sought or used the service of any professional agencies to produce this work.
4) I have not allowed, and shall not allow anyone to copy my work with the intention of passing
it off as his/her own work.
5) I understand that any false claim in respect of this work shall result in disciplinary action, in
accordance with University anti-plagiarism policy.
Signature:
…………………………………………………
Date:
………………………………………………………………………
i
CERTIFICATION
This report has been submitted to the Department of Electrical and Information Engineering,
University of Nairobi with my approval as supervisor:
Date: ..........................................
ii
DEDICATION
iii
ACKNOWLEDGEMENTS
First I would like to thank God, for His unending grace and love throughout my academic life.
Without it, I would not have made it this far.
I would also like to extend my sincere gratitude to my supervisor, Prof. Nicodemus Abungu
Odero for his priceless motivation, support and guidance.
I also extend my appreciation to Mr. Peter Musau for his time, for patiently being there for
us, and for his valuable insights into my project, and above all, the encouragement.
I appreciate all my lecturers and all non-teaching staff at the Department of Electrical
and Electronic Engineering, University of Nairobi, for their contribution towards my degree.
I would also like to extend my heartfelt gratitude to my classmates and especially my friends
Ng’etich Kiplimo Brian and Nyasimi Ronald for their encouragement and contribution to this
project.
To my classmates, I am thankful for their moral support as I did the project and the conducive
environment.
Finally I would like to thank my family for their help and understanding throughout my
academic life.
iv
DECLARATION OF ORIGINALITY ..................................................................................................................... i
CERTIFICATION .............................................................................................................................................. ii
DEDICATION ................................................................................................................................................. iii
ACKNOWLEDGEMENTS ................................................................................................................................ iv
LIST OF FIGURES ......................................................................................................................................... viii
LIST OF TABLES ............................................................................................................................................. ix
LIST OF ABBREVIATIONS ............................................................................................................................... x
ABSTRACT..................................................................................................................................................... xi
CHAPTER 1 .................................................................................................................................................... 1
INTRODUCTION ......................................................................................................................................... 1
1.1 Hydrothermal Economic Dispatch. ................................................................................................. 1
1.1.1 What is Economic Dispatch? .................................................................................................... 1
1.1.2 What is Hydrothermal Economic Dispatch? ............................................................................ 1
1.1.3 What is Particle Swarm Optimization (P.S.O)? ........................................................................ 2
1.2. Survey of Earlier Work. .................................................................................................................. 3
1.2.1. Optimization Techniques ........................................................................................................ 3
1.3. Conventional Methods................................................................................................................... 4
1.3.1 Unconstrained optimization approaches................................................................................. 4
1.3.2 Linear programming (L.P)......................................................................................................... 4
1.3.3 Non-linear programming (N.L.P) .............................................................................................. 5
1.3.4 Quadratic programming........................................................................................................... 5
1.3.5 Newton’s method .................................................................................................................... 5
1.3.6 Interior points (I.P) methods .................................................................................................... 5
1.3.7 Mixed integer programming .................................................................................................... 5
1.3.8 Network flow programming..................................................................................................... 5
1.4. Intelligent Search Methods ............................................................................................................ 6
1.4.1 Neural network (NN) ................................................................................................................ 6
1.4.2 Evolutionary algorithms ........................................................................................................... 6
1.4.2.1 Genetic algorithm (GA) ..................................................................................................... 7
v
1.4.3 Tabu Search (T.S)...................................................................................................................... 8
1.4.4. Ant colony optimization (A.C.O) ............................................................................................. 9
1.4.5. Particle Swarm Optimization (P.S.O) ...................................................................................... 9
1.4.6. Simulated Annealing (S.A) ....................................................................................................... 9
1.5. Non-Quantity Approaches ........................................................................................................... 10
1.6. Problem Statement ...................................................................................................................... 10
1.7 Organization of the Report. .......................................................................................................... 11
CHAPTER 2 .................................................................................................................................................. 12
Literature Review .................................................................................................................................... 12
2.1 Literature Review of Hydrothermal Economic Load Dispatch ...................................................... 12
2.2 Classical Economic Dispatch ......................................................................................................... 13
2.2.1 Input Output Characteristics of Generator Units................................................................... 13
2.2.2. Calculation of input-output parameters of a thermal system. ............................................. 15
2.3. Hydrothermal System Economic Dispatch ................................................................................... 17
2.4.1 System Constraints ................................................................................................................ 17
2.4.1.1 Power balance constraints (Demand Constraints) ......................................................... 18
2.4.1.2 Thermal Generator Constraints ...................................................................................... 18
2.4.2 Hydraulic Network Constraints .............................................................................................. 18
2.5 Particle Swarm Optimization ........................................................................................................ 19
2.5.1 PSO Terminologies ................................................................................................................. 19
2.5.2 PSO Parameter Selection ....................................................................................................... 20
2.5.2.1 Swarm Size. ..................................................................................................................... 20
2.5.2.2 Velocity components ...................................................................................................... 20
2.5.2.3 Inertia Weight ................................................................................................................. 21
2.5.2.4 Constriction Factor.......................................................................................................... 21
CHAPTER 3 .................................................................................................................................................. 22
Solution of Hydrothermal Economic Dispatch Using P.S.O .................................................................... 22
3.1 Formulation of Hydrothermal Dispatch Problem ......................................................................... 22
3.2 Economic Load Dispatch with Network losses.............................................................................. 23
3.3 Formulation of P.S.O ..................................................................................................................... 26
3.4 Pso Algorithm .................................................................................................................................... 27
vi
3.5 Flow Chart ......................................................................................................................................... 29
CHAPTER 4 .................................................................................................................................................. 30
4.1 30 Bus Test Network ......................................................................................................................... 30
4.2: Particle Swarm Optimization Method ......................................................................................... 32
4.3 Analysis and Discussion................................................................................................................. 34
4.3.1: Case Study: 600mw Case For both Thermal and Hydrothermal System .............................. 35
4.3.2: Convergence Characteristics of the PSO Method for 30 Bus system. .................................. 36
4.3.2: Power Losses ......................................................................................................................... 37
CHAPTER 5 .................................................................................................................................................. 38
5.1 Conclusion and Recommendation for Future Works........................................................................ 38
5.1.1 Conclusion .................................................................................................................................. 38
5.1.2 Recommendation ....................................................................................................................... 38
REFERENCES ................................................................................................................................................ 39
APPENDICES ................................................................................................................................................ 41
APPENDIX 1: Program for the Thermal Economic Dispatch ................................................................... 41
APPENDIX 2: Program for the Hydrothermal Economic Dispatch. ......................................................... 42
APPENDIX 3: Code for plotting the Convergence Characteristics........................................................... 43
APPENDIX 3: Main program code for the PSO Toolbox Used. ................................................................ 46
vii
LIST OF FIGURES
Fig 4. 1 : 30 Bus IEEE test network with six generating units. .................................................................. 30
Fig 4. 2: Thermal optimum generation ....................................................................................................... 34
Fig 4. 3: Hydrothermal optimum generation .............................................................................................. 34
Fig 4. 4: Generation trend for combined thermal and hydrothermal system .............................................. 35
Fig 4. 5: Convergence Characteristics for 30 bus hydrothermal generating system. (700 MW) ................ 36
Fig 4. 6: Convergence Characteristics for 30 bus all thermal generating system. (700 MW) .................... 36
Fig 4. 7: Hydrothermal Power Loss ............................................................................................................ 37
Fig 4. 8 : Thermal power loss ..................................................................................................................... 37
viii
LIST OF TABLES
ix
LIST OF ABBREVIATIONS
NN Neural Network
TS Tabu Search
x
ABSTRACT
The objective of this project is to solve the hydrothermal economic load dispatch using PSO. The
Energy Management System or (EMS) as we know it today had its origin in the need for electric
utility companies to operate their generators as economically as possible. To operate the system
as economically as possible, one requires that the characteristics of all generating units be
available so that the most efficient units could be dispatched properly along with the less
efficient. In addition, there is a requirement that the on/off scheduling of generators units be done
in an efficient manner as well.
Various methods have been used to solve this economic dispatch problem. These include but not
limited to goal programming, neural networks and genetic algorithm. In this paper, a heuristic
method called the Particle Swarm Optimization (PSO) has been developed and used to solve a
hydrothermal economic dispatch problem, having multi-reservoirs cascaded hydro plants and
thermal plants.
The developed algorithm has been tested on a 6 unit IEEE 30-bus network and has been
found to be robust, and quick, converging at just over a hundred iterations. Hydrothermal power
was found to be much cheaper compared to thermal power as cost dropped from Rs/Hr.
36,912.00 when using thermal power to just Rs/Hr. 647.35 for a power demand of 700 MW. This
signifies a drop of over a thousand percent, and hence the need to use hydropower to supply the
base load as it’s much cheaper and efficient.
xi
CHAPTER 1
INTRODUCTION
Economic dispatch is the operation of generation facilities to produce energy at the lowest cost to
reliably serve customers while recognizing any operational limits of generation and transmission
facilities. Economic dispatch is part of multilevel problems in power generation since different
power plants, with different units have different characteristics which give different
generating costs at any load at any point in time [2,21].
The main aim of economic load dispatch is to reduce the cost. However, for optimal system
operation other important factors may come into play namely, reliability, the system’s security,
emissions (in the case of fossil-fuel plants), and optimal water discharge (for hydro generation).
Ideally this multilevel problem, up to where we have the solution of economic load dispatch can
be summarized as shown in Figure 1.1 below.
Hydrothermal economic dispatch is where we have both hydro and thermal units being used in
the generation of power. Planning or scheduling has to be done to determine the amount of hydro
and thermal power needed to satisfy a given load [15, 20].
A hydrothermal system is a more complex one as compared to an all thermal system since it is
dynamic as the water levels keep changing, whereas the thermal problem is a static one.
The main constraints in the hydrothermal system may include ;the time coupling effect of the
water flow in an earlier time interval that affects the discharge capability at a later period
of time, the time varying system long demand, the cascade nature of the hydraulic network, the
varying hourly reservoir inflows, the physical limitations on the reservoir storage and
turbine flow rate and loading limits of both the thermal and hydro plants.
1
Load Flow Casting (What load do
we need to supply?)
2
inspired by social dynamics and an emergent behavior that arises in socially organized colonies.
In this context, the population is called the swarm and the individuals are called the particles.
The particles change their positions by flying around in a multidimensional search space until a
relatively unchanged position has been encountered or the maximum number of complications
has been reached [22].
Eberhart and Jim Kennedy describe a swarm as an apparently disorganized collection of moving
individuals that tend to cluster together while each individual seems to be moving in a random
direction for instance schools of fish or flocks of birds.
Optimization is the art of achieving the best possible solution to a problem in which there are a
number of competing or conflicting parameters [10]
Optimization techniques, both traditional and modern can be classified into 3 major groups:
i) Conventional methods
ii) Intelligence search methods
iii) Non-quantity approaches to address uncertainties in objectives and constraints.
3
1.3. Conventional Methods
From the book, Conventional Optimization Techniques by Mark S. Hillier and Fredrick S. Hillier
[1], before solving an optimization model, it is important to consider the form and mathematical
properties of the objective function, constraints and decision variables. For instance, the
objective function might be linear or non-linear, differentiable or non-differentiable concave or
convex. The decision variables might be continuous or discrete. Those differences impact how
the model can be solved and hence are used to classify optimization techniques .under
conventional optimization methods we have the following:
The review of each and every method follows in the pages below:
The major unconstrained optimization methods used in power systems operations are the
gradient method, linear search, Lagrange multiplier, Newton-Raphson optimization,
trust region optimization, quasi-newton and conjugate gradient optimization.
The term unconstrained means that no restriction is placed on the range of x. It is important to
note that unconstrained approaches form the basis of constrained algorithms.
1.3.2 Linear programming (L.P)
This is a widely used method of solving power system operation problems such as optimal power
flow, reactive power optimization or even security constrained economic dispatch, as practical
operations show that this method generally meets the requirements of engineering precision.
Its main advantages are:
Reliable
Quickly identifies infeasibility
Accommodates a large variety of power system operating limits.
4
This technique basically linearizes the non-linear power system optimization problem so that the
objective function and the constraints of power system operation have linear forms.
Power systems operation problems are non-linear; hence this method can easily solve such
problems. NLP based methods have higher accuracy than LP methods.
This is a special form of non-linear programming where the objective function of the model is
quadratic and the constraints are in linear form. A good example is the generator cost function,
which is generally quadratic.
This is also called the second-order method as it requires the computation of the partial second
order derivatives of the power flow equations. It is favored for its quadratic convergence
properties.
This is generally used to solve linear programming problems as it is faster and perhaps better
than the simplex algorithm used in L.P.
This is mostly used to solve O.P.F problems, M.I.P methods mostly used are the recursive mixed
integer programming technique using an approximation method and the branch & bound (B&B)
method. This method is extremely demanding of computer resources.
This is a special linear programming method that is faster and has simpler calculations.
It is mainly used to solve simplified O.P.F problems such as security constrained, economic
dispatch and multi-area systems economic dispatch.
5
1.4. Intelligent Search Methods
It is a Multi-Agent System (MAS) that contains an environment, objects and agents, relations
between all the entities, a set of operation that can be performed by the entities and the changes
due to these actions.
This method was first to solve linear programming problems thou it has been extended to solve
non-linear programming problems in recent times. This method is different from the traditional
methods of optimization as it does change the solution of an optimization problem into an
equilibrium point (state) of non-linear dynamic system and changes the optimal criterion into
energy functions for dynamic systems.
This approach is mainly used to solve the classic economic dispatch, multi area systems
economic dispatch and the reactive power optimization.
Neural networks are modeled on the mechanism of the brain and hence the networks have the
ability to learn from examples and their tolerance to noise and damage is considerable.
Some of the methods that belong to this category include; evolutionary programming (EP);
evolutionary strategy (ES) and genetic algorithm (GA).
6
1.4.2.1 Genetic algorithm (GA)
This technique first appeared in the 1950s and early 1960s while biologists were explicitly
seeking the model of a natural evolution and hence we can say that this is a family of
computation models, inspired by evolution.
These algorithms encode a potential solution to a specific problem on a simple chromosome lie
data structure.
This method utilizes the operators of selection, crossover and mutation. Ideally, it combines
survival of the fittest among string structures with a structured; yet random information
exchange.
In every generation, a new set of artificially developed string is produced using elements of the
fittest of the old; an occasional new element is experimented with for enhancement.
Then, a starting population is built with random genes values and it evolves through several
generations in which selection, crossover and mutation are repeated until a satisfactory value has
been found or the maximum number of interactions has been reached.
The algorithm then identifies the individuals with optimizing fitness values while those with
lower fitness are discarded.
One limitation, however is that GA cannot ensure constant optimization response times;
therefore limiting its application in real time applications.
7
The above G.A process can be summarized as follows:
This is an interactive search algorithm characterized by use of flexible memory and mainly used
for solving combinatorial optimization problems. It eliminates the local mining and is able to
search areas beyond local minima.
This method works by the means of an evaluation function; that chooses the highest evaluation
situation at each interaction. It then selects the more that produces the most improvement or the
least deterioration in the objective function.
A tabu list is then employed to store the above information to be used for classification in later
interactions.
To avoid recycling, a forbidding strategy is used to control and update the tabu list to avoid
previously visited paths, hence the need for a flexible memory.
8
1.4.4. Ant colony optimization (A.C.O)
As the name suggests, this optimization method was inspired by the behavior of real ants.
The A.C.O algorithm forms part of the swarm intelligence algorithms with other being particle
swarm optimization and swarm robotics.
According to Marco Dorigo and Glanni Di Caro in their scholarly paper [6], the ant colony
optimization meta-heuristic, a colony of ants is able to succeed in its task to find the shortest path
between the next and the food by depositing a chemical substance trail, called pheromone on the
ground as they move.
This pheromone can then be observed by other ants and this motivates them to follow the path
with the highest probability hence, in this technique, simple agents called artificial ants are
created and mediated by an artificial pheromone trail.
This pheromone trail serves as distributed, numerical information which ants use to
probabilistically (by use of probability) construct solutions to the problem.
By this way the best solution has the highest levels of pheromone and hence a much higher
probability to be chosen.
This is a swarm intelligence algorithm inspired by social dynamics and an emergent behavior
that arises in socially organized colonies.
In this context, the population is called the swarm and the individuals are called the particles.
The particles change their positions by flying around in a multidimensional search space until a
relatively unchanged position has been encountered or the maximum number of complications
has been reached. Particle Swarm Optimization is reviewed in detail in Chapter 2.
Annealing is the physical process of heating up a solid and then cooling it down slowly until it
crystallizes. At high temperatures, the atoms have higher energies which decrease as the
temperature is reduced. At minimum energy, a crystal ball with regular structure is obtained.
In this method, if the cooling is done very quickly, then widespread defects and irregularities are
seen as opposed to slow cooling. We can then deduce and say that:
The state of the solid represents feasible solutions to the optimization problem, and the energies
of the state correspond to the values of the objective function.
9
The minimum energy state represents the optimal solution to the problem while rapid cooling
represents the local optimization.
This theory accounts for uncertainties in information and goals related to multiple and usually
conflicting objectives in power system optimization.
The satisfactory parameters (fully sets) for objectives and constraints represent the degree of
closeness to the optimum and the degree of enforcement of constraints respectively.
The main aim of this project is to understand optimal power system and come up with an
effective, robust and reliable Particle Swarm Optimization method (PSO) which will be used to
solve the Hydrothermal Economic Load Dispatch Problem.
Since the Optimization Technique to be used is the Particle Swarm Algorithm, PSO operation
and the operators involved are to be thoroughly understood. This knowledge will be used to write
a software program in MATLAB programming software package to solve the Hydrothermal
Economic Load Dispatch Problem.
The Matlab programme written is then to be tested on standard IEEE buses. Hence, in summary,
the objectives can be stated as follows:
10
1.7 Organization of the Report.
The project report has been organized into the following chapters:
Chapter 2 gives review of the Hydrothermal Economic Load Dispatch and Particle Swarm
Optimization method.
Chapter 3 formulates the Hydrothermal Economic load dispatch problem .Formulation of PSO
and its implementation is also discussed.
Chapter 4 documents the simulation results obtained from programming in MATLAB, for one
line diagram of IEEE 30 bus test network. Comparison of an all thermal system and a
hydrothermal system is also done and the results analyzed.
Chapter 5 contains the conclusions and the recommendations for further work.
11
CHAPTER 2
Literature Review
The Economic Load dispatch problem is also known as load scheduling. The optimal
scheduling of generation in a hydrothermal system involves the allocation of generation
among the hydroelectric and thermal plants so as to minimize the total operation costs of
thermal plants while satisfying the various constraints on the hydraulic and power system
network[11,20].
A hydrothermal system is usually more complex than the economic operation of an all thermal
system. This is due to:
The coordination of the operation of hydroelectric plants involves the scheduling of water release
where this can be grouped into two;
Long range scheduling –This is for hydro schemes with a capacity for impounding water
over several seasons. Typically, this ranges between one day to one week.
Short term scheduling- This involves the hour by hour scheduling of all generations on a
hydrothermal system to achieve minimum production cost (minimum consumption of
fuel) for the given period.
The below constraints also exist in a hydrothermal system and they end up making it even more
complex [15, 17, 20].
The time coupling effect of the hydro sub problem, where the water flow in an
earlier time
Intervals affects the discharge capability at a later period of time.
The time varying system long demand.
The cascade nature of the hydraulic network.
The varying hourly reservoir inflows.
The physical limitations on the reservoir storage and turbine flow rate and loading
limits of both thermal and hydro plants.
12
Further constraints could be depending on the particular requirements of a given power
system, such as the need to satisfy activities including, flood control, irrigation, fishing, or
water supply. [11]
This is the determination of the power output of each generating unit under the constraint
conditions of the system load demands so as to minimize the operating costs of the power
system; where the line security constraints are neglected.
The fundamental of the economic dispatch problem (ECD) is the set of input output
characteristics [8].
We will briefly analyze the input-output characteristics of thermal units and then combine both
hydro and thermal to obtain hydrothermal systems. For thermal units, the input-output
characteristic is called the generating unit fuel consumption function or simply operating cost
function.
The unit of the operating cost function is the BTU (British thermal unit) per hr. or MBtu/hr fuel.
{1Btu=0.29307107w}.
In addition to the fuel consumption costs, there are other additional cots like labor, maintenance
cost, fuel transportation cost that are represented by a constant C.
The thermal unit system generally consists of the boiler, the steam turbine and the generator; as
shown below [8].
13
Boiler Generator
Turbine
QinQin
Pump Condenser
WP Qout
Hence, the input-output characteristics of the whole generating unit system can be obtained by
directly combining the above; and it is a convex curve shown below.
14
Fig 2. 2 Input - output characteristic of a thermal generating unit.
.
From the curve above, the power output PG, is limited by:
Generally, the input-output characteristic equation of the generating unit is non-linear and is
given by:
Where the constant C, is the equivalent to the fuel consumption of the generating
unit operation without power output.
In practical however, we can easily obtain the fuel statistic data and power output static data
(FK, PK) and then use the least squares method to get the line of best fit [16].
15
Let (FK, PK) be obtained from the statistical data where k=1, 2……n and the fuel curve will be a
quadratic function. To determine the co-efficiency a, b and c, we compute the error for each data
pair [FK, PK]
This is the main equation from here you just multiply with PK to obtain the below equations:
16
2.3. Hydrothermal System Economic Dispatch
Operation of a system having both hydro and thermal plants is far more complex as hydro plants
have negligible operating cost, but are required to operate under constraints of water available
for hydro generation in a given period of time. Hence, this is a problem of dynamic optimization.
This problem of minimizing the operating cost of a hydrothermal system can be viewed as one
of minimizing the fuel cost of thermal plants under the constraint of water availability
(storage and inflow) for hydro generation over a given period of operation.[12]
J (inflow)
PGT PGH
PGT
Hydro plant
Thermal plant
PD
PGT
q (Discharge)
Fig 2. 3 :A Fundamental Hydrothermal System.
i) Equality constraints.
17
This non-linear constrained hydrothermal scheduling optimization problem is subjected to
a variety of constraints depending upon practical implications like the varying system load
demand or the time coupling effect of hydro subsystem as discussed below[11]:
This constraint is based on the principle of equilibrium between the total active power
generation from the hydro and thermal plants and the total system demand plus the system
losses in each time interval of scheduling.
Where;
The hydraulic operational constraints comprise the water balance (Continuity) equations for each
hydro unit (System) as well as the bounds on reservoir storage and release targets. These bounds
are determined by the physical reservoir and plant limitations as well as the multipurpose
requirements of the hydro system. These constraints include:
18
2.5 Particle Swarm Optimization
Particle swarm optimization is one of the most recent developments in the category of
combinatorial metaheuristic optimizations. This method has been developed under the scope
of artificial life where PSO is inspired by the natural phenomenon of fish schooling or
bird flocking.
PSO is basically based on the fact that in quest of reaching the optimum solution in a
multi-dimensional space, a population of particles is created whose present coordinate
determines the cost function to be minimized. After each iteration the new velocity and
hence the new position of each particle is updated on the basis of a summated influence of each
particle’s present velocity, distance of the particle from its own best performance, achieved
so far during the search process and the distance of the particle from the leading particle,
that is the particle which at present is globally the best particle producing till now the best
performance i.e. minimum of the cost function achieved so far.[11]
The set of neighbor connections between all of the particles forms the swarms topology
or sociometry [13,16] and affects the swarm’s exploitation and exploration behavior [13].
There have been two basic topologies used in the literature:
Ring Topology
Star Topology (global neighborhood).
Personal best (Pbest): The personal best position associated with ith particle is the best position
that the particle has visited yielding the highest fitness value for that particle.
Global best (Gbest): This is the best position associated with ith particle that any particle in the
swarm has visited yielding the highest fitness value for that particle. This represents the best
fitness of all the particles of a swarm at any point of time.
19
The optimization process uses a number of particles constituting a swarm that moves around a
pre-defined search space looking for the best solution. Each particle is treated as a point in the D-
dimensional space in which the particle adjusts its “flying” according to its own flying
experience as well as the flying experience of other neighbouring particles of the swarm. Each
particle keeps track of its coordinates in the pre-defined space which are associated with the best
solution (fitness) that it has achieved so far. This value is called Pbest. Another best value that is
tracked by the PSO is the best value obtained so far by any particle in the whole swarm. This
value is called Gbest.
The concept consists of changing the velocity of each particle toward its Pbest and the Gbest
position at the end of every iteration. Each particle tries to modify its current position and
velocity according to the distance between its current position and Pbest, and the distance
between its current position and Gbest.
Swarm size or population size is the number of particles n in the swarm. A big swarm generates
larger parts of the search space to be covered per iteration. A large number of particle may
reduce the number of iterations need to obtain a good optimization result. In contrast, huge
amounts of particles increase the computational complexity per iteration, and more time
consuming.
This is an important parameter in PSO and typically the only one adjusted. It is important since it
clamps particles velocities on each dimension and determines ‘fineness’ with which regions are
searched [16].
Large values of Vmax could result in particles moving past optimal solutions,
Small values could result in insufficient exploration of the search space.
This lack of a control mechanism for the velocity resulted in low efficiency whereby PSO
located the area of the optimum faster than techniques, but once in the region of the optimum, it
could not adjust its velocity step size to continue the search at a finer grain. This has since been
rectified by incorporating an inertia weight [19].
20
2.5.2.3 Inertia Weight
This helps in controlling the PSO convergence behavior. It controls the impact of the previous
history of velocities on the current one.[16] Suitable selection of inertia weight provides a
balance between global and local explorations, thus requiring less iteration on an average to find
a sufficiently optimal solution.
From experiments conducted by Shi and Eberhart, W decreases linearly from about 0.9 to 0.4
quite often during a run, and hence the following weighing function is used.
Iter max
Where;
The inertia constant can be either implemented as a fixed value or can be dynamically changing.
Essentially, this parameter controls the exploration of the search space, therefore an initially
higher value (typically 0.9) allows the particles to move freely in order to find the global
optimum neighborhood fast. Once the optimal region is found, the value of the inertia weight can
be decreased (usually to 0.4) in order to narrow the search, shifting from an exploratory mode to
an exploitative mode.
However, one main disadvantage of the inertia method is that once the inertia weight is
decreased, the swarm loses its ability to search new areas because it is not able to recover its
exploration mode. This led to the use of the constriction factor to alternatively limit velocity.
Constriction factor controls the magnitude of the velocities in a way similar to Vmax parameter,
resulting in a variant of PSO, different with the one for inertia weight.
This method was developed by Clerc and Kennedy. Ideally, in general, the constriction factor
improves the convergence of the particle over time by damping the oscillations once the
particle is focused on the best point in an optimal region.
The main disadvantage, however, of this method is that the particles may follow wider cycles
and may not converge when the individual best performance is far from the
neighborhood’s best performance.
21
CHAPTER 3
For a certain period of operation T (which can be one year, one month or one day, depending
upon the requirement), it is assumed that:
(i) Storage of hydro reservoir at the reservoir at the beginning and the end are specified.
(ii) Water inflow to reservoir (after accounting for irrigation use) and load demand on the
system are known as functions of time with complete certainty (deterministic case).
The main aim here is to achieve minimum production cost (or minimum consumption fuel) for
the given time period.
Let PT; F (PY) be the power output and input-output characteristics of a hydro-electric plant.
Then, the hydrothermal system economic dispatch problem can be expressed as:
𝑇
Min F∑= ∫0 𝐹[𝑃𝑇 (𝑡) ]……….. (Objective Function) (3.1)
S.t;
PH(t) + PT(t) - P∆(t) = 0 (3.1.1)
𝑇
∫0 𝑊[𝑃𝐻(𝑡) 𝑑𝑡] − 𝑊∑=0 (3.1.2)
Equation 3.1 is the objective function for the hydrothermal system economic discharge.
The integration sign, from 0 to T covers the hydro part of the dispatch problem as it enables us to
divide the operating period into time stages, either hourly or an interval of one’s own choice
.This may result in short-term hydrothermal dispatch if the planning task is done for just a day or
long term if the planning is done over a longer period of time.
22
As the source for hydropower is the natural water resources, the operational cost of hydroelectric
plants is insignificant. Thus, the objective of minimizing the operational cost of a hydrothermal
system essentially reduces to minimize the fuel cost of thermal plants, which is also covered in
Equation 3.1(denoted as 𝐹[𝑃𝑇 (𝑡) ]) where F denotes the cost of fuel of the thermal plants.
𝑇
Hence, equation 3.1, Min F∑= ∫0 𝐹[𝑃𝑇 (𝑡) ], fully covers for both the hydro and thermal part
of the hydrothermal economic dispatch problem.
The active power transmission losses may amount to 20 to 30% of the total load demand, ideally,
the exact power flow equations should be used to obtain the active power transmission losses in
the system, however, and the electric power system engineer may use OPF for expressing the
losses in terms of power generations only.
One common practice for including the effect of transmission losses is to express the total
transmission loss as a quadratic function of the generator power outputs in one of the following
forms according to Daniel S. Kirschen,2004[24].
Simple form:
N N
PL p i Bij p j (3.2)
i 1 j 1
For hydrothermal economic dispatch, being a relatively new problem, one has to calculate the
generator losses using Kron’s loss formula.The B coefficients used in this paper were adapted
from an International Journal, Improved Particle Swarm Optimization Algorithm for
Hydrothermal Generation Scheduling [20] and were obtained using Kron’s loss formula.
23
A review of the formula is given below:
Bij are called the loss coefficients, which are assumed to be constant for a base range of loads,
and reasonable accuracy is expected when actual operating conditions are close to the base case
conditions used to compute the coefficients. The economic dispatch problem is to minimize the
overall generation cost, C, which is a function of plant output, constrained by:
Each plant output is within the upper and lower generation limits inequality constraints.
Mathematically:
N N
F : Ctotal Ci ai bi pi ci pi2 (3.3.2)
i 1 i 1
N
g: pi PD PL (3.3.3)
i 1
N
N
L Ctotal PD PL pi i (max) ( pi (max) pi )
i 1 i 1
N
i (min) ( pi pi (min) ) (3.3.5)
i 1
pi pi (max) : i (max) 0 pi pi (min) : i (min) 0
24
The effect of transmission losses introduces a penalty factor that depends on the location of the
plant. The minimum cost is obtained when the incremental cost of each plant multiplied by its
penalty factor is the same for all plants.
The incremental transmission loss is obtained from Kron’s loss formula as,
PL N
(3.3.6)
2 Bij p j Boi
p i j 1
dC i
bi 2c i p i (3.3.7)
dp i
Further substitution equation of equations (3.3.6) and (3.3.7) when generator limits are not
constrained yields:
dC i P N
L bi 2ci p i 2 Bij p j Boi (3.3.8)
dpi p i j 1
ci N 1 b (3.3.9)
Bii p i Bij p j 1 Boi i
j 1 2
j i
And extending equation (3.3.9) for all plants results in the following linear equations (in matrix
form),
c1 b1
B11 B12 B1N p1 1 Bo1 (3.3.10)
b2
B2 N p 2 1 1 B02
c2
B21 B22
2
p
N B NN N
c b
B N 1 BN 2 1 BoN N
(1)
To find the optimal dispatch for in estimated value of λ ,the simultaneous linear equation
given by (25) is solved. In MATLAB, the command P=E \ D is used.
25
3.3 Formulation of P.S.O
Let X and V denote a particle position and its corresponding velocity in a search space,
respectively.
The best previous known positions of the ith particle recorded are presented as Pbest1, Pbest2 ,
Pbest3, and the best particle among all the particles is represented by Gbestd.
Hence, the modified velocity and the position of each particle can be calculated by using the
current velocity and the distance from Pbestd to Gbestd as shown in the formulas below:
Equations (3.4) and (3.5) are the initial version of PSO where no actual mechanism for
controlling the velocity of a particle, maximum value Vmax was imposed.
This lack of a control mechanism for the velocity resulted in low efficiency for PSO[19] and the
problem was addressed by incorporating a weight for the previous velocity of the
particle.
Thus in the largest versions of PSO, equations (3.6) and (3.7) below are now used.
V n+1id= k {wv nid +c1r1 (p nid – x nid) +c2r2 2 id (p ngd – x nid) (3.6)
26
Where: w = inertia weight
Hence, equation (3.6) has three important parts and can be analyzed as follows:
The first component is referred to as “inertia,” .It models the tendency of the particle to
continue in the same direction it has been traveling. This component can be scaled by a
constant as in the modified versions of PSO.
The second component is a linear attraction towards the best position ever found by the
given particle, whose corresponding fitness value is called the particle’s best (Pbest)
scaled by a random weight (c1r1) .This component is referred to as “memory,” or
“remembrance.”
The third component of the velocity update equation is a linear attraction towards the
best position found by any particle, whose corresponding fitness value is called global
best(Gbest) scaled by another random weight (c2r2 ) .This component is referred to as
“cooperation,” “social knowledge, “or “shared information.”
‘N’ is number of generating units. Population is initialized with random values and velocities
within the d-dimensional search space.
27
5) Compare the particle’s fitness evaluation with its previous P-best. If the current value
is better than the previous P-best, then set the P-best value equal to the current value
and the P-best location equal to the current location in the d-dimensional search
space.
6) Compare the best current fitness evaluation with the population G-best. If the current
value is better than the population G-best, then reset the G-best to the current best
position and the fitness value to current fitness value.
7) Repeat steps (2-5) until a stopping criterion, such as sufficiently good G-best
fitness or a maximum number of iterations/function evaluations is met.
28
3.5 Flow Chart
START
Iter=0
Iteration iter=iter+1
Measureme
Calculate fitness for each
nt data
population
If pbest(i)>fitnesspbest(i-1)
Y
N Pbest (i)=pbest(i-1)
O Pbest(i)=pbest(i)
Next Iteration
Compute gbesst
Y
If gbest(i)>gbest(i-1) Gbest(i)=gbest(i--1)
N
N
O Gbest(i)=gbest(i)
O
29
END
CHAPTER 4
Comparison was done between a whole thermal system and a hydrothermal system, both being
30 bus and having six generating units. For the hydrothermal system, the coefficients were
obtained from a respected journal [20], the results having been experimentally obtained.
30
Table 4. 1 : Thermal System Generator Coefficients
31
Table 4. 4 : B-Coefficient Matrix, Hydrothermal System
0.0005 0 0 0 0 0
0 0.0003 0 0 0 0
0 0 0.0004 0 0 0
0 0 0 0.00004 0 0
0 0 0 0 0. 0005 0
0 0 0 0 0 0.00025
PSO was applied to the above system for obtaining economic load dispatch of various loads.
32
Table 4. 6 : Optimal scheduling of a 6-unit system, 3 Hydro and 3 Thermal Generators by PSO
Method (Loss included).
Table 4. 7: Comparison of optimal power output for both thermal and hydrothermal system
(Load=600MW)
HYDROTHERMAL
THERMAL GENERATION GENERATION
LOWE ACTUAL LOWE ACTUAL
GENERAT R UPPER GENERATION R UPPER GENERATION
OR NO. LIMIT LIMIT (MW) LIMIT LIMIT (MW)
P1 10 125 28.8603 12 126 125.9723
P2 10 150 10.0000 20 180 153.1651
P3 35 225 95.6395 30 240 240.0000
P4 35 210 100.7082 50 200 50.00000
P5 130 325 202.8315 40 170 40.00000
P6 125 315 181.1979 30 215 30.00000
TOTAL
GENERATI
ON 614.2373 639.137
LOSSES 14.2373 39.137
GENERAT
OR COST 36,912.00 543.7079
33
4.3 Analysis and Discussion
For analysis, a power generation of 600mW for both thermal and hydrothermal systems was
considered.
THERMAL
350
300
Power Generated
250
200
150
100
50
0
P1 P2 P3 P4 P5 P6
GEN. LOWER LIMIT 10 10 35 35 130 125
GEN. UPPER LIMIT 125 150 225 210 325 315
ACTUAL GENERATION 28.8603 10 95.6395 100.7082 202.8315 181.1979
HYDROTHERMAL
300
250
Power Generated
200
150
100
50
0
P1 P2 P3 P4 P5 P6
GEN. LOWER LIMIT 12 20 30 50 40 30
GEN. UPPER LIMIT 126 180 240 200 170 215
ACTUAL GENERATION 125.9723 153.1651 240 50 40
34
From figure 4.3, which shows the hydrothermal optimum generation, we can clearly see that the
first three generators, which are hydro generators are fully utilized, almost to their upper limits.
However the reverse is true for the next three thermal generators. The thermal generators
produce minimum amount of power, almost corresponding to their lower limit. This means that
the thermal generators are just in operation to cater for the fixed cost, c, which must be incurred
regardless of the progress.
From figure 4.2, which shows thermal optimum generation, the actual generation has an even
trend that is equally influenced by both the upper and lower limits of the generators.
4.3.1: Case Study: 600mw Case For both Thermal and Hydrothermal System
Both the hydrothermal and thermal system was interconnected to serve the same load of 600MW
and the results obtained are discussed below;
250
200
150
100
50
0
P1 P2 P3 P4 P5 P6
THERMAL 28.8603 10 95.6395 100.7082 202.5315 181.1979
HYDROTHERMAL 125.9723 153.1651 240 50 40 30
From the figure above, hydro generation was found to serve the base load. From power flow
studies, the most efficient or the cheapest is used to supply the base load.
In this case, hydro power is used to supply the base load as it is very cheap compared to thermal
which is used to supply the peak load.
35
4.3.2: Convergence Characteristics of the PSO Method for 30 Bus system.
Fig 4. 5: Convergence Characteristics for 30 bus hydrothermal generating system. (700 MW)
Fig 4. 6: Convergence Characteristics for 30 bus all thermal generating system. (700 MW)
36
4.3.2: Power Losses
30
25
20
15
10
5
0
570 600 700 800
POWER LOSS(KW) 36.3905 39.1374 43.3785 45.7943
25
20
Power Loss
15
10
0
570 600 700 800
THERMAL POWER LOSS(MW) 12.8441 14.2373 19.4319 25.3309
37
CHAPTER 5
5.1.1 Conclusion
This project applied PSO for the solution of Hydrothermal Economic Dispatch. The objectives of
the project were to combine the thermal economic dispatch in literature with the hydro ones.
.This was successfully done and the proposed algorithm successfully tested on IEEE 30-bus
system and the results obtained have been validated using results from published work.
Hydrothermal power was found to be much cheaper as compared to an all thermal system and
hence was subsequently used to cover the base load. This is because the source for hydropower
is the natural water resources, which is almost freely available, and hence the operational cost of
hydroelectric plants is insignificant.
For a power demand of 700MW the thermal cost was Rs/Hr 36,912.00 .For the same demand of
700MW, using the hydrothermal system, the cost decreased very significantly to Rs/Hr
647.35.This large variance in cost is due to the very high costs of the fuels used in thermal
station making it expensive to operate. Above all, hydro power is also clean as it does not also
produce emissions, hence conserves the environment.
The hydrothermal system converges to an optimum solution much later than the thermal system,
in this case, slightly after 100 iterations. This can be attributed to the dynamic nature of the
hydrothermal system, hence taking longer to converge to an optimum value.
5.1.2 Recommendation
This paper focused on the economic dispatch for hydrothermal systems, having combined both
hydro and thermal ones. This, being a relatively new area of study, important material is scarce
to come across and future works into the subject should consider:
Carrying out conclusive analysis for different IEEE buses, determining their generator
and loss coefficients. Even though this would be difficult due to the cascade nature of the
hydraulic network, the varying hourly reservoir inflows, and the different physical
limitations on the reservoir storage, it would go a long way in advancing this area of
study.
38
REFERENCES
[1] “Conventional Optimization Techniques”, Mark S. Hillier, Fredrick S. Hillier
[2] “Modern Power Systems Analysis” PG 276-284,D.P Kothari and I.J Nagrath
Mc Graw Hill Education Ltd, 3rd Edition.
[6] “The Ant Colony Meta –Heuristic Scholarly Paper “,Marco Dorigo & Gianni D. Caro
University of Bruxelles.
.
[11] “P.S.O based short term Hydrothermal Scheduling with prohibited discharge zones”,
( IJACSA) International Journal of Advanced Computer Science and Applications, Vol. 2,
Issue No. 9, 2011
[12] “Modern Power Systems Analysis”, D.P Kothari &Nagrath, Tata McGraw Hill
Education Private Limited, 3rdEdition, 2003.
39
[13] “ A Modified Particle Swarm Optimizer”, Shi Y, Eberhart R in Evolutionary Computation
Proceedings , 1998 IEEE World Congress on Computational Intelligence(Pp. 69-73)
[15] “ Power Generation Scheduling for Multiarea Hydrothermal power systems with Tie-line
constraints, cascaded reservoirs and uncertain data”, Wang C Shahidehpour S.M
IEEE Trans,PWRS Vol 8,No. 3 Pg. 1333-1340
[18] “Particle Swarm Optimization: developments, applications and Energy Conversion and
Management 2008; R.C Eberhart and Y. Shi, vol-49, pp2966–2972.
[19] “Abido MA, “Multi-objective Evolutionary algorithms for Electric power dispatch problem”, IEEE
Transactions on Evolutionary computation; 2006, vol-10(3), pp315-329.
[20] “Improved Particle Swarm Optimization Algorithm for Hydrothermal Generation Scheduling.”
Deepika Yadav, R. Naresh and Sharma
[21] “A review of recent advanced in Economic Dispatch.” IEEE Transaction on Power System,
vol.5 No.4 November 1990.
[22] “Hybrid Particles Swarm Optimization for solving Multi Area Economic Dispatch problem.” IJSC
vol.4 No.2 May 2013
[23] “Introduction to Genetic Algorithms.” N. Sivanandam & SN Deepa, Spring verlag Berlin Heldelberg.
[25] “Thermal Economic Dispatch using PSO” Danson Muthiani, The University of Nairobi
40
APPENDICES
%Thermal code
% the data matrix should have 5 columns of fuel cost coefficients and plant
limits.
41
APPENDIX 2: Program for the Hydrothermal Economic Dispatch.
%Hydrothermal code
% the data matrix should have 5 columns of fuel cost coefficients and plant
limits.
% 1.a ($/MW^2) 2. b $/MW 3. c ($) 4.lower lomit(MW) 5.Upper limit(MW)
%no of rows denote the no of plants(n)
clear
clc;
format long;
global data B Pd
data=[0.00001829 0.187 1.423 12 126;
0.0000203 0.198 1.714 20 180;
0.0000192 0.149 1.055 30 240;
0.01 0.1 100 50 200;
0.02 0.1 120 40 170;
0.01 0.1 150 30 215;
]
B=[0.0005 0 0 0 0 0;
0 0.0003 0 0 0 0;
0 0 0.0004 0 0 0;
0 0 0 0.00004 0 0;
0 0 0 0 0.0005 0;
0 0 0 0 0 0.00025];
Pd=600;
l=data(:,4)';
u=data(:,5)';
ran=[l' u'];
n=length(data(:,1));
Pdef = [50 1000 100 2 2 0.9 0.4 1500 1e-6 5000 NaN 0 0];
[OUT]=pso_Trelea_vectorized('psoeld',n,1,ran,0,Pdef);
out=abs(OUT)
P=out(1:n)
[F P Pl]=psoeld(P')
42
APPENDIX 3: Code for plotting the Convergence Characteristics.
% goplotpso.m
% default plotting script used in PSO functions
%
% this script is not a function,
% it is a plugin for the main PSO routine (pso_Trelea_vectorized)
% so it shares all the same variables, be careful with variable names
% when making your own plugin
% Brian Birge
% Rev 2.0
% 3/1/06
plot3(pos(:,1),pos(:,D),out,'b.','Markersize',7)
hold on
plot3(pbest(:,1),pbest(:,D),pbestval,'g.','Markersize',7);
plot3(gbest(1),gbest(D),gbestval,'r.','Markersize',25);
% crosshairs
offx = max(abs(min(min(pbest(:,1)),min(pos(:,1)))),...
abs(max(max(pbest(:,1)),max(pos(:,1)))));
offy = max(abs(min(min(pbest(:,D)),min(pos(:,D)))),...
abs(min(max(pbest(:,D)),max(pos(:,D)))));
plot3([gbest(1)-offx;gbest(1)+offx],...
[gbest(D);gbest(D)],...
[gbestval;gbestval],...
'r-.');
plot3([gbest(1);gbest(1)],...
[gbest(D)-offy;gbest(D)+offy],...
[gbestval;gbestval],...
'r-.');
hold off
xlabel('Dimension 1','color','y')
ylabel(['Dimension ',num2str(D)],'color','y')
zlabel('Cost','color','y')
title('Particle Dynamics','color','w','fontweight','bold')
set(gca,'Xcolor','y')
43
set(gca,'Ycolor','y')
set(gca,'Zcolor','y')
set(gca,'color','k')
% camera control
view(2)
try
axis([gbest(1)-offx,gbest(1)+offx,gbest(D)-offy,gbest(D)+offy]);
catch
axis([VR(1,1),VR(1,2),VR(D,1),VR(D,2)]);
end
if D==1
titstr1=sprintf(['%11.6g = %s( [ %9.6g ] )'],...
gbestval,strrep(functname,'_','\_'),gbest(1));
elseif D==2
titstr1=sprintf(['%11.6g = %s( [ %9.6g, %9.6g ] )'],...
gbestval,strrep(functname,'_','\_'),gbest(1),gbest(2));
elseif D==3
titstr1=sprintf(['%11.6g = %s( [ %9.6g, %9.6g, %9.6g ] )'],...
gbestval,strrep(functname,'_','\_'),gbest(1),gbest(2),gbest(3));
else
titstr1=sprintf(['%11.6g = %s( [ %g inputs ] )'],...
gbestval,strrep(functname,'_','\_'),D);
end
title(titstr1,'color','m','fontweight','bold');
grid on
% axis tight
set(gca,'Xcolor','y')
set(gca,'Ycolor','y')
set(gca,'Zcolor','y')
set(gca,'color','k')
set(gca,'YMinorGrid','off')
44
PSOtype = (['Trelea Type ',num2str(trelea)]);
xtraname = ' ';
xtraval = ' ';
elseif trelea==3
PSOtype = (['Clerc Type 1"']);
xtraname = '\chi value : ';
xtraval = num2str(chi);
end
if isnan(errgoal)
errgoalstr='Unconstrained';
else
errgoalstr=num2str(errgoal);
end
if minmax==1
minmaxstr = ['Maximize to : '];
elseif minmax==0
minmaxstr = ['Minimize to : '];
else
minmaxstr = ['Target to : '];
end
if rstflg==1
rststat1 = 'Environment Change';
rststat2 = ' ';
else
rststat1 = ' ';
rststat2 = ' ';
end
text(.1,1,[titstr{1,1},titstr{1,2}],'color','g','fontweight','bold');
hold on
text(.1,.9,[titstr{2,1},titstr{2,2}],'color','m');
text(.1,.8,[titstr{3,1},titstr{3,2}],'color','m');
text(.1,.7,[titstr{4,1}],'color','w');
text(.55,.7,[titstr{4,2}],'color','m');
text(.1,.6,[titstr{5,1},titstr{5,2}],'color','m');
text(.1,.5,[titstr{6,1},titstr{6,2}],'color','w','fontweight','bold');
text(.1,.4,[titstr{7,1},titstr{7,2}],'color','r','fontweight','bold');
45
Sn(lyrcnt) = net.layers{lyrcnt}.dimensions;
hiddlyrstr = [hiddlyrstr,', ',TF{lyrcnt}];
end
hiddlyrstr = hiddlyrstr(3:end);
end
hold off
set(gca,'color','k');
set(gca,'visible','off');
drawnow
46
% pso_Trelea_vectorized.m
% a generic particle swarm optimizer
% to find the minimum or maximum of any
% MISO matlab function
%
% Implements Common, Trelea type 1 and 2, and Clerc's class 1". It will
% also automatically try to track to a changing environment (with varied
% success - BKB 3/18/05)
%
% This vectorized version removes the for loop associated with particle
% number. It also *requires* that the cost function have a single input
% that represents all dimensions of search (i.e., for a function that has 2
% inputs then make a wrapper that passes a matrix of ps x 2 as a single
% variable)
%
% Usage:
% [optOUT]=PSO(functname,D)
% or:
% [optOUT,tr,te]=...
% PSO(functname,D,mv,VarRange,minmax,PSOparams,plotfcn,PSOseedValue)
%
% Inputs:
% functname - string of matlab function to optimize
% D - # of inputs to the function (dimension of problem)
%
% Optional Inputs:
% mv - max particle velocity, either a scalar or a vector of length D
% (this allows each component to have it's own max velocity),
% default = 4, set if not input or input as NaN
%
% VarRange - matrix of ranges for each input variable,
% default -100 to 100, of form:
% [ min1 max1
% min2 max2
% ...
% minD maxD ]
%
% minmax = 0, funct minimized (default)
% = 1, funct maximized
% = 2, funct is targeted to P(12) (minimizes distance to errgoal)
% PSOparams - PSO parameters
% P(1) - Epochs between updating display, default = 100. if 0,
% no display
% P(2) - Maximum number of iterations (epochs) to train, default = 2000.
% P(3) - population size, default = 24
%
% P(4) - acceleration const 1 (local best influence), default = 2
% P(5) - acceleration const 2 (global best influence), default = 2
% P(6) - Initial inertia weight, default = 0.9
% P(7) - Final inertia weight, default = 0.4
% P(8) - Epoch when inertial weight at final value, default = 1500
% P(9)- minimum global error gradient,
% if abs(Gbest(i+1)-Gbest(i)) < gradient over
% certain length of epochs, terminate run, default = 1e-25
% P(10)- epochs before error gradient criterion terminates run,
% default = 150, if the SSE does not change over 250 epochs
47
% then exit
% P(11)- error goal, if NaN then unconstrained min or max, default=NaN
% P(12)- type flag (which kind of PSO to use)
% 0 = Common PSO w/intertia (default)
% 1,2 = Trelea types 1,2
% 3 = Clerc's Constricted PSO, Type 1"
% P(13)- PSOseed, default=0
% = 0 for initial positions all random
% = 1 for initial particles as user input
%
% plotfcn - optional name of plotting function, default 'goplotpso',
% make your own and put here
%
% PSOseedValue - initial particle position, depends on P(13), must be
% set if P(13) is 1 or 2, not used for P(13)=0, needs to
% be nXm where n<=ps, and m<=D
% If n<ps and/or m<D then remaining values are set random
% on Varrange
% Outputs:
% optOUT - optimal inputs and associated min/max output of function, of
form:
% [ bestin1
% bestin2
% ...
% bestinD
% bestOUT ]
%
% Optional Outputs:
% tr - Gbest at every iteration, traces flight of swarm
% te - epochs to train, returned as a vector 1:endepoch
%
% Example: out=pso_Trelea_vectorized('f6',2)
% Brian Birge
% Rev 3.3
% 2/18/06
function [OUT,varargout]=pso_Trelea_vectorized(functname,D,varargin)
rand('state',sum(100*clock));
if nargin < 2
error('Not enough arguments.');
end
% PSO PARAMETERS
if nargin == 2 % only specified functname and D
VRmin=ones(D,1)*-100;
VRmax=ones(D,1)*100;
VR=[VRmin,VRmax];
minmax = 0;
P = [];
mv = 4;
plotfcn='goplotpso';
elseif nargin == 3 % specified functname, D, and mv
VRmin=ones(D,1)*-100;
VRmax=ones(D,1)*100;
48
VR=[VRmin,VRmax];
minmax = 0;
mv=varargin{1};
if isnan(mv)
mv=4;
end
P = [];
plotfcn='goplotpso';
elseif nargin == 4 % specified functname, D, mv, Varrange
mv=varargin{1};
if isnan(mv)
mv=4;
end
VR=varargin{2};
minmax = 0;
P = [];
plotfcn='goplotpso';
elseif nargin == 5 % Functname, D, mv, Varrange, and minmax
mv=varargin{1};
if isnan(mv)
mv=4;
end
VR=varargin{2};
minmax=varargin{3};
P = [];
plotfcn='goplotpso';
elseif nargin == 6 % Functname, D, mv, Varrange, minmax, and psoparams
mv=varargin{1};
if isnan(mv)
mv=4;
end
VR=varargin{2};
minmax=varargin{3};
P = varargin{4}; % psoparams
plotfcn='goplotpso';
elseif nargin == 7 % Functname, D, mv, Varrange, minmax, and psoparams,
plotfcn
mv=varargin{1};
if isnan(mv)
mv=4;
end
VR=varargin{2};
minmax=varargin{3};
P = varargin{4}; % psoparams
plotfcn = varargin{5};
elseif nargin == 8 % Functname, D, mv, Varrange, minmax, and psoparams,
plotfcn, PSOseedValue
mv=varargin{1};
if isnan(mv)
mv=4;
end
VR=varargin{2};
minmax=varargin{3};
P = varargin{4}; % psoparams
plotfcn = varargin{5};
PSOseedValue = varargin{6};
49
else
error('Wrong # of input arguments.');
end
df = P(1);
me = P(2);
ps = P(3);
ac1 = P(4);
ac2 = P(5);
iw1 = P(6);
iw2 = P(7);
iwe = P(8);
ergrd = P(9);
ergrdep = P(10);
errgoal = P(11);
trelea = P(12);
PSOseed = P(13);
% error checking
if ((minmax==2) & isnan(errgoal))
error('minmax= 2, errgoal= NaN: choose an error goal or set minmax to 0
or 1');
end
if exist('PSOseedValue')
tmpsz=size(PSOseedValue);
if D < tmpsz(2)
error('PSOseedValue column size must be D or less');
end
if ps < tmpsz(1)
error('PSOseedValue row length must be # of particles or less');
end
end
50
plotflg=1;
else
plotflg=0;
end
% PLOTTING
message = sprintf('PSO: %%g/%g iterations, GBest = %%20.20g.\n',me);
51
% this works for straight minimization
[gbestval,idx1] = min(pbestval);
elseif minmax==2
% this works when you know target but not direction you need to go
% good for a cost function that returns distance to target that can be
either
% negative or positive (direction info)
[temp,idx1] = min((pbestval-ones(size(pbestval))*errgoal).^2);
gbestval = pbestval(idx1);
end
% this part used for implementing Carlisle and Dozier's APSO idea
% slightly modified, this tracks the global best as the sentry whereas
% their's chooses a different point to act as sentry
% see "Tracking Changing Extremea with Adaptive Particle Swarm Optimizer",
% part of the WAC 2002 Proceedings, June 9-13, http://wacong.com
sentryval = gbestval;
sentry = gbest;
if (trelea == 3)
% calculate Clerc's constriction coefficient chi to use in his form
kappa = 1; % standard val = 1, change for more or less constriction
if ( (ac1+ac2) <=4 )
chi = kappa;
else
psi = ac1 + ac2;
chi_den = abs(2-psi-sqrt(psi^2 - 4*psi));
chi_num = 2*kappa;
chi = chi_num/chi_den;
end
end
out = feval(functname,[pos;gbest]);
outbestval = out(end,:);
52
out = out(1:end-1,:);
%assignin('base','bestpos',bestpos(i,1:D+1));
%------------------------------------------------------------------------
% this section does the plots during iterations
if plotflg==1
if (rem(i,df) == 0 ) | (i==me) | (i==1)
fprintf(message,i,gbestval);
cnt = cnt+1; % count how many times we display (useful for movies)
if chkdyn==1
threshld = 0.05; % percent current best is allowed to change, .05 = 5%
etc
letiter = 5; % # of iterations before checking environment, leave at
least 3 so PSO has time to converge
outorng = abs( 1- (outbestval/gbestval) ) >= threshld;
samepos = (max( sentry == gbest ));
53
gbestval = pbestval(idx1);
end
gbest = pbest(idx1,:);
sentryval = gbestval;
sentry = gbest;
[iterbestval,idx1] = min(pbestval);
[iterbestval,idx1] = max(pbestval);
if gbestval <= iterbestval
gbestval = iterbestval;
gbest = pbest(idx1,:);
% used with trainpso, for neural net training
% assign gbest to net at each iteration, these interim
assignments
% are for plotting mostly
if strcmp(functname,'pso_neteval')
net=setx(net,gbest);
end
54
end
elseif minmax == 2 % this won't work as it is, fix it later
egones = errgoal*ones(ps,1); % vector of errgoals
sqrerr2 = ((pbestval-egones).^2);
sqrerr1 = ((out-egones).^2);
[tempi,dum] = find(sqerr1 <= sqrerr2); % find particles closest
to targ
pbestval(tempi,1) = out(tempi,1); % update pbestvals
pbest(tempi,:) = pos(tempi,:); % update pbest positions
%gbest_pred(i,:)=gbest;
%assignin('base','gbest_pred',gbest_pred);
%PSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSO
55
rannum1 = rand([ps,D]); % for Trelea and Clerc types
rannum2 = rand([ps,D]);
if trelea == 2
% from Trelea's paper, parameter set 2
vel = 0.729.*vel... % prev vel
+1.494.*rannum1.*(pbest-pos)... % independent
+1.494.*rannum2.*(repmat(gbest,ps,1)-pos); % social
elseif trelea == 1
% from Trelea's paper, parameter set 1
vel = 0.600.*vel... % prev vel
+1.700.*rannum1.*(pbest-pos)... % independent
+1.700.*rannum2.*(repmat(gbest,ps,1)-pos); % social
elseif trelea ==3
% Clerc's Type 1" PSO
vel = chi*(vel... % prev vel
+ac1.*rannum1.*(pbest-pos)... % independent
+ac2.*rannum2.*(repmat(gbest,ps,1)-pos)) ; % social
else
% common PSO algo with inertia wt
% get inertia weight, just a linear funct w.r.t. epoch parameter iwe
if i<=iwe
iwt(i) = ((iw2-iw1)/(iwe-1))*(i-1)+iw1;
else
iwt(i) = iw2;
end
% random number including acceleration constants
ac11 = rannum1.*ac1; % for common PSO w/inertia
ac22 = rannum2.*ac2;
if posmaskmeth == 1
% this is the saturation method
pos = ( minposmask_throwaway.*posmaskmin ) + ( minposmask_keep.*pos
);
56
pos = ( maxposmask_throwaway.*posmaskmax ) + ( maxposmask_keep.*pos
);
elseif posmaskmeth == 2
% this is the wraparound method
pos = ( minposmask_throwaway.*posmaskmax ) + ( minposmask_keep.*pos
);
pos = ( maxposmask_throwaway.*posmaskmin ) + ( maxposmask_keep.*pos
);
elseif posmaskmeth == 3
% this is the bounce method, particles bounce off the boundaries
with -vel
pos = ( minposmask_throwaway.*posmaskmin ) + ( minposmask_keep.*pos
);
pos = ( maxposmask_throwaway.*posmaskmax ) + ( maxposmask_keep.*pos
);
%PSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSO
% check for stopping criterion based on speed of convergence to desired
% error
tmp1 = abs(tr(i) - gbestval);
if tmp1 > ergrd
cnt2 = 0;
elseif tmp1 <= ergrd
cnt2 = cnt2+1;
if cnt2 >= ergrdep
if plotflg == 1
fprintf(message,i,gbestval);
disp(' ');
disp(['--> Solution likely, GBest hasn''t changed by at least ',...
num2str(ergrd),' for ',...
num2str(cnt2),' epochs.']);
eval(plotfcn);
end
break
end
end
if plotflg == 1
fprintf(message,i,gbestval);
disp(' ');
disp(['--> Error Goal reached, successful termination!']);
57
eval(plotfcn);
end
break
end
eval(plotfcn);
end
break
end
end % end if minmax==2
end % end ~isnan if
return
58