Optimal Dispatch Ot Genrating Units

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 70

UNIVERSITY OF NAIROBI

FACULTY OF ENGINEERING
DEPARTMENT OF ELECTRICAL AND INFORMATION
ENGINEEERING

HYDROTHERMAL ECONOMIC DISPATCH


USING PARTICLE SWARM OPTIMIZATION (P.S.O)
PROJECT INDEX: 055
SUBMITTED BY
KENNEDY WANJAHI KIMANI
F17/1356/2010
SUPERVISOR: PROF. NICODEMUS ABUNGU ODERO
EXAMINER: DR. C WEKESA

PROJECT REPORT SUBMITTED IN PARTIAL FULFILLMENT


OF THE REQUIREMENT FOR THE AWARD OF THE DEGREE OF
BACHELOR OF SCIENCE IN ELECTRICAL AND ELECTRONIC ENGINEERING
OF THE UNIVERSITY OF NAIROBI 2015
SUBMITTED ON: 23TH APRIL 2015

i
DECLARATION OF ORIGINALITY

NAME OF STUDENT KIMANI KENNEDY WANJAHI


REGISTRATION NUMBER F17/1356/2010
COLLEGE ARCHITECTURE AND ENGINEERING
FACULTY ENGINEERING
DEPARTMENT ELECTRICAL AND INFORMATION ENGINEERING
TITLE OF WORK HYDROTHERMAL ECONOMIC DISPATCH USING
PARTICLE SWARM OPTIMIZATION (P.S.O)

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:

Prof. Nicodemus Abungu Odero.

Date: ..........................................

ii
DEDICATION

I dedicate my work to my family, for their continued support and love.

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 1. 1 The Multilevel Optimal System Operation...................................................................................... 2


Fig 1. 2 The Genetic Algorithm Process ....................................................................................................... 8

Fig 2. 1 : A Thermal Unit............................................................................................................................ 14


Fig 2. 2 Input - output characteristic of a thermal generating unit. ............................................................. 15
Fig 2. 3 :A Fundamental Hydrothermal System. ........................................................................................ 17

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

Table 4. 1 : Thermal System Generator Coefficients.................................................................................. 31


Table 4. 2 : B-Coefficient Matrix................................................................................................................ 31
Table 4. 3 : Hydrothermal System Generator Coefficients; 3 Hydro and 3 Thermal Generators. .............. 31
Table 4. 4 : B-Coefficient Matrix, Hydrothermal System .......................................................................... 32
Table 4. 5 : Optimal Scheduling of Thermal Generators of a 6-unit system by PSO Method (Loss
included). .................................................................................................................................................... 32
Table 4. 6 : Optimal scheduling of a 6-unit system, 3 Hydro and 3 Thermal Generators by PSO Method
(Loss included)............................................................................................................................................ 33
Table 4. 7: Comparison of optimal power output for both thermal and hydrothermal system
(Load=600MW) .......................................................................................................................................... 33

ix
LIST OF ABBREVIATIONS

N.L.P Non-Linear Programming

I.P Interior Points Methods

N.F.P Network Flow Programming

L.P Linear Programming

N.L.P Non-Linear Programming

N.F.P Network Flow Programming

L.P Linear Programming

G.A Genetic Algorithm

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.

Basically, 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.

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

1.1 Hydrothermal Economic Dispatch

1.1.1 What is Economic Dispatch?

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.

1.1.2 What is Hydrothermal Economic Dispatch?

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?)

Number of Power Plants Available


(Each power plant has several units)

Maintenance (Units on maintenance


are not available for power
generation)

Unit Commitment (Which units


should be on and which should be
off?)

Economic Dispatch (How do we


effectively and cheaply produce the
energy?)

Fig 1. 1 The Multilevel Optimal System Operation.

1.1.3 What is Particle Swarm Optimization (P.S.O)?

Particle swarm optimization (PSO) is a population based stochastic optimization technique


developed by Eberhart and Kennedy in 1995 [3], inspired by social behavior of bird
flocking or fish schooling. Hence, it can also be described as swarm intelligence algorithm

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.

P.S.O has the following advantages over other optimization methods:

 P.S.O is easier to implement as there are fewer parameters to adjust


 In P.S.O, each particle remembers its own previous best as well as the neighborhood’s
