0% found this document useful (0 votes)
6 views32 pages

Optimal power flow

Chapter 6 discusses the optimal power flow (OPF) problem, which aims to determine the active and reactive power dispatch of generating units in a power system to supply loads at minimum cost while adhering to network and technical constraints. It introduces the security-constrained optimal power flow (SCOPF) problem, which incorporates security constraints to ensure reliability during contingencies. The chapter includes formulations, constraints, and examples related to the OPF and SCOPF problems, as well as methods for solving them.

Uploaded by

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

Optimal power flow

Chapter 6 discusses the optimal power flow (OPF) problem, which aims to determine the active and reactive power dispatch of generating units in a power system to supply loads at minimum cost while adhering to network and technical constraints. It introduces the security-constrained optimal power flow (SCOPF) problem, which incorporates security constraints to ensure reliability during contingencies. The chapter includes formulations, constraints, and examples related to the OPF and SCOPF problems, as well as methods for solving them.

Uploaded by

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

Chapter 6

Optimal Power Flow

This chapter describes the optimal power flow problem. The objective of this
problem is to find out the active and reactive power dispatch (output) of every
generating unit in a power system that is needed to supply all loads at minimum cost,
while satisfying network and technical constraints. Particularly, voltage magnitudes
throughout the network should be at acceptable levels, and transmission-capacity
limits of all transmission lines should be satisfied. Objectives other than minimum
generation cost are also common.

6.1 Introduction

Active and reactive power demands in a power system need to be supplied both
efficiently and reliably. This is done using the available generating units and the
interconnections with neighboring power systems. In this context, the objective of
the optimal power flow (OPF) problem [1, 3] is determining the active and reactive
power needed from each generating unit to supply all demands, while satisfying
network and technical constraints.
The active and reactive power dispatch (output) of each generating unit is
generally decided with the aim of minimizing costs. However, other objectives are
also possible, e.g., minimum active power losses throughout the network.
The time frame of the OPF problem is typically several minutes prior to power
delivery. That proximity to real-time operation requires a very precise modeling
of all technical constraints governing the generation, transmission, distribution,
and supply of electricity. Such precise modeling is embedded within the OPF
constraints.
The solution of the OPF problem constitutes a snapshot of a future optimal
operating condition of the power system under study. However, since the OPF
problem is solved before power delivery, it may occur that one of the generating

© Springer International Publishing AG 2018 165


A.J. Conejo, L. Baringo, Power System Operations, Power Electronics and Power
Systems, https://doi.org/10.1007/978-3-319-69407-8_6
166 6 Optimal Power Flow

units that is scheduled to provide active and reactive power becomes unavailable
due to a contingency. Thus, the solution of the OPF problem is optimal from an
economic point of view, but it might not be secure since some demands might not
be supplied if a contingency occurs.
In the above context, it is appropriate to consider the security-constrained optimal
power flow (SCOPF) problem, which is an OPF problem that includes security
constraints, so that the failure of one or several generating units, or of one or several
transmission lines does not cause any operation issue.
The remaining of this chapter is organized as follows. Section 6.2 describes
and provides the formulation of the OPF problem. This problem is extended in
Sect. 6.3, which describes and provides the formulation of the SCOPF problem.
Both problems are illustrated through a number of examples. Section 6.4 sum-
marizes the chapter and includes some references for further reading. Section 6.5
provides the GAMS codes [4] needed to solve the illustrative simple examples of
Sects. 6.2 and 6.3. Finally, Sect. 6.6 includes some exercises to further comprehend
the concepts addressed in this chapter.

6.2 Optimal Power Flow

This section describes and formulates the OPF problem.

6.2.1 Description

First, we describe the ingredients of the OPF problem.


We consider a power system with the following characteristics:
• The system has n nodes indexed by i (i D 1; : : : ; n).
• Generating units and demands, indexed by g and by d, respectively, are located
at different nodes of the system.
• Nodes are connected through transmission lines, which are represented using the
-model described in Sect. 3.5 of Chap. 3 of this book.
The OPF problem ensures that all demands are supplied and that all network and
technical constraints are satisfied. This is described in the sections below.
It is important to note that all variables and constants used in this chapter are
represented using the per-unit system described in Sect. 2.6 of Chap. 2 of this book.

6.2.1.1 Power Balance

One of the key constraints of the OPF problem is the power balance (active and
reactive) at each node of the system.
6.2 Optimal Power Flow 167

On the one hand, the active power balance at any node needs to be enforced, i.e.:
X X X
pg  LdP D pik ./; 8i; (6.1)
g2˝i d2 i k2i

where:
• pg is the active power output of generating unit g,
• ˝i is the set of generating units located at node i,
• LdP the active power load of demand d,
• i is the set of demands located at node i,
• pik ./ is the active power flowing from node i to node k through transmission line
ik, which is a function of the voltage magnitudes, vi , vk , and the voltage angles,
ıi , ık , at nodes i and k, and
• i is the set of nodes directly connected to node i through transmission lines.
On the other hand, reactive power balance at any node needs to be imposed as
well and thus:
X X Q X
qg  Ld D qik ./; 8i; (6.2)
g2˝i d2 i k2i

where:
• qg is the reactive power output of generating unit g,
• LdQ is the reactive power load of demand d, and
• qik ./ is the reactive power flowing from node i to node k through transmission
line ik, which is a function of the voltage magnitudes, vi , vk , and the voltage
angles, ıi , ık , at nodes i and k.

6.2.1.2 Power Flows Through Transmission Lines

The active power pik ./ flowing from node i to node k through transmission line ik,
as described in Chap. 4 of this book, is:

pik ./ D vi2 YLik cos. Lik /  vi vk YLik cos.ıi  ık  Lik /

1
C vi2 YSik cos. Sik /; 8i; 8k 2 i ; (6.3)
2
where:
• vN i D vi †ıi and vN k D vk †ık are the voltages (magnitudes and angles) at nodes i
and k, respectively,
• YN Lik D YLik † Lik is the per-unit admittance of transmission line ik, and
• YN Sik D YSik † Sik is the per-unit shunt admittance of transmission line ik.
168 6 Optimal Power Flow

Similarly, the reactive power qik ./ flowing from node i to node k through
transmission line ik, as described in Chap. 4 of this book, is:

qik ./ D vi2 YLik sin. Lik /  vi vk YLik sin.ıi  ık  Lik /

1
 vi2 YSik sin. Sik /; 8i; 8k 2 i : (6.4)
2

6.2.1.3 Active Power Limits

Any generating unit g that is online can produce active power above and below a
lower and an upper limit, respectively, i.e.:

Pmin
g  pg  Pmax
g ; 8g; (6.5)

where:
• Pmin
g (nonnegative) is the minimum active power output of generating unit g and
• Pmax
g is the maximum active power output of generating unit g.
For most thermal units (not nuclear ones), Pmin
g is close to 0:1  Pmax
g , while for
min
hydroelectric units Pg is close to zero.

6.2.1.4 Reactive Power Limits

Similarly, any generating unit g that is online can produce reactive power above and
below a lower and an upper limit, respectively, i.e.:

Qmin
g  qg  Qmax
g ; 8g; (6.6)

where:
• Qmin
g (nonrestricted in sign) is the minimum reactive power output of generating
unit g and
• Qmax
g is the maximum reactive power output of generating unit g.
Typically, Qmax
g  Qmin g , i.e., the capacity of an electric generating unit to
produce reactive power is similar to its capacity to consume reactive power.

6.2.1.5 Transmission Line Limits

The apparent power (magnitude of the complex power sNik ./) flowing from node i to
node k through transmission line ik is (as described in Chap. 4 of this book):
p
sik ./ D C .pik .//2 C .qik .//2 ; 8i; 8k 2 i : (6.7)
6.2 Optimal Power Flow 169

This apparent power is limited at each transmission line and thus:


q
C .pik .//2 C .qik .//2  Sikmax ; 8i; 8k 2 i ; (6.8)

where Sikmax if the maximum apparent power through transmission line ik.
This limit is related to the thermal capacity of the conductors of the line.
However, stability constraints may further reduce this limit.

6.2.1.6 Voltage Magnitude Limits

The voltage magnitude of any node i throughout the network is bounded above and
below. Therefore:

Vimin  vi  Vimax ; 8i; (6.9)

where Vimin and Vimax are, respectively, the lower and upper limits of the voltage
magnitude at node i.

6.2.1.7 Voltage Angle Limits

Finally, the voltage angles should be within given bounds, i.e.:

   ıi  ; 8i: (6.10)

Moreover, the voltage angle at the reference node is known and thus:

ıi D 0; i: ref. (6.11)

6.2.1.8 Objective Function

The objective of the OPF problem is to find out the active and reactive power
production of each generating unit that minimizes the overall cost and satisfies all
the constraints described in the previous sections.
It is important to note that there is no significant cost for reactive power
production or consumption. Thus, the overall cost comprises the active power
production cost of each generating unit.
If Cg is the marginal cost of active power production by generating unit g, then
the total production cost is:
X
Cg pg : (6.12)
g
170 6 Optimal Power Flow

