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] = ...
# W+ k7 p+ c3 z% U7 y. ^! [ opf(varargin)
# ?7 p& @" M6 D' }, j%OPF Solves an optimal power flow.) u2 z* W6 I. ?
% [RESULTS, SUCCESS] = OPF(MPC, MPOPT)
5 s+ c7 z( U6 [% A2 A%
: V0 l1 Y' L% @% Returns either a RESULTS struct and an optional SUCCESS flag, or individual8 B+ A0 |8 b7 K/ R8 _& k
% data matrices, the objective function value and a SUCCESS flag. In the; M5 E& J$ A" ?1 p
% latter case, there are additional optional return values. See Examples
5 o4 ?) W8 ?) h6 ~ H3 r% below for the possible calling syntax options.) `& N) T. f. j, t4 a1 v
%
4 O4 ]- m6 N: u' X% Examples:
5 q" ~' I2 v% V9 |- O0 z% Output argument options:
- P2 [ e$ a/ s; V( R% o%" G8 C2 F1 ~+ s [% O" p4 e7 e$ S
% results = opf(...): D, U2 u5 r/ B1 ~" c z
% [results, success] = opf(...)( }4 |# v& ~; ~1 I6 }9 m6 I! w Z- o' H. n
% [bus, gen, branch, f, success] = opf(...)0 ~6 K! F+ B+ P# V9 ?+ K& V& Z! k: S* u
% [bus, gen, branch, f, success, info, et, g, jac, xr, pimul] = opf(...)$ K# S% B, j0 K) o- y' I* E
%
3 v+ E1 ?3 x0 m' v! o% Input arguments options:7 f l. J' e7 \ X( X% W
%" M) H/ U5 D- h9 C) p5 d g
% opf(mpc): Y/ Q; l. Y3 A
% opf(mpc, mpopt)7 E5 t" N# j1 D ^1 S I
% opf(mpc, userfcn, mpopt)
! O Y8 l" V" E6 y) |8 g% opf(mpc, A, l, u)
' ~& P& O/ R5 j) E& |- o% opf(mpc, A, l, u, mpopt)" c0 Q( d& h6 J7 A7 }
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw): H' Z8 W" S& @$ S
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw, z0, zl, zu)) j8 |+ U4 Y! r0 z
%2 g U. Y( G, z. Z+ I$ _3 g
% opf(baseMVA, bus, gen, branch, areas, gencost)
7 `5 h# x- R+ s& ~: F' `% opf(baseMVA, bus, gen, branch, areas, gencost, mpopt)
9 v# R, e5 [' x4 I2 u% opf(baseMVA, bus, gen, branch, areas, gencost, userfcn, mpopt)' Y( ~" p. l* B
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u)' ~3 q- K8 F) C8 t
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, mpopt)
y7 B5 E4 A. s6 [% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ..., a/ x! ~, V* X# `3 z4 t9 [
% mpopt, N, fparm, H, Cw)
7 Z9 z: J0 |( H6 X+ @/ d& t+ _4 @% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...
$ f( K- j7 v! T2 P+ k% mpopt, N, fparm, H, Cw, z0, zl, zu)0 _+ P5 t' H9 j% d
%
- _) B* y3 K) Y3 b/ ~% The data for the problem can be specified in one of three ways:9 ?6 G% _0 G5 z$ p
% (1) a string (mpc) containing the file name of a MATPOWER case
! R' U! f6 F9 G# ^# I5 p% which defines the data matrices baseMVA, bus, gen, branch, and
8 p# m; G" s* P" K2 \) _, b% gencost (areas is not used at all, it is only included for
# X. {) M& R1 a* R% backward compatibility of the API).# y/ D# o5 e8 U! a' ^/ c1 b5 q: C. p
% (2) a struct (mpc) containing the data matrices as fields.
z5 K: `0 p0 V, Z9 B% (3) the individual data matrices themselves.
2 j' R& f8 l6 D5 x%
/ O$ ~, ?; f; p/ j0 R: `% The optional user parameters for user constraints (A, l, u), user costs' I: [. _$ M3 A6 L$ N2 n+ J
% (N, fparm, H, Cw), user variable initializer (z0), and user variable
5 W# N0 P( i) ^% F( t% G% limits (zl, zu) can also be specified as fields in a case struct,
! L5 X1 n/ c, _; P% either passed in directly or defined in a case file referenced by name.( o( Q' }" t u+ U! I0 n
%
4 E' u0 H" r; p% When specified, A, l, u represent additional linear constraints on the
& q9 c- t0 F+ n* ^+ J) A* m0 Z% optimization variables, l <= A*[x; z] <= u. If the user specifies an A
4 x6 O% l+ B& C% matrix that has more columns than the number of "x" (OPF) variables,
+ \) g/ c% t: @9 v2 ]5 R" j% then there are extra linearly constrained "z" variables. For an
" i0 u( C/ b# W6 Q9 s" y% explanation of the formulation used and instructions for forming the
3 }+ H8 n; U! ]. |' X0 M/ ~' p% A matrix, see the manual.
# V# v- M, T; Y6 y% B& G! `%$ P, h G2 ^! @5 N/ j) t% o# c2 R
% A generalized cost on all variables can be applied if input arguments/ M2 [4 }2 B0 [% @
% N, fparm, H and Cw are specified. First, a linear transformation* `( R% L3 R# s. s( r1 ^/ E
% of the optimization variables is defined by means of r = N * [x; z]., k B& S, o) `1 y
% Then, to each element of r a function is applied as encoded in the+ [, |% w7 }: ]; B0 d4 |
% fparm matrix (see manual). If the resulting vector is named w,' `& I+ s( K2 f( [2 t2 g9 G
% then H and Cw define a quadratic cost on w: (1/2)*w'*H*w + Cw * w .
2 p e [- L- d1 t. Y7 p% H and N should be sparse matrices and H should also be symmetric.% U, k' R- \% z$ V2 @
%6 H9 r9 {, e `" {, p* B& X( I
% The optional mpopt vector specifies MATPOWER options. If the OPF
- k1 Z: i) E3 M% algorithm is not explicitly set in the options MATPOWER will use
. |' s, C, K! K: v8 b% the default solver, based on a primal-dual interior point method.( U, I8 }- D4 k5 x: N3 y
% For the AC OPF this is OPF_ALG = 560, unless the TSPOPF optional1 X* B% n; h- S9 s9 |+ _
% package is installed, in which case the default is 540. For the
0 R$ v8 D- d+ P3 w5 a3 f% DC OPF, the default is OPF_ALG_DC = 200. See MPOPTION for2 u3 g. n# o1 a3 e) e, k T9 {
% more details on the available OPF solvers and other OPF options8 ?1 w# A" F- H5 ^* X
% and their default values. @0 D: L0 l% ?& F5 H
%
# I8 I3 f+ C' n9 T0 _% t8 R% The solved case is returned either in a single results struct (described
" s: ~3 @& `' R$ t3 |% P- m! T) T% below) or in the individual data matrices, bus, gen and branch. Also. ^- v' n+ B: U) }' ^+ g; P
% returned are the final objective function value (f) and a flag which is1 L+ L. Y7 w# H1 E+ Z
% true if the algorithm was successful in finding a solution (success).% O; ?3 v4 z! }5 x/ G4 y8 \
% Additional optional return values are an algorithm specific return status5 j: } H2 u9 ?8 L0 M9 F
% (info), elapsed time in seconds (et), the constraint vector (g), the( Y& N/ K: Z. q$ S5 D% i' _6 k8 v1 C# m
% Jacobian matrix (jac), and the vector of variables (xr) as well $ D8 k( W3 b9 P" z, g
% as the constraint multipliers (pimul).5 U! i3 N$ |! j$ t& R7 \' i
%) [% w# A i. l7 e1 q0 e5 u
% The single results struct is a MATPOWER case struct (mpc) with the1 I( W1 ]2 S4 k7 v% X
% usual baseMVA, bus, branch, gen, gencost fields, along with the8 h1 ?1 p4 N& a+ S( V
% following additional fields:4 `% a# A2 W5 k2 z: L# t/ B
%
& |, z$ W6 Z$ N& ^( W5 ?2 `) w% .order see 'help ext2int' for details of this field
6 w/ C/ Q3 @ F0 @3 z1 @6 d0 T% .et elapsed time in seconds for solving OPF/ P4 _) i3 l4 N
% .success 1 if solver converged successfully, 0 otherwise" Z. d/ B) i1 `$ T" J9 A. [' q7 H
% .om OPF model object, see 'help opf_model'7 }! C" y+ ]# J+ x8 J
% .x final value of optimization variables (internal order)2 e# k" S+ ~$ H& \4 W
% .f final objective function value
# }9 p& r1 |7 k& [% .mu shadow prices on ...
( k& g5 T9 U( Q8 f1 f! J% .var
: d* M# O* ]+ ?. M% .l lower bounds on variables
, a0 m% @5 o; p+ _& E8 r% .u upper bounds on variables
) l S6 ^( ]$ T. n+ @! U/ B5 r# n% .nln
% C2 B6 N/ q% R( @; d5 W% .l lower bounds on nonlinear constraints
( {/ h5 M7 U- }, O- S7 E% .u upper bounds on nonlinear constraints
- m. H w% E0 H) V/ J% .lin
B1 J$ s) k( ?6 O% .l lower bounds on linear constraints4 E% p; l. H' L& ]7 E
% .u upper bounds on linear constraints
9 t( [3 W( L0 s2 W7 y7 ^% .raw raw solver output in form returned by MINOS, and more
3 ~$ X' U# ?- M) z I; L: A( f0 g* Q% .xr final value of optimization variables
$ H1 i6 ?' `! w' a& |7 h! Q1 O: i% .pimul constraint multipliers6 D" p9 J" J) t; p0 n
% .info solver specific termination code7 G& ~6 @+ d H- y% Z5 @8 I% P* [
% .output solver specific output information9 V3 ]- e/ U* b" L
% .alg algorithm code of solver used2 u9 L6 a. O& }/ J: W: Z
% .g (optional) constraint values
+ z' R' A5 L2 D% .dg (optional) constraint 1st derivatives( Y$ ]; G3 {5 I5 y6 \( l
% .df (optional) obj fun 1st derivatives (not yet implemented)7 {+ Y# i# e8 n! M
% .d2f (optional) obj fun 2nd derivatives (not yet implemented)
8 t7 J! T: ?1 ^' [* {4 r% .var
$ r9 f I* y% I4 c( B" J% .val optimization variable values, by named block
- o4 Q( s' q( N Z% .Va voltage angles
, Y! I3 s7 R/ D$ T: d E M% .Vm voltage magnitudes (AC only)
+ V3 [% u [2 R9 J; e& v/ o' V3 v% .Pg real power injections' |$ c# r- p% j% ~/ E
% .Qg reactive power injections (AC only)/ X, Z+ s/ t7 g& N0 k' h4 G
% .y constrained cost variable (only if have pwl costs)
7 n( N2 h, F: `% k/ J1 n* M8 Y) Q% (other) any user defined variable blocks: l" G) i" S% M8 V( R! Q
% .mu variable bound shadow prices, by named block& E) Y( s8 H/ m1 Q d
% .l lower bound shadow prices
( B/ b. J9 U5 t7 ?1 S% .Va, Vm, Pg, Qg, y, (other)
, }$ Z$ s: _% i7 P% .u upper bound shadow prices# ? X5 T. X; s5 s3 O
% .Va, Vm, Pg, Qg, y, (other)
2 Q9 _+ M' x+ M% .nln (AC only)
7 g. Q1 I3 S+ U0 {# m! ~$ d r% .mu shadow prices on nonlinear constraints, by named block h. Q/ g# l% I
% .l lower bounds
5 e$ y; ]$ v7 m3 h% .Pmis real power mismatch equations3 `4 L7 E+ ? q- w) {/ |4 j1 y
% .Qmis reactive power mismatch equations
4 S4 u) G4 N& m) e8 V8 F& L: n' l2 [% .Sf flow limits at "from" end of branches3 [) o$ g' A3 V3 U
% .St flow limits at "to" end of branches
$ t1 U- E; n. g6 h) c8 l& Y, C- \% .u upper bounds& I$ f. A8 K) g+ E& Q' H p2 X- b8 Y! A
% .Pmis, Qmis, Sf, St8 V9 }9 I4 h; d
% .lin
0 K* K3 O; X9 U# y: d+ @' k% c% .mu shadow prices on linear constraints, by named block
# B5 o! O: h0 T, \& b8 y% .l lower bounds. b" c3 x1 R* i3 X6 O: ]
% .Pmis real power mistmatch equations (DC only)
1 K2 X1 ]6 T; m/ I! I5 g% .Pf flow limits at "from" end of branches (DC only)
" ?2 b! W3 N: B. e6 p/ s% .Pt flow limits at "to" end of branches (DC only)
. W) q% ~. Z$ I. x& e% .PQh upper portion of gen PQ-capability curve (AC only)
% O$ Z$ E. I4 Z' O6 _% .PQl lower portion of gen PQ-capability curve (AC only)
+ T! B/ g+ A% r$ K: ~* ^ Z1 E% .vl constant power factor constraint for loads (AC only)
& W; g& s$ @0 g% k( c' D. S% .ycon basin constraints for CCV for pwl costs
+ V3 s! O+ Y3 B2 M) a; B% (other) any user defined constraint blocks! D2 ?% S' a# s6 l& O
% .u upper bounds
$ m) Z* [# @: }* M% a0 D9 Q: v% .Pmis, Pf, Pf, PQh, PQl, vl, ycon, (other)
# g4 f' f+ h, y6 F% .cost user defined cost values, by named block
' {; t' T D7 I5 v0 v%: }$ ]2 z8 A y; w9 {( @9 n
% See also RUNOPF, DCOPF, UOPF, CASEFORMAT.8 I7 K$ q/ F' l7 m0 o+ i3 s
) U; u3 Z2 P( F& s6 a4 Q$ q3 c
% MATPOWER: j! D `$ {* d" G8 f0 H
% $Id: opf.m,v 1.73 2010/06/09 14:56:58 ray Exp $- w+ J8 m- q) T3 I# _% P( A5 R
% by Ray Zimmerman, PSERC Cornell; I. c1 `5 A/ \- y
% and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales
' a+ h+ @( ~7 X4 E( _2 c6 h: i/ F% Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)& z9 C* [0 i3 L" i
%
+ c4 w8 G% d6 Q; m0 `2 t* U% This file is part of MATPOWER.! x# [5 v- Y( e, x
% See http://www.pserc.cornell.edu/matpower/ for more info.; J, n' ?7 B$ [/ x6 B
%
) Z: G: W( b. i3 s0 N9 u/ b* E% MATPOWER is free software: you can redistribute it and/or modify' T# L! D0 V) ?/ L5 [
% it under the terms of the GNU General Public License as published
4 p+ P9 }3 t% J5 t% by the Free Software Foundation, either version 3 of the License,
* K( c. l9 r0 d7 _, [% or (at your option) any later version.
3 J g8 R/ E8 }$ D% a%$ ~% m K$ _& |% v$ U: M: [
% MATPOWER is distributed in the hope that it will be useful,
( T: l. f) {; Z, b. e! @8 E: U' r+ Q% but WITHOUT ANY WARRANTY; without even the implied warranty of
' G6 x; r6 j3 u# t6 G' c9 h% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- f. j' P/ J& z! G+ i
% GNU General Public License for more details.
: a* s1 g" D- o( J6 W! t%
8 e$ E: X- g7 H: q8 ]% You should have received a copy of the GNU General Public License
) }- g4 \' @/ m7 M! w, ~8 F% along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
I0 ~* @4 y" a8 H& O# L" X2 W( @$ a' \%, q6 M1 t* \" ]' [: {' S* K
% Additional permission under GNU GPL version 3 section 7+ {+ B3 F$ I0 n" t& w" ^( p( r
%
5 C# m# X5 q- K- i% \% If you modify MATPOWER, or any covered work, to interface with. K9 Z3 Q/ u: V1 ~+ o' Y# e ]; n; |
% other modules (such as MATLAB code and MEX-files) available in a
( j$ B' R( s+ H# g0 H/ [% MATLAB(R) or comparable environment containing parts covered
9 {: k: H! G( k' I% under other licensing terms, the licensors of MATPOWER grant
& o# C6 S4 [4 ?/ P8 E4 O( U% you additional permission to convey the resulting work.$ C) C& w" b( n" a- d2 O! S
0 K3 E& ^' g7 o" o%%----- initialization -----
5 ?1 F2 L; k2 g! D9 st0 = clock; %% start timer; m: @5 G, `1 R, q9 u9 i4 ]
& m/ G' g6 b$ A: n+ A
%% define named indices into data matrices
: J/ _0 J2 D+ S% R1 u[PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
- v' A S5 O8 s# Y VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;+ M6 P' N* X6 o" `7 g; `0 g
[GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ..., I6 j- l3 t _5 k7 F
MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
4 E! H) d$ p, {4 b& J; d. \ QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
/ n. F3 h% q* p# R V! E) B[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
3 X; S6 K; P: t$ Z) o TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...( `* A* i- \) v% a0 f9 t/ l
ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;" s) a) j& D6 J2 Z. b; g3 @( J
[PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
: `7 M N, p! K) h5 ?
1 H1 O5 a1 }( L9 G$ r2 G%% process input arguments
" o" C- O; E. M }( e[mpc, mpopt] = opf_args(varargin{:});( C+ N* D5 M7 d2 W S% N& w9 h
( [/ e B" N, S# i" ~; W% D$ z
%% add zero columns to bus, gen, branch for multipliers, etc if needed
- s/ ~8 J2 ~6 [0 }7 Z8 _nb = size(mpc.bus, 1); %% number of buses
9 d" Q) v: e+ R" A" e+ Fnl = size(mpc.branch, 1); %% number of branches
* s! y$ P& O3 @! R5 Ing = size(mpc.gen, 1); %% number of dispatchable injections
7 x8 p# O3 x/ k5 _8 c0 U- X0 W* r5 Yif size(mpc.bus,2) < MU_VMIN6 \* i* e3 U8 d2 x" X' e
mpc.bus = [mpc.bus zeros(nb, MU_VMIN-size(mpc.bus,2)) ];2 M6 k* D' e- a; B: e# }0 F
end# w* }, u# \( W2 j
if size(mpc.gen,2) < MU_QMIN/ h3 y* f' M0 W
mpc.gen = [ mpc.gen zeros(ng, MU_QMIN-size(mpc.gen,2)) ];
( m0 s$ s# [9 y& T3 Yend& P! h# X' g( _3 E% v1 _- J$ ?2 h
if size(mpc.branch,2) < MU_ANGMAX
' M% e# ^9 x ^' K/ l% m' P# C; E mpc.branch = [ mpc.branch zeros(nl, MU_ANGMAX-size(mpc.branch,2)) ];
; |! v, A ~" z( q- c/ Bend
6 l9 X2 r9 @9 q3 m% }2 a. }3 Z( Y; \+ L/ W4 P4 f7 K+ |
%%----- convert to internal numbering, remove out-of-service stuff -----
8 S' b7 d& g& l$ Zmpc = ext2int(mpc);
2 ~7 i6 Y' R1 h) V2 @1 t
0 V4 f0 m7 V& Z! n%%----- construct OPF model object -----4 N- j4 O9 k/ Q1 Q M$ D5 R4 r
om = opf_setup(mpc, mpopt);* K4 a8 G, w, c2 | y
$ v* B8 c! U) O3 Y1 T* `2 p: z+ [%%----- execute the OPF -----
4 K8 U+ {8 e$ K/ Xif nargout > 7* k" Z7 S$ v( V8 N2 C6 z
mpopt(52) = 1; %% RETURN_RAW_DER5 n2 z( n1 l5 f! C# F$ s
end
5 x1 C& e8 d. \9 i[results, success, raw] = opf_execute(om, mpopt);7 v* J$ s6 D. B% Y V
: Z6 e" o; I/ E1 H3 K( N3 r
%%----- revert to original ordering, including out-of-service stuff -----
! ?5 `# W1 T+ A2 y/ v) @results = int2ext(results);! D+ C, N) C- k, ?
) w8 y' v4 C3 T5 p* l
%% zero out result fields of out-of-service gens & branches& `# w( G5 \9 j3 a0 d
if ~isempty(results.order.gen.status.off)7 ~% \6 N8 H- Y3 ~
results.gen(results.order.gen.status.off, [PG QG MU_PMAX MU_PMIN]) = 0;
, S. l, f$ l& e9 Oend
5 |) e$ z( I e; f# C3 k; Rif ~isempty(results.order.branch.status.off)" h5 O0 B0 \% B- g; N: d: s
results.branch(results.order.branch.status.off, [PF QF PT QT MU_SF MU_ST MU_ANGMIN MU_ANGMAX]) = 0;8 e W9 n7 y" K3 u$ M, B `# k3 M
end
2 V, B8 Q% d0 `7 S: M6 H& F& N, ~; M0 e' Y
%%----- finish preparing output -----7 `9 g2 P1 n/ e2 V6 @
et = etime(clock, t0); %% compute elapsed time& U5 P6 F) a% g- Y& @1 ]" u4 l% f1 x
if nargout > 0
1 ?3 |' Y5 ~' U if nargout <= 2
; ~1 D& i( @& \" n+ } results.et = et;
* Q/ [4 l. J, G; L results.success = success;+ ~4 s: l4 M* G. J/ W2 q
results.raw = raw;
' X" y6 n9 O* e3 J: D busout = results;- ]! H# S" Z& D; C5 x
genout = success;
* J$ r8 G" H- B- A else
# j3 J o8 B. [( l [busout, genout, branchout, f, info, xr, pimul] = deal(results.bus, ...
4 O# e- b4 }- W4 I0 h- R" @ results.gen, results.branch, results.f, raw.info, raw.xr, raw.pimul);
# z8 ^+ W6 K2 ^) q$ D i3 K7 I if isfield(results, 'g')4 K* a7 G! e5 J2 @2 L
g = results.g;8 h" J" k; U3 X, {" q# I
end4 b; G! ~- S0 h( B5 [4 g' x8 D
if isfield(results, 'dg')
, H3 l$ A1 v3 M9 R$ `; w# C jac = results.dg;
( s1 ~) K7 Q7 `( C1 D" d end
% p8 T y2 w; r( e. d; Z1 D8 n end. C% g% V4 F! _4 a: \
elseif success) b/ y4 S0 w' K T, T. L y0 s8 N
results.et = et;$ J* X+ q. Y8 [! q3 E
results.success = success;3 f7 j4 F, O% e) K* T5 E+ _
printpf(results, 1, mpopt);
/ \% c c2 ~# iend |
|