best, hence a more effective memory than Genetic Algorithm (G.A)
 P.S.O is more efficient in maintaining the diversity of the swarm since all the particles
use the information related to the best or most successful particle in order to improve
themselves whereas in G.A, worse solutions are discarded and only the good ones are
saved

1.2. Survey of Earlier Work.

1.2.1. Optimization Techniques

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:

i) Unconstrained optimization approaches


ii) Non-linear programming (N.L.P)
iii) Linear programming (L.P)
iv) Quadratic programming
v) Generalized reduced gradient method
vi) Newton method
vii) Network flow programming (N.F.P)
viii) Mixed inter programming
ix) Interior points (I.P) methods

The review of each and every method follows in the pages below:

1.3.1 Unconstrained optimization approaches

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.

1.3.3 Non-linear programming (N.L.P)

Power systems operation problems are non-linear; hence this method can easily solve such
problems. NLP based methods have higher accuracy than LP methods.

1.3.4 Quadratic programming

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.

1.3.5 Newton’s method

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.

1.3.6 Interior points (I.P) methods

This is generally used to solve linear programming problems as it is faster and perhaps better
than the simplex algorithm used in L.P.

1.3.7 Mixed integer programming

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.

1.3.8 Network flow programming

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

Artificial intelligence is the intelligence shown by machines or software. According to Jacques


Ferber, in his book Multi-Agent System, an introduction to Distributed Artificial Intelligence [5],
an intelligent agent can be a physical or virtual entity that can act, perceive its environment in a
partial way and communicate with others. It is autonomous and has skills to achieve its goals and
tendencies.

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.

In optimization techniques, intelligence search methods can be classified as follows:

i) Neural network (NN)


ii) Evolutionary algorithms (EAS)
iii) Tabu Search (TS)
iv) Particle swarm optimization
v) Ant colony
vi) Bee Colony

1.4.1 Neural network (NN)

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.

1.4.2 Evolutionary algorithms


Natural evolution is a population based optimization problem. These algorithms are based on the
mechanics of natural selection such as mutation, recombination, reproduction, crossover or even
selection and hence no need to differentiate cost functions and constraints.

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:

Starting Of a Population with Random


Genes

Evolving of the Population through Several


Generations (selection, mutation)

Choosing Values with Optimal Levels of


Fitness.

Discarding Values with Less Levels of


Fitness

Fig 1. 2: The Genetic Algorithm Process

1.4.3 Tabu Search (T.S)

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.

1.4.5. Particle Swarm Optimization (P.S.O)

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.

1.4.6. Simulated Annealing (S.A)

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.

1.5. Non-Quantity Approaches

This is the application of fully set theory.

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.

1.6. Problem Statement

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:

 To obtain an optimal solution to the Hydrothermal Economic Load Dispatch Problem,


having satisfied all the constraints.

 To develop a Particle Swarm Algorithm to be used in obtaining the optimal solution to


the Hydrothermal Economic Load Dispatch and test it on standard IEEE buses.

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.

Here, the PSO concept is explained in detail.

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

2.1 Literature Review of Hydrothermal Economic Load Dispatch

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 natural differences in watersheds.


 The differences in man-made storage and release elements used to control the water
flows.
 The different types of natural man-made constraints imposed on the operation of hydro
systems.

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]

2.2 Classical Economic Dispatch

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].

2.2.1 Input Output Characteristics of Generator Units.

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

Fig 2. 1 : A Thermal Unit.


For the: Boiler-input = fuel

Output = volume of steam

Turbine-generator unit- input = volume of steam

Output = electrical power

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:

PG max ≥ PG ≥ PG min (2.1)

The maximum value is normally determined by the design capacity.

Generally, the input-output characteristic equation of the generating unit is non-linear and is
given by:

𝐹𝑖 (𝑃𝑖 ) =𝑎𝑃𝑖2 +b𝑃𝑖 +c (2.2)

 Where the constant C, is the equivalent to the fuel consumption of the generating
unit operation without power output.

2.2.2. Calculation of input-output parameters of a thermal system.

This can be done by using of the following methods:

 Based on the experiments of the generating unit efficiency.


 Based on historic records of the generating unit operation.
 Based on the design data of the generating unit provided.

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]