It should be noted that a general cost function may be considered instead and
thus:
X  
cg pg ; (6.13)
g

X 
e.g., we may consider a quadratic cost function, i.e., CgF C CgL pg C CgQ p2g ,
g2˝
where CgF , CgL , and CgQ are the fixed, linear, and quadratic cost terms, respectively,
of the cost function of generating unit g.

6.2.2 Formulation

Considering the description in Sect. 6.2.1, the OPF problem can be formulated as:
min
X
cg .pg / (6.14a)
g

subject to
X X X
pg  LdP D pik ./; 8i; (6.14b)
g2˝i d2 i k2i
X X X
qg  LdQ D qik ./; 8i; (6.14c)
g2˝i d2 i k2i

pik ./ D vi2 YLik cos. Lik /  vi vk YLik cos.ıi  ık  Lik /

1
C vi2 YSik cos. Sik /; 8i; 8k 2 i ; (6.14d)
2
qik ./ D vi2 YLik sin. Lik /  vi vk YLik sin.ıi  ık  Lik /

1
 vi2 YSik sin. Sik /; 8i; 8k 2 i (6.14e)
2
q
C .pik .//2 C .qik .//2  Sikmax ; 8i; 8k 2 i ; (6.14f)

Pmin
g  pg  Pmax
g ; 8g; (6.14g)
Qmin
g  qg  Qmax
g ; 8g; (6.14h)
Vimin  vi  Vimax ; 8i; (6.14i)
   ıi  ; 8i; (6.14j)
ıi D 0; i: ref.; (6.14k)
6.2 Optimal Power Flow 171

˚
where variables in set  D vi ; ıi ; 8iI pg ; qg ; 8gI pik ; qik ; sik ; 8i; 8k 2 i are the
optimization variables of problem (6.14).
Problem (6.14) is the so-called OPF problem. Objective function (6.14a) is
the total cost. Constraints (6.14b) and (6.14c) impose the active and reactive
power balance at each node, respectively. Active and reactive power flows through
transmission lines are defined by constraints (6.14d) and (6.14e), respectively. Con-
straints (6.14f) enforce the capacity limits for transmission lines. Constraints (6.14g)
and (6.14h) limit the active and reactive power production of each generating unit,
respectively. Constraints (6.14i) and (6.14j) enforce the voltage magnitude and angle
limits at each node, respectively. Finally, constraint (6.14k) sets the voltage angle
at the reference node.

6.2.3 Solution

The OPF problem (6.14) is a nonlinear programming (NLP) problem [6], whose
solution can be obtained using one of the methods below:
1. Iterative methods, e.g., Newton methods [8].
2. NLP optimization solvers, e.g., CONOPT [2].
3. Specific software tools, e.g., Matpower [9].
For the sake of simplicity, in the remaining of this chapter we use CONOPT
under GAMS [4] to obtain the solution of OPF problem.
Illustrative Example 6.1 Optimal power flow
We consider a power network with three nodes and three transmission lines, as
the one depicted in Fig. 6.1.
Using the series impedance of transmission lines, we first compute the series
admittances in per unit and radians as follows:

1
YL12 † L12 D YL13 † L13 D YL23 † L23 D D 9:9504†  1:4711 puS:
0:01 C j0:1

We assume that the shunt admittances are null.


Additionally, we consider the following data (see Fig. 6.1):
1. Node 1 includes a generating unit with lower and upper bounds of active power
generation equal to 0 and 3 puW, respectively, and of reactive power generation
equal to 2 puvar and 2 puvar, respectively.
2. Node 2 includes a generating unit with lower and upper bounds of active power
generation equal to 0 and 0.8 puW, respectively, and of reactive power generation
equal to 2 puvar and 2 puvar, respectively.
3. Node 3 is a load node with active and reactive power demands equal to 0.8 puW
and 0.6 puvar, respectively.
4. The lower and upper limits of voltage magnitudes for all three nodes are 0.95 puV
and 1.10 puV, respectively.
172 6 Optimal Power Flow

0 ≤ p1 ≤ 3 0 ≤ p2 ≤ 0.8
−2 ≤ q1 ≤ 2 −2 ≤ q 2 ≤ 2
C1 = 2 Z¯ L12 = 0.01 + j 0.1 C2 = 1
max = S max = 0.25
S 12 21

0.95 ≤ v 1 ≤ 1.10 1 2 0.95 ≤ v 2 ≤ 1.10

max = S max = 2
S 13 max = S max = 2
S 23
31 32
¯
Z L13 = 0.01 + j 0.1 ¯
Z L23 = 0.01 + j 0.1

3 0.95 ≤ v 3 ≤ 1.10
d3 = 0

0.8 + j 0.6

Fig. 6.1 Illustrative Example 6.1: three-node power system

5. The marginal production costs of generating units at nodes 1 and 2 are $2/puW
and $1/puW, respectively.
6. The capacity limits of transmission lines 1–2, 1–3, and 2–3 (in both directions)
are 0.25 puVA, 2 puVA, and 2 puVA, respectively.
7. The reference node is node 3 and, thus, ı3 D 0.
The OPF problem formulation is provided below.
On the one hand, the objective is to:
minp1 ;p2 ;q1 ;q2 ;v1 ;v2 ;v3 ;ı1 ;ı2 ;ı3

2p1 C 1p2 :

Note that the objective function above is linear.


On the other hand, the constraints of the OPF problem are provided and briefly
described below.
The active power balance constraints at nodes 1, 2, and 3 are, respectively:

p1 D 9:9504 cos.1:4711/v12  9:9504v1 v2 cos.ı1  ı2 C 1:4711/


C 9:9504 cos.1:4711/v12  9:9504v1 v3 cos.ı1  ı3 C 1:4711/;
p2 D 9:9504 cos.1:4711/v22  9:9504v2 v1 cos.ı2  ı1 C 1:4711/
C 9:9504 cos.1:4711/v22  9:9504v2 v3 cos.ı2  ı3 C 1:4711/;
 0:8 D 9:9504 cos.1:4711/v32  9:9504v3 v1 cos.ı3  ı1 C 1:4711/
C 9:9504 cos.1:4711/v32  9:9504v3 v2 cos.ı3  ı2 C 1:4711/:
6.2 Optimal Power Flow 173

The reactive power balance constraints at nodes 1, 2, and 3 are, respectively:

q1 D 9:9504 sin.1:4711/v12  9:9504v1 v2 sin.ı1  ı2 C 1:4711/


 9:9504 sin.1:4711/v12  9:9504v1 v3 sin.ı1  ı3 C 1:4711/;
q2 D 9:9504 sin.1:4711/v22  9:9504v2 v1 sin.ı2  ı1 C 1:4711/
 9:9504 sin.1:4711/v22  9:9504v2 v3 sin.ı2  ı3 C 1:4711/;
 0:6 D 9:9504 sin.1:4711/v32  9:9504v3 v1 sin.ı3  ı1 C 1:4711/
 9:9504 sin.1:4711/v32  9:9504v3 v2 sin.ı3  ı2 C 1:4711/:

The capacity constraints of transmission lines in directions 1–2, 1–3, and 2–3
are, respectively:
h 2
9:9504 cos.1:4711/v12  9:9504v1 v2 cos.ı1  ı2 C 1:4711/
 2 i1=2
C 9:9504 sin.1:4711/v12  9:9504v1 v2 sin.ı1  ı2 C 1:4711/  0:25;
h 2
9:9504 cos.1:4711/v12  9:9504v1 v3 cos.ı1  ı3 C 1:4711/
 2 i1=2
C 9:9504 sin.1:4711/v12  9:9504v1 v3 sin.ı1  ı3 C 1:4711/  2;
h 2
9:9504 cos.1:4711/v22  9:9504v2 v3 cos.ı2  ı3 C 1:4711/
 2 i1=2
C 9:9504 sin.1:4711/v22  9:9504v2 v3 sin.ı2  ı3 C 1:4711/  2:

Similarly, the capacity constraints of transmission lines in directions 2–1, 3–1,


and 3–2 are, respectively:
h 2
9:9504 cos.1:4711/v22  9:9504v2 v1 cos.ı2  ı1 C 1:4711/
 2 i1=2
C 9:9504 sin.1:4711/v22  9:9504v2 v1 sin.ı2  ı1 C 1:4711/  0:25;
h 2
9:9504 cos.1:4711/v32  9:9504v3 v1 cos.ı3  ı1 C 1:4711/
 2 i1=2
C 9:9504 sin.1:4711/v32  9:9504v3 v1 sin.ı3  ı1 C 1:4711/  2;
h 2
9:9504 cos.1:4711/v32  9:9504v3 v2 cos.ı3  ı2 C 1:4711/
 2 i1=2
C 9:9504 sin.1:4711/v32  9:9504v3 v2 sin.ı3  ı2 C 1:4711/  2:
174 6 Optimal Power Flow

Active power limits are:

0  p1  3;
0  p2  0:8:

Reactive power limits are:

 2  q1  2;
 2  q2  2:

Voltage magnitude limits are:

0:95  v1  1:10;
0:95  v2  1:10;
0:95  v3  1:10:

Finally, voltage angle limits are:

   ı1  ;
   ı2  ;
ı3 D 0:

The solution of the OPF problem in per unit (angles in radians) is provided in
Tables 6.1, 6.2, 6.3, and 6.4 (note that superscript indicates optimal value).
Table 6.1 provides the total cost, as well as the active and reactive power
outputs of generating units. As expected, most of the active power is supplied
by the generating unit at node 2, whose marginal production cost is half the
marginal production cost of the generating unit at node 1. Both generating units
are used to supply a demand of 0.8 puW and 0.6 puvar of active and reactive power,
respectively. However, the total active and reactive power outputs are 0.8052 puW

Table 6.1 Illustrative Cost [$] 0.8361


Example 6.1: cost, active, and
p
1 [puW] 0.0309
reactive power outputs
p
2 [puW] 0.7743
q
1 [puvar] 0.3209
q
2 [puvar] 0.3308

Table 6.2 Illustrative vN1 [puV] 1:0977†0:0212


Example 6.1: voltage outputs
vN2 [puV] 1:1000†0:0419
vN3 [puV] 1:0664†0
6.2 Optimal Power Flow 175

Table 6.3 Illustrative s [puVA] 0.2495


12
Example 6.1: apparent power
s
21 [puVA] 0.2500
flows
s
13 [puVA] 0.4244
s
31 [puVA] 0.4123
s
23 [puVA] 0.6184
s
32 [puVA] 0.5995

Table 6.4 Illustrative Example 6.1: complex power flows and losses
sN
12 [puVA] 0:24946688 C j0:00228492
sN
21 [puVA] 0:24998341 C j0:00288037 sN N
12 C s 21 [puVA] 5:1653  10
4
C j5:1653  103
sN
13 [puVA] 0:28037374 C j0:31863181
sN
31 [puVA] 0:27887877  j0:30368212 sN N
13 C s 31 [puVA] 0:0014950 C j0:0149497
sN
23 [puVA] 0:52428159 C j0:32792149
sN
32 [puVA] 0:52112123  j0:29631788 sN N
23 C s 32 [puVA] 0:0031604 C j0:0316036

and 0.6517 puvar, respectively. These differences are due to the active and reactive
power losses in transmission lines.
Table 6.2 provides the voltage at each node. Voltage magnitudes are in per unit,
while voltage angles are in radians. Note that the voltage magnitude at node 2 is at
its upper limit.
Table 6.3 provides the apparent power flows in each transmission line and in
both directions. All these flows are below the corresponding limits. However, the
apparent power flow of transmission line 1–2 (in direction 2–1) is at its upper limit,
which means that this line is congested.
Finally, Table 6.4 provides complex power flows and line losses.

The OPF problem in Illustrative Example 6.1 is solved using CONOPT [2] under
GAMS [4]. Two GAMS codes to solve this problem are provided in Sect. 6.5.
Illustrative Example 6.2 Impact of voltage magnitude and transmission capacity
limits on the OPF problem
If we observe the data and results of Illustrative Example 6.1, it seems logical
that the active power supplied by the generating unit at node 2 is higher than the
active power supplied by the generating unit at node 1 since the marginal cost of the
latter is twice the marginal cost of the former.
However, note that the maximum power that can be supplied by the generating
unit at node 2 is 0.8 puW, while only 0.7743 puW are supplied by that unit. This is
due to the network constraints of the power system under study. If we look at the
results of Illustrative Example 6.1, we observe that both the voltage magnitude at
node 2 and the apparent power flow in transmission line 1–2 (in direction 2–1) are
at their upper limits. This prevents the cheap generating unit at node 2 to be used at
capacity.
176 6 Optimal Power Flow

Table 6.5 Illustrative Original limits Relaxed limits


Example 6.2: cost, active, and
reactive power outputs Cost 0.8361 0.8088
p
1 [puW] 0.0309 0.0044
p
2 [puW] 0.7743 0.8000
q
1 [puvar] 0.3209 0.3370
q
2 [puvar] 0.3308 0.3070

Table 6.6 Illustrative Original limits Relaxed limits


Example 6.2: voltage
magnitude output vN1 [puV] 1:0977†0:0212 1:1988†0:0170
vN2 [puV] 1:1000†0:0419 1:2000†0:0357
vN3 [puV] 1:0664†0 1:1699†0

Table 6.7 Illustrative Original limits Relaxed limits


Example 6.2: apparent power
output s
12 [puVA] 0.2495 0.2672
s
21 [puVA] 0.2500 0.2675
s
13 [puVA] 0.4244 0.4209
s
31 [puVA] 0.4123 0.4108
s
23 [puVA] 0.6184 0.6199
s
32 [puVA] 0.5995 0.6044

To verify this, we relax these two limits and consider that the upper bound for
voltage magnitudes at every node is 1.2 puV, while the capacity of transmission line
1–2 in both directions is considered to be 2 puVA.
The solution of the OPF problem in both cases (with original and relaxed limits)
are provided in Tables 6.5, 6.6, and 6.7.
Table 6.5 provides the total cost, as well as the active and reactive power outputs
of the generating units. By relaxing the voltage magnitude and apparent power
limits, the active power output of the generating unit at node 2 is at its upper limit
(0.8 puW). This translates into a 3.27% reduction of the total cost.
Table 6.6 provides the voltage at each node. Note that if voltage magnitude and
apparent power limits are relaxed, the voltage magnitude at all nodes is above its
original limit, which was 1.1 puV.
Finally, Table 6.7 provides the apparent power flows in each transmission line
and in both directions. Note that by considering the relaxed limits, the apparent
power flow in transmission line 1–2 (in both directions) is above its original limit,
which was 0.25 puVA.

6.2 Optimal Power Flow 177

6.2.4 dc Formulation

The OPF problem (6.14) formulated in the previous section is an NLP problem.
Solving it may require a very large computation time in power systems with a large
number of nodes and transmission lines.
For off-line analysis, it might be possible to use a dc formulation of the power
flow problem. However, note that the solution of this linearized problem is only
approximate and does not guarantee that all technical constraints are satisfied.
As explained in Sect. 4.10 of Chap. 4 of this book, the approximations considered
in the dc power flow are threefold:
1. Voltage magnitudes are equal to 1 in per unit.
2. Resistances are neglected.
3. Voltage angle differences across lines are considered to be small.
These assumptions allow formulating the linearized OPF problem as the follow-
ing linear programming (LP) problem:
min
X
cg .pg / (6.15a)
g

subject to
X X X
pg  LdP D pik ./; 8i; (6.15b)
g2˝i d2 i k2i

ıi  ı k
pik ./ D ; 8i; 8k 2 i ; (6.15c)
Xik
pik ./  Pmax
ik ; 8i; 8k 2 i ; (6.15d)
Pmin
g  pg  Pmax
g ; 8g; (6.15e)
   ıi  ; 8i; (6.15f)
ıi D 0 i: ref.; (6.15g)

where:
• Xik is the reactance of transmission line ik,
• Pmax
ik is the maximum active power flow through transmission line ik, and
• variables in set  D fpg ; 8gI pik ./; 8i; 8k 2 i I ıi ; 8ig are the optimization
variables of problem (6.15).
Problem (6.15) is a dc OPF problem. The objective function (6.15a) is the
total production cost. Constraints (6.15b) impose the active power balance at
each node of the system. The active power flows through transmission lines are
defined by constraints (6.15c) and limited by the corresponding capacity limits by
178 6 Optimal Power Flow

constraints (6.15d). Constraints (6.15e) impose lower and upper limits on the power
outputs of generating units. Finally, constraints (6.15f) and (6.15g) impose bounds
on voltage angles and fix to 0 the voltage angle at the reference node, respectively.
It is relevant to note that using model (6.15), pik D pki since losses are ignored.
Moreover, no constraints can be enforced on voltage magnitudes, apparent power
flows, or reactive power generation. Hence, the outcome of this model might not be
realizable in practice.
Illustrative Example 6.3 dc OPF problem
We consider again the data of Illustrative Example 6.1. However, in this case, we
solve a dc OPF problem.
Considering the assumptions of the dc OPF problem, the formulation is as
follows:
minp1 ;p2 ;ı1 ;ı2 ;ı3

2p1 C 1p2

subject to

ı1  ı 2 ı 1  ı3
p1 D C ;
0:1 0:1
ı2  ı 1 ı 2  ı3
p2 D C ;
0:1 0:1
ı3  ı1 ı3  ı2
 0:8 D C ;
0:1 0:1
ı1  ı 2
 0:25;
0:1
ı1  ı3
 2;
0:1
ı2  ı3
 2;
0:1
ı2  ı1
 0:25;
0:1
ı3  ı1
 2;
0:1
ı3  ı2
 2;
0:1
0  p1  3;
0  p2  0:8;
   ı1  ;
