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] = ...
$ f: i x; n% j opf(varargin)% J% h! \. P. h; p# d. |6 D' S
%OPF Solves an optimal power flow.- K; F3 H w+ M; i8 t O c
% [RESULTS, SUCCESS] = OPF(MPC, MPOPT)
6 o9 L& h0 S3 O0 D+ | u/ w m1 ?; g, m%+ V) O' _! A0 r Q! P7 O1 l/ P
% Returns either a RESULTS struct and an optional SUCCESS flag, or individual
0 B# `2 i+ {& ~0 L( {3 s% data matrices, the objective function value and a SUCCESS flag. In the
1 |6 o9 T3 A" x) p6 o% latter case, there are additional optional return values. See Examples, b- y. n; F. v% Z" A9 {/ c3 d
% below for the possible calling syntax options.
4 X- k- ]: ^9 |" k' i%- L+ J7 x' B- z0 C: L& p
% Examples:1 ^# l: `, h/ z$ o7 o1 p* X1 V& _
% Output argument options: K! p: o) I" j* q
%
+ T# A1 m! j; g1 p% results = opf(...)% q7 g3 J; F ~- l8 F9 J
% [results, success] = opf(...)4 `( D) h2 `" z5 F$ S0 h. v
% [bus, gen, branch, f, success] = opf(...)3 j6 y2 a, e9 s
% [bus, gen, branch, f, success, info, et, g, jac, xr, pimul] = opf(...) P- l& F: a6 R( F; m* s0 l" X: @
%
q% ?: @" ?% _' {( L% Input arguments options:
% @' X5 M) R: C%
' E0 r* b! j# q% Z% opf(mpc)2 v" H7 W, g) G. M$ [
% opf(mpc, mpopt)' n: U. L; L, a0 A: G2 s& i$ A
% opf(mpc, userfcn, mpopt)
+ L* o c2 p- y5 W% opf(mpc, A, l, u)
/ f9 {% W6 |: R/ p3 B5 G* I% opf(mpc, A, l, u, mpopt)5 f; `0 o. |% l5 P
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw); S$ V( [; m8 C) T: {( B
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw, z0, zl, zu)
; z4 r1 M* O% l! C! m%
U# U: f7 a1 f1 A( O9 J% opf(baseMVA, bus, gen, branch, areas, gencost)$ }# d P- ^) K5 N0 _: w
% opf(baseMVA, bus, gen, branch, areas, gencost, mpopt)
7 c0 G0 C8 b/ M2 {) d# w% opf(baseMVA, bus, gen, branch, areas, gencost, userfcn, mpopt)$ T4 D1 H% u {1 J' l/ X8 B1 ~/ @
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u)) ?) k& H8 y6 a/ L4 A3 D0 D9 _
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, mpopt)
6 V0 ]7 N; W; s, B' L, v% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...
+ h, N! a2 t8 @/ T% mpopt, N, fparm, H, Cw), g- K: `* y# S2 E# v
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...! s: \* U' `. S: Z
% mpopt, N, fparm, H, Cw, z0, zl, zu)8 x- U" x6 {' l. |! ?8 |2 b
%; g- v' @9 L' `8 b m r
% The data for the problem can be specified in one of three ways:0 U; X5 u* k8 k/ \8 h8 m
% (1) a string (mpc) containing the file name of a MATPOWER case: p# u" c+ Z4 T; ~8 `
% which defines the data matrices baseMVA, bus, gen, branch, and& e4 J. f- J h, O( d
% gencost (areas is not used at all, it is only included for, Z0 l: F8 P( H3 B
% backward compatibility of the API).
9 o, c5 @% d: h4 I% (2) a struct (mpc) containing the data matrices as fields.% X8 R6 R% N- ^% U: @& Y# ~
% (3) the individual data matrices themselves.
6 u5 ^ d% X3 Z+ e6 A: ?9 g$ P% $ j% P% t \0 S" T
% The optional user parameters for user constraints (A, l, u), user costs
4 g# }; N% w) @- @3 @7 {% (N, fparm, H, Cw), user variable initializer (z0), and user variable ?4 ?4 F4 C: _. E6 v
% limits (zl, zu) can also be specified as fields in a case struct,
2 @; S) s/ r7 x; R% either passed in directly or defined in a case file referenced by name. B7 J3 p$ u" P- q+ W6 t
%
7 T+ v! S' E. I/ S" c. _% When specified, A, l, u represent additional linear constraints on the
, b% l/ E; o& K( m8 N* C% optimization variables, l <= A*[x; z] <= u. If the user specifies an A. l: C* J$ {5 T O$ q4 {$ O3 }6 D
% matrix that has more columns than the number of "x" (OPF) variables,
6 R3 U4 e- P$ }0 K% then there are extra linearly constrained "z" variables. For an
3 l) n! ^, A9 o% explanation of the formulation used and instructions for forming the. p! [, D8 y/ @% i3 U
% A matrix, see the manual.
b. x# |5 z3 O%. Z- o! k% l3 o
% A generalized cost on all variables can be applied if input arguments3 }. |1 `, z9 u
% N, fparm, H and Cw are specified. First, a linear transformation+ N- h5 E1 ^3 g2 f$ @ l
% of the optimization variables is defined by means of r = N * [x; z].
1 w5 _# W. x$ ~5 z9 J/ A% Then, to each element of r a function is applied as encoded in the0 m* A) g2 k2 |! H
% fparm matrix (see manual). If the resulting vector is named w, Q% D$ `* u# r( V7 @
% then H and Cw define a quadratic cost on w: (1/2)*w'*H*w + Cw * w .- s: Q( O* M: s/ C. C' F
% H and N should be sparse matrices and H should also be symmetric.& E4 Q1 A2 [9 Z
%3 N0 w% Q `+ l! ?: v% k' C
% The optional mpopt vector specifies MATPOWER options. If the OPF# T5 k2 o( ^! J* ]
% algorithm is not explicitly set in the options MATPOWER will use7 s9 {1 q* [2 i: y
% the default solver, based on a primal-dual interior point method.
& U+ P1 G- I5 b% For the AC OPF this is OPF_ALG = 560, unless the TSPOPF optional& N0 w. @* T1 ~1 \2 o
% package is installed, in which case the default is 540. For the+ X8 _) P+ n# w y5 F- X7 a
% DC OPF, the default is OPF_ALG_DC = 200. See MPOPTION for0 {/ i, s3 a) P
% more details on the available OPF solvers and other OPF options
# q1 ~. Z/ z/ S- T' i7 `% and their default values.* L0 X& u" U1 G+ O& L
%
K$ g/ n5 K& ` _0 Q% The solved case is returned either in a single results struct (described: s0 g9 a, O3 j+ W2 {9 \3 d( @
% below) or in the individual data matrices, bus, gen and branch. Also
" V4 B3 n% Y1 @8 @# U% S) G% returned are the final objective function value (f) and a flag which is
, h5 c7 t. J3 f3 G0 ^) u# r) U% true if the algorithm was successful in finding a solution (success).
u$ F5 N+ M8 h+ v w+ ?% Additional optional return values are an algorithm specific return status: k7 W, ?1 a; o0 e
% (info), elapsed time in seconds (et), the constraint vector (g), the
- k* j: p- w6 S; i; e" ^% Jacobian matrix (jac), and the vector of variables (xr) as well , u& V) o) k$ W, Z
% as the constraint multipliers (pimul)./ Q: Y. K2 q$ c. }8 N
%9 ]9 G8 s ]" C. } T+ i3 _
% The single results struct is a MATPOWER case struct (mpc) with the2 q* c& Z* Q9 w0 r* J$ t7 g7 z
% usual baseMVA, bus, branch, gen, gencost fields, along with the
1 O4 a' Y' T% |4 d% following additional fields:
+ z9 @2 B) v. X) Q! H4 T%5 I, N# m8 Q6 I% n' w4 R; \3 G, U
% .order see 'help ext2int' for details of this field
* E- E- O, J, O& s5 {/ K6 N$ F% .et elapsed time in seconds for solving OPF" C; p, A8 A7 j% ~7 N: \8 Y, V
% .success 1 if solver converged successfully, 0 otherwise
" S9 y+ C5 l! X% .om OPF model object, see 'help opf_model'
( c+ t& Q v7 D& q% .x final value of optimization variables (internal order)
" [* U- B; D2 G5 M% V% .f final objective function value
4 t; b7 Q$ ?3 m ~8 W4 H+ l/ p% .mu shadow prices on ...) m3 k% c- u) N. ^* ]
% .var
5 z; | K; p9 U$ i Q, @4 _% .l lower bounds on variables
- ?/ `1 h7 h' Y# v' i3 f$ t% .u upper bounds on variables
4 C! {5 Q$ W- o7 M& \. v; D1 I( T% .nln$ D* `+ ?, V3 z
% .l lower bounds on nonlinear constraints* k9 w) I3 m. a. Y! G
% .u upper bounds on nonlinear constraints! W( w) }& c k8 Y1 @
% .lin
$ i1 j. b5 G% _; ?/ v! F% .l lower bounds on linear constraints% H; i' ^$ j& i3 M: P6 {6 r
% .u upper bounds on linear constraints4 i B1 Q; z9 {' I) B
% .raw raw solver output in form returned by MINOS, and more. d5 z. f4 p' ?& K
% .xr final value of optimization variables2 B* p) J9 H- [# i1 G: f: i5 D4 Y
% .pimul constraint multipliers
: J: t5 o2 c- Q- X# ^% .info solver specific termination code
# N; D* n- {( l5 [7 o: q% .output solver specific output information
; G2 Z" |% x4 `% f% .alg algorithm code of solver used
7 t$ \' N0 E* g( B4 R' m5 o% .g (optional) constraint values5 D* o4 J: o2 Y Z# x2 c. Q/ K
% .dg (optional) constraint 1st derivatives6 f, |' X; M5 n5 m- x
% .df (optional) obj fun 1st derivatives (not yet implemented)
: o2 ?( P5 G5 V% .d2f (optional) obj fun 2nd derivatives (not yet implemented)
$ p8 L! p' O1 l) ?% .var
3 z f5 x4 z% m* O! @% .val optimization variable values, by named block
: y1 {4 b5 @. j- `- g3 b% .Va voltage angles8 j4 h# V# Y( B; A8 V) l; g% ]. a
% .Vm voltage magnitudes (AC only)
0 H' L) k/ Q6 E# J' i1 {# J/ X% .Pg real power injections4 Z, `/ T0 e3 \. R6 `, T. U
% .Qg reactive power injections (AC only)
$ A& q0 a0 B2 @ H9 s Y) J! A& R% .y constrained cost variable (only if have pwl costs)
+ G& n; j2 R( D4 ~: g. z/ S% (other) any user defined variable blocks
& Y. d; u2 c# _( |# v% .mu variable bound shadow prices, by named block) C& c! @" V$ P, D
% .l lower bound shadow prices
p! w, A& m5 p% ]. h. ^% .Va, Vm, Pg, Qg, y, (other) D9 {+ a8 `7 N; \3 S6 }
% .u upper bound shadow prices
: t( x* D$ g/ ?2 r% .Va, Vm, Pg, Qg, y, (other)2 f9 ]( e) u, l$ X" J" c- q
% .nln (AC only)( y, O3 \ w( L8 |8 m1 p
% .mu shadow prices on nonlinear constraints, by named block
, Y8 F8 Q$ ^" C; a m% .l lower bounds3 u, ^4 @# {7 g
% .Pmis real power mismatch equations
) b" x7 p" C0 N! K) S+ p- Y% .Qmis reactive power mismatch equations4 |+ a0 S6 Q' E7 K: P
% .Sf flow limits at "from" end of branches
1 T& _; t8 W4 G/ X/ t& C% .St flow limits at "to" end of branches4 ^, M; g( n2 j# H
% .u upper bounds4 d3 q+ k! b& J- h: s9 E. k
% .Pmis, Qmis, Sf, St6 q; ^: ?# ?( Z
% .lin$ p$ s9 R5 b& D/ Z
% .mu shadow prices on linear constraints, by named block
) t" Y7 ]9 C0 Q3 e8 _" u% .l lower bounds5 S7 E6 f3 k4 l9 G9 l2 v6 W+ w
% .Pmis real power mistmatch equations (DC only)) s5 g9 Z5 q* B! |" q9 [8 r
% .Pf flow limits at "from" end of branches (DC only)& \6 h/ Z) F: ~2 h" T% E& T5 I( Y$ G
% .Pt flow limits at "to" end of branches (DC only)( [" {* c- r* ~( `1 }- ]
% .PQh upper portion of gen PQ-capability curve (AC only)
( }- H, l8 w- o" x) [2 G; E% .PQl lower portion of gen PQ-capability curve (AC only)
; S0 i- ]' p9 N4 I' v7 L% .vl constant power factor constraint for loads (AC only)% ]# X; x" }. _5 S9 V
% .ycon basin constraints for CCV for pwl costs
& h7 n- w4 \7 N( F# w5 Z! g; w% (other) any user defined constraint blocks
7 }4 {; H5 E F6 @% .u upper bounds2 P- ^1 J5 M% S# h, `4 p: \! U+ U% J
% .Pmis, Pf, Pf, PQh, PQl, vl, ycon, (other)
. o) m; K e4 q d3 _3 t% .cost user defined cost values, by named block
6 |1 \+ R) e) T" [# ]% l- c; ]%( g/ a! A- N" b9 J$ U7 R
% See also RUNOPF, DCOPF, UOPF, CASEFORMAT.
. V' a2 T! e0 c- `8 ~6 t/ B- J% K' m4 l2 W3 A9 I$ u; ?' u( A
% MATPOWER
6 w9 ~. a8 ]! s3 Z* ^ n6 y2 T( l% $Id: opf.m,v 1.73 2010/06/09 14:56:58 ray Exp $
; b% q0 R% m: E+ Q7 M% by Ray Zimmerman, PSERC Cornell
1 T* t' B4 t5 X( V7 Y/ J; J% and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales
- {$ g1 f7 s" f4 O: f) X! L% Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
# m% ?9 \: \& b) Q1 t) I%2 U& _+ S8 K# r+ [
% This file is part of MATPOWER.- {" n- L2 w h
% See http://www.pserc.cornell.edu/matpower/ for more info.- v/ ]: @! Y; ]5 I
%
- S3 B% p3 O3 v: j. ]4 u' J% MATPOWER is free software: you can redistribute it and/or modify* Y" p* z- y# H- P) H0 } g
% it under the terms of the GNU General Public License as published
# s- V1 t) q2 C% by the Free Software Foundation, either version 3 of the License,9 h" ]- h* @/ T
% or (at your option) any later version./ ~$ e; t) F& k1 ^
%
2 z7 S/ b# G9 ?7 L% MATPOWER is distributed in the hope that it will be useful,* _6 a" q4 L, O8 _ C8 h9 E* M
% but WITHOUT ANY WARRANTY; without even the implied warranty of, X/ ?5 z& B. j7 P! [6 `
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Z& H8 q& P$ z2 o% GNU General Public License for more details.
: T! \9 o$ U9 E3 G%: }7 N; n1 g# V' ]) g1 _ h$ E
% You should have received a copy of the GNU General Public License
9 o' d( O( x; K8 }* ~% along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.( W* p+ x# a+ g! d2 |8 b5 O6 J
%# E0 R$ S+ b6 d& C- g
% Additional permission under GNU GPL version 3 section 7
9 V/ k2 h. s4 Z8 d, y _& G%
( H7 }, x# S* c$ y* P% If you modify MATPOWER, or any covered work, to interface with- h6 m- E; |1 a `, o! s
% other modules (such as MATLAB code and MEX-files) available in a4 p }, w9 \- Q# b# Q
% MATLAB(R) or comparable environment containing parts covered" L: y: R3 b: K. i8 h
% under other licensing terms, the licensors of MATPOWER grant4 r5 F- C# @% I
% you additional permission to convey the resulting work., ^- V! g6 j. S
) q+ D% \9 q$ x ~$ m* v0 L%%----- initialization -----
/ h3 x! r, |' it0 = clock; %% start timer+ I- ^/ s5 [, r- h* j! o
! \3 @+ E2 e! X%% define named indices into data matrices
- {% r1 Z) ^6 ]5 a( P[PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...! e# |% G0 t# ?) s
VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
1 E* o/ R! G3 Y3 n) U[GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
' ?' O: z4 Z9 A* | MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
; K4 J: j, m7 V, n! r$ e& K! j QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
* n7 ]: k1 @7 Z* Y- w; @2 v! |[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
$ y: a7 h/ u8 P% ]0 E m# W! b TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0 K8 m, e$ E7 ~, @( | ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
& b6 m W1 j& l. Y[PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
. j0 [1 G" U- W0 _" m4 U8 ^, f1 s O# a
%% process input arguments
% Y, @$ t6 p; z% D5 D5 l* Z# k[mpc, mpopt] = opf_args(varargin{:});( k) G% C9 b$ x0 b
6 P, A+ l! k ~+ H* N# k @" t/ l2 x
%% add zero columns to bus, gen, branch for multipliers, etc if needed
" ]* D& l; h" ~3 `* lnb = size(mpc.bus, 1); %% number of buses
% Q8 O0 v6 A9 V8 l+ k( d5 Bnl = size(mpc.branch, 1); %% number of branches" x9 N4 ^8 e v0 t4 S g5 Z3 f! H2 `
ng = size(mpc.gen, 1); %% number of dispatchable injections: T8 r! ^! C- k. L, E
if size(mpc.bus,2) < MU_VMIN& w0 J, H% d- j7 r# D
mpc.bus = [mpc.bus zeros(nb, MU_VMIN-size(mpc.bus,2)) ];
9 p: R/ P# A$ a pend: N2 S' c5 \ I O1 ?2 Y8 O
if size(mpc.gen,2) < MU_QMIN' x3 L$ r# f/ k" r+ ?: O9 d& m+ P
mpc.gen = [ mpc.gen zeros(ng, MU_QMIN-size(mpc.gen,2)) ];
+ g* X. G- X, T E- Rend+ a V k' \0 R9 N% n
if size(mpc.branch,2) < MU_ANGMAX% z2 w8 I; o+ j
mpc.branch = [ mpc.branch zeros(nl, MU_ANGMAX-size(mpc.branch,2)) ];
+ L, b5 q$ x' qend& s; X) T3 l2 W5 v4 r& J/ c$ m
" } ~$ N! j; I0 g, O%%----- convert to internal numbering, remove out-of-service stuff ----- o0 I d6 Y0 k7 q1 v+ \; g/ V) N
mpc = ext2int(mpc);
! \) ]3 h2 O1 f1 \* }& H/ T4 F2 e$ U' C% t" K/ ?- l
%%----- construct OPF model object -----1 o% t( R P, U. w
om = opf_setup(mpc, mpopt);/ G/ t1 u" i# @7 z) C C; H
2 f2 Y8 `% c$ ~% P
%%----- execute the OPF -----
, i6 L' u4 }5 }9 J6 Tif nargout > 76 h( o6 ~2 j z. ^6 m% A3 U& n2 e
mpopt(52) = 1; %% RETURN_RAW_DER
# W5 x" m y. H9 x3 J9 }+ x. E9 W6 Hend6 F- R5 P7 k& h5 l
[results, success, raw] = opf_execute(om, mpopt);
% b/ e1 z( ?3 g; W/ a7 d% F! ]2 x
( }/ x$ o( B0 s/ Y4 a%%----- revert to original ordering, including out-of-service stuff -----6 D$ y% L4 [) s; F! ^
results = int2ext(results);" ~" c. [6 i2 n) W" S4 N1 u& Z
9 \3 Q6 D+ H9 z5 P%% zero out result fields of out-of-service gens & branches
# D( s: H! `; ~4 d. \! Mif ~isempty(results.order.gen.status.off)
6 m. e0 V) j, G* t results.gen(results.order.gen.status.off, [PG QG MU_PMAX MU_PMIN]) = 0;
1 f# x4 `0 A& a7 B' Cend% t9 [6 K D9 u/ O2 ^' x' J
if ~isempty(results.order.branch.status.off)" U: A' Z& J0 ]9 E% K3 M
results.branch(results.order.branch.status.off, [PF QF PT QT MU_SF MU_ST MU_ANGMIN MU_ANGMAX]) = 0;) T3 M0 C8 h/ ] z$ g4 k* D- w }
end
1 H+ j4 H/ i: r3 Q+ G' _
) F9 p% t: w, z! F' x% I1 M# X%%----- finish preparing output -----
( {- Y7 Y! _; h! ~2 [1 bet = etime(clock, t0); %% compute elapsed time
3 [7 Z! m, |3 F( }* Zif nargout > 0% b- q8 |+ D; M3 I" y
if nargout <= 2$ s, X: ?) x, L3 c) ~) W
results.et = et;
! C* [/ N, E3 i# Z4 p) ~6 d s; C$ L results.success = success;/ K; h7 z0 M: T+ T* r, X
results.raw = raw;
3 ?1 m6 B2 t) ]( r7 w( D busout = results;* r% F K* n( m! F1 B
genout = success;- ?+ K/ E' _9 _7 @4 D
else* u- @7 K$ ?- Z1 y
[busout, genout, branchout, f, info, xr, pimul] = deal(results.bus, ...5 Y; h! S9 f) |1 v* T7 m
results.gen, results.branch, results.f, raw.info, raw.xr, raw.pimul);2 @! z, p. e+ c) L* v/ Q: g: L. K
if isfield(results, 'g')+ u0 V2 m; a' c* j
g = results.g;/ E! E5 r, ~" }# a8 N
end2 J: l0 K% L& d7 A
if isfield(results, 'dg')2 g/ w. s5 p: f
jac = results.dg;
% H) v7 X- Z' L+ |% m end# n) U3 o6 m1 ?) {
end# K( b& a5 @' R( n% B5 H
elseif success
$ ^/ o P) g7 h( j. E k6 c1 S2 M results.et = et;
1 Z9 _% u7 q+ ? B, p results.success = success;; T6 n' X: j- m; a" }
printpf(results, 1, mpopt);
- J: {, W9 @ @. Q H4 u# Xend |
|