∆FK = (Ap2K + BpK + c) – FK (2.3)

According to the method /principle of least squares:

∆= (∆ FK=1)2 =∑ nK (Ap2K+BpK + c – FK) 2 (2.4)

We then differentiate with respect to a, b, c respectively;

∂j =∑n K=1 =2P2K {Ap2K + BpK + c – FK} =0 (2.4.1)


∂a

∂j = ∑n K=1= 2PK (Ap2K+BpK+c-FK) = 0 (2.4.2)


∂b

∂j = ∑n K=1 2(Ap2K+BpK + c – FK) = 0 (2.4.3)


∂c

Hence from (i-iii) we get:

(∑n K=1 P2K) a + (∑n K=1 PK) b + n c = ∑n K=1 FK (2.5)

This is the main equation from here you just multiply with PK to obtain the below equations:

(∑n K=1 P2K) a + (∑n K=1 PK) b + n c = ∑n K=1 FK

(∑n K=1 P3K) a + ∑n K=1 (P2K) b + ( ∑n K=1 PK) c = ∑n K=1 FK PK (2.6.2)

( ∑n K=1 P4K) a + ( ∑n K=1 P3K) b + ( ∑n K=1 P2K) c = ∑n K=1 FK P2K (2.6.3)

Hence, coefficient a, b, and c can be obtained by solving equations (2.6.1-2.6.3).

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]

A fundamental hydrothermal system is shown in the figure below:

J (inflow)

PGT PGH
PGT

Hydro plant
Thermal plant
PD
PGT
q (Discharge)
Fig 2. 3 :A Fundamental Hydrothermal System.

2.4.1 System Constraints

Generally there are two types of constraints [17].

i) Equality constraints.

ii) Inequality 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]:

2.4.1.1 Power balance constraints (Demand Constraints)

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.

PH(t) + PT(t) =PD(t) +PL(t) (2.7)

Where;

PT(t) = thermal generation of the ith unit.

PH(t) = hydro generation in the ith unit.

PL(t) =transmission losses

2.4.1.2 Thermal Generator Constraints


The operating limit of equivalent thermal generator has a lower and upper bound so that it lies in
between these bounds.

PT(t) MAX > PT(t) > PT(t)MIN (2.8)

2.4.1.3 Hydro Generator Constraints


The operating limit of hydro plant must also lie in between its upper and lower bounds.

PH(t) MAX > PH(t) > PH(t)MIN (2.9)

2.4.2 Hydraulic Network Constraints

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:

 Reservoir Capacity Constraints


 The Water Discharge Constraints
 Reservoir end conditions
 Water Continuity Equation Constraint
 Power Generation Characteristics

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).

2.5.1 PSO Terminologies

Particle (X): This is a candidate solution represented by an m-dimensional vector, where m is


the number of optimized parameters.

Swarm: According to R.C Eberhart and Y. Shi, a swarm is an apparently disorganized


population of moving particles that tend to cluster together towards a common optimum while
each particle seems to be moving in a random direction[18].

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.

2.5.2 PSO Parameter Selection

2.5.2.1 Swarm Size.

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.

2.5.2.2 Velocity components

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].

It is also important to note that:

 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.

W=Wmax - {Wmax-Wmin}*Iter (2.10)

Iter max

Where;

 Wmax is the initial weight.


 Wmin is the final weight.
 Itermax is the maximum iteration number.
 Iter is the current iteration number.

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.

2.5.2.4 Constriction Factor

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

Solution of Hydrothermal Economic Dispatch Using P.S.O

3.1 Formulation of Hydrothermal Dispatch Problem

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.

3.2 Economic Load Dispatch with Network losses

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

 Kron’s loss formula:


N N N
PL   pi Bij p j   B0 j p j  B00 (3.3)
i 1 j 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:

 Kron’s loss formula:


N N N
PL   pi Bij p j   B0 j p j  B00 (3.3.1)
i 1 j 1 j 1

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:

 The generation equals the total load demand plus transmission


Losses,

 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

h: pi (min)  pi  pi (max) i  1,..., N (3.3.4)

The resulting optimization equation becomes:

 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