6.3 Security-Constrained Optimal Power Flow 179

Table 6.8 Illustrative ac OPF dc OPF


Example 6.3: cost and active
power outputs Cost 0.8361 0.8250
p
1 [puW] 0.0309 0.0250
p
2 [puW] 0.7743 0.7750

Table 6.9 Illustrative ac OPF dc OPF


Example 6.2: apparent power
output p
12 [puVA] -0.2495 -0.2500
p
21 [puVA] 0.2500 0.2500
p
13 [puVA] 0.2804 0.2750
p
31 [puVA] -0.2789 -0.2750
p
23 [puVA] 0.5243 0.5250
p
32 [puVA] -0.5211 -0.5250

   ı2  ;
ı3 D 0:

The solution of the dc OPF problem and its comparison with the solution of the
ac OPF problem solved in Illustrative Example 6.1 are provided in Tables 6.8 and
6.9.
Table 6.8 provides the total cost and the active power outputs of the generating
units. Solutions of both problems are similar. However, the total power output in the
dc OPF problem is lower than that in the ac OPF problem. This is so because in the
dc OPF problem, resistances are not considered, and thus active power losses are
null.
Table 6.9 provides the active power flows through transmission lines. Solutions
of both problems are also similar in this case.

The OPF problem in Illustrative Example 6.3 is solved using CPLEX [7] under
GAMS [4].
A GAMS code to solve this problem is provided in Sect. 6.5.

6.3 Security-Constrained Optimal Power Flow

The OPF problem analyzed in the previous section is extended in this section by
including security constraints. The resulting problem is known as the security-
constrained optimal power flow (SCOPF), i.e., an OPF problem with security
constraints.
180 6 Optimal Power Flow

6.3.1 Description

The output of the OPF problem analyzed in the previous section provides the
operating condition of the system that minimizes total production cost and meets
all the technical and network constraints. This solution is economically optimal;
however, it is generally not secure. For example, if we consider the solution of
the OPF problem and assume that a transmission line is unavailable due to a
contingency, the output from the OPF problem may no longer be feasible.
To deal with this issue, the SCOPF problem seeks to identify an operating
condition that renders minimum operating cost, but that is also secure with respect
to a prespecified set of contingencies, i.e., of component failures.
Typical contingencies include the failure of a transmission line or of a generating
unit. Multiple-element contingencies are also possible, including the failure of
one or more transmission lines, and/or of one or more generating units. In this
sense, if we ensure security for any contingency involving just one element (either
transmission line or generating unit), we say that the operation state of the system
is n  1 secure. If, on the other hand, we ensure that the system operation state is
secure for any contingency involving at most k elements, we say that the operation
state of the system is n  k secure.
This security enforcement can be done either in a preventive or in a corrective
manner. The preventive approach ensures that the system operates without limit
violations (including transmission line capacity and voltage level) after the contin-
gency. On the other hand, the corrective approach ensures that, after the contingency,
the system can transition to another feasible operating condition without limit
violations.
For the sake of simplicity, we adopt below a corrective approach, which is
generally more economical than a preventive approach. However, a preventive
approach can be implemented similarly.

6.3.2 Formulation

A SCOPF problem embodying a corrective approach and considering a selected


number of contingencies indexed by ! is provided below:
min;!
X  
cg pg (6.16a)
g

subject to
X X X
pg  LdP D pik ./; 8i; (6.16b)
g2˝i d2 i k2i
X X X
qg  LdQ D qik ./; 8i; (6.16c)
g2˝i d2 i k2i
6.3 Security-Constrained Optimal Power Flow 181

pik ./ D vi2 YLik cos. Lik /  vi vk YLik cos.ıi  ık  Lik /

1
C vi2 YSik cos. Sik /; 8i; 8k 2 i ; (6.16d)
2
qik ./ D vi2 YLik sin. Lik /  vi vk YLik sin.ıi  ık  Lik /

1
 vi2 YSij sin. Sik /; 8i; 8k 2 i ; (6.16e)
2
q
C .pik .//2 C .qik .//2  Sikmax ; 8i; 8k 2 i ; (6.16f)

Pmin
g  pg  Pmax
g ; 8g; (6.16g)
Qmin
g  qg  Qmax
g ; 8g; (6.16h)
Vimin  vi  Vimax ; 8i; (6.16i)
   ıi  ; 8i; (6.16j)
ıi D 0; i: ref.; (6.16k)
X X X
pg!  LdP D pik! ./; 8i; 8!; (6.16l)
g2˝i d2 i k2i
X X X
qg!  LdQ D qik! ./; 8i; 8!; (6.16m)
g2˝i d2 i k2i

2
pik! ./ D vi! YLik cos. Lik /  vi! vk! YLik cos.ıi!  ık!  Lik /

1 2
C vi! YSik cos. Sik /; 8i; 8k 2 i ; 8!; (6.16n)
2
2
qik! ./ D vi! YLik sin. Lik /  vi! vk! YLik sin.ıi!  ık!  Lik /

1 2
 vi! YSik sin. Sik /; 8i; 8k 2 i ; 8!; (6.16o)
2
q
C .pik! .//2 C .qik! .//2  Sik!
max
; 8i; 8k 2 i ; 8!; (6.16p)

g!  pg!  Pg! ;
Pmin 8g; 8!;
max
(6.16q)

g!  qg!  Qg! ;
Qmin 8g; 8!;
max
(6.16r)
Vimin  vi!  Vimax ; 8i; 8!; (6.16s)
   ıi!  ; 8i; 8!; (6.16t)
ıi! D 0; i: ref.; 8!; (6.16u)
pg!  pg  Rg ; 8g; 8!; (6.16v)
pg  pg!  Rg ; 8g; 8!; (6.16w)
182 6 Optimal Power Flow

where variables in sets  D fvi ; ıi ; 8iI pg ; qg ; 8gI pik ; qik ; sik ; 8i; 8k 2 i g
and ! D fvi! ; ıi! ; 8iI pg! , qg! ; 8gI pik! ; qik! ; sik! ; 8i; 8k 2 i g, 8!, are the
optimization variables of the SCOPF problem (6.16).
Equation (6.16a) is the objective function of the SCOPF problem and rep-
resents total production cost. This problem includes three sets of constraints,
namely (6.16b)–(6.16k), (6.16l)–(6.16u), and (6.16v) and (6.16w).
Constraints (6.16b)–(6.16k) are the conventional constraints of the OPF problem.
Note that these constraints are identical to those considered in the OPF prob-
lem (6.14b)–(6.14k).
Constraints (6.16l)–(6.16u) are OPF constraints per contingency !. These
constraints ensures that if contingency ! occurs, then there is a feasible system
operating condition. Note that constraints (6.16l)–(6.16u) are similar to con-
straints (6.14b)–(6.14k) but including subscript !.
Finally, constraints (6.16v) and (6.16w) are coupling conditions (ramping limits)
liking pre- and post-contingency operating conditions. Note that Rg is the active
power up-/down-ramp limit of generating unit g.
Illustrative Example 6.4 Security-constrained optimal power flow
A single-contingency SCOPF example is provided below. We consider Illus-
trative Example 6.1 and impose corrective protection against a contingency that
reduces the capacity of transmission line 2–3 to 0:4 puVA. The ramp limits of
generating units at nodes 1 and 2 are 3 puW and 0.2 puW, respectively.
The formulation of the SCOPF problem includes all the constraints considered in
Illustrative Example 6.1 and some additional constraints that allow considering the
contingency in transmission line 2–3. Thus, the formulation of this SCOPF problem
is as follows:
min

2p1 C 1p2

subject to

Constraints in Illustrative Example 6.1;


p1! D 9:9504 cos.1:4711/v12  9:9504v1! v2! cos.ı1!  ı2! C 1:4711/
2
C 9:9504 cos.1:4711/v1!  9:9504v1! v3! cos.ı1!  ı3! C 1:4711/;
2
p2! D 9:9504 cos.1:4711/v2!  9:9504v2! v1! cos.ı2!  ı1! C 1:4711/
2
C 9:9504 cos.1:4711/v2!  9:9504v2! v3! cos.ı2!  ı3! C 1:4711/;
2
 0:8 D 9:9504 cos.1:4711/v3!  9:9504v3! v1! cos.ı3!  ı1! C 1:4711/
2
C 9:9504 cos.1:4711/v3!  9:9504v3! v2! cos.ı3!  ı2! C 1:4711/;
2
q1! D 9:9504 sin.1:4711/v1!  9:9504v1! v2! sin.ı1!  ı2! C 1:4711/
6.3 Security-Constrained Optimal Power Flow 183

2
 9:9504 sin.1:4711/v1!  9:9504v1! v3! sin.ı1!  ı3! C 1:4711/;
2
q2! D 9:9504 sin.1:4711/v2!  9:9504v2! v1! sin.ı2!  ı1! C 1:4711/
2
 9:9504 sin.1:4711/v2!  9:9504v2! v3! sin.ı2!  ı3! C 1:4711/;
