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] = ...
& A7 {& z E1 l8 i! V opf(varargin)
8 L& U' X7 |' e/ `( i2 m; v%OPF Solves an optimal power flow.
2 C$ O1 H( S7 \8 L! N% [RESULTS, SUCCESS] = OPF(MPC, MPOPT)
6 o4 ~% `5 C: H6 r%! C4 J( Z: W) G- s3 m
% Returns either a RESULTS struct and an optional SUCCESS flag, or individual/ _7 e8 H+ B& d1 l' }7 H: ~# I6 k
% data matrices, the objective function value and a SUCCESS flag. In the
( g# _- n& }- T7 `0 m, Y8 s! J% latter case, there are additional optional return values. See Examples+ l& d# }$ \# H2 d8 l! D+ J* e
% below for the possible calling syntax options.
# M6 U; r* ^* k) ?+ H1 N+ y# \7 v%0 n& {+ B) q7 T. ?
% Examples:
. ?! v5 ^4 c: i% Output argument options:- A, d1 H, G9 {5 I0 z
%; {: p8 R/ K9 u6 P6 F/ I
% results = opf(...)
( s: D# e: k) ?; o& o. ~( l% [results, success] = opf(...)4 F, D0 u" w: B, U- W
% [bus, gen, branch, f, success] = opf(...)
- ?5 L1 c* c0 p7 ~6 b% [bus, gen, branch, f, success, info, et, g, jac, xr, pimul] = opf(...)8 P$ R" E( v% Q
%
- @( ?/ x* w' {& b* O% Input arguments options:
7 M1 {. x3 G) {4 j, _' n& m2 |; e%1 ^' [% _1 W- X1 w9 K" c
% opf(mpc)
, F9 R; J: H5 X, Q0 x% opf(mpc, mpopt)
8 {: Q& [3 @$ d! F Y% opf(mpc, userfcn, mpopt)
* k# w. X! p( P2 R5 T% D1 D% i% opf(mpc, A, l, u): P: m j- N; k: J
% opf(mpc, A, l, u, mpopt)
: @* @% V! n+ D [ }% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw)( [) y( y) Y" ]! |' s
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw, z0, zl, zu). r; Q: N/ ~' Q* o
%
& e5 T/ L" k9 Q' P) z% opf(baseMVA, bus, gen, branch, areas, gencost)! d7 B$ U5 @, y& k" l ? v
% opf(baseMVA, bus, gen, branch, areas, gencost, mpopt)
9 F3 q8 r) V0 v2 ]% opf(baseMVA, bus, gen, branch, areas, gencost, userfcn, mpopt)
7 H5 ]; @6 r; _) R2 g% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u)
8 p! E. ~0 N: Q+ v% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, mpopt)+ x. d9 Z& P+ f% `( B! s1 p2 F& E/ Y
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...
- r2 @2 w! `8 S- l2 v. ]. E" h% mpopt, N, fparm, H, Cw)
! V7 y4 D/ P3 Q" d1 o) D% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...
! f3 v! }4 d; @, P/ F2 g- v" X% mpopt, N, fparm, H, Cw, z0, zl, zu)
" v; {) B% x4 f9 M9 C+ s% y%
! Y; Y) @; ^1 b' u- s% v% The data for the problem can be specified in one of three ways:7 t+ q W) L- j. B4 k
% (1) a string (mpc) containing the file name of a MATPOWER case6 A1 t. S2 H2 H* G
% which defines the data matrices baseMVA, bus, gen, branch, and( v9 Q0 t7 F. b+ Y, _6 W
% gencost (areas is not used at all, it is only included for
4 w# l9 w/ f6 y. z5 c, E8 u% backward compatibility of the API).2 j, F+ g5 p3 B- b" G; P" G
% (2) a struct (mpc) containing the data matrices as fields.
9 s9 c, j" J1 L% (3) the individual data matrices themselves.3 D" U5 D: |, g3 y4 `! l
%
+ d; s4 a5 x$ e2 c/ M- t$ M- u% The optional user parameters for user constraints (A, l, u), user costs
+ j* o. s; a+ Y7 d+ c3 Z5 {: ^% (N, fparm, H, Cw), user variable initializer (z0), and user variable' h) h0 O9 L6 u" s" h, j
% limits (zl, zu) can also be specified as fields in a case struct,$ V2 K0 G. _! n$ k; k! A) T. o
% either passed in directly or defined in a case file referenced by name.4 K! P! ^9 U9 \$ Q
%
6 e' K' n: }1 S( `* E% When specified, A, l, u represent additional linear constraints on the9 O4 G+ L% S1 w
% optimization variables, l <= A*[x; z] <= u. If the user specifies an A. ^$ L* T* V$ N' L8 \. g% ]
% matrix that has more columns than the number of "x" (OPF) variables,' l# z) a, w+ ?6 y9 F$ ^
% then there are extra linearly constrained "z" variables. For an; s7 ^3 z* X2 }
% explanation of the formulation used and instructions for forming the" b9 r2 z' ^; @5 I, E3 Z
% A matrix, see the manual.
( Y# P& ^: `. j3 @+ F; w%
4 H7 Y' P# J- P+ B- @( M% A generalized cost on all variables can be applied if input arguments& ?# }& }" q: H. p! b& t- d
% N, fparm, H and Cw are specified. First, a linear transformation
3 X& B/ f2 ` E1 ?* T% of the optimization variables is defined by means of r = N * [x; z].
% _/ m6 o. L9 e" j5 U- w0 I% Then, to each element of r a function is applied as encoded in the9 b8 K I0 {$ j" N# V I7 p
% fparm matrix (see manual). If the resulting vector is named w,
( b+ n) c! d0 w$ y# c2 M% S% then H and Cw define a quadratic cost on w: (1/2)*w'*H*w + Cw * w .
% r4 C7 }: O' O4 J- n% H and N should be sparse matrices and H should also be symmetric.; b# a% ]5 O @" e+ w9 P* A
%, j: g& a* C- `* Y; \) I. z2 I- e
% The optional mpopt vector specifies MATPOWER options. If the OPF' b" j3 A8 b) l# f2 P
% algorithm is not explicitly set in the options MATPOWER will use
! N" V" \1 `0 r3 u% the default solver, based on a primal-dual interior point method.
( T$ j* L- L( z% For the AC OPF this is OPF_ALG = 560, unless the TSPOPF optional
; G$ @6 R1 x8 E% w' } q4 q% package is installed, in which case the default is 540. For the
( w/ y# K% s$ S% DC OPF, the default is OPF_ALG_DC = 200. See MPOPTION for- O1 L8 F7 t a3 F: ?) F
% more details on the available OPF solvers and other OPF options
$ V, c3 X2 a: }% s% and their default values.; g$ s6 \3 @7 z4 t/ r+ b
%( ^# Q) @" {) o. W I
% The solved case is returned either in a single results struct (described
9 q4 _, t' e& s: t" a" P: `4 W% below) or in the individual data matrices, bus, gen and branch. Also
8 r/ j% c% V& s0 F+ T% returned are the final objective function value (f) and a flag which is
9 x/ j( L$ \6 i7 @' K3 l0 M% true if the algorithm was successful in finding a solution (success).
# `) U3 b$ I% U# D% y" Q7 V% Additional optional return values are an algorithm specific return status' h: u; y* j0 ]. c: I& Z
% (info), elapsed time in seconds (et), the constraint vector (g), the7 m5 M( k5 [8 Z: u) B' X
% Jacobian matrix (jac), and the vector of variables (xr) as well
! q- W: ]' s0 C% as the constraint multipliers (pimul).5 _, z1 b1 B- _* q
%( I9 T5 H# G w1 ]
% The single results struct is a MATPOWER case struct (mpc) with the' P: k$ S6 B+ [7 e% g, p+ J' a
% usual baseMVA, bus, branch, gen, gencost fields, along with the# s" ]/ z) e/ q8 o# k5 o
% following additional fields:/ x7 y5 p' ?! k4 q' M6 t8 H9 l
%# J' F" h7 s- k2 b+ [
% .order see 'help ext2int' for details of this field$ J: g2 v/ N: E* O* w2 g( e* M
% .et elapsed time in seconds for solving OPF& \. N: @% o8 s2 o8 E2 b
% .success 1 if solver converged successfully, 0 otherwise {' Y. b: _! Y& R' P5 P0 J
% .om OPF model object, see 'help opf_model'& ]$ D: l: Q9 A% ^+ _0 Y
% .x final value of optimization variables (internal order)
9 N/ V3 f( Z, F4 o* }% .f final objective function value+ Z( x, n* G' W; M/ `
% .mu shadow prices on ...) `! V+ J0 `1 U% ?7 [) E9 d: P: X
% .var* `) f; W1 A [5 X/ S- W1 ]/ p6 \
% .l lower bounds on variables+ o2 `7 I2 }! I% v- q# I
% .u upper bounds on variables
) Z/ }" N4 j: {6 M% .nln
3 @. S" Q8 `' c3 {% .l lower bounds on nonlinear constraints8 z4 d, T) W7 V; X
% .u upper bounds on nonlinear constraints
$ h6 |1 D: g2 R! k: W# ^% .lin2 p( m, w* y, N. |' e8 m
% .l lower bounds on linear constraints
7 q' \2 ?2 o6 u9 V9 X. i% .u upper bounds on linear constraints v' B: A9 l3 `
% .raw raw solver output in form returned by MINOS, and more
9 c! \$ g9 o/ G3 V$ I. d+ O% .xr final value of optimization variables U; @6 w1 S* u5 \
% .pimul constraint multipliers9 R& k% B7 a# Y6 Z+ W9 i& N( }
% .info solver specific termination code
4 `7 s0 @) T& t0 K9 v" t% .output solver specific output information
9 c8 l6 r. V" }6 @6 E; h2 J4 c# |% .alg algorithm code of solver used
' u9 N7 s3 o' y8 v. M: X7 u% .g (optional) constraint values9 M# M; D) d- z' [/ ?
% .dg (optional) constraint 1st derivatives
% s( v v9 h) N5 {% .df (optional) obj fun 1st derivatives (not yet implemented)- p9 d: H" K) d
% .d2f (optional) obj fun 2nd derivatives (not yet implemented)! q0 H+ s7 c0 {3 ` b0 v4 o, O* z
% .var
9 z" A8 [4 Y* ~0 l' }. @ |; w% .val optimization variable values, by named block
! j9 @* q! M8 f3 \: z7 r+ U* r% .Va voltage angles" l3 D7 h$ m0 F- C: Y6 f9 y3 R/ Y
% .Vm voltage magnitudes (AC only)
" }9 `/ H6 X0 [4 ]( `2 U' G% .Pg real power injections8 P* P) F4 N* {
% .Qg reactive power injections (AC only)
# w$ S9 [) y% a: B) \5 ~9 o/ e$ X" ?% .y constrained cost variable (only if have pwl costs)
% c P* p" m4 i4 P1 r% (other) any user defined variable blocks
: O3 F2 |. G9 K" E! L$ s% .mu variable bound shadow prices, by named block
% k4 M2 s5 B7 M% .l lower bound shadow prices
6 K7 |( j$ ~- Z0 P% z$ i3 P% .Va, Vm, Pg, Qg, y, (other)
4 C |1 n; | P2 T% ^$ v, V% .u upper bound shadow prices0 d1 i, q) O8 z9 c9 }; Q
% .Va, Vm, Pg, Qg, y, (other)
2 d% f+ q% ~3 [& L, m% [% .nln (AC only)" U0 ?3 s$ |% J, f9 P; ^) L% @: J
% .mu shadow prices on nonlinear constraints, by named block
+ T8 K3 v- \" `) I& x6 u% .l lower bounds
g! A) k- K, p) y) T7 t9 n0 q% .Pmis real power mismatch equations
; {+ o' u( a2 l% F/ u% .Qmis reactive power mismatch equations
; q/ I% m) v5 @3 D- m/ M) g9 O% .Sf flow limits at "from" end of branches' I) w- O( w/ q: x
% .St flow limits at "to" end of branches
8 ^% M9 t( `* T. T& X% .u upper bounds
/ m& f4 P0 M. Q8 d" c9 ^% .Pmis, Qmis, Sf, St
) P6 T& l W7 j% .lin! u* T& a6 F& S9 _
% .mu shadow prices on linear constraints, by named block
: j( v) ?5 o" Z a2 R0 @" L% j d% .l lower bounds. M B: z9 X) b* e" R
% .Pmis real power mistmatch equations (DC only)0 M/ j4 `0 Y9 O
% .Pf flow limits at "from" end of branches (DC only)# }/ _: p% M- S8 q
% .Pt flow limits at "to" end of branches (DC only)! h, ]" z% g z& E& K
% .PQh upper portion of gen PQ-capability curve (AC only)$ W/ o, j) Z6 w/ r
% .PQl lower portion of gen PQ-capability curve (AC only)& f; B0 V, r7 P* m$ g. [4 ?
% .vl constant power factor constraint for loads (AC only)4 ~9 ]# M5 H$ d: B
% .ycon basin constraints for CCV for pwl costs
0 k9 P* D3 }$ B5 h7 Q+ z% (other) any user defined constraint blocks2 i9 G; y+ Z4 J2 i5 V+ D1 o
% .u upper bounds' r+ q* c/ C7 q; }3 {+ _/ y
% .Pmis, Pf, Pf, PQh, PQl, vl, ycon, (other)/ d+ C2 M" S& F8 k$ ?3 l( I
% .cost user defined cost values, by named block V, n6 x; O! z$ T6 D9 x3 [ Z8 I
%- Y+ Q1 T* `8 ~: J; C# \/ S6 s
% See also RUNOPF, DCOPF, UOPF, CASEFORMAT.
6 c( V* Y0 K& ]
7 q, ?8 `; z8 `( J% MATPOWER8 h, T' v; O. C. L, s5 x
% $Id: opf.m,v 1.73 2010/06/09 14:56:58 ray Exp $# e2 U$ ]5 l" P+ u9 v
% by Ray Zimmerman, PSERC Cornell; ^2 u- ~5 U" x& a/ q2 W! {
% and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales5 R3 a" u: g1 p/ ]% t- s
% Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
8 A/ S d2 u- f* L0 }% b- [%
' o7 B5 k; t+ W( j8 g r, W/ Y% This file is part of MATPOWER.. e ?* G7 M! C, r( m
% See http://www.pserc.cornell.edu/matpower/ for more info.+ N9 t, j8 F- G& C0 |0 N7 |0 F
%& e. H7 y! Z1 d0 r0 @6 e
% MATPOWER is free software: you can redistribute it and/or modify
3 ?9 j1 }/ v' ~7 Z& f+ Z% it under the terms of the GNU General Public License as published
/ c7 |/ ~8 h8 y% by the Free Software Foundation, either version 3 of the License,
- t. a: ?' e( Y6 o1 I' y& y6 I% or (at your option) any later version.
4 V o& p+ K( e4 d P3 u* A4 i G6 d0 T%( n; b6 y. B: }8 J) ^7 s
% MATPOWER is distributed in the hope that it will be useful,% Q- O- S5 i% U2 M5 @( P
% but WITHOUT ANY WARRANTY; without even the implied warranty of0 s; i0 q* e) X
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4 q6 W6 W, u6 v9 _* z% p% GNU General Public License for more details.
: E) S5 Z w* z/ [%% o! M4 {) t! }' X1 ^6 G7 I" ^/ }
% You should have received a copy of the GNU General Public License \. b/ B7 x! j# i5 ~7 ^9 ~8 ]
% along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.0 Q4 d+ N$ Q- ]$ L- r1 c
%) E6 h6 p n& \
% Additional permission under GNU GPL version 3 section 7
9 d+ ?) Z0 `1 z( P( A9 M% l7 n. V5 ~%& f- N9 v. B2 {) Y- O; m
% If you modify MATPOWER, or any covered work, to interface with1 {+ Z" T" O1 k; E3 c( k. [/ i
% other modules (such as MATLAB code and MEX-files) available in a0 \0 ?% F) t1 |( K7 b
% MATLAB(R) or comparable environment containing parts covered
/ i8 p7 a7 F) D. l; ]$ n% under other licensing terms, the licensors of MATPOWER grant `& j4 D# ?( @) w8 {: D0 M
% you additional permission to convey the resulting work.
+ r8 U' a; k2 h2 t; f# ~
" v+ ~/ ~7 ]" G1 d% o: d: u%%----- initialization -----
# u' N2 \; E& h, K3 at0 = clock; %% start timer
% H% T: e: V( E
1 {" q5 r3 J" \; v% u' h%% define named indices into data matrices
2 `4 @6 z8 J- ]3 U/ I0 p[PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...8 i; r! ]% |, h2 D+ y8 {/ N5 {6 t
VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;7 Z- n% _6 H3 D! h |) m- O0 a
[GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
. B' o* @ [) ?2 v* x4 e5 O MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...: V7 _, V, w; }4 M. ]9 p
QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
1 D3 X8 l4 [# r8 C/ n3 z* T[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
% J' s3 k1 f, Y: E$ n; f9 g6 Z TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
c7 Z7 m( I6 f# _ ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;2 M3 p5 H3 ^- ]5 a" q# D- j
[PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
) I' t% W. Y& o2 _/ i r- j9 |
/ s; ^8 ~9 |# v" T%% process input arguments5 H/ E0 _) ?& z, O4 O% E; m! U
[mpc, mpopt] = opf_args(varargin{:});9 O& o" c7 \- k
: `4 {" W [* Q* b/ Y
%% add zero columns to bus, gen, branch for multipliers, etc if needed' n9 D J4 Z9 ?% C
nb = size(mpc.bus, 1); %% number of buses# D& l$ x- F6 P, F
nl = size(mpc.branch, 1); %% number of branches
; W. d+ v4 {8 M! \2 @( cng = size(mpc.gen, 1); %% number of dispatchable injections
, h& G- a, x1 K$ o: N% eif size(mpc.bus,2) < MU_VMIN: F$ ]0 f( Y# z
mpc.bus = [mpc.bus zeros(nb, MU_VMIN-size(mpc.bus,2)) ];
3 t2 a0 P1 b2 ~ g& qend
0 K" Q* {; j. W) m+ F6 u2 _1 Kif size(mpc.gen,2) < MU_QMIN" s+ @9 C) f" ?9 {7 H- H
mpc.gen = [ mpc.gen zeros(ng, MU_QMIN-size(mpc.gen,2)) ];
- A1 H) U" H' C0 f3 Wend
4 { ^' f4 W+ q, _- Y8 F( |3 oif size(mpc.branch,2) < MU_ANGMAX
0 b9 _6 l; K4 d' [5 w* e8 ^ mpc.branch = [ mpc.branch zeros(nl, MU_ANGMAX-size(mpc.branch,2)) ];$ @( Z7 n( ~7 k! W
end/ e0 O- o7 f5 n6 x
; [' z4 y3 ~5 l/ t0 ?%%----- convert to internal numbering, remove out-of-service stuff -----
* C* f$ I( ]$ r- t( y7 z% Tmpc = ext2int(mpc);9 I- r3 D! `# h, H
$ H9 w- h- d7 F; G7 J- T
%%----- construct OPF model object -----: R$ P' q3 `' L
om = opf_setup(mpc, mpopt);
, t" t2 u% W% S6 j0 q5 U
3 K* y+ v+ S9 z; Z$ L%%----- execute the OPF -----
8 A$ P2 ^6 s) L3 _) vif nargout > 7
# J" ]$ e" U' C0 g, a( f8 q7 ?. t mpopt(52) = 1; %% RETURN_RAW_DER
9 |% [5 B; l- w7 V8 vend E+ C- s, ^0 R8 J
[results, success, raw] = opf_execute(om, mpopt);1 f6 U( E4 A) l
4 G) Y( P( { i$ K' j%%----- revert to original ordering, including out-of-service stuff -----, p0 N8 I1 ~5 R9 K. Z( H2 C
results = int2ext(results);
) s$ g' A2 ]. V8 g( F! z2 e4 j- U1 g4 V- Z/ v
%% zero out result fields of out-of-service gens & branches) v1 p" U( @9 c1 b
if ~isempty(results.order.gen.status.off)
" \! d$ \. J+ O S, g results.gen(results.order.gen.status.off, [PG QG MU_PMAX MU_PMIN]) = 0;( \" }0 C+ f6 P" [) T
end0 x& M' g& U# u! Q' H- X7 D9 S$ I7 O$ O
if ~isempty(results.order.branch.status.off)+ g+ Q* V6 d3 \
results.branch(results.order.branch.status.off, [PF QF PT QT MU_SF MU_ST MU_ANGMIN MU_ANGMAX]) = 0;
) O4 y4 k$ K; C* Q3 m' n) Xend
+ S5 K3 V5 T9 E. |1 l5 G V8 _4 L0 G4 e8 e0 U: R; p
%%----- finish preparing output -----+ w5 G) w7 i# E0 ~3 d0 W! c9 k
et = etime(clock, t0); %% compute elapsed time( F+ q+ _, S; }) e1 T! T
if nargout > 07 m. \( Y4 j' M& {. Y3 u# o
if nargout <= 2
# d- {' G: W& \7 o results.et = et;: E8 V9 l/ B4 m( I
results.success = success;' l& Z1 C' W. U, |0 \& v8 g
results.raw = raw;. S( u% S" {: a6 W& z3 @
busout = results;/ e/ m% q/ l7 G; B# C0 y
genout = success;/ N& q. h! {3 d- ^& k8 k% z- I7 K
else
& y# r- f; Y5 I8 ^; Q2 l [busout, genout, branchout, f, info, xr, pimul] = deal(results.bus, ...
; h# B2 z6 F( {, f3 i- G' R results.gen, results.branch, results.f, raw.info, raw.xr, raw.pimul);9 T4 Y( L7 Y$ Y
if isfield(results, 'g')
: e: f$ m" z- _0 L# O g = results.g;4 E% O' [$ d4 R; a2 Y! `$ J
end
3 x9 G; L8 @1 c' J6 {' f4 ~ if isfield(results, 'dg')
7 W) H" O+ C; ?; _/ f6 X- ~ jac = results.dg;
+ [" V1 {' v+ M5 X end o* k4 s% d3 v1 m
end. U& v- N- }# H, r0 N$ P' R, h: d
elseif success2 c) a$ A: ~5 b* S# _5 h6 H
results.et = et;( w9 }; `, _& c, `
results.success = success;
2 n0 u9 S( c) j s2 ^7 X6 D$ V printpf(results, 1, mpopt);
9 G/ o- P" Y# q2 jend |
|