By setting the fuel cost equal to 1 $/MBTU can be rewritten as:

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

Rearranging the above equation as:

 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.

Hence, the ith particle is represented as:

Xi=Xi1, Xi2, Xi3, Xi4…………Xid, in the‘d’ dimensional space.

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:

V n+1id= {v nid +cr1 (p nid – x nid) +cr2 n id (p ngd – x nid) } (3.4)

x n+1id = x nid + v n+1id (3.5)

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)

x n+1id = x nid + v n+1id (3.7)

26
Where: w = inertia weight

c1, c2 = two positive constants; cognitive and social parameter respectively;

K = constriction factor which is used, alternatively to w to limit velocity.

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.”

3.4 PSO Algorithm

The step by step procedure of PSO algorithm is given as follows [16]:

Initialize a population of particles as; Pi = (Pi1, Pi2, Pi3…. Pi N).

‘N’ is number of generating units. Population is initialized with random values and velocities
within the d-dimensional search space.

1) Initialize the maximum allowable velocity magnitude of any particle Vmax.


2) Evaluate the fitness of each particle and assign the particle's position to P-best
position and fitness to P-best fitness. Identify the best among the P-best as G-best and
store the fitness value of G-best.
3) Change the velocity and position of the particle according to equations (3.6) and (3.7),
respectively.
4) For each particle, evaluate the fitness, if all decisions variable are within the search
ranges.

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

Initialize PSO parameters

Iter=0

Compute fitness function f

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

Update velocity and particle position

Check stopping criteria

Gbest is the optimal


solution

29
END
CHAPTER 4

4.1 30 Bus Test Network


The one line diagram of an IEEE-30 bus system is shown in Fig. 4.I. The generator cost
coefficients, data are provided in Table 1. The B-loss coefficients matrix of the system is given
in Table 1.2.

Fig 4. 1 : 30 Bus IEEE test network with six generating units.

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

UNIT ai (MW/$) bi (MW/$) ci ($) Pimin(MW) Pimax(MW)


1 0.15240 38.53973 756.79886 10 125
2 0.10587 46.39655 451.32513 10 150
3 0.02803 40.39655 1049.9977 35 225
4 0.03546 38.32782 1243.5311 35 210
5 0.02111 36.32782 1658.5596 130 325
6 0.01799 38.27041 1356.6592 125 315

Table 4. 2 : B-Coefficient Matrix

0.000140 0.000017 0.000015 0.000019 0.000026 0.000022

0.000060 0.000013 0.000016 0.000015 0.00


0.000017
0.000013 0.000065 0.000017 0.000024 0.000019
0.000015
0.000016 0.000017 0.000071 0.000030 0.000025
0.000019
0.000015 0.000024 0.000030 0.000069 0.000032
0.000026
0.000020 0.000019 0.000025 0.000032 0.000085
0.000022

Table 4. 3 : Hydrothermal System Generator Coefficients; 3 Hydro and 3 Thermal Generators.

UNIT ai (MW/$) bi(MW/$) ci($) Pimin(MW) Pimax(MW)


1 0.00001829 0.187 1.423 12 126
2 0.0000203 0.198 1.714 20 180
3 0.0000192 0.149 1.055 30 240
4 0.01 0.1 50 50 200
5 0.02 0.1 40 40 170
6 0.01 0.1 30 30 215

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

4.2: Particle Swarm Optimization Method

PSO was applied to the above system for obtaining economic load dispatch of various loads.

PSO was implemented according to the flow chart shown.

PSO Method Parameters:

Population Size 100


Iterations 1000
Inertia Weight Wmax- 0.9 and Wmin=0.4
Acceleration Constants C1=2 and C2=2
Convergence 1.00E-06

Table 4. 5 : Optimal Scheduling of Thermal Generators of a 6-unit system by PSO Method


(Loss included).

DEMAND LOSS TOTAL COST


(MW) P1 P2 P3 P4 P5 P6 (MW) (MW) (Rs/Hr)
22.5 88.69 95.35 194.4 171.7
570 430 10 69 55 877 611 12.8441 582.8441 30,682.00
23.8 95.63 100.7 202.8 181.1
600 603 10 95 082 315 979 14.2373 614.2373 32,095.00
28.2 118.9 118.6 230.7 212.7
700 908 10 584 748 63 449 19.4319 719.4319 36,912.00
32.5 14.4 141.5 136.0 257.6 243.0
800 861 839 476 435 624 074 25.3309 825.3309 41,497.00