2
 0:6 D 9:9504 sin.1:4711/v3!  9:9504v3! v1! sin.0  ı1! C 1:4711/
2
 9:9504 sin.1:4711/v3!  9:9504v3! v2! sin.0  ı2! C 1:4711/;
h 2
2
9:9504 cos.1:4711/v1!  9:9504v1! v2! cos.ı1!  ı2! C 1:4711/
 2
2 i1=2
C 9:9504 sin.1:4711/v1! 9:9504v1! v2! sin.ı1! ı2! C1:4711/  0:25;
h 2
2
9:9504 cos.1:4711/v1!  9:9504v1! v3! cos.ı1!  ı3! C 1:4711/
 2
2 i1=2
C 9:9504 sin.1:4711/v1!  9:9504v1! v3! sin.ı1!  ı3! C 1:4711/  2;
h 2
2
9:9504 cos.1:4711/v2!  9:9504v2! v3! cos.ı2!  ı3! C 1:4711/
 2
2 i1=2
C 9:9504 sin.1:4711/v2! 9:9504v2! v3! sin.ı2! ı3! C1:4711/  0:4;
h 2
2
9:9504 cos.1:4711/v2!  9:9504v2! v1! cos.ı2!  ı1! C 1:4711/
 2
2 i1=2
C 9:9504 sin.1:4711/v2! 9:9504v2! v1! sin.ı2! ı1! C1:4711/  0:25;
h 2
2
9:9504 cos.1:4711/v3!  9:9504v3! v1! cos.0  ı1! C 1:4711/
 2
2 i1=2
C 9:9504 sin.1:4711/v3!  9:9504v3! v1! sin.ı3!  ı1! C 1:4711/  2;
h 2
2
9:9504 cos.1:4711/v3!  9:9504v3! v2! cos.ı3!  ı2! C 1:4711/
 2
2 i1=2
C 9:9504 sin.1:4711/v3! 9:9504v3! v2! sin.ı3! ı2! C1:4711/  0:4;

0:95  v1!  1:10;


0:95  v2!  1:10;
0:95  v3!  1:10;
0  p1!  3;
0  p2!  0:8;
 2  q1!  2;
 2  q2!  2;
184 6 Optimal Power Flow

Table 6.10 Illustrative OPF SCOPF


Example 6.4: cost, active, and
reactive power outputs Cost [$] 0.8361 1.1876
p
1 [puW] 0.0309 0.3832
p
2 [puW] 0.7743 0.4212
q
1 [puvar] 0.3209 0.3236
q
2 [puvar] 0.3308 0.3202

Table 6.11 Illustrative OPF SCOPF


Example 6.4: voltage
magnitude outputs v1 [puV] 1.0977 1.1000
v2 [puV] 1.1000 1.1000
v3 [puV] 1.0664 1.0676

Table 6.12 Illustrative OPF SCOPF


Example 6.4: apparent power
outputs s
12 [puVA] 0:2495 0:0128
s
21 [puVA] 0:2500 0:0128
s
13 [puVA] 0:4244 0:5106
s
31 [puVA] 0:4123 0:4956
s
23 [puVA] 0:6184 0:5198
s
32 [puVA] 0:5995 0:5045

   ı1!  ;
   ı2!  ;
ı3! D 0;
p1!  p1  3;
p1  p1!  3;
p2!  p2  0:2;
p2  p2!  0:2;

where the set  D fp1 , p2 , q1 , q2 , v1 , v2 , v3 , ı1 , ı2 , p1! , p2! , q1! , q2! , v1! , v2! ,
v3! , ı1! , ı2! , ı3! g includes the optimization variables of the considered SCOPF
problem.
Results of the SCOPF problem and its comparison with the results of the OPF
problem in Illustrative Example 6.1 are provided in Tables 6.10, 6.11, and 6.12.
Table 6.10 provides the total cost, as well as the active and reactive power outputs
of the generating units. These results verify that enforcing security constraints
results in a different operating condition. The resulting optimal cost is higher than
that without security enforcement, but protection is in place. We observe that the
expensive generating unit at node 1 picks a higher share of the load.
Table 6.11 provides the voltage magnitude at each node. Note that in this case
the results of the OPF and the SCOPF problems are rather similar.
6.5 GAMS Codes 185

Finally, Table 6.12 provides the apparent power flows in each transmission line
and in both directions. Note that, considering the SCOPF problem, transmission line
1–2 becomes slightly loaded.

An input GAMS [4] file to solve the SCOPF problem with a single contingency
(as the one in Illustrative Example 6.4 above) is provided in Sect. 6.5.4.

6.4 Summary and Further Reading

This chapter describes and analyzes the OPF and SCOPF problems.
On the one hand, the OPF problem allows determining the active and reactive
power outputs of each generating unit that are needed to supply all demands in
a power system with a desired objective (e.g., minimum production cost) but, at
the same time, enforcing operation limits of both the generation and transmission
systems.
On the other hand, a SCOPF problem is an OPF problem with constraints
ensuring an appropriate functioning of the system even if contingencies occur.
Security is generally enforced in a corrective, not preventive, manner.
The OPF and SCOPF problems are important tools in any power system control
center. Particularly, the SCOPF problem ensures a secure operation minutes prior to
power delivery.
Additional details regarding the OPF and the SCOPF problems is provided in the
monograph by Gómez-Expósito et al. [5] and in that by Wood et al. [8].

6.5 GAMS Codes

This section includes different GAMS [4] codes to solve the illustrative examples
in Sects. 6.2 and 6.3 namely:
1. Two GAMS codes to solve the OPF problem in Illustrative Example 6.1: (1) a
simple code that is only valid for the system and data considered in Illustrative
Example 6.1 and (2) a rather general code that can be readily used for any power
system.
2. A GAMS code to solve the dc OPF problem in Illustrative Example 6.3.
3. A GAMS code to solve the SCOPF problem in Illustrative Example 6.4.
186 6 Optimal Power Flow

6.5.1 Simple OPF Code

A simple input GAMS [4] file to solve the OPF problem in Illustrative Example 6.1
is provided below:
1 parameters
2 yl / 9.95037190209989/
3 al / -1.47112767430373/;
4 variables
5 z, p1, p2, q1, q2, v1, v2, v3, d1, d2;
6 p1.lo = 0; p2.lo = 0;
7 p1.up = 3; p2.up = 0.8;
8 q1.lo = -2; q2.lo = -2;
9 q1.up = 2; q2.up = 2;
10 v1.lo = .95; v2.lo = .95; v3.lo = .95;
11 v1.up = 1.1; v2.up = 1.1; v3.up = 1.1;
12 d1.lo = -pi; d2.lo = -pi;
13 d1.up = pi; d2.up = pi;
14 v1.l=1; v2.l=1; v3.l=1;
15 d1.l=0; d2.l=0;
16 equations
17 of, bp1, bp2, bp3, bq1, bq2, bq3, l12, l21, l13, l31, l23, l32;
18 of.. z =e= 2*p1 + p2;
19 bp1.. p1 =e= yl*cos(al)*(v1)**2-yl*v1*v2*cos(d1-d2-al)+
20 yl*cos(al)*(v1)**2-yl*v1*v3*cos(d1- 0-al);
21 bp2.. p2 =e= yl*cos(al)*(v2)**2-yl*v2*v1*cos(d2-d1-al)+
22 yl*cos(al)*(v2)**2-yl*v2*v3*cos(d2- 0-al);
23 bp3.. -0.8 =e= yl*cos(al)*(v3)**2-yl*v3*v1*cos( 0-d1-al)+
24 yl*cos(al)*(v3)**2-yl*v3*v2*cos( 0-d2-al);
25 bq1.. q1 =e= -yl*sin(al)*(v1)**2-yl*v1*v2*sin(d1-d2-al)-
26 yl*sin(al)*(v1)**2-yl*v1*v3*sin(d1- 0-al);
27 bq2.. q2 =e= -yl*sin(al)*(v2)**2-yl*v2*v1*sin(d2-d1-al)-
28 yl*sin(al)*(v2)**2-yl*v2*v3*sin(d2- 0-al);
29 bq3.. -0.6 =e= -yl*sin(al)*(v3)**2-yl*v3*v1*sin( 0-d1-al)-
30 yl*sin(al)*(v3)**2-yl*v3*v2*sin( 0-d2-al);
31 l12.. sqrt(sqr(yl*cos(al)*(v1)**2-yl*v1*v2*cos(d1-d2-al))+
32 sqr(-yl*sin(al)*(v1)**2-yl*v1*v2*sin(d1-d2-al))) =l=
0.25;
33 l21.. sqrt(sqr(yl*cos(al)*(v2)**2-yl*v2*v1*cos(d2-d1-al))+
34 sqr(-yl*sin(al)*(v2)**2-yl*v2*v1*sin(d2-d1-al))) =l=
0.25;
35 l13.. sqrt(sqr(yl*cos(al)*(v1)**2-yl*v1*v3*cos(d1- 0-al))+
36 sqr(-yl*sin(al)*(v1)**2-yl*v1*v3*sin(d1- 0-al))) =l=
2;
37 l31.. sqrt(sqr(yl*cos(al)*(v3)**2-yl*v3*v1*cos( 0-d1-al))+
38 sqr(-yl*sin(al)*(v3)**2-yl*v3*v1*sin( 0-d1-al))) =l=
2;
39 l23.. sqrt(sqr(yl*cos(al)*(v2)**2-yl*v2*v3*cos(d2- 0-al))+
40 sqr(-yl*sin(al)*(v2)**2-yl*v2*v3*sin(d2- 0-al))) =l=
2;
41 l32.. sqrt(sqr(yl*cos(al)*(v3)**2-yl*v3*v2*cos( 0-d2-al))+
42 sqr(-yl*sin(al)*(v3)**2-yl*v3*v2*sin( 0-d2-al))) =l=
2;
6.5 GAMS Codes 187

