In Matpower, an optimal power flow is executed by calling runopf with a case struct or
case file name as the first argument (casedata). In addition to printing output to the
screen, which it does by default, runopf optionally returns the solution in a results
struct.
>> results = runopf(casedata);
The results struct is a superset of the input Matpowercase struct mpc, with some
additional fields as well as additional columns in some of the existing data fields. In
addition to the solution values included in the results for a simple power flow, shown in
Table 4-1 in Section 4.4, the following additional optimal power flow solution values are
stored as shown in Table 6-1.
Table 6-1:Optimal Power Flow Results
name
description
results.f
final objective function value
results.x
final value of optimization variables (internal order)
results.om
OPF model object†
results.bus(:, LAM_P)
Lagrange multiplier on real power mismatch
results.bus(:, LAM_Q)
Lagrange multiplier on reactive power mismatch
results.bus(:, MU_VMAX)
Kuhn-Tucker multiplier on upper voltage limit
results.bus(:, MU_VMIN)
Kuhn-Tucker multiplier on lower voltage limit
results.gen(:, MU_PMAX)
Kuhn-Tucker multiplier on upperlimit
results.gen(:, MU_PMIN)
Kuhn-Tucker multiplier on lowerlimit
results.gen(:, MU_QMAX)
Kuhn-Tucker multiplier on upperlimit
results.gen(:, MU_QMIN)
Kuhn-Tucker multiplier on lowerlimit
results.branch(:, MU_SF)
Kuhn-Tucker multiplier on flow limit at “from” bus
results.branch(:, MU_ST)
Kuhn-Tucker multiplier on flow limit at “to” bus
results.mu
shadow prices of constraints‡
results.g
(optional) constraint values
results.dg
(optional) constraint 1st derivatives
results.raw
raw solver output in form returned by MINOS, and more‡
results.var.val
final value of optimization variables, by named subset‡
results.var.mu
shadow prices on variable bounds, by named subset‡
results.nle
shadow prices on nonlinear equality constraints, by named subset‡
results.nli
shadow prices on nonlinear inequality constraints, by named subset‡
results.lin
shadow prices on linear constraints, by named subset‡
results.cost
final value of user-defined costs, by named subset‡
†See help for opf_model and opt_model for more details.‡See help for opf for more details.
Additional optional input arguments can be used to set options (mpopt) and provide
file names for saving the pretty printed output (fname) or the solved case data
(solvedcase).
Some of the main options that control the optimal power flow simulation are listed in
Tables 6-2 and 6-3. There are many other options that can be used to control the
termination criteria and other behavior of the individual solvers. See Appendix C or the
mpoption help for details. As with runpf the output printed to the screen can be controlled
by the options in Table 4-3, but there are additional output options for the OPF,
related to the display of binding constraints that are listed Table 6-4, along
with an option that can be used to force the AC OPF to return information
about the constraint values and Jacobian and the objective function gradient and
Hessian.
For OPF problems, the preferred way to eliminate the flow limit on a branch is to set
the RATE_A column (6) of the corresponding row in the branch matrix to zero. This
indicates a completely unconstrained flow (as opposed to zero flow).
By default, runopf solves an AC optimal power flow problem using a primal dual
interior point method. To run a DC OPF, the model option must be set to 'DC'. For
convenience, Matpowerprovides a function rundcopf which is simply a wrapper that
sets the model to 'DC' before calling runopf.
Table 6-2:Optimal Power Flow Solver Options
name
default
description
opf.ac.solver
'DEFAULT'
AC optimal power flow solver:
'DEFAULT' –
choose default solver, i.e. 'MIPS'
'MIPS' –
MIPS, MatpowerInterior Point Solver,primal/dual interior point method†
'FMINCON' –
MatlabOptimization Toolbox, fmincon
'IPOPT' –
Ipopt*
'KNITRO' –
Artelys Knitro*
'MINOPF' –
MINOPF*,MINOS-based solver
'PDIPM' –
PDIPM*,primal/dual interior point method‡
'SDPOPF' –
SDPOPF*, solver based on semidefiniterelaxation
'TRALM' –
TRALM*, trust region based augmentedLangrangian method
–
opf.dc.solver
'DEFAULT'
DC optimal power flow solver:
'DEFAULT' –
choose default solver based on availabilityin the following order: 'GUROBI', 'CPLEX','MOSEK', 'OT', 'GLPK' (linear costs only),'BPMPD', 'MIPS'
'MIPS' –
MIPS, MatpowerInterior Point Solver,primal/dual interior point method†
'BPMPD' –
BPMPD*
'CLP' –
CLP*
'CPLEX' –
CPLEX*
'GLPK' –
GLPK*(no quadratic costs)
'GUROBI' –
Gurobi*
'IPOPT' –
Ipopt*
'MOSEK' –
MOSEK*
'OT' –
MatlabOpt Toolbox, quadprog, linprog
–
*Requires the installation of an optional package. See AppendixGfor details on the corresponding package.†For MIPS-sc, the step-controlled version of this solver, the mips.step_control option must be set to 1.‡For SC-PDIPM, the step-controlled version of this solver, the pdipm.step_control option must be set to 1.
Table 6-3:Other OPF Options
name
default
description
opf.current_balance‡
0
use current, as opposed to power, balance formulation forAC OPF, 0 or 1
opf.v_cartesian‡
0
use cartesian, as opposed to polar, representation forvoltages for AC OPF, 0 or 1
opf.violation
constraint violation tolerance
opf.use_vg
0
respect generator voltage setpoint, 0 or 1†
0 –
use voltage magnitude limits specified in bus,ignore VG in gen
1 –
replace voltage magnitude limits specified in busby VG in corresponding gen
–
opf.flow_lim
'S'
quantity to limit for branch flow constraints
'S' –
apparent power flow (limit in MVA)
'P' –
active power flow (limit in MW)
'I' –
current magnitude (limit in MVA at 1 p.u.voltage, i.e. kA)
'2' –
same as 'P', but implemented using squareof active flow, rather than simple max
–
opf.ignore_angle_lim
0
ignore angle difference limits for branches
0 –
include angle difference limits, if specified
1 –
ignore angle difference limits even if specified
–
opf.softlims.default
1
behavior of OPF soft limits for which parameters are notexplicitly provided
0 –
do not include softlims if not explicitly specified
1 –
include softlims with default values if notexplicitly specified
–
opf.init_from_mpc*
-1
specify whether to use the current state in Matpowercase to initialize OPF
-1 –
Matpowerdecides based on solver/algorithm
0 –
ignore current state in Matpowercase‡
1 –
use current state in Matpowercase
–
opf.start
0
strategy for initializing OPF starting point
0 –
default, Matpowerdecides based on solver,(currently identical to 1)
1 –
ignore current state in Matpowercase‡
2 –
use current state in Matpowercase
3 –
solve power flow and use resulting state
–
opf.return_raw_der
0
for AC OPF, return constraint and derivative info inresults.raw (in fields g, dg, df, d2f)
*Deprecated. Use opf.start instead.†Using a value between 0 and 1 results in the limits being determined by the corresponding weighted average of the 2 options.‡Only applies to fmincon, Ipopt, Artelys Knitro and MIPS solvers, which use an interior point estimate; others use currentstate in Matpowercase, as with opf.start = 2.
Table 6-4:OPF Output Options
name
default
description
out.lim.all
-1
controls constraint info output
-1 –
individual flags control what is printed
0 –
do not print any constraint info†
1 –
print only binding constraint info†
2 –
print all constraint info†
–
out.lim.v
1
control output of voltage limit info
0 –
do not print
1 –
print binding constraints only
2 –
print all constraints
–
out.lim.line
1
control output of line flow limit info‡
out.lim.pg
1
control output of gen active power limit info‡
out.lim.qg
1
control output of gen reactive power limit info‡
†Overrides individual flags.‡Takes values of 0, 1 or 2 as for out.lim.v.
Internally, the runopf function does a number of conversions to the problem data
before calling the appropriate solver routine for the selected OPF algorithm. This
external-to-internal format conversion is performed by the ext2int function, described in
more detail in Section 7.3.1, and includes the elimination of out-of-service equipment and
the consecutive renumbering of buses. All computations are done using this internal
indexing. When the simulation has completed, the data is converted back to external
format by int2ext before the results are printed and returned. In addition, both
ext2int and int2ext can be customized via user-supplied callback routines to
convert data needed by user-supplied variables, constraints or costs into internal
indexing.