32
Table 4. 6 : Optimal scheduling of a 6-unit system, 3 Hydro and 3 Thermal Generators by PSO
Method (Loss included).

DEMAND LOSS TOTAL COST


(MW) P1 P2 P3 P4 P5 P6 (MW) (MW) (Rs/Hr)
124.8 121.5
570 526 379 240 50 40 30 36.3905 606.3905 537.05
125.9 153.1
600 723 651 240 50 40 30 39.1374 639.137 543.71
125.9 179.9 239.9 76.31 43.9 77.1
700 848 758 9 88 109 982 43.3785 743.3785 647.35
125.9 179.9 239.9 140.2 63.1 96.1
800 766 152 999 527 187 187 45.7943 845.7943 870.75

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

Fig 4. 2: Thermal optimum generation

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

Fig 4. 3: Hydrothermal optimum generation

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;

GENERATION TREND(600 MW)


400
350
300
POWER GENERATED

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

Fig 4. 4: Generation trend for combined thermal and hydrothermal system

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

HYDROTHERMAL POWER LOSS(KW)


50
45
40
35
Power Loss

30
25
20
15
10
5
0
570 600 700 800
POWER LOSS(KW) 36.3905 39.1374 43.3785 45.7943

Fig 4. 7: Hydrothermal Power Loss

THERMAL POWER LOSS(MW)


30

25

20
Power Loss

15

10

0
570 600 700 800
THERMAL POWER LOSS(MW) 12.8441 14.2373 19.4319 25.3309

Fig 4. 8 : Thermal power loss

37
CHAPTER 5

5.1 Conclusion and Recommendation for Future Works

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.

[3] “Particle Swarm Optimization” , Vol IV, PP 1942-1948,Kennedy and R. Eberhart


Perth, Australia

[4] “Unconstrained Nonlinear Optimization Algorithms,” Mathworks.com

[5] “Multi-Agent System: An Introduction To Distributed Artificial Intelligence”


Jacques Ferber
Harlow: Addson Wesley Longman 1999
Paper: ISBN 0-201-36048-9

[6] “The Ant Colony Meta –Heuristic Scholarly Paper “,Marco Dorigo & Gianni D. Caro
University of Bruxelles.

[7] “Computational Intelligence P.C Tools”, Eberhart, Dobbins &Simpson


Academic Press 1996.

[8] “Optimization of Power System Operation”, Jizhong Zhu, PhD


IEEE Press,445 Hoes Lane, Piscataway, NJ 0885, John Wiley and Sons Inc. Publication.

[9] “International Journal of Communication and Computer Technologies”, Volume 01-No 63


Issue Of Aug 2013, ISSN Number 2278-9723.

[10] “Intelligent Optimization Techniques” D.T. Pham and D. Karaboga,


Springer-Verlag, London Limited, 2000.

.
[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)

[14] “Particle swarm Optimization based on Short term hydrothermal Scheduling”,


M Basu, N Chakraborty
Apple soft computing 8(2008)Pg. 1392-1399