43 model simpleopf /all/;


44 solve simpleopf using nlp minimizing z;
45 option decimals = 8;
46 display z.l, p1.l, p2.l, q1.l, q2.l, v1.l, v2.l, v3.l, d1.l,
47 d2.l, l12.l, l21.l, l13.l, l31.l, l23.l, l32.l;

This GAMS code above follows almost verbatim the mathematical formulation
of the OPF problem in Sect. 6.2.
The part of the GAMS output file that provides the optimal solution is given
below:
1 ---- 46 VARIABLE z.L = 0.83607872
2 VARIABLE p1.L = 0.03090686
3 VARIABLE p2.L = 0.77426500
4 VARIABLE q1.L = 0.32091674
5 VARIABLE q2.L = 0.33080185
6 VARIABLE v1.L = 1.09770030
7 VARIABLE v2.L = 1.10000000
8 VARIABLE v3.L = 1.06635924
9 VARIABLE d1.L = 0.02123196
10 VARIABLE d2.L = 0.04191265
11 EQUATION l12.L = 0.24947734
12 EQUATION l21.L = 0.25000000
13 EQUATION l13.L = 0.42442392
14 EQUATION l31.L = 0.41230595
15 EQUATION l23.L = 0.61838798
16 EQUATION l32.L = 0.59947612

Note that this output file is self-explanatory.

6.5.2 Generic OPF Code

A rather general input GAMS [4] file to solve the OPF problem in Illustrative
Example 6.1 is provided below. It is relevant to note that any number of nodes,
generating units, transmission lines, and demands can be considered if this GAMS
code is used.
1 $title opf
2 set
3 g index of units /g1*g2/
4 n index of nodes /n1*n3/
5 g2n(g,n) units to nodes /g1.n1,g2.n2/;
6 alias(n,np);
7 table Gdat(g,*) unit data
8 Pmin Pmax Qmin Qmax Cost
9 g1 0.0 3.0 -2.0 2.0 2
10 g2 0.0 0.8 -2.0 2.0 1;
11 table Ndat(n,*) node data
12 Vmin Vmax Pd Qd
13 n1 0.95 1.10 0.0 0.0
188 6 Optimal Power Flow

14 n2 0.95 1.10 0.0 0.0


15 n3 0.95 1.10 0.8 0.6;
16 table Ldat(n,np,*) line data
17 yl thel yshalf thes cap
18 n1.n2 9.95037190209989 -1.47112767430373 0 0 0.25
19 n1.n3 9.95037190209989 -1.47112767430373 0 0 2
20 n2.n3 9.95037190209989 -1.47112767430373 0 0 2;
21 Ldat(n,np,’yl’) $(ord(n) gt ord(np))=Ldat(np,n,’yl’);
22 Ldat(n,np,’thel’)$(ord(n) gt ord(np))=Ldat(np,n,’thel’);
23 Ldat(n,np,’yshalf’) $(ord(n) gt ord(np))=Ldat(np,n,’yshalf’);
24 Ldat(n,np,’thes’)$(ord(n) gt ord(np))=Ldat(np,n,’thes’);
25 Ldat(n,np,’cap’) $(ord(n) gt ord(np))=Ldat(np,n,’cap’);
26 variables
27 z objective function
28 p(g) unit g P generation
29 q(g) unit g Q generation
30 v(n) node n voltage magnitude
31 d(n) node n angle
32 pf(n,np) P flow per line
33 qf(n,np) Q flow per line;
34 p.lo(g)=Gdat(g,’Pmin’);
35 p.up(g)=Gdat(g,’Pmax’);
36 q.lo(g)=Gdat(g,’Qmin’);
37 q.up(g)=Gdat(g,’Qmax’);
38 v.lo(n)=Ndat(n,’Vmin’);
39 v.up(n)=Ndat(n,’Vmax’);
40 d.lo(n)=-pi;
41 d.up(n)= pi;
42 d.fx(’n3’)=0;
43 equations
44 cost objective function
45 Pfcal(n,np) P flow calculation
46 Qfcal(n,np) Q flow calculation
47 Pbal(n) P node balance
48 Qbal(n) Q node balance
49 Slim(n,np) S flow limit;
50 Pfcal(n,np)..pf(n,np)=e=
51 v(n)**2*Ldat(n,np,’yl’)*cos(-Ldat(n,np,’thel’))-
52 v(n)*v(np)*Ldat(n,np,’yl’)*cos(d(n)-d(np)-Ldat(n,np,’thel’))+
53 (1/2)*v(n)**2*Ldat(n,np,’yshalf’)*cos(-Ldat(n,np,’thes’));
54 Qfcal(n,np)..qf(n,np)=e=
55 v(n)**2*Ldat(n,np,’yl’)*sin(-Ldat(n,np,’thel’))-
56 v(n)*v(np)*Ldat(n,np,’yl’)*sin(d(n)-d(np)-Ldat(n,np,’thel’))+
57 (1/2)*v(n)**2*Ldat(n,np,’yshalf’)*sin(-Ldat(n,np,’thes’));
58 cost.. z =e= sum(g,Gdat(g,’cost’)*p(g));
59 Pbal(n).. sum(g$g2n(g,n),p(g))-Ndat(n,’Pd’)=e=sum(np,pf(n,np));
60 Qbal(n).. sum(g$g2n(g,n),q(g))-Ndat(n,’Qd’)=e=sum(np,qf(n,np));
61 Slim(n,np).. sqrt(power(pf(n,np),2)+power(qf(n,np),2))=l=Ldat(n,
np,’cap’);
62 model opf /all/;
63 solve opf using nlp minimizing z;
64 option decimals = 8;
65 display p.l, q.l, v.l, d.l, pf.l, qf.l, Slim.l, z.l;
6.5 GAMS Codes 189

The part of the GAMS output file that provides the optimal solution is given
below:

1 ---- 65 VARIABLE p.L unit g P generation


2 g1 0.03090686, g2 0.77426500
3 ---- 65 VARIABLE q.L unit g Q generation
4 g1 0.32091673, g2 0.33080186
5 ---- 65 VARIABLE v.L node n voltage magnitude
6 n1 1.09770030, n2 1.10000000, n3 1.06635924
7 ---- 65 VARIABLE d.L node n angle
8 n1 0.02123196, n2 0.04191265
9 ---- 65 VARIABLE pf.L P flow per line
10 n1 n2 n3
11 n1 -0.24946688 0.28037374
12 n2 0.24998341 0.52428159
13 n3 -0.27887877 -0.52112123
14 ---- 65 VARIABLE qf.L Q flow per line
15 n1 n2 n3
16 n1 0.00228492 0.31863181
17 n2 0.00288037 0.32792149
18 n3 -0.30368212 -0.29631788
19 ---- 65 EQUATION Slim.L S flow limit
20 n1 n2 n3
21 n1 0.24947734 0.42442392
22 n2 0.25000000 0.61838798
23 n3 0.41230595 0.59947612
24 ---- 65 VARIABLE z.L = 0.83607872
objective function

Note that this output file is self-explanatory.


As expected, the simple GAMS code and the generic one provide identical
results. The simple one allows comprehending easily the OPF problem, while the
generic one allows solving problems with an arbitrary number of nodes, generating
units, transmission lines, and demands.

6.5.3 dc OPF Code

A simple input GAMS [4] file to solve the dc OPF problem in Illustrative
Example 6.3 is provided below:
1 parameters
2 x / 0.1/;
3 variables
4 z, p1, p2, d1, d2;
5 p1.lo = 0; p2.lo = 0;
6 p1.up = 3; p2.up = 0.8;
7 d1.lo = -pi; d2.lo = -pi;
8 d1.up = pi; d2.up = pi;
9 d1.l=0; d2.l=0;
10 equations
11 of, bp1, bp2, bp3, p12, p21, p13, p31, p23, p32;
190 6 Optimal Power Flow

12 of.. z =e= 2*p1 + p2;


