TA的每日心情 | 开心 2021-3-9 07:58 |
|---|
签到天数: 6 天 连续签到: 1 天 [LV.2]偶尔看看I 累计签到:6 天 连续签到:1 天
|
发表于 2012-4-20 20:00:12
|
显示全部楼层
function [busout, genout, branchout, f, success, info, et, g, jac, xr, pimul] = ...8 p- x+ Z! G: q7 Z1 A
opf(varargin)3 \# C- B+ V) H c
%OPF Solves an optimal power flow.
- s" g; p- b; q5 X. j6 M' s* Y% [RESULTS, SUCCESS] = OPF(MPC, MPOPT) X) c- U7 o( z; [) r, o
%
% O- b% ?) S( s0 \& ]" w) s* O( q4 l8 N% Returns either a RESULTS struct and an optional SUCCESS flag, or individual& Z+ L! P& C3 j0 a% m9 D& N
% data matrices, the objective function value and a SUCCESS flag. In the
/ r8 }* X- h' z4 p) c% latter case, there are additional optional return values. See Examples+ T+ _; Q/ a% U" D* x
% below for the possible calling syntax options.0 S- _% i' a( Q6 H6 B$ \. S
%* J) m8 e9 A, _2 U% |! W
% Examples:
' ?6 J8 L. V6 U9 K$ ?/ C% Output argument options:
3 R2 |7 h2 D2 }6 v, H%
9 P' r5 H: s7 N3 `7 n" ^1 ^% results = opf(...)3 k& G) W p9 f6 n& E, Z# I
% [results, success] = opf(...)
0 T' ?1 j* ?; Z- h9 `% v/ h% [bus, gen, branch, f, success] = opf(...)4 L9 O8 V/ u3 a6 F* H
% [bus, gen, branch, f, success, info, et, g, jac, xr, pimul] = opf(...)
S6 W7 Z7 K7 |, h$ d7 e* p%/ ~* C+ I, f5 o; e& c- q' ?: o
% Input arguments options:
: M$ G7 r( ^! N4 ]) I( x%2 y: ?2 m$ T& N7 C7 G
% opf(mpc)2 C v' |9 a0 C; v8 c, _! J R
% opf(mpc, mpopt)
: r. V: u# _! }# W2 t4 Y% opf(mpc, userfcn, mpopt)3 B8 E+ N v, M( T/ n
% opf(mpc, A, l, u)( v1 }5 k2 X" D8 |8 W3 P/ M1 Y
% opf(mpc, A, l, u, mpopt)% o( @4 ?! n& }$ Y8 C. y# N
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw)
- U8 G y- q3 o2 X& Z% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw, z0, zl, zu)
! j7 f0 t+ g1 D1 Z: ~%+ e5 _: V' E& |* d
% opf(baseMVA, bus, gen, branch, areas, gencost)
8 A) J2 r( b' k( ~; `* _: J6 ~" H% opf(baseMVA, bus, gen, branch, areas, gencost, mpopt)2 s/ r( T) g- L p5 ~& B
% opf(baseMVA, bus, gen, branch, areas, gencost, userfcn, mpopt)
9 {! A- k$ {% K% }; i% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u)
% a& `* @; c! a* [3 P& S% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, mpopt)- h: M3 b) c8 @! {
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...
4 S* k* ?& c7 F, z ~2 O% mpopt, N, fparm, H, Cw)
% k" |# @ |. A2 N9 l8 g4 g7 `% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...6 R4 v. B5 G/ P; [0 S
% mpopt, N, fparm, H, Cw, z0, zl, zu)
! [) {, W/ c' ]%
/ u* p, Q) `. t ^* O- {6 F% The data for the problem can be specified in one of three ways:
. G9 A: N/ w6 X# S+ Y) F" o% (1) a string (mpc) containing the file name of a MATPOWER case3 [* ?: Z* \$ T$ k
% which defines the data matrices baseMVA, bus, gen, branch, and. T: \! B* V+ t) C2 K& F
% gencost (areas is not used at all, it is only included for
, t" \4 p7 C% w! S/ S1 l% o% backward compatibility of the API).
" d9 {2 d3 y" j! B! }% (2) a struct (mpc) containing the data matrices as fields., ~: p# f& \! V, D$ Z6 U! ]! t
% (3) the individual data matrices themselves.! H2 }9 H" t% {$ r, x. {" |2 _
% 6 |) k9 {0 z; E1 T5 c2 z6 Y
% The optional user parameters for user constraints (A, l, u), user costs
1 t6 {8 v' p& R; @0 ]% (N, fparm, H, Cw), user variable initializer (z0), and user variable
. C! @" n0 D; R% limits (zl, zu) can also be specified as fields in a case struct,1 C: s% u1 N8 ~' d V. _: Y" [
% either passed in directly or defined in a case file referenced by name.
+ ?% a7 R( j) C" L%
" T- j/ L# ]$ y/ p3 A1 m0 y% When specified, A, l, u represent additional linear constraints on the* Q" r* l0 ?0 \1 g! h/ p
% optimization variables, l <= A*[x; z] <= u. If the user specifies an A; N9 e( f8 _, s( }8 L! l) B
% matrix that has more columns than the number of "x" (OPF) variables,
4 k6 e9 N* d4 p8 [. k1 X% then there are extra linearly constrained "z" variables. For an, q. [# W4 o: G. T4 \1 q
% explanation of the formulation used and instructions for forming the) B$ I9 V5 h# Y/ x" K% W8 o' U! ]
% A matrix, see the manual.) k4 ]) z* ?$ j8 h) q1 l
%/ {$ ^5 C$ I; a9 L
% A generalized cost on all variables can be applied if input arguments3 ]; E. ^0 g. S0 M n. o
% N, fparm, H and Cw are specified. First, a linear transformation
8 ^3 g# k8 X" o- V9 A4 T4 a% of the optimization variables is defined by means of r = N * [x; z].
- Q/ m5 o; y& E" x- a% Then, to each element of r a function is applied as encoded in the
3 d( o0 ^4 V! Q% fparm matrix (see manual). If the resulting vector is named w,
( V) `+ {7 z* T1 _# M% then H and Cw define a quadratic cost on w: (1/2)*w'*H*w + Cw * w .# a; g) x6 O, q* {
% H and N should be sparse matrices and H should also be symmetric., |% q. G8 X- P1 h
%
; q A& X) j/ ]! }2 X( C! t( Y1 Q% The optional mpopt vector specifies MATPOWER options. If the OPF( U' p: W* n) e
% algorithm is not explicitly set in the options MATPOWER will use
- u5 |' C$ \6 @' c5 g% the default solver, based on a primal-dual interior point method.
+ o, ]6 [" G, A9 z3 G' b% For the AC OPF this is OPF_ALG = 560, unless the TSPOPF optional9 k: c: A& f( R& M
% package is installed, in which case the default is 540. For the0 k0 G5 l1 v# @3 G' ]& R$ T
% DC OPF, the default is OPF_ALG_DC = 200. See MPOPTION for
6 i: v2 M# m. t0 E% more details on the available OPF solvers and other OPF options
" l# p7 u+ }& H% and their default values.
. ~ I* e) I* I: s( y2 S%
- S! G- T, s# @# q' Z% The solved case is returned either in a single results struct (described i% I/ S5 X) M& i# W* n1 V" b$ @
% below) or in the individual data matrices, bus, gen and branch. Also+ E$ j- S3 Q2 |5 R( Q n( _4 S1 H
% returned are the final objective function value (f) and a flag which is
5 S( d t( _% {1 P- `- H2 E% true if the algorithm was successful in finding a solution (success).; l! H, W! N. e
% Additional optional return values are an algorithm specific return status
. ]' `) |+ ^! p% (info), elapsed time in seconds (et), the constraint vector (g), the
4 R; Y' k' _7 s( U. C, b. \" }' d% Jacobian matrix (jac), and the vector of variables (xr) as well
% w4 `+ ]# |6 a$ F% as the constraint multipliers (pimul).- A! n9 F# ~1 G6 E4 n
%
3 M. a# q1 @( x% The single results struct is a MATPOWER case struct (mpc) with the1 d) W+ C: }# g
% usual baseMVA, bus, branch, gen, gencost fields, along with the) v _5 K; W$ j# J( ?" G0 }4 J% m
% following additional fields:" u! j: }) t( z2 q& U/ a: s
%. ^6 Q6 @6 S8 b8 C
% .order see 'help ext2int' for details of this field
( Y9 R! i9 q3 w v3 S% .et elapsed time in seconds for solving OPF
( o2 m6 M0 p7 a1 K4 ]% .success 1 if solver converged successfully, 0 otherwise$ m1 z; A; `7 |) f' H; h, k* H
% .om OPF model object, see 'help opf_model'
# u) m& N2 m9 i/ n, t% .x final value of optimization variables (internal order)
5 l+ ]7 T2 b4 k5 m% .f final objective function value3 H, m* b2 E8 x3 r8 Y& t
% .mu shadow prices on ...
( i8 D4 r2 R& M: _9 P4 D% .var
: c% w$ R C% q- j& C% .l lower bounds on variables, B8 y" Z, }! e% B
% .u upper bounds on variables1 @ |* y' F# e- u2 _5 `4 Y9 q
% .nln' q5 f8 {" v, N5 U% p; r
% .l lower bounds on nonlinear constraints
6 w; R9 p" ~4 M9 O* ]$ T, S/ C0 O% .u upper bounds on nonlinear constraints
# e+ T T- t: J! @; D% .lin
" M. ?+ E9 j6 p5 P, I" e% .l lower bounds on linear constraints% o" N) R Y9 k! |6 X# f1 F* A" B
% .u upper bounds on linear constraints* H. _% i* J0 p) h. X, G
% .raw raw solver output in form returned by MINOS, and more
) E4 |5 n5 V- l/ h% .xr final value of optimization variables0 ^6 l" {$ R. K4 y' G
% .pimul constraint multipliers
) \) p7 Z! ?0 f& Y% .info solver specific termination code
. } B$ Y( s" d1 R, I: k% .output solver specific output information- [+ F8 H! Z9 {7 `% O1 I; _
% .alg algorithm code of solver used5 U" t& R6 ]( a
% .g (optional) constraint values
h3 y! l* ?2 O+ i! y) L. ^% .dg (optional) constraint 1st derivatives7 Z3 p3 j% r& D/ G( o' F w* r
% .df (optional) obj fun 1st derivatives (not yet implemented)
7 R( V! |/ `. k( f' f$ s% .d2f (optional) obj fun 2nd derivatives (not yet implemented)# Z$ }/ f' x, j+ B, C
% .var H' @& |7 b$ h4 c c1 ~1 _- M
% .val optimization variable values, by named block% {+ [1 y: y1 y: `
% .Va voltage angles
0 j# w; n& N; w+ |1 ^: U, a% .Vm voltage magnitudes (AC only)
# X0 [5 \+ Z1 L% T) a+ Y- @% .Pg real power injections
+ A- h( H; _1 t. b2 W- i% .Qg reactive power injections (AC only)
8 U3 x5 D4 ]/ ~" C% .y constrained cost variable (only if have pwl costs)
% B# j8 Z7 X& d0 g% (other) any user defined variable blocks: Y+ I. r- p' j
% .mu variable bound shadow prices, by named block
1 l! i8 P7 \9 Z0 ~- q% .l lower bound shadow prices3 k, y$ P6 O9 F- P3 r
% .Va, Vm, Pg, Qg, y, (other)3 D: a' y9 K4 v- d y3 @) Z+ I
% .u upper bound shadow prices$ M) h' O/ W' K8 H" Z0 v6 o2 g T7 u
% .Va, Vm, Pg, Qg, y, (other)
, h) L8 L( p# }! }5 g, b% .nln (AC only). q! @7 b# |7 C: R$ a
% .mu shadow prices on nonlinear constraints, by named block; a. u: h: S4 c
% .l lower bounds; L+ w& t4 U: ]- w( ?2 [8 e
% .Pmis real power mismatch equations" p+ q" ^" R, ~8 f D1 l
% .Qmis reactive power mismatch equations. [# n/ r# k+ h$ p
% .Sf flow limits at "from" end of branches" f2 A1 o0 n8 s5 n
% .St flow limits at "to" end of branches; {, m5 T. p% h
% .u upper bounds+ o1 i- n) c6 q+ M& r/ K
% .Pmis, Qmis, Sf, St
7 `& P" c& b% r) W) E: |% .lin
, p' P5 H0 M! n Z3 V* \( }% .mu shadow prices on linear constraints, by named block3 |1 P: e# m9 T. L5 k8 C4 c
% .l lower bounds7 c0 |& I, i; F; I
% .Pmis real power mistmatch equations (DC only)
9 b, X |* o* _, `' A5 c4 D4 P7 E+ r8 r& r% .Pf flow limits at "from" end of branches (DC only)
6 F: c- ?# R+ A2 U1 p" H" z% .Pt flow limits at "to" end of branches (DC only)
2 U% A9 R5 a2 {; ]: A M% .PQh upper portion of gen PQ-capability curve (AC only)
# r( x' X# s( [+ I g: D! a% .PQl lower portion of gen PQ-capability curve (AC only)3 [; ~* u( z& `" g" V {4 [
% .vl constant power factor constraint for loads (AC only)% t0 }$ p- h% h: q! }
% .ycon basin constraints for CCV for pwl costs
5 ^8 r0 p: e9 k- J% (other) any user defined constraint blocks
- J/ A" Q0 J( g/ h! i% Q9 ~% .u upper bounds
* O9 `& t5 ]6 ~+ Z7 V& w# ~- Z% .Pmis, Pf, Pf, PQh, PQl, vl, ycon, (other)2 v7 a6 k0 h( A$ s& T
% .cost user defined cost values, by named block& Z% X3 R6 }: _" i/ c" Q+ ]( v
%
) S. ?0 X, j s6 y0 F. ]% See also RUNOPF, DCOPF, UOPF, CASEFORMAT.4 ~ z- c4 d" R/ l) C$ V- l
9 P/ k2 C \- t7 ?, @
% MATPOWER
+ ] x3 J+ S6 t L2 R A3 x" {3 R% $Id: opf.m,v 1.73 2010/06/09 14:56:58 ray Exp $
% @1 L q, N# ]% by Ray Zimmerman, PSERC Cornell: E4 v% t4 `$ f
% and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales
4 R1 ]( @2 _' [, | M3 G1 F% Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
( X7 T8 n" X; s! y2 y) i%
% F b0 m3 ]7 e/ G% This file is part of MATPOWER.4 q( g6 {9 Q( u, k: H4 [
% See http://www.pserc.cornell.edu/matpower/ for more info.( y( t* Y! K/ n& a+ E
%, | w7 y& p! Z8 ?
% MATPOWER is free software: you can redistribute it and/or modify
# u" _4 g) S) ]: s+ }% it under the terms of the GNU General Public License as published* l) ]; q6 {. ?4 O' Q0 O1 |
% by the Free Software Foundation, either version 3 of the License,
: r& I! p9 b5 x0 X6 C4 n% or (at your option) any later version.
$ S- E6 r, {9 u( f* G%
# f5 d' r* T7 D9 C/ B% MATPOWER is distributed in the hope that it will be useful,
) R( L) b S8 N( c8 [% but WITHOUT ANY WARRANTY; without even the implied warranty of0 ?2 ?! e) _$ H% W
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0 p; u1 f& z6 Q2 h6 B/ L& {" X% GNU General Public License for more details.
& F; N7 k" W: \3 w5 U! H%
# `6 \, F; `6 C7 E M% |; C6 h& ?% You should have received a copy of the GNU General Public License" G1 t$ j0 L5 P. h% t
% along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.7 K x- B* l( f& p' u% r
% h) |" G; @* U3 x$ X
% Additional permission under GNU GPL version 3 section 7
6 J' R4 T2 M9 D" \8 D7 K%- N' [6 d' E# c {- j3 l5 F9 @3 _
% If you modify MATPOWER, or any covered work, to interface with# n9 ^$ L3 a$ a
% other modules (such as MATLAB code and MEX-files) available in a
`- w: {& q1 h& J* e* v% MATLAB(R) or comparable environment containing parts covered; ^* h \- W- ~: B6 P
% under other licensing terms, the licensors of MATPOWER grant# w* a' j+ p* y, J; D4 p' J0 j
% you additional permission to convey the resulting work.$ R1 N" }+ T6 w4 Z
( _7 d2 p' n' j7 A% S' u4 ]. u6 q6 C
%%----- initialization -----$ q- q0 w* y, X
t0 = clock; %% start timer
- {9 r s& \0 z B: e- N- S
: V1 v, p1 ~: e& d \$ V3 _%% define named indices into data matrices
: D/ z: B! o9 b( K' r9 o[PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
. r* h' q5 w [/ a VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
7 _7 J- A7 K' n3 T& q c. S$ y[GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...: L7 M1 d+ r. r
MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
+ v( ^" P8 y. W6 R& | QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
. q. T. [3 J7 ^5 z[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
4 ]& ^2 t7 D- j" J$ F; c% b TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
8 S: A1 F( z9 O- k ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
5 \: d" y) m$ j( J[PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
. g( s8 Z6 P8 b( r5 s0 K3 {
" r$ X# o" O1 h$ F%% process input arguments
' j3 Y4 O" i5 g[mpc, mpopt] = opf_args(varargin{:});) j6 I3 r, ?. Z
- E) O. Z2 I5 l# J
%% add zero columns to bus, gen, branch for multipliers, etc if needed" d- e" B4 `- q$ R! T2 d9 \
nb = size(mpc.bus, 1); %% number of buses
+ _8 d0 A( E' ~* r( r6 hnl = size(mpc.branch, 1); %% number of branches
* t7 p+ Y0 f G4 zng = size(mpc.gen, 1); %% number of dispatchable injections. Q5 w+ j/ S- m. Q
if size(mpc.bus,2) < MU_VMIN
+ p, x0 e: I, D9 H# {( L( Y mpc.bus = [mpc.bus zeros(nb, MU_VMIN-size(mpc.bus,2)) ]; v3 ~" s% I. s, s; c- I
end
. D2 k5 E2 }" v0 T; `if size(mpc.gen,2) < MU_QMIN
, \, T$ R& t: J mpc.gen = [ mpc.gen zeros(ng, MU_QMIN-size(mpc.gen,2)) ];+ g3 n4 _) l6 Y; Y% G# s6 H
end% f+ N5 D; M+ E% n, ^
if size(mpc.branch,2) < MU_ANGMAX
8 H4 G: s3 F0 X3 | mpc.branch = [ mpc.branch zeros(nl, MU_ANGMAX-size(mpc.branch,2)) ];# Q- e+ a3 R5 \: ]7 q! ~5 F
end
5 ?( u+ g/ D' x1 l
, W. r1 U; M) \%%----- convert to internal numbering, remove out-of-service stuff ------ T. S8 r" _3 i
mpc = ext2int(mpc);
) ^' e" l" O: F, D0 g9 b! h+ Y6 y4 u5 u+ K' d8 F7 m7 q# ?
%%----- construct OPF model object -----
3 Y, Z z' [& u/ ?+ H* }* _, \om = opf_setup(mpc, mpopt);
( _: T" j7 _2 Y' J, l' I: x/ r
/ m4 [9 I2 b3 G7 O1 y9 v9 ?%%----- execute the OPF -----; O; L! S {" O3 {6 p
if nargout > 72 w% L4 @$ [, _" j
mpopt(52) = 1; %% RETURN_RAW_DER2 o b7 _$ o F `; @) m! k. D% F
end8 d" J6 r; }$ }/ e
[results, success, raw] = opf_execute(om, mpopt);
$ W: t% B8 W# v. p
' X' U5 |! L* J9 r! J/ m%%----- revert to original ordering, including out-of-service stuff -----
8 T' s- H/ M( L P- Y0 d* Rresults = int2ext(results);
5 d# v; o& q, _6 M& l3 b$ [' G* t/ U. k% Z
%% zero out result fields of out-of-service gens & branches
4 o5 q1 K( d' z; _: D5 m1 J0 lif ~isempty(results.order.gen.status.off)
, G/ P; Q F9 ?8 B4 Y& h0 Q results.gen(results.order.gen.status.off, [PG QG MU_PMAX MU_PMIN]) = 0;
$ \3 ^5 V! Y3 M% D2 tend
, z9 L( ]" J! s8 Iif ~isempty(results.order.branch.status.off)! V6 [5 `; l _, e. T$ j6 x' r% c0 ]
results.branch(results.order.branch.status.off, [PF QF PT QT MU_SF MU_ST MU_ANGMIN MU_ANGMAX]) = 0;9 p' ?4 C9 O/ h1 W
end" u- X) R: l$ M/ L
/ a6 r! L* {1 I+ {: r
%%----- finish preparing output -----
. ^5 \8 Y+ h) ^$ Det = etime(clock, t0); %% compute elapsed time
0 H& U! i1 l+ R# L' s. ]! bif nargout > 0
& E0 r) a1 n+ r. L) E if nargout <= 2
! }0 n% s$ \. E! j+ C% g/ l; T results.et = et;
- A I9 P% C0 T, b1 L& ^$ U results.success = success;6 O' F3 \, \" x9 m, ?
results.raw = raw;" I, ~, @ B O! G: R& r' I
busout = results;
4 L9 t; D/ y) S1 @$ H6 h genout = success;
5 I3 {; b2 Z8 B else
1 ` z M3 @$ G, M [busout, genout, branchout, f, info, xr, pimul] = deal(results.bus, ...
5 L. Y% M* J r3 H9 I" ]7 T results.gen, results.branch, results.f, raw.info, raw.xr, raw.pimul);7 n" Q6 N& ?! n7 x' Z& H3 |
if isfield(results, 'g')3 E2 t7 Z+ C/ ] Y; K' F
g = results.g;' l% a8 J( N) V
end
: M# R$ |! {* S# N$ a* d- { if isfield(results, 'dg')& u/ t+ B2 ]: o4 w8 |; N0 z
jac = results.dg;$ p& I7 w4 N/ {2 B" ?
end+ U% Z, }! c: R: {. {1 u' D5 S
end
7 j8 C5 H# D0 Z& D1 g. celseif success
/ ]$ M( g/ m3 H results.et = et;! P% L4 j; w% J+ E# E) n, v. p
results.success = success;) ~7 N" K7 _8 Q9 n2 K0 V9 z
printpf(results, 1, mpopt);* |" d9 G5 R. K7 B2 P$ K) P% l; W
end |
|