[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

[16] “ Solution to Economic Load Dispatch using Particle Swarm Optimization”


Prof. Nicodemus Abungu Odero and Patricia Lucy Onundo,
Department of Electrical and Information Engineering, School of Engineering,
University of Nairobi, Kenya

[17] “ Electrical Power System”.Wadhwa, C.L


New Age publishers(2009)

[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.

[24] “Fundamentals of Power System Economic “Daniel S. Kirschen,,March 2004 Hardback

[25] “Thermal Economic Dispatch using PSO” Danson Muthiani, The University of Nairobi

40
APPENDICES

APPENDIX 1: Program for the Thermal Economic Dispatch

%Thermal 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.15247 38.53973 756.79886 10 125
0.10587 46.15916 451.32513 10 150
0.02803 40.3965 1049.9977 35 225
0.03546 38.30553 1243.5311 35 210
0.02111 36.32782 1658.569 130 325
0.01799 38.27041 1356.6592 125 315];
B=1e-4*[1.4 .17 .15 .19 .26 .22;
.17 .60 .13 .16 .15 .20;
.15 .13 .65 .17 .24 .19;
.19 .16 .17 .71 .30 .25;
.26 .15 .24 .30 .69 .32;
.22 .20 .19 .25 .32 .85];
Pd=800;
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')

%[P1 Fcost1 Pl1]=eld(data,B,Pd)

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

% setup figure, change this for your own machine


clf
set(gcf,'Position',[651 31 626 474]); % this is the computer
dependent part
%set(gcf,'Position',[743 33 853 492]);
set(gcf,'Doublebuffer','on');

% particle plot, upper right


subplot('position',[.7,.6,.27,.32]);
set(gcf,'color','k')

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

% error plot, left side


subplot('position',[0.1,0.1,.475,.825]);
semilogy(tr(find(~isnan(tr))),'color','m','linewidth',2)
%plot(tr(find(~isnan(tr))),'color','m','linewidth',2)
xlabel('epoch','color','y')
ylabel('gbest val.','color','y')

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')

% text box in lower right


% doing it this way so I can format each line any way I want
subplot('position',[.62,.1,.29,.4]);
clear titstr
if trelea==0
PSOtype = 'Common PSO';
xtraname = 'Inertia Weight : ';
xtraval = num2str(iwt(length(iwt)));

elseif trelea==2 | trelea==1

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

titstr={'PSO Model: ' ,PSOtype;...


'Dimensions : ' ,num2str(D);...
'# of particles : ',num2str(ps);...
minmaxstr ,errgoalstr;...
'Function : ' ,strrep(functname,'_','\_');...
xtraname ,xtraval;...
rststat1 ,rststat2};

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');

% if we are training a neural net, show a few more parameters


if strcmp('pso_neteval',functname)
% net is passed from trainpso to pso_Trelea_vectorized in case you are
% wondering where that structure comes from
hiddlyrstr = [];
for lyrcnt=1:length(net.layers)
TF{lyrcnt} = net.layers{lyrcnt}.transferFcn;

45
Sn(lyrcnt) = net.layers{lyrcnt}.dimensions;
hiddlyrstr = [hiddlyrstr,', ',TF{lyrcnt}];
end
hiddlyrstr = hiddlyrstr(3:end);

text(0.1,.35,['#neur/lyr = [ ',num2str(net.inputs{1}.size),' ',...


num2str(Sn),' ]'],'color','c','fontweight','normal',...
'fontsize',10);
text(0.1,.275,['Lyr Fcn: ',hiddlyrstr],...
'color','c','fontweight','normal','fontsize',9);

end

legstr = {'Green = Personal Bests';...


'Blue = Current Positions';...
'Red = Global Best'};
text(.1,0.025,legstr{1},'color','g');
text(.1,-.05,legstr{2},'color','b');
text(.1,-.125,legstr{3},'color','r');

hold off

set(gca,'color','k');
set(gca,'visible','off');

drawnow

APPENDIX 3: Main program code for the PSO Toolbox Used.

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

% sets up default pso params


Pdef = [100 2000 24 2 2 0.9 0.4 1500 1e-25 250 NaN 0 0];
Plen = length(P);
P = [P,Pdef(Plen+1: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);

% used with trainpso, for neural net training


if strcmp(functname,'pso_neteval')
net = evalin('caller','net');
Pd = evalin('caller','Pd');
Tl = evalin('caller','Tl');
Ai = evalin('caller','Ai');
Q = evalin('caller','Q');
TS = evalin('caller','TS');
end

% 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 ( (PSOseed==1) & ~exist('PSOseedValue') )


error('PSOseed flag set but no PSOseedValue was input');
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

% set plotting flag


if (P(1))~=0

50
plotflg=1;
else
plotflg=0;
end

% preallocate variables for speed up


tr = ones(1,me)*NaN;

% take care of setting max velocity and position params here


if length(mv)==1
velmaskmin = -mv*ones(ps,D); % min vel, psXD matrix
velmaskmax = mv*ones(ps,D); % max vel
elseif length(mv)==D
velmaskmin = repmat(forcerow(-mv),ps,1); % min vel
velmaskmax = repmat(forcerow( mv),ps,1); % max vel
else
error('Max vel must be either a scalar or same length as prob dimension D');
end
posmaskmin = repmat(VR(1:D,1)',ps,1); % min pos, psXD matrix
posmaskmax = repmat(VR(1:D,2)',ps,1); % max pos
posmaskmeth = 3; % 3=bounce method (see comments below inside epoch loop)

% PLOTTING
message = sprintf('PSO: %%g/%g iterations, GBest = %%20.20g.\n',me);

% INITIALIZE INITIALIZE INITIALIZE INITIALIZE INITIALIZE INITIALIZE

% initialize population of particles and their velocities at time zero,


% format of pos= (particle#, dimension)
% construct random population positions bounded by VR
pos(1:ps,1:D) = normmat(rand([ps,D]),VR',1);

if PSOseed == 1 % initial positions user input, see comments above


tmpsz = size(PSOseedValue);
pos(1:tmpsz(1),1:tmpsz(2)) = PSOseedValue;
end

% construct initial random velocities between -mv,mv


vel(1:ps,1:D) = normmat(rand([ps,D]),...
[forcecol(-mv),forcecol(mv)]',1);

% initial pbest positions vals


pbest = pos;

% VECTORIZE THIS, or at least vectorize cost funct call


out = feval(functname,pos); % returns column of cost values (1 for each
particle)
%---------------------------

pbestval=out; % initially, pbest is same as pos

% assign initial gbest here also (gbest and gbestval)


if minmax==1
% this picks gbestval when we want to maximize the function
[gbestval,idx1] = max(pbestval);
elseif minmax==0

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

% preallocate a variable to keep track of gbest for all iters


bestpos = zeros(me,D+1)*NaN;
gbest = pbest(idx1,:); % this is gbest position
% 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
%tr(1) = gbestval; % save for output
bestpos(1,1:D) = gbest;

% 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

% INITIALIZE END INITIALIZE END INITIALIZE END INITIALIZE END


rstflg = 0; % for dynamic environment checking
% start PSO iterative procedures
cnt = 0; % counter used for updating display according to df in the
options
cnt2 = 0; % counter used for the stopping subroutine based on error
convergence
iwt(1) = iw1;
for i=1:me % start epoch loop (iterations)

out = feval(functname,[pos;gbest]);
outbestval = out(end,:);

52
out = out(1:end-1,:);

tr(i+1) = gbestval; % keep track of global best val


te = i; % returns epoch number to calling program when
done
bestpos(i,1:D+1) = [gbest,gbestval];

%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)

eval(plotfcn); % defined at top of script

end % end update display every df if statement


end % end plotflg if statement

% check for an error space that changes wrt time/iter


% threshold value that determines dynamic environment
% sees if the value of gbest changes more than some threshold value
% for the same location
chkdyn = 1;
rstflg = 0; % for dynamic environment checking

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 ));

if (outorng & samepos) & rem(i,letiter)==0


rstflg=1;
% disp('New Environment: reset pbest, gbest, and vel');
%% reset pbest and pbestval if warranted
% outpbestval = feval( functname,[pbest] );
% Poutorng = abs( 1-(outpbestval./pbestval) ) > threshld;
% pbestval = pbestval.*~Poutorng + outpbestval.*Poutorng;
% pbest = pbest.*repmat(~Poutorng,1,D) +
pos.*repmat(Poutorng,1,D);

pbest = pos; % reset personal bests to current positions


pbestval = out;
vel = vel*10; % agitate particles a little (or a lot)

% recalculate best vals


if minmax == 1
[gbestval,idx1] = max(pbestval);
elseif minmax==0
[gbestval,idx1] = min(pbestval);
elseif minmax==2 % this section needs work
[temp,idx1] = min((pbestval-ones(size(pbestval))*errgoal).^2);

53
gbestval = pbestval(idx1);
end

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
end % end if outorng

sentryval = gbestval;
sentry = gbest;

end % end if chkdyn

% find particles where we have new pbest, depending on minmax choice


% then find gbest and gbestval
%[size(out),size(pbestval)]
if rstflg == 0
if minmax == 0
[tempi] = find(pbestval>=out); % new min pbestvals
pbestval(tempi,1) = out(tempi); % update pbestvals
pbest(tempi,:) = pos(tempi,:); % update pbest positions

[iterbestval,idx1] = min(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
end
elseif minmax == 1
[tempi,dum] = find(pbestval<=out); % new max pbestvals
pbestval(tempi,1) = out(tempi,1); % update pbestvals
pbest(tempi,:) = pos(tempi,:); % update pbest positions

[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

sqrerr = ((pbestval-egones).^2); % need to do this to


reflect new pbests
[temp,idx1] = min(sqrerr);
iterbestval = pbestval(idx1);

if (iterbestval-errgoal)^2 <= (gbestval-errgoal)^2


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
end
end
end

% % build a simple predictor 10th order, for gbest trajectory


% if i>500
% for dimcnt=1:D
% pred_coef = polyfit(i-250:i,(bestpos(i-250:i,dimcnt))',20);
% % pred_coef = polyfit(200:i,(bestpos(200:i,dimcnt))',20);
% gbest_pred(i,dimcnt) = polyval(pred_coef,i+1);
% end
% else
% gbest_pred(i,:) = zeros(size(gbest));
% end

%gbest_pred(i,:)=gbest;
%assignin('base','gbest_pred',gbest_pred);

% % convert to non-inertial frame


% gbestoffset = gbest - gbest_pred(i,:);
% gbest = gbest - gbestoffset;
% pos = pos + repmat(gbestoffset,ps,1);
% pbest = pbest + repmat(gbestoffset,ps,1);

%PSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSOPSO

% get new velocities, positions (this is the heart of the PSO


algorithm)
% each epoch get new set of random numbers

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;

vel = iwt(i).*vel... % prev vel


+ac11.*(pbest-pos)... % independent
+ac22.*(repmat(gbest,ps,1)-pos); % social
end

% limit velocities here using masking


vel = ( (vel <= velmaskmin).*velmaskmin ) + ( (vel > velmaskmin).*vel
);
vel = ( (vel >= velmaskmax).*velmaskmax ) + ( (vel < velmaskmax).*vel
);

% update new position (PSO algo)


pos = pos + vel;

% position masking, limits positions to desired search space


% method: 0) no position limiting, 1) saturation at limit,
% 2) wraparound at limit , 3) bounce off limit
minposmask_throwaway = pos <= posmaskmin; % these are psXD matrices
minposmask_keep = pos > posmaskmin;
maxposmask_throwaway = pos >= posmaskmax;
maxposmask_keep = pos < posmaskmax;

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
);

vel = (vel.*minposmask_keep) + (-vel.*minposmask_throwaway);


vel = (vel.*maxposmask_keep) + (-vel.*maxposmask_throwaway);
else
% no change, this is the original Eberhart, Kennedy method,
% it lets the particles grow beyond bounds if psoparams (P)
% especially Vmax, aren't set correctly, see the literature
end

%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

% this stops if using constrained optimization and goal is reached


if ~isnan(errgoal)
if ((gbestval<=errgoal) & (minmax==0)) | ((gbestval>=errgoal) &
(minmax==1))

if plotflg == 1
fprintf(message,i,gbestval);
disp(' ');
disp(['--> Error Goal reached, successful termination!']);

57
eval(plotfcn);
end
break
end

% this is stopping criterion for constrained from both sides


if minmax == 2
if ((tr(i)<errgoal) & (gbestval>=errgoal)) | ((tr(i)>errgoal) ...
& (gbestval <= errgoal))
if plotflg == 1
fprintf(message,i,gbestval);
disp(' ');
disp(['--> Error Goal reached, successful termination!']);

eval(plotfcn);
end
break
end
end % end if minmax==2
end % end ~isnan if

% % convert back to inertial frame


% pos = pos - repmat(gbestoffset,ps,1);
% pbest = pbest - repmat(gbestoffset,ps,1);
% gbest = gbest + gbestoffset;

end % end epoch loop

%% clear temp outputs


% evalin('base','clear temp_pso_out temp_te temp_tr;');

% output & return


OUT=[gbest';gbestval];
varargout{1}=[1:te];
varargout{2}=[tr(find(~isnan(tr)))];

return

58

You might also like