13 bp1.. p1 =e= (d1-d2)/x+(d1- 0)/x;
14 bp2.. p2 =e= (d2-d1)/x+(d2- 0)/x;
15 bp3.. -0.8 =e= ( 0-d1)/x+( 0-d2)/x;
16 p12.. (d1-d2)/x =l= 0.25;
17 p21.. (d2-d1)/x =l= 0.25;
18 p13.. (d1- 0)/x =l= 2;
19 p31.. ( 0-d1)/x =l= 2;
20 p23.. (d2- 0)/x =l= 2;
21 p32.. ( 0-d2)/x =l= 2;
22 model simpleopf /all/;
23 solve simpleopf using lp minimizing z;
24 option decimals = 8;
25 display z.l, p1.l, p2.l, d1.l, d2.l, p12.l, p21.l,
26 p13.l, p31.l, p23.l, p32.l;

Note that this GAMS code reproduces almost verbatim the mathematical formu-
lation of the OPF problem in Illustrative Example 6.3.
The part of the GAMS output file that provides the optimal solution is given
below:
1 ---- 25 VARIABLE z.L = 0.82500000
2 VARIABLE p1.L = 0.02500000
3 VARIABLE p2.L = 0.77500000
4 VARIABLE d1.L = 0.02750000
5 VARIABLE d2.L = 0.05250000
6 EQUATION p12.L = -0.25000000
7 EQUATION p21.L = 0.25000000
8 EQUATION p13.L = 0.27500000
9 EQUATION p31.L = -0.27500000
10 EQUATION p23.L = 0.52500000
11 EQUATION p32.L = -0.52500000

Note that this output file is self-explanatory.

6.5.4 SCOPF GAMS Code

An input GAMS [4] file to solve the SCOPF problem in Illustrative Example 6.4,
i.e., a SCOPF problem with a single contingency, is provided below. This code
admits any number of nodes, demands, transmission lines, and generating units, but,
for simplicity, it considers a single contingency involving just transmission lines.
1 $title scopf
2 set
3 g index of units /g1*g2/
4 n index of nodes /n1*n3/
5 g2n(g,n) units to nodes /g1.n1,g2.n2/;
6 alias(n,np);
7 table Gdat(g,*) unit data
8 Pmin Pmax Qmin Qmax Cost Ramp
9 g1 0.0 3.0 -2.0 2.0 2 3
6.5 GAMS Codes 191

10 g2 0.0 0.8 -2.0 2.0 1 0.2;


11 table Ndat(n,*) node data
12 Vmin Vmax Pd Qd
13 n1 0.95 1.10 0.0 0.0
14 n2 0.95 1.10 0.0 0.0
15 n3 0.95 1.10 0.8 0.6;
16 table Ldat(n,np,*) line data
17 yl thel yshalf thes cap
18 n1.n2 9.95037190209989 -1.47112767430373 0 0 0.25
19 n1.n3 9.95037190209989 -1.47112767430373 0 0 2
20 n2.n3 9.95037190209989 -1.47112767430373 0 0 2;
21 Ldat(n,np,’yl’) $(ord(n) gt ord(np))=Ldat(np,n,’yl’);
22 Ldat(n,np,’thel’)$(ord(n) gt ord(np))=Ldat(np,n,’thel’);
23 Ldat(n,np,’yshalf’) $(ord(n) gt ord(np))=Ldat(np,n,’yshalf’);
24 Ldat(n,np,’thes’)$(ord(n) gt ord(np))=Ldat(np,n,’thes’);
25 Ldat(n,np,’cap’) $(ord(n) gt ord(np))=Ldat(np,n,’cap’);
26 table Ldatc(n,np,*) line data under contingency
27 yl thel yshalf thes cap
28 n1.n2 9.95037190209989 -1.47112767430373 0 0 0.25
29 n1.n3 9.95037190209989 -1.47112767430373 0 0 2
30 n2.n3 9.95037190209989 -1.47112767430373 0 0 0.4;
31 Ldatc(n,np,’yl’) $(ord(n) gt ord(np))=Ldatc(np,n,’yl’);
32 Ldatc(n,np,’thel’)$(ord(n) gt ord(np))=Ldatc(np,n,’thel’);
33 Ldatc(n,np,’yshalf’) $(ord(n) gt ord(np))=Ldatc(np,n,’yshalf’)
;
34 Ldatc(n,np,’thes’)$(ord(n) gt ord(np))=Ldatc(np,n,’thes’);
35 Ldatc(n,np,’cap’) $(ord(n) gt ord(np))=Ldatc(np,n,’cap’);
36 variables
37 z objective function
38 p(g) unit g P generation
39 q(g) unit g Q generation
40 v(n) node n voltage magnitude
41 d(n) node n angle
42 pf(n,np) P flow per line
43 qf(n,np) Q flow per line
44 pc(g) unit g P generation under contingency
45 qc(g) unit g Q generation under contingency
46 vc(n) node n voltage magnitude under contingency
47 dc(n) node n angle under contingency
48 pfc(n,np) P flow per line under contingency
49 qfc(n,np) Q flow per line under contingency
50 cp(g) change in p due to contingency
51 cq(g) change in q due to contingency;
52 p.lo(g)=Gdat(g,’Pmin’);
53 p.up(g)=Gdat(g,’Pmax’);
54 q.lo(g)=Gdat(g,’Qmin’);
55 q.up(g)=Gdat(g,’Qmax’);
56 v.lo(n)=Ndat(n,’Vmin’);
57 v.up(n)=Ndat(n,’Vmax’);
58 d.lo(n)=-pi;
59 d.up(n)= pi;
60 d.fx(’n3’)=0;
61 pc.lo(g)=Gdat(g,’Pmin’);
62 pc.up(g)=Gdat(g,’Pmax’);
192 6 Optimal Power Flow

63 qc.lo(g)=Gdat(g,’Qmin’);
64 qc.up(g)=Gdat(g,’Qmax’);
65 vc.lo(n)=Ndat(n,’Vmin’);
66 vc.up(n)=Ndat(n,’Vmax’);
67 dc.lo(n)=-pi;
68 dc.up(n)= pi;
69 dc.fx(’n3’)=0;
70 equations
71 cost objective function
72 Pfcal(n,np) P flow calculation
73 Qfcal(n,np) Q flow calculation
74 Pbal(n) P node balance
75 Qbal(n) Q node balance
76 Slim(n,np) S flow limit
77 Pfcalc(n,np) P flow calculation under contingency
78 Qfcalc(n,np) Q flow calculation under contingency
79 Pbalc(n) P node balance under contingency
80 Qbalc(n) Q node balance under contingency
81 Slimc(n,np) S flow limit under contingency
82 changep(g) change in P calculation
83 changeq(g) change in Q calculation
84 pchlimup(g) ramping up limit
85 pchlimdw(g) ramping down limit;
86 Pfcal(n,np)..pf(n,np)=e=
87 v(n)**2*Ldat(n,np,’yl’)*cos(-Ldat(n,np,’thel’))-
88 v(n)*v(np)*Ldat(n,np,’yl’)*cos(d(n)-d(np)-Ldat(n,np,’thel’))+
89 (1/2)*v(n)**2*Ldat(n,np,’yshalf’)*cos(-Ldat(n,np,’thes’));
90 Qfcal(n,np)..qf(n,np)=e=
91 v(n)**2*Ldat(n,np,’yl’)*sin(-Ldat(n,np,’thel’))-
92 v(n)*v(np)*Ldat(n,np,’yl’)*sin(d(n)-d(np)-Ldat(n,np,’thel’))+
93 (1/2)*v(n)**2*Ldat(n,np,’yshalf’)*sin(-Ldat(n,np,’thes’));
94 Pfcalc(n,np)..pfc(n,np)=e=
95 vc(n)**2*Ldatc(n,np,’yl’)*cos(-Ldatc(n,np,’thel’))-
96 vc(n)*vc(np)*Ldatc(n,np,’yl’)*cos(dc(n)-dc(np)-Ldatc(n,np,’
thel’))+
97 (1/2)*vc(n)**2*Ldatc(n,np,’yshalf’)*cos(-Ldatc(n,np,’thes’));
98 Qfcalc(n,np)..qfc(n,np)=e=
99 vc(n)**2*Ldatc(n,np,’yl’)*sin(-Ldatc(n,np,’thel’))-
100 vc(n)*vc(np)*Ldatc(n,np,’yl’)*sin(dc(n)-dc(np)-Ldatc(n,np,’
thel’))+
101 (1/2)*vc(n)**2*Ldatc(n,np,’yshalf’)*sin(-Ldatc(n,np,’thes’));
102 cost.. z =e= sum(g,Gdat(g,’cost’)*p(g));
103 Pbal(n).. sum(g$g2n(g,n),p(g))-Ndat(n,’Pd’)=e=sum(np,pf(n,np));
104 Qbal(n).. sum(g$g2n(g,n),q(g))-Ndat(n,’Qd’)=e=sum(np,qf(n,np));
105 Slim(n,np).. sqrt(power(pf(n,np),2)+power(qf(n,np),2))=l=Ldat(n,
np,’cap’);
106 Pbalc(n).. sum(g$g2n(g,n),pc(g))-Ndat(n,’Pd’)=e=sum(np,pfc(n,np))
;
107 Qbalc(n).. sum(g$g2n(g,n),qc(g))-Ndat(n,’Qd’)=e=sum(np,qfc(n,np))
;
108 Slimc(n,np).. sqrt(power(pfc(n,np),2)+power(qfc(n,np),2))=l=Ldatc
(n,np,’cap’);
109 changep(g).. cp(g) =e= pc(g)-p(g);
110 changeq(g).. cq(g) =e= qc(g)-q(g);
6.5 GAMS Codes 193

