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] = ...
" K( t- M( L* r opf(varargin)
$ @2 c* A% n1 {9 q5 N b+ r3 }%OPF Solves an optimal power flow., D) _( N9 x5 g0 M7 n
% [RESULTS, SUCCESS] = OPF(MPC, MPOPT): t( o; r. v5 X% b; P# `
%
5 }; |+ ^$ n5 }% Returns either a RESULTS struct and an optional SUCCESS flag, or individual
) t1 N. R. E, G, D- {8 A% data matrices, the objective function value and a SUCCESS flag. In the# D3 U" [- A' z; ]5 s
% latter case, there are additional optional return values. See Examples
" s, a( d8 c/ W# R l0 R+ s! A5 L% below for the possible calling syntax options.; Q: z& K7 p8 X' ?
%0 `- h4 k) f7 o8 V3 g# k! q
% Examples:( r1 t6 |6 O! E( [
% Output argument options:
- J+ a6 c8 Z9 F6 C! _/ ?1 F) I# J%
! C1 F H. `; h/ v% results = opf(...)
$ V+ B8 ?' r5 e% [results, success] = opf(...)
+ q3 ~7 f% k! o' _) L% [bus, gen, branch, f, success] = opf(...). k Y' J& v ]) k8 ?
% [bus, gen, branch, f, success, info, et, g, jac, xr, pimul] = opf(...). O6 Z1 {' B, y5 R3 S" F* Q
%
' W% d) y. m3 ]6 `+ \4 o# d! X1 q% Input arguments options:5 f! i; J8 E0 j. H# ]( z# U4 i) H
%
/ Q$ M- q1 ^) U% opf(mpc) ~5 |* P( ~) B" p* z) B. U$ o3 `8 N# o
% opf(mpc, mpopt)2 ^7 j$ @4 \4 d. d, P1 ~" @3 k
% opf(mpc, userfcn, mpopt)% C3 d/ c/ @9 a+ T4 ^* b
% opf(mpc, A, l, u)7 r! ^8 Z$ W3 i. _2 L. Q
% opf(mpc, A, l, u, mpopt)
& S/ X* B% X3 Y3 \. z i, C9 e/ T% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw)' T' }5 w H" D" I$ V n p
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw, z0, zl, zu)& i0 P x1 J2 z: X
%/ `! }6 ~1 @, V5 D0 h; d2 ^4 L
% opf(baseMVA, bus, gen, branch, areas, gencost)
& N/ V: u3 W# Z% opf(baseMVA, bus, gen, branch, areas, gencost, mpopt)
! \$ ?! | P, n8 e+ R% opf(baseMVA, bus, gen, branch, areas, gencost, userfcn, mpopt)
2 ~" D1 O1 Y* Q! Y9 g; d( n) {/ z% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u)
) N, |2 w* [7 j( T( i( H& Q% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, mpopt)9 x; Q- d( y* E; l) Y' c
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...$ K- i. V5 `: F$ E
% mpopt, N, fparm, H, Cw)" J, W. \6 }( O( b
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...
2 w/ I6 s w' t A0 v3 g% mpopt, N, fparm, H, Cw, z0, zl, zu)5 ~% k# m* J& p3 L; o6 j
%
7 O G9 U: f7 y% The data for the problem can be specified in one of three ways:' _1 T; s. |; V& D+ S4 g$ u
% (1) a string (mpc) containing the file name of a MATPOWER case
( f! E) p$ v2 t1 H+ k% which defines the data matrices baseMVA, bus, gen, branch, and. M; c, |: E; ~, Q6 o
% gencost (areas is not used at all, it is only included for
/ M# K% }+ t$ J* T% backward compatibility of the API).) I9 d' E: w* s$ ?/ M; v
% (2) a struct (mpc) containing the data matrices as fields.
) N8 ?, M/ M; @% (3) the individual data matrices themselves.! n$ q4 l9 o& E. o& p3 |
% % P& ^- }7 a$ i" `4 E
% The optional user parameters for user constraints (A, l, u), user costs% I# a/ n# H$ S* c% ]' ]
% (N, fparm, H, Cw), user variable initializer (z0), and user variable
# v: Y3 I$ H' O% V: G- `% limits (zl, zu) can also be specified as fields in a case struct, ~6 r; g8 v$ ~( _- F
% either passed in directly or defined in a case file referenced by name.4 e+ y5 ^$ |, |% E7 |, V: H
% 3 ]/ f. c8 _2 A/ r6 [" T+ `
% When specified, A, l, u represent additional linear constraints on the
* Q5 ]+ E* O0 f& P. t( n$ m) f- R/ e% optimization variables, l <= A*[x; z] <= u. If the user specifies an A8 `' _( W$ f/ P0 Y
% matrix that has more columns than the number of "x" (OPF) variables,
4 S [0 q" b7 I3 K' e% then there are extra linearly constrained "z" variables. For an0 m9 h! j: U6 D# M& e+ W1 }) [
% explanation of the formulation used and instructions for forming the
' B; O' d) [; B1 B: s& q% A matrix, see the manual.
# j0 D0 A. q4 D& b1 P%1 O/ T, u; E7 b# a5 ~) K* H
% A generalized cost on all variables can be applied if input arguments
8 L: z5 N: g/ [3 W' V P% N, fparm, H and Cw are specified. First, a linear transformation$ _! G. ^) Z% o# M1 B Q+ l
% of the optimization variables is defined by means of r = N * [x; z].
! O4 }; D2 q0 c7 q% Then, to each element of r a function is applied as encoded in the. y; m; P+ q0 y9 D
% fparm matrix (see manual). If the resulting vector is named w,) ^# x0 q) l; E1 u t1 X( j' _
% then H and Cw define a quadratic cost on w: (1/2)*w'*H*w + Cw * w .
3 N. d# l3 _2 r7 M8 C0 Q9 g% H and N should be sparse matrices and H should also be symmetric.. P! h2 x+ J) c+ z; r7 E0 q1 F
%
) b7 ]- r/ O8 E: w% The optional mpopt vector specifies MATPOWER options. If the OPF/ x$ g% q4 Z6 f7 e* @& ~
% algorithm is not explicitly set in the options MATPOWER will use9 X* j) Y4 K& t6 b% [4 H3 P
% the default solver, based on a primal-dual interior point method.0 q5 D/ x& I8 d8 M
% For the AC OPF this is OPF_ALG = 560, unless the TSPOPF optional
3 r7 s, t- f: ? f( K4 z% package is installed, in which case the default is 540. For the
9 i( P" ?0 u5 v% DC OPF, the default is OPF_ALG_DC = 200. See MPOPTION for
* a/ |7 }7 g" D. g8 Z5 D& \% more details on the available OPF solvers and other OPF options% ^5 w$ \8 R: h* k, V, M
% and their default values.
: `) w5 X' k# W; y6 I4 e% x) T1 E' m' w%
$ y+ x- m9 ~0 w/ Z% The solved case is returned either in a single results struct (described
+ X. K3 ~' K6 b q3 b% below) or in the individual data matrices, bus, gen and branch. Also7 i! w: \# l. p o5 ?4 W7 C
% returned are the final objective function value (f) and a flag which is
: g$ [# z/ V3 N3 Z" O% true if the algorithm was successful in finding a solution (success).) [: w! l" Z7 {" w7 j2 w# n
% Additional optional return values are an algorithm specific return status
- d( R4 K5 k# d% (info), elapsed time in seconds (et), the constraint vector (g), the
5 [* Q3 [) o4 F+ I- _: y6 h, s% Jacobian matrix (jac), and the vector of variables (xr) as well : t& Y0 C' |1 F
% as the constraint multipliers (pimul).2 w9 n T1 p$ H6 `( t( Z) L! V0 M
%
4 z, B( s7 Y' I# X% The single results struct is a MATPOWER case struct (mpc) with the
) f" D+ ^% D* E% s% usual baseMVA, bus, branch, gen, gencost fields, along with the
% T0 r% y$ c/ K! x+ y% following additional fields:- e+ ]; e0 O/ o7 w
%
$ p) N h1 ]' Y0 h! }/ y% .order see 'help ext2int' for details of this field" q3 J7 `# a) j3 A" w% Q5 ^
% .et elapsed time in seconds for solving OPF0 ?! m; ~6 S/ u& O0 s9 x& n' a
% .success 1 if solver converged successfully, 0 otherwise
! s& x& ~+ N+ l% Q- I% .om OPF model object, see 'help opf_model'
& Q1 C {' i5 Z$ `% .x final value of optimization variables (internal order)
) r7 @6 a) A8 r) u- F- z' [0 X% .f final objective function value- e' @3 R& f+ I: U) C+ P
% .mu shadow prices on ...
0 K# _, W7 W8 l8 j& x+ e, e% .var
( e3 j: C5 i8 t! g% .l lower bounds on variables7 I2 D) G+ t* c
% .u upper bounds on variables4 Z# d3 M9 h8 d5 H% K# B+ n+ N9 M
% .nln9 d' [. C8 j9 ?1 }4 p" @
% .l lower bounds on nonlinear constraints
4 M4 b( n. r, X A% .u upper bounds on nonlinear constraints4 D9 w, n" y/ m+ ~! K0 R9 M/ Q
% .lin2 d6 I, O: f3 Z
% .l lower bounds on linear constraints
2 J5 O; }8 `6 y% .u upper bounds on linear constraints
$ N$ u" A& o1 M% .raw raw solver output in form returned by MINOS, and more
) h* i# g4 u9 v. d% .xr final value of optimization variables
o4 E+ I( A5 P1 Q5 W- `8 G- t% .pimul constraint multipliers9 ?7 }' A% Z. q, a" J* G7 A1 p
% .info solver specific termination code
3 N6 H ?6 @( G' a% .output solver specific output information
" Y0 d# D1 S! A$ ?7 N6 O% .alg algorithm code of solver used
! h3 ^$ m" B1 M9 N& a% .g (optional) constraint values+ M- C/ b) W7 n2 [2 b! K# Y
% .dg (optional) constraint 1st derivatives
, P9 p! z1 q' V1 R8 E3 C' l% .df (optional) obj fun 1st derivatives (not yet implemented)
) j* F1 Z4 Z- l6 O3 G; H7 @ P% .d2f (optional) obj fun 2nd derivatives (not yet implemented)3 I1 F, W" U5 b5 P
% .var9 G' R: _$ `. O6 }4 f! [8 E. a
% .val optimization variable values, by named block: {. C% {: N4 c! G1 l
% .Va voltage angles
. y7 Y7 G( e+ ~! E% .Vm voltage magnitudes (AC only)7 F1 p! _7 m, N$ h ~3 |6 s
% .Pg real power injections$ `/ L: n5 k7 J0 \, @7 B
% .Qg reactive power injections (AC only)* o6 m- I' B0 ~$ P$ H; r
% .y constrained cost variable (only if have pwl costs)( w+ Y0 o4 P/ ^
% (other) any user defined variable blocks2 D- \+ D4 M7 j+ G) \
% .mu variable bound shadow prices, by named block0 m( P9 s8 Y: W$ E4 N t) r
% .l lower bound shadow prices
" U) w4 H* p- a( W% .Va, Vm, Pg, Qg, y, (other)/ `8 b l- B4 P: r* q
% .u upper bound shadow prices. @4 f9 I, q( s% ]+ [
% .Va, Vm, Pg, Qg, y, (other)
' K: u& F1 K3 e+ H& W( D2 T% .nln (AC only)7 y* z& E, z0 V/ G
% .mu shadow prices on nonlinear constraints, by named block
: N A o+ \: |5 `% .l lower bounds: H l: z+ k; `7 E
% .Pmis real power mismatch equations# |+ K7 z1 o* L; Z6 [
% .Qmis reactive power mismatch equations
$ Z2 A% B) b) p9 v) O2 C8 B" ^% .Sf flow limits at "from" end of branches* f2 V" B9 X' E" A( |
% .St flow limits at "to" end of branches
, T! [; C: G, ^% V6 z; O% .u upper bounds
: H# S: X# A6 a5 ?# r: D& F% .Pmis, Qmis, Sf, St
4 _# c) Y1 M5 F' f' x: s% .lin
* O' T% S! x# @. V% .mu shadow prices on linear constraints, by named block
- T8 P4 M/ q" l6 N; d2 C# {% .l lower bounds- m+ r& v8 C1 r% o, c7 ^* A3 S, m' H
% .Pmis real power mistmatch equations (DC only)% A( A, L7 ?9 I) f! W( [" z& n
% .Pf flow limits at "from" end of branches (DC only)( S3 J" L! g2 Z3 Q. A) F
% .Pt flow limits at "to" end of branches (DC only). o* x! a! X/ f/ e6 Z, t/ Q* }+ W
% .PQh upper portion of gen PQ-capability curve (AC only)
: N' F. l; x5 r! H- f$ r* F% .PQl lower portion of gen PQ-capability curve (AC only)
$ e3 u& D4 W5 |( `! u( R6 }+ o% .vl constant power factor constraint for loads (AC only)3 i) K6 V# P. z0 F0 l
% .ycon basin constraints for CCV for pwl costs3 Q' J* ~* J) H3 y" x
% (other) any user defined constraint blocks
( f3 e/ j( U- f) i/ r6 }. S$ p/ u% .u upper bounds
6 a& n% M% ^$ {6 A% .Pmis, Pf, Pf, PQh, PQl, vl, ycon, (other)3 s- c9 r9 ~$ k, v) u: K. |
% .cost user defined cost values, by named block
* Q' x0 Z9 q- _6 x9 Z+ s6 |1 t- C! d# V%1 c% G+ q# _8 h8 G# K0 L$ _& L
% See also RUNOPF, DCOPF, UOPF, CASEFORMAT., @" h- s/ k# s$ d; x5 n, ^1 c
! X6 p. R: l* M9 M% MATPOWER( l2 A; E4 Y8 D
% $Id: opf.m,v 1.73 2010/06/09 14:56:58 ray Exp $" u8 @1 g0 K( }* E
% by Ray Zimmerman, PSERC Cornell# V4 J% S! G# R0 ^! s
% and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales
/ }7 R" b0 X& `0 Q: J5 T% Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
% P# V1 n# `" g8 ?: G%
+ [. r3 e' p1 N4 c; Z% This file is part of MATPOWER.
# p7 d) l. g9 E* z: @0 a% See http://www.pserc.cornell.edu/matpower/ for more info.; ^$ M2 h+ M7 @2 Z) s1 h9 h& D/ w
%
' l- [* o1 q* k- ~5 D: I% MATPOWER is free software: you can redistribute it and/or modify m: n7 Q$ l0 q5 o# j
% it under the terms of the GNU General Public License as published
) U. v7 L4 T8 b2 M( W Q/ }0 }3 E3 S% by the Free Software Foundation, either version 3 of the License,
9 G- c0 u* o5 l5 s* O% or (at your option) any later version.
: U' q$ l2 Y [7 ^%
! Q4 T0 M( I& F+ `. m% MATPOWER is distributed in the hope that it will be useful,2 {+ F; ]* J- g
% but WITHOUT ANY WARRANTY; without even the implied warranty of* ^% e7 @$ ?3 d/ K& B6 @
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the% m) t! S8 q# P, m2 X' v0 B4 L2 k
% GNU General Public License for more details.- F* {8 q% P8 w, a! E ~
%
9 u$ ~& s6 d* g0 Y" t% You should have received a copy of the GNU General Public License' _3 i( z5 {! _- `( x1 W7 I! G
% along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
- G, H/ V9 ~6 Y8 X, D2 ] j%
( \) U0 @3 _; {! w) x- M% I% Additional permission under GNU GPL version 3 section 7, y! F" F, h" X2 A
%' ~4 A% u0 Y+ k
% If you modify MATPOWER, or any covered work, to interface with
% n6 s0 N; f1 g+ G% other modules (such as MATLAB code and MEX-files) available in a7 F, h Q; y! i% w: d- l3 v
% MATLAB(R) or comparable environment containing parts covered
2 m, ~" F# ~0 ?& U/ E% under other licensing terms, the licensors of MATPOWER grant/ Y4 D: `) Z/ s9 g
% you additional permission to convey the resulting work.
2 J/ `3 |, }: ^2 L2 E5 @) k, S& c# H% B0 u
%%----- initialization -----
9 Q$ e, Z4 Q4 t- H. Ot0 = clock; %% start timer8 e; d; F8 e& P# ^$ p, e
9 t% u. | ~/ @8 \, ~; I%% define named indices into data matrices" z6 n6 D" o4 @+ ]5 a" b, Q
[PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ... P" H9 ]* D2 n4 m
VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;" m: q2 o% i& U' k
[GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
9 D7 r* }. S; |' K" c MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
) B3 R2 u' Q4 V" ]4 k QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;; f& u3 e+ h( a7 T
[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...1 e5 A) Y; ?# j# z
TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
9 y5 j! |7 {( p1 ~9 {% P* @% } ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;' Y3 T, X' C% ^, a0 f0 h" G
[PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;7 q6 h" p9 \1 x4 h; v$ `
" d2 B3 k5 d1 n, H
%% process input arguments- d3 U; C2 U R0 a K
[mpc, mpopt] = opf_args(varargin{:});
3 }! R$ z3 D3 T1 t+ j; }4 H% J: e+ V- u+ c6 O M7 `
%% add zero columns to bus, gen, branch for multipliers, etc if needed* u! c. z" T* ]
nb = size(mpc.bus, 1); %% number of buses; y- g* a+ l5 ~7 D* }2 C, x1 X
nl = size(mpc.branch, 1); %% number of branches; w, J' k" m- Q( i- r
ng = size(mpc.gen, 1); %% number of dispatchable injections
; s( W, V3 d$ p) W9 P/ F: Pif size(mpc.bus,2) < MU_VMIN v0 O; V8 p- ^% K/ j! R0 s
mpc.bus = [mpc.bus zeros(nb, MU_VMIN-size(mpc.bus,2)) ];/ u+ r% l$ Z9 V/ J9 F. @. p% A
end D! z9 s6 M/ A: i
if size(mpc.gen,2) < MU_QMIN
6 J; m' U w+ Z mpc.gen = [ mpc.gen zeros(ng, MU_QMIN-size(mpc.gen,2)) ];5 E( X5 O* x! B) E
end9 ^! G$ p9 i5 r: e9 u
if size(mpc.branch,2) < MU_ANGMAX' S0 M* k4 X8 T1 @
mpc.branch = [ mpc.branch zeros(nl, MU_ANGMAX-size(mpc.branch,2)) ];
) ^$ o3 w( ?, I2 m# ]9 Bend9 |3 A' ~- N9 W# m6 n
$ }8 O4 Y) }! {( J( Y%%----- convert to internal numbering, remove out-of-service stuff -----
/ W: s0 T1 Q0 L8 H6 umpc = ext2int(mpc);6 _+ N" }1 L' H2 r
' z1 f) Q' N% z4 h$ N
%%----- construct OPF model object -----
/ l9 ?/ o) o3 o. S0 V" Z0 Mom = opf_setup(mpc, mpopt);- M h9 i! w# v; L- u- a
& W5 |# g7 t$ I$ ?0 B! H( C
%%----- execute the OPF -----; E1 D8 Q8 a: |2 _+ ]# Y8 o
if nargout > 78 e! `8 T3 U+ m
mpopt(52) = 1; %% RETURN_RAW_DER
) N; K- L# C6 B/ mend7 U& D! B) [- v( `
[results, success, raw] = opf_execute(om, mpopt);
# g0 Q. }, t/ n$ v; Y* U S6 X% X6 z& m. c8 w& c# D
%%----- revert to original ordering, including out-of-service stuff -----' p' ]0 y, h% U# v3 V, V5 k+ O
results = int2ext(results);. ]5 M2 X$ P! q8 Z, L
$ L' u' |5 L5 h" s; q
%% zero out result fields of out-of-service gens & branches
0 x$ V8 P# Z2 R6 D+ D; \) h# Sif ~isempty(results.order.gen.status.off)
3 n5 Q; f$ v* Q( d9 p9 J0 N results.gen(results.order.gen.status.off, [PG QG MU_PMAX MU_PMIN]) = 0;
* Q, W, v" m- b) g5 Bend
* k1 k; g! s6 ~! ~* Y s# |$ v4 k2 Qif ~isempty(results.order.branch.status.off)6 r8 ^4 H: L# U6 o
results.branch(results.order.branch.status.off, [PF QF PT QT MU_SF MU_ST MU_ANGMIN MU_ANGMAX]) = 0;
. x v4 ]" l; Uend
6 R; y5 v; ^, s* R- ]8 b
$ Z& O/ P: x- G%%----- finish preparing output -----3 B8 s1 M' e0 y# y t
et = etime(clock, t0); %% compute elapsed time4 p& W8 M/ S: K, z
if nargout > 0& V8 _2 a7 b/ h& n/ F
if nargout <= 2) C4 U0 ]4 U$ r/ k8 n$ Y
results.et = et;
/ [2 B1 w4 z( o9 ~6 P results.success = success;
3 {. g6 S4 K4 o% a* a results.raw = raw; H# ^) @" L7 G
busout = results;5 Y6 j+ c8 Z2 s7 }( w
genout = success;& T4 A* m' z: i5 M, k: }
else3 Z* n1 y+ e- r& Q% O, d
[busout, genout, branchout, f, info, xr, pimul] = deal(results.bus, ...3 _2 i) m2 I" Y, Y% i$ }) C
results.gen, results.branch, results.f, raw.info, raw.xr, raw.pimul);
, g+ @" `! k8 Q if isfield(results, 'g')
$ v& F! i; q% a( W g = results.g;: f' J4 E& d) r, S* n
end5 E# H( q' J* ?0 ~" y
if isfield(results, 'dg')# }7 S7 g7 V* U H$ W
jac = results.dg;4 n @: }* G ?
end
0 i; l" q; O9 x/ p5 \5 C end
. x: v7 u6 P: n9 ]* @elseif success) l0 p8 Y+ U% l8 m' }. w# g. `
results.et = et;5 `) f1 s5 h* v7 N8 J s6 P% l
results.success = success;6 {; ^% T$ I' N& m8 s
printpf(results, 1, mpopt);
' K- W/ L; O% U3 H/ }& f* Nend |
|