Optimal power flow
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
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.1 Description
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.
The active power pik ./ flowing from node i to node k through transmission line ik,
as described in Chap. 4 of this book, is:
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:
1
vi2 YSik sin. Sik /; 8i; 8k 2 i : (6.4)
2
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.
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.
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
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.
The voltage magnitude of any node i throughout the network is bounded above and
below. Therefore:
where Vimin and Vimax are, respectively, the lower and upper limits of the voltage
magnitude at node i.
ıi ; 8i: (6.10)
Moreover, the voltage angle at the reference node is known and thus:
ıi D 0; i: ref. (6.11)
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
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
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
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
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 :
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:
0 p1 3;
0 p2 0:8:
2 q1 2;
2 q2 2:
0:95 v1 1:10;
0:95 v2 1:10;
0:95 v3 1:10:
ı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.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
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
ı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.
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
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
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
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;
ı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.
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].
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
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
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
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
The part of the GAMS output file that provides the optimal solution is given
below:
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
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
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
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
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
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
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
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)