111 pchlimup(g).. cp(g) =l= Gdat(g,’ramp’);


112 pchlimdw(g).. -cp(g) =l= Gdat(g,’ramp’);
113 model opf /all/;
114 solve opf using nlp minimizing z;
115 option decimals = 8;
116 display p.l, q.l, v.l, d.l, pf.l, qf.l,
117 pc.l, qc.l, vc.l, dc.l, pfc.l, qfc.l
118 cp.l, cq.l, Slim.l, z.l;

Note that this GAMS code reproduces almost verbatim the mathematical formu-
lation of the SCOPF problem in Illustrative Example 6.4.
The part of the GAMS output file that provides the optimal solution is given
below:
1 ---- 116 VARIABLE p.L unit g P generation
2 g1 0.38321178, g2 0.42117706
3 ---- 116 VARIABLE q.L unit g Q generation
4 g1 0.32364526, g2 0.32024311
5 ---- 116 VARIABLE v.L node n voltage magnitude
6 n1 1.10000000, n2 1.10000000, n3 1.06760682
7 ---- 116 VARIABLE d.L node n angle
8 n1 0.03097860, n2 0.03204448
9 ---- 116 VARIABLE pf.L P flow per line
10 n1 n2 n3
11 n1 -0.01276879 0.39598057
12 n2 0.01277016 0.40840690
13 n3 -0.39382588 -0.40617412
14 ---- 116 VARIABLE qf.L Q flow per line
15 n1 n2 n3
16 n1 0.00128375 0.32236151
17 n2 -0.00127014 0.32151325
18 n3 -0.30081460 -0.29918540
19 ---- 116 VARIABLE pc.L unit g P generation under contingency
20 g1 0.58407515, g2 0.22117706
21 ---- 116 VARIABLE qc.L unit g Q generation under contingency
22 g1 0.65651618, g2 -0.00399412
23 ---- 116 VARIABLE vc.L node n voltage magnitude under
contingency
24 n1 1.10000000, n2 1.07898824, n3 1.05674798
25 ---- 116 VARIABLE dc.L node n angle under contingency
26 n1 0.03621330, n2 0.02799306
27 ---- 116 VARIABLE pfc.L P flow per line under contingency
28 n1 n2 n3
29 n1 0.11952171 0.46455344
30 n2 -0.11900518 0.34018224
31 n3 -0.46119208 -0.33880792
32 ---- 116 VARIABLE qfc.L Q flow per line under contingency
33 n1 n2 n3
34 n1 0.21957814 0.43693804
35 n2 -0.21441285 0.21041873
36 n3 -0.40332442 -0.19667558
37 ---- 116 VARIABLE cp.L change in p due to contingency
38 g1 0.20086337, g2 -0.20000000
194 6 Optimal Power Flow

39 ---- 116 VARIABLE cq.L change in q due to contingency


40 g1 0.33287092, g2 -0.32423723
41 ---- 116 EQUATION Slim.L S flow limit
42 n1 n2 n3
43 n1 0.01283317 0.51060509
44 n2 0.01283317 0.51977588
45 n3 0.49556861 0.50446934
46 ---- 116 VARIABLE z.L = 1.18760061
objective function

Note that this output file is self-explanatory.

6.6 End-of-Chapter Exercises

6.1 What is the objective of the OPF problem?


6.2 What is the key difference between an OPF and a SCOPF problem?
6.3 Discuss the validity of the following statement: the cost of the optimal operating
condition that results from the SCOPF problem is always higher than the cost of the
optimal operating condition that results from the OPF problem.
6.4 Formulate the SCOPF problem considering a dc formulation of the power flow
equations.
6.5 Consider the two-node power system and data provided in Fig. 6.2:
1. Formulate the corresponding OPF problem.
2. Write a specific GAMS code (not generic) to solve this OPF problem.
3. Solve the OPF problem and discuss the solution achieved.

0 £ p1 £ 3 0 £ p 2 £ 0.8
-2 £ q 1 £ 2 -2 £ q 2 £ 2
C1 = 2 Z̄ L12a = 0.01 + j 0.1 C2 = 1
max = S max = 0.25
S 12a 21a

Line 12a 0.95 £ v 2 £ 1.10


0.95 £ v 1 £ 1.10 1 2
Line 12b d2 = 0
Z̄ L12b = 0.01 + j 0.1
0.8 + j 0.6 max = S max = 2
S 12b 1.2 + j 0.6
21b

Fig. 6.2 Exercise 6.1: two-node power system


6.6 End-of-Chapter Exercises 195

0 £ p1 £ 2 0 £ p2 £ 4
- 2 £ q1 £ 2 - 4 £ q2 £ 4
C1 = 2 C2 = 4 3+ j2

0.90 £ v i £ 1.10
1 2 3 i = 1, 2, 3
Z̄ L12 = j 0.2 Z̄ L23 = 0.01 + j 0.1 d2=0
max = S max = 2 max = S max = 5
S 23
S 12 21 32

Fig. 6.3 Exercise 6.8: three-node power system

6.6 Consider again the data of Exercise 6.5:


1. Formulate the corresponding SCOPF problem. Assume that there are two
possible contingencies, namely (1) the capacity of line 12a is reduced to 0 and
(2) the capacity of line 12b is reduced to 1 puVA. The ramp limits of generating
units at nodes 1 and 2 are 1 puW and 0.4 puW, respectively.
2. Write a specific GAMS code (not generic) to solve this SCOPF problem.
3. Solve the SCOPF problem. Compare the results with those achieved in Exer-
cise 6.5.
6.7 Consider again the data of Exercise 6.5:
1. Formulate the corresponding dc OPF problem.
2. Write a specific GAMS code (not generic) to solve this dc OPF problem.
3. Solve the dc OPF problem. Compare the results with those achieved in Exer-
cise 6.5.
6.8 Repeat Exercises 6.5–6.7 for the three-node power system depicted in Fig. 6.3.
Assume that the possible contingencies are (1) the capacity of line 12 is reduced to
1 puVA and (2) generating unit at node 1 becomes unavailable. The ramp limits of
generating units at nodes 1 and 2 are 2 puW and 0.5 puW, respectively.
6.9 Repeat Exercises 6.5–6.7 for the four-node power system depicted in Fig. 6.4.
All transmission lines have the same characteristics with a series impedance of
.0:01 C j0:1/ pu˝ and a capacity of 2 puVA (in both directions). Assume that the
possible contingencies are (1) the capacity of line 12 is reduced to 1 puVA, (2) the
capacity of line 13 is reduced to 0, and (3) the capacity of line 14 is reduced to
1 puVA. The ramp limits of generating units at nodes 1 and 3 are 1 puW and 2 puW,
respectively.
6.10 Extend the GAMS code provided in Sect. 6.5.4 for the SCOPF problem so that
any number of contingencies can be considered.
196 6 Optimal Power Flow

Fig. 6.4 Exercise 6.9: 0 ≤ p3 ≤ 4


four-node power system −4 ≤ q 3 ≤ 4
C3 = 3
2 + j1

3 4

0.95 ≤ v i ≤ 1.10
i = 1, 2, 3, 4
d1 = 0

1 2
.5 + j 1

2+ j 1
0 ≤ p1 ≤ 4
−4 ≤ q 1 ≤ 4
C1 = 1

References

1. Carpentier, J.: Contribution à l’étude du dispatching économique (in French). Bull. Soc. Fr.
Elect. 8(3), 431-447 (1962)
2. CONOPT. Available at www.conopt.com (2016)
3. Dommel, H.W., Tinney, W.F.: Optimal power flow solutions. IEEE Trans. Power Apparatus Syst.
PAS-87(10), 1866-1876 (1968)
4. GAMS. Available at www.gams.com (2016)
5. Gómez-Expósito, A., Conejo, A.J., Cañizares, C.: Electric Energy Systems: Analysis and
Operation. Taylor and Francis, Boca Raton (2008)
6. Sioshansi, R., Conejo, A.J.: Optimization in Engineering. Models and Algorithms. Springer,
New York (2017)
7. The ILOG CPLEX. Available at www.ilog.com/products/cplex/ (2016)
8. Wood, A.J., Wollenberg, B.F., Sheblé, G.B.: Power Generation, Operation, and Control, 3rd edn.
Wiley, New York (2013)
9. Zimmerman, R.D., Murillo-Sánchez, C.E., Thomas R.J.: MATPOWER: steady-state operations,
planning and analysis tools for power systems research and education. IEEE Trans. Power Syst.
26(1), 12-19 (2011)

You might also like