UNIVERSITY OF NAIROBI SUBSTATION DESIGN PRJ 100 BY: SAIDI FELIX JUMA REG. NO. F17/9366/2002 SUPERVISOR: DR. CYRUS WEKESA EXAMINER: DR. MAURICE .K. MANGOLI MAY, 2009 DEPARTMENT OF ELECTRICAL AND INFORMATION ENGINEERING PROJECT REPORT SUBMITTED IN PARTIAL FULFILLMENT OF THE REQUIREMENT FOR THE AWARD OF BACHELOR OF SCIENCE DEGREE IN ELECTRICAL AND ELECTRONIC ENGINEERING, UNIVERSITY OF NAIROBI.
69
Embed
UNIVERSITY OF NAIROBI SUBSTATION DESIGN SAIDI …eie.uonbi.ac.ke/sites/default/files/cae/engineering/eie/SUBSTATION... · university of nairobi substation design prj 100 by: saidi
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
UNIVERSITY OF NAIROBI
SUBSTATION DESIGN
PRJ 100
BY:
SAIDI FELIX JUMA
REG. NO. F17/9366/2002
SUPERVISOR: DR. CYRUS WEKESA
EXAMINER: DR. MAURICE .K. MANGOLI
MAY, 2009
DEPARTMENT OF ELECTRICAL AND INFORMATION ENGINEERING
PROJECT REPORT SUBMITTED IN PARTIAL FULFILLMENT OF THE REQUIREMENT FOR THE AWARD OF BACHELOR OF SCIENCE
DEGREE IN ELECTRICAL AND ELECTRONIC ENGINEERING, UNIVERSITY OF NAIROBI.
i
I dedicate this project to all those who stood by me in my times of need especially my parents.
I thank God for always being there.
ii
ACKNOWLEDGEMENTS
The completion of this work would not have been possible without the assistance of many people who devoted their time, energy and knowledge. Very special thanks to Dr Cyrus Wekesa lecturer, School of Engineering, University of Nairobi and supervisor of my project.
I would also like to acknowledge all my lecturers who have been a fountain of knowledge for me to quench my thirst for knowledge. The knowledge I have gained as a student from them is truly immense.
I thank my friends who constantly edged me onwards.
iii
Table of Contents DEDICATION...................................................................................................................i
A genetic algorithm methodology is presented, conceived to assist the electric system planning engineers in the selection of the distribution substation locations, taking into account the current substation locations and the candidate points of new ones. The objective of the project was to develop an algorithm for distribution substation location.
At first the bisector perpendicular rule which was investigated and it was seen from literature that it is not an effective method for determining substation location. However it usually provided a good starting/initial solution which should be subject to further refinement.
The choice of using genetic algorithm was made based on the fact that GAs by definition is a search technique used in computing to find exact or approximate solutions to optimization and search problems.The substation location is an optimization problem of continuous variables (the substation geographical co-ordinates).
The report describes how the genetic algorithm was developed and shows that the project was accomplished.
1
CHAPTER ONE: INTRODUCTION
1.1 General background The distribution system is the most extensive part of an electrical system and it is the
main loss of electric energy .Therefore the application of optimisation techniques in
the design and expansion of such subsystem can lead to significant economic gains,
finding networks that minimize immediate costs (facility installation costs) and
further costs (related to energy losses and system maintenance).
Electrical energy distribution systems are, intrinsically, systems in steady evolution.
They are frequently exposed to several changes, such as the appearance of new
consumer centres, a change of load pattern in existing centres, a change in geographic
distribution of loads in existing centres, and so forth. That situation does not favour
the application of efficient design methodologies, since the system would be
frequently redesigned in some small part. Traditional approaches only consider this
fragment of the system for planning the expansion, disregarding a lot of possible
solutions to this combinatorial problem, often resulting in more expensive and lossy
networks than would be obtained with global design techniques.
In some cases the existing substation facilities are not sufficient to supply a service
region with energy. Regions where the cities are growing are a good example of such
cases. This phenomenon occurs more often in developing countries, but the economic
fluctuations that are intrinsic to globalisation provoke demographic changes even in
developed nations. Existing electrical distribution systems which are operating in
places where such changes are in progress must follow the eventual increase in the
load, keeping some slack capacity to allow future load increments, in a trade-off
between the minimisation of the present installation costs and the minimisation of the
future needs of facility redesign. In these cases new substations (substation) must be
installed and the distribution system must be resized, or completely replaced in some
critical cases, to supply the new demand.
2
System expansion in these cases involves two sub problems:
• The substation location
• The network topology design.
These problems should not be treated separately since they exhibit a strong
interaction: when the solution of one of them is changed, the solution of the other also
changes.
However due to the fact that network topology design is not within the scope of this
project it will not be delved into in this project. This will be taken up as further work
after the objective of optimal substation location has been achieved.
1.2 Objective of the project The aim of the project was to design an algorithm that could be used for the planning
of the location of distribution substations in a network.
The substation location is an optimisation problem of continuous variables (the
substation geographical co-ordinates). As the substation location varies, the lengths of
the conductors which immediately connect the substation to the network nodes vary
continuously too. This influences the problem of optimal network topology design.
1.3 Usual design procedure
1.3.1 Bisector perpendicular Rule In current engineering practice there is no globally accepted criterion to define the
substation position. Generally the proposed solutions are based on designer
experience. A criterion usually adopted is based on a graphical method, called the
bisector perpendicular rule. The method is briefly described here. This traditional
procedure is based on the idea of assisting the consumer with the nearest substation,
which is supposed to guarantee the minimum distribution line distance, reducing the
losses, failure rates and the installation costs. The bisector perpendicular rule can be
divided into some basic steps as follows:
a) Estimate a feasible initial position for the substation.
b) Draw a line between the estimated substation position and each neighbour
substation.
c) Bisect each line perpendicularly with another line.
d) The set of bisections defines the service area of the substation.
3
e) If this area is not the desired one the substation must be moved to a correcting
direction and the steps (b)-(e) must be re-executed.
f) The load assisted by the substation is the sum of all loads in its service area.
This procedure can be time-consuming for the designer and is not an efficient tool in
the search of optimal solutions. However, the solution that is found often represents a
good initial solution which may be subject to further refinement.
This report uses a, genetic algorithm (GA) to solve the optimal substation location
problem. It’s seen that the approach taken her considers only one of the two sub
problems mentioned (i.e. substation location).
4
LITERATURE REVIEW
2.1 Electrical substation
An electrical substation is a subsidiary station of an electricity generation,
transmission and distribution system where voltage is transformed from high to low or
the reverse using transformers. Electric power may flow through several substations
between generating plant and consumer, and may be changed in voltage in several
steps.
A substation that has a step-up transformer increases the voltage while decreasing the
current, while a step-down transformer decreases the voltage while increasing the
current for domestic and commercial distribution. The word substation comes from
the days before the distribution system became a grid. The first substations were
connected to only one power station where the generator was housed, and were
subsidiaries of that power station.
2.1.1 Elements of a substation
Substations generally contain one or more transformers, and have switching,
protection and control equipment. In a large substation, circuit breakers are used to
interrupt any short-circuits or overload currents that may occur on the network.
Smaller distribution stations may use recloser circuit breakers or fuses for protection
of branch circuits. Substations do not (usually) have generators, although a power
plant may have a substation nearby. A typical substation will contain line termination
structures, high-voltage switchgear, one or more power transformers, low voltage
switchgear, surge protection, controls, grounding (earthing) system, and metering.
Other devices such as power factor correction capacitors and voltage regulators may
also be located at a substation.
Substations may be on the surface in fenced enclosures, underground, or located in
special-purpose buildings. High-rise buildings may have indoor substations. Indoor
substations are usually found in urban areas to reduce the noise from the transformers,
5
for reasons of appearance, or to protect switchgear from extreme climate or pollution
conditions.
Where a substation has a metallic fence, it must be properly grounded to protect
people from high voltages that may occur during a fault in the transmission system.
Earth faults at a substation can cause ground potential rise at the fault location.
Currents flowing in the earth's surface during a fault can cause metal objects to have a
significantly different voltage than the ground under a person's feet; this touch
potential presents a hazard of electrocution.
2.1.2 Types of substations
2.1.2.1 Transmission substation
A transmission substation connects two or more transmission lines. The simplest case
is where all transmission lines have the same voltage. In such cases, the substation
contains high-voltage switches that allow lines to be connected or isolated for
maintenance. A transmission station may have transformers to convert between two
transmission voltages, or equipment such as phase angle regulators to control power
flow between two adjacent power systems.
Transmission substations can range from simple to complex. A small "switching
station" may be little more than a bus plus some circuit breakers. The largest
transmission substations can cover a large area (several acres/hectares) with multiple
voltage levels, and a large amount of protection and control equipment (capacitors,
relays, switches, breakers, voltage and current transformers).
2.1.2.2 Distribution substation
A distribution substation transfers power from the transmission system to the
distribution system of an area. It is uneconomical to directly connect electricity
consumers to the high-voltage main transmission network, unless they use large
amounts of energy; so the distribution station reduces voltage to a value suitable for
local distribution.
The input for a distribution substation is typically at least two transmission or
subtransmission lines. Input voltage may be, for example, 220kv or 132kv, or
6
whatever is common in the area. The output is a number of feeders. Distribution
voltages are typically medium voltage, between 33kv, 3.3kv or 66kv depending on the
size of the area served and the practices of the local utility.
The feeders will then run overhead, along streets (or under streets, in a city) and
eventually power the distribution transformers at or near the customer premises.
Besides changing the voltage, the job of the distribution substation is to isolate faults
in either the transmission or distribution systems. Distribution substations may also be
the points of voltage regulation, although on long distribution circuits (several
km/miles), voltage regulation equipment may also be installed along the line.
Complicated distribution substations can be found in the downtown areas of large
cities, with high-voltage switching, and switching and backup systems on the low-
voltage side. More typical distribution substations have a switch, one transformer, and
minimal facilities on the low-voltage side.
2.1.3 Layout
The first step in planning a substation layout is the preparation of a one-line diagram
which shows in simplified form the switching and protection arrangement required, as
well as the incoming supply lines and outgoing feeders or transmission lines. It is a
usual practice by many electrical utilities to prepare one-line diagrams with principal
elements (lines, switches, circuit breakers, and transformers) arranged on the page
similarly to the way the apparatus would be laid out in the actual station.
Incoming lines will almost always have a disconnect switch and a circuit breaker. In
some cases, the lines will not have both; with either a switch or a circuit breaker being
all that is considered necessary. A disconnect switch is used to provide isolation, since
it cannot interrupt load current. A circuit breaker is used as a protection device to
interrupt fault currents automatically, and may be used to switch loads on and off.
Where a large fault current flows through the circuit breaker this may be detected
through the use of current transformers. The magnitude of the current transformer
outputs may be used to 'trip' the circuit breaker resulting in a disconnection of the load
supplied by the circuit break from the feeding point. This seeks to isolate the fault
point from the rest of the system, and allow the rest of the system to continue
7
operating with minimal impact. Both switches and circuit breakers may be operated
locally (within the substation) or remotely from a supervisory control centre.
Once past the switching components, the lines of a given voltage connect to one or
more buses. These are sets of bus bars, usually in multiples of three, since three-phase
electrical power distribution is largely universal around the world.
The arrangement of switches, circuit breakers and buses used affects the cost and
reliability of the substation. For important substations a ring bus, double bus or so-
called "breaker and a half" setup can be used, so that the failure of any one circuit
breaker does not interrupt power to branch circuits for more than a brief time, and so
that parts of the substation may be de-energized for maintenance and repairs.
Substations feeding only a single industrial load may have minimal switching
provisions, especially for small installations.
Once having established buses for the various voltage levels, transformers may be
connected between the voltage levels. These will again have a circuit breaker, much
like transmission lines, in case a transformer has a fault (commonly called a 'short
circuit').
Along with this, a substation always has control circuitry needed to command the
various breakers to open in case of the failure of some component.
2.1.4 Switching function
An important function performed by a substation is switching, which is the
connecting and disconnecting of transmission lines or other components to and from
the system. Switching events may be "planned" or "unplanned".
A transmission line or other component may need to be de-energized for maintenance
or for new construction; for example, adding or removing a transmission line or a
transformer.
To maintain reliability of supply, no company ever brings down its whole system for
maintenance. All work to be performed, from routine testing to adding entirely new
substations, must be done while keeping the whole system running.
8
Perhaps more importantly, a fault may develop in a transmission line or any other
component. Some examples of this: a line is hit by lightning and develops an arc, or a
tower is blown down by a high wind. The function of the substation is to isolate the
faulted portion of the system in the shortest possible time.
There are two main reasons: a fault tends to cause equipment damage; and it tends to
destabilize the whole system. For example, a transmission line left in a faulted
condition will eventually burn down, and similarly, a transformer left in a faulted
condition will eventually blow up. While these are happening, the power drain makes
the system more unstable. Disconnecting the faulted component, quickly, tends to
minimize both of these problems.
2.2 Genetic algorithm
A genetic algorithm (GA) is a search technique used in computing to find exact or
approximate solutions to optimization and search problems. Genetic algorithms are a
particular class of evolutionary algorithms that use techniques inspired by
evolutionary biology such as inheritance, mutation, selection, and crossover (also
called recombination).
Computer programs that "evolve" in ways that resemble natural selection can solve
complex problems even their creators do not fully understand
by John H. Holland
Genetic algorithms are implemented as a computer simulation in which a population
of abstract representations (called chromosomes) of candidate solutions (called
individuals) to an optimization problem evolves toward better solutions. Usually,
solutions are represented in binary as strings of 0s and 1s, but other encodings are also
possible. In this report that traditional representation of using bit strings is adopted.
The evolution usually starts from a population of randomly generated individuals and
happens in generations. In each generation, the fitness of every individual in the
population is evaluated, multiple individuals are selected from the current population
(based on their fitness), and modified (recombined and possibly randomly mutated) to
9
form a new population. The new population is then used in the next iteration of the
algorithm. Each successive generation should have a much better average fitness than
the previous one.
An analogy can be used here of children inheriting most of the desirable traits of their
parents and very few of the undesirable ones. It should be noted that a little of the less
fit attributes are introduced to the next generation to avoid running into a plateau
situation where all individuals are fit and successive generations yield no difference.
Commonly, the algorithm terminates when either a maximum number of generations
has been produced, or a satisfactory fitness level has been reached for the population.
If the algorithm has terminated due to a maximum number of generations, a
satisfactory solution may or may not have been reached.
Genetic algorithms find application in quite a number of places; computational
science, engineering, economics, chemistry, manufacturing, mathematics, physics and
other fields.
Typical genetic algorithm requirements:
1. A genetic representation of the solution domain,
2. A fitness function to evaluate the solution domain.
A standard representation of the solution is as an array of bits. Arrays of other types
and structures can be used in essentially the same way. The main property that makes
these genetic representations convenient is that their parts are easily aligned due to
their fixed size, which facilitates simple crossover operation. Variable length
representations may also be used, but crossover implementation is more complex in
this case.
The fitness function is defined over the genetic representation and measures the
quality of the represented solution. The fitness function is always problem dependent.
In some problems, it is hard or even impossible to define the fitness expression; in
these cases, interactive genetic algorithms are used.
10
Once we have the genetic representation and the fitness function defined, GA
proceeds to initialize a population of solutions randomly, and then improve it through
repetitive application of mutation, crossover, inversion and selection operators
2.2.1 Initialization Initially many individual solutions are randomly generated to form an initial
population. The population size depends on the nature of the problem, but typically
contains several hundreds or thousands of possible solutions. Traditionally, the
population is generated randomly, covering the entire range of possible solutions (the
search space). Occasionally, the solutions may be "seeded" in areas where optimal
solutions are likely to be found.
2.2.2 Selection During each successive generation, a proportion of the existing population is selected
to breed a new generation. Individual solutions are selected through a fitness-based
process, where fitter solutions (as measured by a fitness function) are typically more
likely to be selected. Certain selection methods rate the fitness of each solution and
preferentially select the best solutions. Other methods rate only a random sample of
the population, as this process may be very time-consuming.
Most functions are designed so that a small proportion of less fit solutions are
selected. This helps keep the diversity of the population large, preventing premature
convergence on poor solutions. Popular and well-studied selection methods include
roulette wheel selection and tournament selection.
2.2.2.1 Roulette Wheel selection This is a way of choosing members from the population of chromosomes in a way
that is proportional to their fitness. It does not guarantee that the fittest member goes
through to the next generation merely that it has a very good chance of doing so. The
Roulette Wheel Selection operation is as shown below:
Imagine that the population’s total fitness score is represented by a pie chart (or
roulette wheel). Now you assign a slice of the wheel to each member of the
population. The size of the slice is proportional to that chromosomes fitness score. I.e.
the fitter a member is the bigger the slice of pie it gets. Now, to choose a chromosome
all you have to do is spin the ball and grab the chromosome at the point it stops.
11
In roulette wheel selection, individuals are given a probability of being selected that is
directly proportionate to their fitness. Two individuals are then chosen randomly
based on these probabilities and produce offspring. Pseudo-code for a roulette wheel
selection algorithm is shown below.
for all members of population sum += fitness of this individual end for for all members of population probability = sum of probabilities + (fitness / sum) sum of probabilities += probability end for loop until new population is full do this twice number = Random between 0 and 1 for all members of population if number > probability but less than next probability then you have been selected end for end create offspring end loop
While this code is very general and will obviously not compile, it illustrates the basic
structure of a selection algorithm.
2.2.3 Reproduction
The next step is to generate a second generation population of solutions from those
selected through genetic operators:
• Crossover (also called recombination)
• And/or mutation.
12
2.2.3.1 CROSSOVER
Crossover is a genetic operator that combines (mates) two chromosomes (parents) to
produce a new chromosome (offspring). The idea behind crossover is that the new
chromosome may be better than both of the parents if it takes the best characteristics
from each of the parents. Crossover occurs during evolution according to a user-
definable crossover probability. Sometimes, based on a set probability, no crossover
occurs and the parents are copied directly to the new population. The probability of
crossover occurring is usually 60% to 70%.
2.2.3.1.1OnePoint
A crossover operator that randomly selects a crossover point within a chromosome
then interchanges the two parent chromosomes at this point to produce two new
offspring.
Consider the following 2 parents which have been selected for crossover. The “|”
symbol indicates the randomly chosen crossover point.
Parent 1: 11001|010
Parent 2: 00100|111
After interchanging the parent chromosomes at the crossover point, the following
offspring are produced:
Offspring1: 11001|111
Offspring2: 00100|010
2.2.3.1.2 Two Point
A crossover operator that randomly selects two crossover points within a chromosome
then interchanges the two parent chromosomes between these points to produce two
new offspring.
13
Consider the following 2 parents which have been selected for crossover. The “|”
symbols indicate the randomly chosen crossover points.
Parent 1: 110|010|10
Parent 2: 001|001|11
After interchanging the parent chromosomes between the crossover points, the
following offspring are produced:
Offspring1: 110|001|10
Offspring2: 001|010|11
2.2.3.1.3 Uniform A crossover operator that decides (with some probability – known as the mixing ratio)
which parent will contribute each of the gene values in the offspring chromosomes.
This allows the parent chromosomes to be mixed at the gene level rather than the
segment level (as with one and two point crossover). For some problems, this
additional flexibility outweighs the disadvantage of destroying building blocks.
Consider the following 2 parents which have been selected for crossover:
Parent 1: 11001010
Parent 2: 00100111
If the mixing ratio is 0.5, approximately half of the genes in the offspring will come
from parent 1 and the other half will come from parent 2. Below is a possible set of
offspring after uniform crossover:
2.2.3.1.4 Arithmetic
A crossover operator that linearly combines two parent chromosome vectors to
produce two new offspring according to the following equations:
Offspring1 = a * Parent1 + (1- a) * Parent2
Offspring2 = (1 – a) * Parent1 + a * Parent2
14
where a is a random weighting factor (chosen before each crossover operation).
Consider the following 2 parents (each consisting of 4 float genes) which have been
selected for crossover:
Parent 1: (0.3)(1.4)(0.2)(7.4)
Parent 2: (0.5)(4.5)(0.1)(5.6)
If a = 0.7, the following two offspring would be produced:
Table 10: Showing which substation each of the loads is connected.
4.6 Analysis of tables and figures From the tables and figures given it can be seen that the loads are linked to one of the
transformers. The exact one is determined by the optimization algorithm with starts its
evolution from the initially given positions of the current substations and the
candidate points. It can be seen that the loads are connected one of the provided
substations which can either a current substation or the candidate substation location.
Examples are: (3600, 6200) which is a current substation position, (6175.79,
3441.58) which is a candidate position, (5600, 3800) current position, (3400, 5200)
candidate point, (3500, 5700) current position,
The algorithm thus ensures that the best substation among the numerous ones
provided as candidate points would be ideal.
The figure that was plotted (figure 5 & figure 6) gives a better view of how the
information contained in the file RESULTS.xls.
42
The capacities in KVA are indicated in red for each substation. The load centres are
also shown with the green lines showing the substation they should be connected to.
43
CONCLUSIONS
5.1 Conclusion In this project a comprehensive genetic algorithm for optimal location of distribution
substations and determination of their capacity and service area was generated. At
first, information was sought on the methods currently being employed for substation
location. It was found that in the current engineering practice no globally accepted
criterion to define the substation position existed. Generally the proposed solutions
are based on designer experience. A criterion usually adopted is based on a graphical
method, called the bisector perpendicular rule which did not always give the proper
location as it was based on trial and error and was also quiet time consuming.
Because Genetic Algorithms are used for optimisation a study of them was
undertaken to learn more about their operation
Therefore the search method based on genetic algorithm to optimize the problem has
been proposed. To have faster convergence of genetic algorithm, generation of many
illegal cases has been prevented in initial population generation. This was achieved by
making sure that each load was connected to only one substation (i.e. only one
element in each column could be 1 representing a connection while the rest were 0
indicating no connection). The creation function (SP_Create) was written in a way to
ensure this.
The objective which was to was to design an algorithm that could be used for the
planning of the location of distribution substations in a network was met as both a
MATLAB plot and xls file RESULTS were the programs output clearly showing
substation location and which loads were connected to which.
5.2 Challenges faced Although the set objective of the project was achieved it was discovered that literatures on substation location were quite hard to come by. A search in the city bookshops and on campus bookshop yielded no results of any book on substations. The university library only contained a few books on power stations as opposed to the target one on substations.
However despite these local problems the guidance my supervisor enabled me to discover some useful journals via the internet which proved quite handy.
44
45
5.3 Recommendations for future work
• The algorithm that was developed was attaining local optima. It can be quite
effective to combine genetic algorithms with other optimization methods. This
is due to the fact that GA tends to be quite good at finding good global
solutions, but quite inefficient at finding the last few mutations to find the
absolute optimum. Other techniques (such as simple hill climbing) are quite
efficient at finding absolute optimum in a limited region. Alternating GA and
hill climbing can improve the efficiency of GA while overcoming the lack of
robustness of hill climbing.
• Reproduction methods used in this project was more biology inspired and
involved the use of two parents. Recent researches suggest that more than two
“parents” are better to be used to produce a good quality chromosome. This
idea should be explored.
46
REFERENCES
[1] “Optimal substation location and energy distribution network design using a
hybrid GA-BFGS algorithm,” IEEE Proc-Gener Trans Dist. 152 (6): 919-926
[2] T. H. Fawzi, K. F. Ali, and S. M. El Sobki, “A new planning model for
distribution systems,” IEEE Trans. Power App. Syst., vol. 102, Sept. 1983.
[3] Zhu, J.Z.: ‘Optimal reconfiguration of electrical distribution network
using the refined genetic algorithm’, Electr. Power Syst. Res., 2002, 62,
(1), pp. 37–42
[4] Duan, G., and Yu, Y.: ‘Problem-specific genetic algorithm for power
transmission system planning’, Electr. Power Syst. Res., 2002, 61
[5] “Optimal location and sizing of HV/MV substation in uncertainty load
environment using genetic algorithm”. Elect Power System Res. 63 : 37-50
[6] D. Crawford and S. Holt, “A mathematical optimization technique for locating
and sizing distribution substations, and deriving their optimal service areas,”
IEEE Trans. Power App. Syst., vol. 94,Mar./Apr. 1975.
[9] A novel method for optimal location and expansion of sub-transmission
substations considering existing medium voltage distribution feeders.
APPENDIX A 6.1 Genetic algorithm codes written in MATLAB
6.1.1 SP_main This is the main program and all the other functions provided in this appendix are linked to it. All the function should be placed be placed in the same directory to facilitate their calling and execution without the provision of errors.
% this program is designed for optimal distribution substation placement %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function SP_main() clear; %Removes items from workspace,freeing up system memory. clc; % clc=Clear Command Window pack; %Consolidate workspace memory tic; % starts a stopwatch timer not necessary but why not display('PROJECT NO. 100: SUBSTATION DESIGN'); display('OPTIMAL SUBSTATION PLACEMENT ALGORITHM BY SAIDI FELIX JUMA STARTED'); display('REG NO.: F17/9366/2002'); % global=Define a global variable global T L FinalTransPow FinalLoad FinalTransCap TransTypes AuxTransCap AuxTransPow K2 K3 MaxT global SelCaseRow FinalTrans_x FinalTrans_y FinalLoad_x FinalLoad_x FinalLoad_y BrTransIndex global AuxFinalTrans_x AuxFinalTrans_y AuxFinalLoad_x AuxFinalLoad_x AuxFinalLoad_y AuxFinalLoad global FinalTLDistances VarCheckPrg global finaltranspow finaltranscap global PowerFactor UtilizationFactor TransformersTypes KWTransformersTypes global InstallCosts OpenCircuitLosses ShortCircuitLosses global CurrentTr_x CurrentTr_y K2 = 0.0035e-3; K3 = 0.64; % determination of load centers & the vector of load values % //in the next five lines of my code the required data is read from the excel file DATA which acts as my input DATA = xlsread('DATA.xls','Loads'); CANDIDATES = xlsread('DATA.xls','Candidates'); CURRENT_SUBSTATIONS = xlsread('DATA.xls','Current_Substation'); DESIGN_CONSTANTS = xlsread('DATA.xls','Design_Constants'); TRANSFORMERS_TYPES = xlsread('DATA.xls','Transformers_Types'); ExcelLoad_x = DATA(:,1); ExcelLoad_y = DATA(:,2); ExcelLoads = DATA(:,3); ExcelCandidates_x = CANDIDATES(:,1);
48
ExcelCandidates_y = CANDIDATES(:,2); PowerFactor = DESIGN_CONSTANTS(1,1); UtilizationFactor = DESIGN_CONSTANTS(1,2)/100; TransformersTypes(1,:) = sort(TRANSFORMERS_TYPES(:,1)); KWTransformersTypes = ceil(UtilizationFactor*PowerFactor*TransformersTypes); InstallCosts(1,:) = sort(TRANSFORMERS_TYPES(:,2)); OpenCircuitLosses(1,:) = sort(TRANSFORMERS_TYPES(:,3)); ShortCircuitLosses(1,:) = sort(TRANSFORMERS_TYPES(:,4)); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Loads(1,:) = ExcelLoads(:,1); Load_x(1,:) = ExcelLoad_x(:,1); Load_y(1,:) = ExcelLoad_y(:,1); Candidates_x(1,:) = ExcelCandidates_x(:,1); Candidates_y(1,:) = ExcelCandidates_y(:,1); if length(CURRENT_SUBSTATIONS) ~= 0 CurrentTr_x = CURRENT_SUBSTATIONS(:,1)'; CurrentTr_y = CURRENT_SUBSTATIONS(:,2)'; CurrentTrCap = CURRENT_SUBSTATIONS(:,3)'; CurrentTrPow = ceil(UtilizationFactor*PowerFactor*CurrentTrCap); else CurrentTr_x = []; CurrentTr_y = []; CurrentTrCap = []; CurrentTrPow = []; end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % initialize transformer locations and powers % one transformer in every load center. initially we assume the first % transformer for all candidate points. TransTypes = length(TransformersTypes); LoadCenters = length(ExcelLoads); CurrentTrNo = length(CurrentTr_x); CandidateNo = length(ExcelCandidates_x); for count1=1:CurrentTrNo, if CurrentTrPow(1,count1) >= ceil((400*UtilizationFactor*PowerFactor)) LimitedCurrentTrPow(1,count1) = KWTransformersTypes(1,6); else LimitedCurrentTrPow(1,count1) = KWTransformersTypes(1,1); end; end; Trans_x = [CurrentTr_x Candidates_x]; Trans_y = [CurrentTr_y Candidates_y]; TransCap = [LimitedCurrentTrPow (KWTransformersTypes(1,1) + zeros(1,length(ExcelCandidates_x)))]; CandidateCenters = length(TransCap); % current + candidate transformers TransPow = zeros(1,CandidateCenters); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % calculation of the distances between transformers % this is a matrice with dimensions: (LoadCenters)*(CandidateCenters) Distances = zeros(LoadCenters,CandidateCenters); for count1=1:LoadCenters,
49
for count2=1:CandidateCenters, Distances(count1,count2) = sqrt((Load_x(1,count1)-Trans_x(1,count2))^2 + (Load_y(1,count1)-Trans_y(1,count2))^2); end; end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CanDistances = zeros(CandidateCenters); for count1=1:CandidateCenters, for count2=1:count1, CanDistances(count1,count2) = sqrt((Trans_x(1,count1)-Trans_x(1,count2))^2 + (Trans_y(1,count1)-Trans_y(1,count2))^2); CanDistances(count2,count1) = CanDistances(count1,count2); end; end; % the distances are pairly compared with 100, if they are smaller than 100 % the transformer with smaller value of load is detached. for count1=1:CandidateCenters, for count2=1:CandidateCenters, if (CanDistances(count1,count2) <= 100) & (count1 ~= count2) & (count1 > CurrentTrNo) TransCap(1,count1) = 0; TransPow(1,count1) = 0; end; end; end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % this function step-up the transformers size until it can feed the total % loads connected to it. % for count1=1:TransTypes, % for count2=1:LoadCenters, % if (TransCap(1,count2) < Loads(1,count2)) && (TransCap(1,count2) ~= 0) % TransCap(1,count2) = SP_stepup(TransCap(1,count2)); % end; % end; % end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % in this subsection, the coordinations of the final possible transformers % are saved in FinalTrans_x & FinalTrans_y and their values in % FinalTransCap. similarly, the coordinations of the loadcenters to be % attached to transformers are saved in FinalLoad_x & FinalLoad_y and their % values in FinalLoad. T = 1; L = LoadCenters; for count1 = 1:CandidateCenters, if (TransCap(1,count1) ~= 0) FinalTransCap(1,T) = TransCap(1,count1); FinalTransPow(1,T) = 0; FinalTrans_x(1,T) = Trans_x(1,count1); FinalTrans_y(1,T) = Trans_y(1,count1); T = T+1; end; end; MaxT = T-1;
50
% MinL = L-1; % if ((MaxT > 23) & (VarCheckPrg == 1)) % warndlg('MATLAB unable to solve! Try smaller number of loads',' DSP Warning'); % display('MATLAB unable to solve! Try smaller number of loads'); % return; % end; AuxTransCap = FinalTransCap; AuxTransPow = FinalTransPow; AuxFinalTrans_x = FinalTrans_x; AuxFinalTrans_y = FinalTrans_y; AuxFinalLoad_x = Load_x; AuxFinalLoad_y = Load_y; AuxFinalLoad = Loads; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % calculation of Distances beetween transformers and loads in a (MinL*MaxT) matrice. for count1=1:LoadCenters, for count2=1:MaxT, TLDistances(count1,count2) = sqrt((AuxFinalLoad_x(1,count1)-AuxFinalTrans_x(1,count2))^2 + (AuxFinalLoad_y(1,count1)-AuxFinalTrans_y(1,count2))^2); end; end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % HERE, THE OPERATION OF GENETIC ALGORITHM IS STARTED. TotalLevels = 0; LowLim = CurrentTrNo; MaxLim = LowLim + (MaxT-CurrentTrNo); for count5=LowLim:MaxLim, TotalLevels = TotalLevels + ceil(nchoosek(MaxT,count5)); end; ScalingFactor = ceil(TotalLevels/20); TotalLevels = ceil(TotalLevels/ScalingFactor); Index = 0; TMat = [(CurrentTrNo+1):MaxT]; % if ((TotalLevels < 20) & (VarCheckPrg == 1)) % warndlg('Try smaller Scaling Factor!',' DSP Warning'); % display('Try smaller Scaling Factor!'); % return; % end; % if ((TotalLevels > 300) & (VarCheckPrg == 1)) % warndlg('Try bigger Scaling Factor!',' DSP Warning'); % display('Try bigger Scaling Factor!'); % return; % end; % if ((VarCheckPrg == 1) & ((TotalLevels <= 300) & (TotalLevels >= 20))) % warndlg('No problem in running program. Push "Run DSP"',' DSP Warning'); % LEVELS = TotalLevels; % LEVELS % display('No problem in running program. Push "Run DSP"'); % return; % end; close all; pack; cfinaltranscap = cell(TotalLevels,1); cfinaltranspow = cell(TotalLevels,1);
51
cfinaltrans_x = cell(TotalLevels,1); cfinaltrans_y = cell(TotalLevels,1); cfinalload = cell(TotalLevels,1); cfinalload_x = cell(TotalLevels,1); cfinalload_y = cell(TotalLevels,1); pack; h = waitbar(0,'PRJ 100.SUBSTATION LOCATION OPTIMIZATION IN PROGRESS.Please wait...BY SAIDI FELIX JUMA.'); for count1=0:(MaxLim-LowLim), % MAIN for. NOTE: "count1" stands for the number of new trans. T = LowLim + count1; % "LowLim" stands for the number of current transformers. numberOfVariables = LoadCenters; L = numberOfVariables; SelCaseMat = nchoosek(TMat,count1); SIZE = size(SelCaseMat); RowNumber = SIZE(1,1); for count2=1:ScalingFactor:RowNumber, Index = Index + 1; Level = Index; SelCaseRow = [[1:CurrentTrNo] SelCaseMat(count2,:)]; % SelCaseRow should be sent to SP_create.m. It is a selection of transformers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % modifying FinalTrans_x,y & FinalLoad_x,y & FinalLoad & % FinalTransPow & FinalTransCap finaltranscap = zeros(1,MaxT) -1; finaltranspow = zeros(1,MaxT) -1; finaltrans_x = zeros(1,MaxT) -1; finaltrans_y = zeros(1,MaxT) -1; for count3=1:T, finaltranscap(1,SelCaseRow(1,count3)) = AuxTransCap(1,SelCaseRow(1,count3)); finaltranspow(1,SelCaseRow(1,count3)) = AuxTransPow(1,SelCaseRow(1,count3)); finaltrans_x(1,SelCaseRow(1,count3)) = AuxFinalTrans_x(1,SelCaseRow(1,count3)); finaltrans_y(1,SelCaseRow(1,count3)) = AuxFinalTrans_y(1,SelCaseRow(1,count3)); end; FinalTransCap = finaltranscap; FinalTransPow = finaltranspow; FinalTrans_x = finaltrans_x; FinalTrans_y = finaltrans_y; cfinaltranscap{Index} = finaltranscap; cfinaltranspow{Index} = finaltranspow; cfinaltrans_x{Index} = finaltrans_x; cfinaltrans_y{Index} = finaltrans_y; finalload = Loads; finalload_x = Load_x; finalload_y = Load_y; % Li = 0; % for count3=1:LoadCenters, % if (size(find(FinalTrans_x==Load_x(1,count3)))==[1 0] | size(find(FinalTrans_y==Load_y(1,count3)))==[1 0]) % Li = Li + 1; % finalload(1,Li) = Loads(1,count3); % finalload_x(1,Li) = Load_x(1,count3); % finalload_y(1,Li) = Load_y(1,count3); % end; % end; FinalLoad = finalload; FinalLoad_x = finalload_x; FinalLoad_y = finalload_y; cfinalload{Index} = finalload; cfinalload_x{Index} = finalload_x; cfinalload_y{Index} = finalload_y;
52
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % calculation of Distances beetween transformers and loads in a (L*T) matrice. Li = 0; FinalTLDistances = 0; BrFinalTransPow = zeros(1,T); BrFinalTransCap = zeros(1,T); BrFinalTrans_x = zeros(1,T); BrFinalTrans_y = zeros(1,T); BrTransIndex = zeros(1,T); for count3=1:MaxT, if (FinalTrans_x(1,count3)~=-1) Li = Li + 1; BrFinalTransPow(1,Li) = FinalTransPow(1,count3); BrFinalTransCap(1,Li) = FinalTransCap(1,count3); BrFinalTrans_x(1,Li) = FinalTrans_x(1,count3); BrFinalTrans_y(1,Li) = FinalTrans_y(1,count3); BrTransIndex(1,Li) = count3; end; end; for r=1:L, for s=1:T, FinalTLDistances(r,s) = sqrt((FinalLoad_x(1,r)-BrFinalTrans_x(1,s))^2 + (FinalLoad_y(1,r)-BrFinalTrans_y(1,s))^2); end; end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % IN THIS SECTION OF MY ALGORITHM IT CAN BE SEEN THAT GA ALGORITHM TOOL IS INVOKED. PLEASE NOTE % THAT I HAVE CREATED MY OWN CROSSOVER,MUTATION AND CREATION FUNCTIONS. WHEN USING THE GA TOOL THIS MUST % BE REMEMBERED.THIS IS WHERE THE OPTIMIZATION ACTUALLY TAKES PLACE FitnessFcn = @(x) SP_fitness(x,FinalTLDistances); options = gaoptimset('PopulationType', 'custom','PopInitRange', ... [1;L]); options = gaoptimset(options,'CreationFcn',@SP_create, ... 'CrossoverFcn',@SP_crossover, ... 'MutationFcn',@SP_mutation, ... 'Generations',300,'PopulationSize',50, ... 'StallGenLimit',20,'StallTimeLimit',inf,'Vectorized','on'); [x(1,Index),fval(1,Index)] = ga(FitnessFcn,numberOfVariables,options); pack; end; Str1 = num2str(floor((Level*100)/((MaxLim-LowLim)+1))); Str2 = '% '; Str3 = ' of 100% Completed'; Message = strcat(Str1,Str2,Str3); disp(Message); disp('INCREASE ACTIVATED....'); waitbar(Level/((MaxLim-LowLim)+1)); end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53
% here, we increase transformers capacities till they could feed % their related loads. close(h); % closes waiting bar [BestVal,BestValIndex] = min(fval); Fitness_Function_Best_Value = BestVal; X = x{BestValIndex}; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % At the end, transformers are stated in terms of their capacities (kVA). % these are saved in "Transformers" variable. note that the positions of % final transformers are saved in FinalTrans_x & FinalTrans_y. % similarly, final loads and their locations are saved in FinalLoad & % FinalLoad_x & FinalLoad_y respectively. Then, every load is connected to % it's correspounding transformer. L = length(X); % T = LoadCenters - L; FinalTransCap = cfinaltranscap{BestValIndex}; FinalTransPow = cfinaltranspow{BestValIndex}; FinalTrans_x = cfinaltrans_x{BestValIndex}; FinalTrans_y = cfinaltrans_y{BestValIndex}; FinalLoad = cfinalload{BestValIndex}; FinalLoad_x = cfinalload_x{BestValIndex}; FinalLoad_y = cfinalload_y{BestValIndex}; for count1=1:MaxT, if (FinalTrans_x(1,count1)~=-1) FinalTransPow(1,count1) = AuxTransPow(1,count1); FinalTransCap(1,count1) = AuxTransCap(1,count1); end; end; Li = 0; BrFinalTransPow = zeros(1,T); BrFinalTransCap = zeros(1,T); BrFinalTrans_x = zeros(1,T); BrFinalTrans_y = zeros(1,T); for count1=1:L, FinalTransPow(1,X(count1,2)) = FinalTransPow(1,X(count1,2)) + FinalLoad(1,X(count1,1)); end; for count3=1:MaxT, if (FinalTrans_x(1,count3) ~= -1) Li = Li + 1; BrFinalTrans_x(1,Li) = FinalTrans_x(1,count3); BrFinalTrans_y(1,Li) = FinalTrans_y(1,count3); BrFinalTransPow(1,Li) = FinalTransPow(1,count3); % last added BrFinalTransCap(1,Li) = FinalTransCap(1,count3); % last added end; end; % newly added for constant transformers positions T = Li; %%%%%%%%%%%%%%%%DELETING ZERO TRANSFORMERS%%%%%%%%%%%%%%%%%%%%%%%% Lj = 1; %an auxalary variable for count3=1:MaxT if (count3 <= CurrentTrNo) DEL_POW(1,Lj) = BrFinalTransPow(1,count3); DEL_CAP(1,Lj) = BrFinalTransCap(1,count3); DEL_X(1,Lj) = BrFinalTrans_x(1,count3); DEL_Y(1,Lj) = BrFinalTrans_y(1,count3); Lj = Lj + 1;
54
elseif (BrFinalTransPow(1,count3) ~= 0) DEL_POW(1,Lj) = BrFinalTransPow(1,count3); DEL_CAP(1,Lj) = BrFinalTransCap(1,count3); DEL_X(1,Lj) = BrFinalTrans_x(1,count3); DEL_Y(1,Lj) = BrFinalTrans_y(1,count3); Lj = Lj + 1; end end BrFinalTransPow = DEL_POW; BrFinalTransCap = DEL_CAP; BrFinalTrans_x = DEL_X; BrFinalTrans_y = DEL_Y; Lj = Lj -1; T = Lj; %%%%%%%%%%%%%%%%ENND OF DELETING ZERO TRANSFORMERS%%%%%%%%%%%%%%%% % newly added for constant transformers positions for count1=1:TransTypes, for count2=1:T, if (BrFinalTransCap(1,count2) < BrFinalTransPow(1,count2)) BrFinalTransCap(1,count2) = SP_stepup(BrFinalTransCap(1,count2),BrFinalTrans_x(1,count2),BrFinalTrans_y(1,count2)); end; end; end; for count1=1:T, Transformers(1,count1) = SP_2kva(BrFinalTransCap(1,count1)); end; % PLOTs plot(Load_x,Load_y,'bo'); % This plots our load centres.. removal leaves only the links hanging hold on; for count1=1:T, if (count1 <= CurrentTrNo) % new transformers are RED plot(BrFinalTrans_x(1,count1),BrFinalTrans_y(1,count1),'b*'); hold on; else plot(BrFinalTrans_x(1,count1),BrFinalTrans_y(1,count1),'r*'); hold on; end; end; for count1=1:L, % The plot function below displays the links/connectors to the loads in the figure TOEXCELCONNECTIONS(count1,1) = count1; TOEXCELCONNECTIONS(count1,2) = FinalLoad_x(1,X(count1,1)); TOEXCELCONNECTIONS(count1,3) = FinalLoad_y(1,X(count1,1)); TOEXCELCONNECTIONS(count1,4) = FinalTrans_x(1,X(count1,2)); TOEXCELCONNECTIONS(count1,5) = FinalTrans_y(1,X(count1,2)); plot([FinalLoad_x(1,X(count1,1)) FinalTrans_x(1,X(count1,2))],[FinalLoad_y(1,X(count1,1)) FinalTrans_y(1,X(count1,2))],'g'); hold on; end; for count1=1:T, TextTransformers(1,count1) = {num2str(Transformers(1,count1))}; end; for count1=1:T, text(BrFinalTrans_x(1,count1)-30,BrFinalTrans_y(1,count1)+40,TextTransformers(1,count1),'FontSize',20,'Color','red'); hold on; end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% new
55
for count1=1:T, plot(BrFinalTrans_x(1,count1),BrFinalTrans_y(1,count1),'r*'); hold on; end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% new for count1=1:LoadCenters, TextAllLoads(1,count1) = {num2str(Loads(1,count1))}; end; for count1=1:LoadCenters, text(Load_x(1,count1)-5,Load_y(1,count1)-20,TextAllLoads(1,count1),'FontSize',8); hold on; end; TransOverLoad = 0; TransOverLoadCandIndex = find(BrFinalTransCap == KWTransformersTypes(1,TransTypes)); % check for overloaded trans.. compared with a 1600kVA Size = length(TransOverLoadCandIndex); for count1=1:Size, if BrFinalTransPow(1,TransOverLoadCandIndex(1,count1)) > BrFinalTransCap(1,TransOverLoadCandIndex(1,count1)) TransOverLoad = 1; break; end; end; if TransOverLoad == 1 warndlg('OverLoaded transformer(s) found!',' DSP Warning'); end; grid on; % Here i have set the grids to be displayed for increased ease in checking the position % OUTPUTS in command window of MATLAB delete ('RESULT.xls'); %Delete files or graphics objects BrFinalTrans_x BrFinalTrans_y Transformers xlswrite('RESULT.xls',Transformers','Transformer Capacities (kVA)'); xlswrite('RESULT.xls',BrFinalTransPow','Transformer Powers (kW)'); xlswrite('RESULT.xls',BrFinalTrans_x','SUBSTATION X coordinates'); xlswrite('RESULT.xls',BrFinalTrans_y','SUBSTATION Y coordinates'); xlswrite('RESULT.xls',TOEXCELCONNECTIONS,'Load(X,Y)-SS(X,Y) Links'); toc; %toc prints the elapsed time since tic was used. display('RESULTS OBTAINED.LOCAL OPTIMA ATTAINED'); display('FIGURE DISPLAYED AND EXCEL FILE "RESULTS" CREATED'); display('(PROJECT NO. 100)');
56
6.1.2 SP_Create
% this function creates the first population used by Genetic Algorithm function pop = SP_create(NVARS,FitnessFcn,options) global T L FinalTransPow FinalLoad FinalTransCap TransTypes AuxTransCap AuxTransPow K2 K3 global SelCaseRow FinalTrans_x FinalTrans_y FinalLoad_x FinalLoad_x FinalLoad_y global AuxFinalTrans_x AuxFinalTrans_y AuxFinalLoad_x AuxFinalLoad_x AuxFinalLoad_y AuxFinalLoad global FinalTLDistances totalPopulationSize = sum(options.PopulationSize); pop = cell(totalPopulationSize,1); for counter=1:NVARS, SelDistance = FinalTLDistances(counter,:); [SelTr,SelectedTrIndex] = min(SelDistance); firstpop(counter,1) = counter; firstpop(counter,2) = SelCaseRow(1,SelectedTrIndex); end; pop{1} = firstpop; for j=2:totalPopulationSize, for count1=1:NVARS, % NVARS=L the number of final loads and also the number of variables. TIndex = randperm(length(SelCaseRow)); popindividual(count1,1) = count1; popindividual(count1,2) = SelCaseRow(1,TIndex(1,1)); end; pop{j} = popindividual; end;
6.1.3 SP_Initialize global VarCheckPrg ScalingFactor SP_main();
6.1.4 SP_fitness
% here, the fitness function is created. the sum of distances from loads to % present transformers are calculated and the set which minimizes this sum % is achieved by MATLAB ga function. % x is an individual % f1= substation installation cost % f2= LV network cost (for conductors loss) % f3= transformers loss cost function scores = SP_fitness(x,FinalTLDistances) global T L FinalTransPow FinalLoad FinalTransCap TransTypes AuxTransCap AuxTransPow K2 K3 MaxT global SelCaseRow FinalTrans_x FinalTrans_y FinalLoad_x FinalLoad_x FinalLoad_y BrTransIndex global AuxFinalTrans_x AuxFinalTrans_y AuxFinalLoad_x AuxFinalLoad_x AuxFinalLoad_y AuxFinalLoad
57
global finaltranspow finaltranscap scores = zeros(size(x,1),1); for u = 1:size(x,1) p = x{u}; VoltageDropWarn = 0; FinalTransPow = finaltranspow; % reset FinalTransPow for every individual FinalTransCap = finaltranscap; % reset FinalTransCap for every individual %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for count1=1:L, FinalTransPow(1,p(count1,2)) = FinalTransPow(1,p(count1,2)) + FinalLoad(1,p(count1,1)); end; for count1=1:TransTypes, for count2=1:MaxT, if (FinalTransPow(1,count2) ~= -1) if (FinalTransCap(1,count2) < FinalTransPow(1,count2)) FinalTransCap(1,count2) = SP_stepup(FinalTransCap(1,count2),FinalTrans_x(1,count2),FinalTrans_y(1,count2)); end; end; end; end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% f1 = 0; for count1=1:MaxT, if (FinalTransCap(1,count1) ~= -1) f1 = f1 + SP_instcost(FinalTransCap(1,count1)); end; end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% f2 = 0; for count1=1:L, % L=NVARS size of final loads c1 = p(count1,1); c2 = p(count1,2); Temp = find(BrTransIndex == c2); f2 = f2 + (1400*K2*(FinalTLDistances(c1,Temp)*(FinalLoad(1,c1)^2))); % check for undervoltage occurence if ((FinalLoad(1,c1)*FinalTLDistances(c1,Temp)) > 7500) VoltageDropWarn = 1; end; end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% f3 = 0; % for count1=1:L, % c1 = p(count1,2); % f3 = f3 + (1400*(K3*SP_tlosscost2(FinalTransCap(1,c1)) + SP_tlosscost1(FinalTransCap(1,c1)))); % end; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if (VoltageDropWarn == 0) scores(u) = f1 + f2 + f3; else scores(u) = f1 + f2 + f3 + (1e9); end; end;
58
6.1.5 SP_Crossover % this function is dedicated for crossover operation used by MATLAB GA % function. function xoverKids = SP_crossover(parents,options,NVARS, ... FitnessFcn,thisScore,thisPopulation) nKids = length(parents)/2; xoverKids = cell(nKids,1); % Normally zeros(nKids,NVARS); index = 1; for i=1:nKids parent = thisPopulation{parents(index)}; index = index + 2; % Flip a section of parent1. p1 = ceil((length(parent) -1) * rand); p2 = p1 + ceil((length(parent) - p1- 1) * rand); child = parent; child(p1:p2) = fliplr(child(p1:p2)); xoverKids{i} = child; % Normally, xoverKids(i,:); end
6.1.6 SP_Mutation % this function is dedicated for crossover operation used by MATLAB ga % function. function mutationChildren = SP_mutation(parents ,options,NVARS, ... FitnessFcn, state, thisScore,thisPopulation,mutationRate) mutationChildren = cell(length(parents),1);% Normally zeros(length(parents),NVARS); for i=1:length(parents) parent = thisPopulation{parents(i)}; % Normally thisPopulation(parents(i),:) p = ceil(length(parent) * rand(1,2)); child = parent; child(p(1)) = parent(p(2)); child(p(2)) = parent(p(1)); mutationChildren{i} = child; % Normally mutationChildren(i,:) end
6.1.7 SP_stepup % this function step-up the transformers size until it can feed the total % loads connected to it. function NextVal = SP_stepup(CurVal,X_Cord,Y_Cord) global KWTransformersTypes TransTypes CurrentTr_x CurrentTr_y global FinalTrans_x FinalTrans_y UtilizationFactor PowerFactor Tag = find(KWTransformersTypes == CurVal); if (Tag ~= TransTypes) if (isempty(find(CurrentTr_x==X_Cord)) & isempty(find(CurrentTr_y==Y_Cord))) %check if a new candidate!? NextVal = KWTransformersTypes(1,Tag+1); elseif (CurVal == KWTransformersTypes(1,5)) % if a 315kVA transformer NextVal = CurVal; else
6.1.8 SP_2kva % this function convert the input to a correspounding kVA. function OutVal = SP_2kva(InVal) global KWTransformersTypes TransformersTypes Tag = find(KWTransformersTypes == InVal); %Tag =Specify a label to associate with a serial port object OutVal = TransformersTypes(1,Tag);
6.1.9 SP_instcost % this function dedicates the primary installation cost % for any distribution substation function subscost = SP_instcost(substation) global KWTransformersTypes InstallCosts Tag = find(KWTransformersTypes == substation); subscost = InstallCosts(1,Tag); d=0;
6.1.10 DSP Running this program invokes the Graphics User Interface (GUI) which was developed in MATLAB. Two buttons will be made available ( run DSP and Help).
function varargout = DSP(varargin) % Pass or return variable numbers of arguments % eg function varargout = foo(n) returns a variable number % of arguments from function foo.m % DSP M-file for DSP.fig % DSP, by itself, creates a new DSP or raises the existing % singleton*. % % H = DSP returns the handle to a new DSP or the handle to % the existing singleton*. % % DSP('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in DSP.M with the given input arguments. % % DSP('Property','Value',...) creates a new DSP or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before DSP_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to DSP_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES
60
% Edit the above text to modify the response to help DSP % Last Modified by GUIDE v2.5 15-MAY-2009 02:23:10 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @DSP_OpeningFcn, ... 'gui_OutputFcn', @DSP_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before DSP is made visible. function DSP_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to DSP (see VARARGIN) % Choose default command line output for DSP handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes DSP wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = DSP_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; function generations_Callback(hObject, eventdata, handles) % hObject handle to generations (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
61
% Hints: get(hObject,'String') returns contents of generations as text % str2double(get(hObject,'String')) returns contents of generations as a double % --- Executes during object creation, after setting all properties. function generations_CreateFcn(hObject, eventdata, handles) % hObject handle to generations (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function populations_Callback(hObject, eventdata, handles) % hObject handle to populations (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of populations as text % str2double(get(hObject,'String')) returns contents of populations as a double % --- Executes during object creation, after setting all properties. function populations_CreateFcn(hObject, eventdata, handles) % hObject handle to populations (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on button press in Run_DSP. function Run_DSP_Callback(hObject, eventdata, handles) % hObject handle to Run_DSP (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) function scalingfactor_Callback(hObject, eventdata, handles)
62
% hObject handle to scalingfactor (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of scalingfactor as text % str2double(get(hObject,'String')) returns contents of scalingfactor as a double % --- Executes during object creation, after setting all properties. function scalingfactor_CreateFcn(hObject, eventdata, handles) % hObject handle to scalingfactor (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
6.1.11 SP_tlosscost1 % this function return the transformer's (input argument) loss function FValue=SP_tlosscost1(InValue) global KWTransformersTypes OpenCircuitLosses Tag = find(KWTransformersTypes == InValue); FValue = OpenCircuitLosses(1,Tag);
6.1.12 SP_losscost2 % this function return the transformer's (input argument) loss function FValue=SP_tlosscost1(InValue) global KWTransformersTypes ShortCircuitLosses Tag = find(KWTransformersTypes == InValue); FValue = ShortCircuitLosses(1,Tag);