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] = ...
9 E* \8 }8 h7 \0 N1 [ opf(varargin); V0 D4 @7 T0 b2 I5 W; I. u
%OPF Solves an optimal power flow.
' C8 O6 D& n, A) M0 I% [RESULTS, SUCCESS] = OPF(MPC, MPOPT)- L' d Q5 s5 t0 `! K
%7 F* x/ F6 e9 c% d6 ]
% Returns either a RESULTS struct and an optional SUCCESS flag, or individual8 e- Y" k! [( s3 ?( K
% data matrices, the objective function value and a SUCCESS flag. In the
5 v: P5 l& I$ H* m+ X% latter case, there are additional optional return values. See Examples
8 `% C; d- H3 R, N% below for the possible calling syntax options.9 ^; c# j( p3 _6 l4 p
%8 S( n' Q6 ^- B O6 p" x( S
% Examples:+ c: y$ N' P! g( c7 M$ W
% Output argument options:
+ ]# R6 [& Q$ w& S2 @%
' n0 u9 ~8 Y) o7 b. `! Q9 c% results = opf(...) a* ^" y+ T0 i) u: H/ @6 W8 z) j0 e
% [results, success] = opf(...)
/ F% s/ @; O$ Y5 ]5 \% [bus, gen, branch, f, success] = opf(...)5 G5 I2 j Z# p5 T" |0 r
% [bus, gen, branch, f, success, info, et, g, jac, xr, pimul] = opf(...)* j1 E/ P5 T8 s
%
+ N. w: Y+ Z' S* n% Input arguments options:- [" y0 e. Z* e( N o* [
%) C# p" f9 Y6 a; G
% opf(mpc)
. R. K, i( ?. `% opf(mpc, mpopt)
) s" C0 c$ H/ `" R' c5 N" R! }: b% opf(mpc, userfcn, mpopt)
3 ?2 P1 \3 X6 i% m2 l% opf(mpc, A, l, u)
! Z% S |! f; u" ^3 X% ~6 F% opf(mpc, A, l, u, mpopt)
" x+ A$ |* ~1 c; ]! E# @% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw)/ H4 ]7 v6 \. h- G4 P( ^
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw, z0, zl, zu)3 i) N3 Y$ P( `3 |
%
% p! O& I* z9 H* i8 {# K% opf(baseMVA, bus, gen, branch, areas, gencost)
* ?& D( M; `9 e5 \; p6 I$ \) h. ^% opf(baseMVA, bus, gen, branch, areas, gencost, mpopt)
8 V N5 Y4 x; a0 G0 p, D- @% opf(baseMVA, bus, gen, branch, areas, gencost, userfcn, mpopt)
* \% Q9 h( S; U1 k3 b9 ~% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u)
# M# I7 t0 V G$ u7 B2 j1 W U% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, mpopt)
1 m/ e9 F+ L {+ R, y; j+ y% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...8 T* P" v8 \) H
% mpopt, N, fparm, H, Cw)
0 j: u# R; K ` F. q5 j9 X7 d) Z* D% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...
! I5 q& J9 B5 m1 P* H- `% mpopt, N, fparm, H, Cw, z0, zl, zu)
' ~2 S6 s6 i; z' Q7 p7 H+ _%
& e9 T2 U9 I P* x9 K9 G5 K# O% The data for the problem can be specified in one of three ways:7 ]+ }. k& {/ l: F$ ~( Q
% (1) a string (mpc) containing the file name of a MATPOWER case- w0 q3 y( E% p' |# {6 ?( c7 W: a
% which defines the data matrices baseMVA, bus, gen, branch, and
3 ^: a: L. E. m. E* d4 E0 u% gencost (areas is not used at all, it is only included for/ M0 n$ P7 L) ^% M6 G/ a
% backward compatibility of the API).: H# ?3 G5 D* T: C \5 p% H
% (2) a struct (mpc) containing the data matrices as fields.. M: G% ?- a4 u/ w( T* g% J/ q% J
% (3) the individual data matrices themselves.
4 {" W8 c5 m8 {. U( u%
$ D3 P6 ^, Y% k: L: m( B+ I% The optional user parameters for user constraints (A, l, u), user costs. U& i0 h9 O+ T I) \
% (N, fparm, H, Cw), user variable initializer (z0), and user variable$ F% {0 x) H, Y
% limits (zl, zu) can also be specified as fields in a case struct,
0 N- {3 m6 p, k. j! l% either passed in directly or defined in a case file referenced by name.
4 y6 L$ `$ q5 w/ D%
' Z3 y& F0 U( R/ z6 y. C, N, Y% When specified, A, l, u represent additional linear constraints on the: y# ?5 \) N1 d) s& m
% optimization variables, l <= A*[x; z] <= u. If the user specifies an A7 u5 q4 W, M# A, O4 m
% matrix that has more columns than the number of "x" (OPF) variables,
+ n( q1 e+ }$ K. O8 d5 @6 i. Q. A% then there are extra linearly constrained "z" variables. For an$ p& t; ?! H+ D/ ]
% explanation of the formulation used and instructions for forming the @: T c' p# ~ C
% A matrix, see the manual.
1 G* J& a. e' G%& J* s6 d0 i# \$ @4 y
% A generalized cost on all variables can be applied if input arguments
0 l4 a H+ N+ o% N, fparm, H and Cw are specified. First, a linear transformation
- |8 r& O% c0 f* Z( s f9 A9 \% of the optimization variables is defined by means of r = N * [x; z].
/ O9 L2 T- F% K9 ~% Then, to each element of r a function is applied as encoded in the. [. Q% t I2 k
% fparm matrix (see manual). If the resulting vector is named w,( w) `$ @/ j' d
% then H and Cw define a quadratic cost on w: (1/2)*w'*H*w + Cw * w .0 d: ^* ?5 y5 w4 A2 R0 R
% H and N should be sparse matrices and H should also be symmetric.7 M @ t& q9 c
%
- ?! [6 w5 R. Z) X3 Z% The optional mpopt vector specifies MATPOWER options. If the OPF
1 X6 [1 f& y; m: b: D" J9 n4 U6 D% algorithm is not explicitly set in the options MATPOWER will use
" _5 N, ~8 g* C$ r @* m( t5 Z$ c% the default solver, based on a primal-dual interior point method.
: @0 o7 u: P9 O5 ~, V% For the AC OPF this is OPF_ALG = 560, unless the TSPOPF optional2 G, S6 {4 e' F
% package is installed, in which case the default is 540. For the4 [' W: q3 e/ t+ c6 x! f, M/ E
% DC OPF, the default is OPF_ALG_DC = 200. See MPOPTION for; O* I; M6 r4 ^ c: z8 w A& ^
% more details on the available OPF solvers and other OPF options
0 ^/ Y% C5 i. n# Q4 t* _3 _% and their default values.
. I5 X R3 ]7 k5 q7 t" G( X%
. `( E6 ~" ?* K6 _7 e% The solved case is returned either in a single results struct (described
, H5 j; F: Q$ y; Y% below) or in the individual data matrices, bus, gen and branch. Also
% M7 W- Q: i5 ?5 s1 ~% returned are the final objective function value (f) and a flag which is
7 u: [- L- K/ \* h% true if the algorithm was successful in finding a solution (success)., k# f8 i* Q( z4 R
% Additional optional return values are an algorithm specific return status' D0 a' |, l$ y( D4 C! s
% (info), elapsed time in seconds (et), the constraint vector (g), the0 r# r D# z' y
% Jacobian matrix (jac), and the vector of variables (xr) as well
" |2 P8 Y5 Z9 m9 n% as the constraint multipliers (pimul).
0 @% W5 A4 [) e" S%
/ h( Y! K7 [1 Q" }2 f% The single results struct is a MATPOWER case struct (mpc) with the3 S! [) ]8 Z5 j: [3 s
% usual baseMVA, bus, branch, gen, gencost fields, along with the
9 j3 g) p7 Z/ r: k" s4 u% following additional fields:+ _! w7 U A/ v7 Q: U
%
0 q+ I( o0 |& z% .order see 'help ext2int' for details of this field. w/ x9 }" D: d$ A2 U1 H
% .et elapsed time in seconds for solving OPF
8 g. m( G: H u) ^/ R3 {+ s% .success 1 if solver converged successfully, 0 otherwise
3 A }. x8 Y: A5 z9 {% .om OPF model object, see 'help opf_model'$ `9 L, f3 O& e" j, t9 [
% .x final value of optimization variables (internal order)2 V3 e* e& J( S) f( A+ J
% .f final objective function value7 ], G% [. M4 v2 C* P9 h; s
% .mu shadow prices on ...
6 I* ^! F' `5 q% .var2 @9 e3 Q$ h- Q `: }6 m7 Y; k
% .l lower bounds on variables
# Y4 N+ y) O$ {0 P+ l% .u upper bounds on variables R5 `7 n6 W% V
% .nln
& T: |/ r1 Q5 Z/ q8 L% .l lower bounds on nonlinear constraints
/ X0 Z, m: n1 q! W% .u upper bounds on nonlinear constraints
" Y; i; D$ y0 i$ c$ l% .lin& [7 T m$ ]/ A' f2 _ E: T
% .l lower bounds on linear constraints
! i1 F9 m5 z" J% .u upper bounds on linear constraints
) Q: D9 b- J& w) Q' E! b% .raw raw solver output in form returned by MINOS, and more3 X9 E% x7 J R# k& @$ X
% .xr final value of optimization variables' X K5 F5 r$ |0 Z
% .pimul constraint multipliers7 S; }$ s5 G8 Y# r4 d3 ?
% .info solver specific termination code& w2 }; o9 m& T# ~
% .output solver specific output information
8 {$ Z3 {+ y3 Q( n% .alg algorithm code of solver used
" H6 \5 d* {0 W7 k# M2 F! T% .g (optional) constraint values
, d- F- H( U: Y! ~) U& B* I0 F% .dg (optional) constraint 1st derivatives
' H0 m, R5 v) `3 v1 F% .df (optional) obj fun 1st derivatives (not yet implemented)7 c: d$ ?0 d9 I, r- c/ M2 E, p* ?/ I
% .d2f (optional) obj fun 2nd derivatives (not yet implemented)
: @$ B' E7 p4 A6 O# G+ }' j/ h: D% .var* d/ |& \' f: {+ C
% .val optimization variable values, by named block
$ w8 Z" o$ q8 N, L- D% .Va voltage angles
9 x8 `# P4 N6 U( H% .Vm voltage magnitudes (AC only)
% s2 X2 O# j q5 @* [) X0 v% .Pg real power injections
+ G6 ~1 f; [- q' s$ |9 a% .Qg reactive power injections (AC only)
6 m6 `4 W( m1 d% .y constrained cost variable (only if have pwl costs)+ }. M v9 F' u% d' U: o3 Y
% (other) any user defined variable blocks
9 G( H, X' I5 A$ f L, |, P% .mu variable bound shadow prices, by named block4 m( w' b; y3 D! A
% .l lower bound shadow prices, ?- o- _; t2 ]; J
% .Va, Vm, Pg, Qg, y, (other)
6 H2 k9 I& g m" v* Q% .u upper bound shadow prices) |! C' ]2 Z' F8 f) l/ {
% .Va, Vm, Pg, Qg, y, (other)/ l, ^/ t$ u' }. ^; N+ \' ~4 F
% .nln (AC only)7 C4 }2 }+ ]. j% F& t" q/ t
% .mu shadow prices on nonlinear constraints, by named block( d9 T1 E8 e2 Q' X' m7 G
% .l lower bounds! n0 G; k0 l$ m+ @# _, W
% .Pmis real power mismatch equations/ L& j4 z# z2 k; d b% f& {$ v
% .Qmis reactive power mismatch equations
' _0 I. o( L1 R/ N% .Sf flow limits at "from" end of branches
0 Z- Y, ]7 U( e8 H9 L. L2 S% c% .St flow limits at "to" end of branches
8 @" P9 _$ t0 f' L: f* @, A) Q% .u upper bounds
4 Z; q6 Y6 H4 N6 ^% .Pmis, Qmis, Sf, St
3 s% e3 l g; V+ i# G2 }% .lin
4 q7 [5 X, O2 S& I% .mu shadow prices on linear constraints, by named block; H4 G$ G/ u& k0 m( ]4 P) K D0 H
% .l lower bounds
6 m$ l& Q5 h0 [' I& b$ w% .Pmis real power mistmatch equations (DC only)
, P- T% p7 Z6 W0 Y4 l0 M% .Pf flow limits at "from" end of branches (DC only) Z" P1 ?. y+ B& }: J7 V
% .Pt flow limits at "to" end of branches (DC only) f; i1 h# X4 [( A; S
% .PQh upper portion of gen PQ-capability curve (AC only)
6 |$ @$ ?3 r* G& a% .PQl lower portion of gen PQ-capability curve (AC only)
! [/ d3 B8 {9 u! V1 S% .vl constant power factor constraint for loads (AC only)
! x4 z7 r6 m/ Q% .ycon basin constraints for CCV for pwl costs' ~0 T! L# T+ Y L. `. M
% (other) any user defined constraint blocks
; l' a: n* l- C+ }- ^/ R8 u6 U0 C4 Y% .u upper bounds
' @6 D% |6 ~# a5 }$ c! }% .Pmis, Pf, Pf, PQh, PQl, vl, ycon, (other)
/ o7 y) E2 [; M; q1 l: o% .cost user defined cost values, by named block1 C( U" M1 f/ q7 {: r8 _
%
$ r. i0 {! x( a, _* ~0 s5 g% See also RUNOPF, DCOPF, UOPF, CASEFORMAT.
* q, b! K$ R& F* O6 l
) g$ m- D) E. [9 Z$ \. o% MATPOWER
. S1 I* i/ {7 I% $Id: opf.m,v 1.73 2010/06/09 14:56:58 ray Exp $4 r% a/ z0 u$ C
% by Ray Zimmerman, PSERC Cornell
: U b2 E2 L" r+ O' y% and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales
) A6 p5 K/ n- K7 z6 b% Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)* w! m/ d/ l3 b/ U' h8 {7 m4 n
%/ C" A6 \: }' ^4 E% s. Z; i
% This file is part of MATPOWER.
* F3 I) S' B: P( G9 K( C% See http://www.pserc.cornell.edu/matpower/ for more info.( r- t0 Z5 j4 Z
%# R y6 }- o. r5 E
% MATPOWER is free software: you can redistribute it and/or modify
2 d- S a5 L+ \% it under the terms of the GNU General Public License as published" G: k, {7 V. ?" U
% by the Free Software Foundation, either version 3 of the License,
1 S# y* b3 M9 |, O% or (at your option) any later version.
" l- M0 y5 |( l. w: P/ X" K& p%
. r7 ]: S! I9 i9 I% MATPOWER is distributed in the hope that it will be useful,
3 h8 _9 s! @# K2 O7 `4 N9 V% but WITHOUT ANY WARRANTY; without even the implied warranty of
( v8 s9 B! p; y! G% f# c% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
z# K' o# C4 Y; _% GNU General Public License for more details.
w7 n( k: n0 u# Q%) o' g( |# I5 R N' N4 ~% b+ X3 [# O0 F
% You should have received a copy of the GNU General Public License) D( W% `3 ~# `( n0 u( q* M
% along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.# R% ~9 a. O3 [8 I8 W/ C
%0 w9 [& u/ i/ e5 ^8 w' M5 {/ K( z
% Additional permission under GNU GPL version 3 section 7
! Z1 M O3 t1 \7 d/ T5 e2 p% Y' f%
/ n" ^; R8 ^( \3 y5 `% If you modify MATPOWER, or any covered work, to interface with
" B6 f2 _. Q3 o4 E% other modules (such as MATLAB code and MEX-files) available in a
, K& l6 O. y" c- b- ?/ ~% MATLAB(R) or comparable environment containing parts covered
$ J1 A* W; K$ L6 H) l& j7 b( t! `& ?% under other licensing terms, the licensors of MATPOWER grant! N4 W4 N$ s$ t' F# Q; `/ {2 m! r8 G
% you additional permission to convey the resulting work.
& p+ {- j3 m. P0 z
1 ~1 b) r2 v& q# _5 G% y# X* {0 Z$ p%%----- initialization -----9 v5 L+ U) K* k
t0 = clock; %% start timer" P8 O9 K Y5 r; P c/ n e/ `9 n6 e2 W& i
) n {1 c- ^$ F' l8 T%% define named indices into data matrices, c) [. t7 k6 @# O( ^ v
[PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
8 L ?: K. f' c* e9 O0 p VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;7 J0 P' M" j2 V: U7 M" O# A7 O5 M
[GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ..., e9 K$ l$ I0 a6 v$ V# X$ |$ d
MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...5 v$ K0 N9 h" A0 C7 }7 k1 O
QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;! ?9 X) N4 g- F6 ~- m
[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
5 |4 O* J$ z5 v# U J TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ... d6 ~& b& b+ x! p1 U+ N( s `
ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
2 F1 X' n1 L$ H0 P: e/ G9 B. J j[PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;9 F) B$ B: e/ ?! C/ }2 s& W
9 @" e# ^% p2 h+ w" X8 Y& x8 B
%% process input arguments5 p r# f! R9 O5 T
[mpc, mpopt] = opf_args(varargin{:});% E9 f9 z, Y. D$ I; j
2 u% @7 ^+ ~' {' t5 L! c ]
%% add zero columns to bus, gen, branch for multipliers, etc if needed
$ s* _2 U1 x9 y2 x0 d" T. U( C h% ]nb = size(mpc.bus, 1); %% number of buses2 ^$ x) u" |9 o# q. [
nl = size(mpc.branch, 1); %% number of branches
* t& W8 H9 u# }ng = size(mpc.gen, 1); %% number of dispatchable injections
# X; a! [. Y2 A2 z" [% ^if size(mpc.bus,2) < MU_VMIN
+ O# h9 ]# C W$ ]5 ~$ w3 u( t mpc.bus = [mpc.bus zeros(nb, MU_VMIN-size(mpc.bus,2)) ];: V( U i+ H3 I' G
end
' [8 W0 n8 h: J" l/ \ ]/ \% b6 V5 Tif size(mpc.gen,2) < MU_QMIN- D3 |$ o' e# e; [
mpc.gen = [ mpc.gen zeros(ng, MU_QMIN-size(mpc.gen,2)) ];
2 V/ M; j$ w. ^" m" {6 ]9 ^" ~, S$ ^end. R! r( D2 ~) d2 E/ r
if size(mpc.branch,2) < MU_ANGMAX0 a+ X) l: ]3 ~: d b3 e
mpc.branch = [ mpc.branch zeros(nl, MU_ANGMAX-size(mpc.branch,2)) ];& N4 M4 l2 s# X/ ?8 V8 d& z/ W
end
; o+ g+ E; S! f' F3 W; b4 N! n4 l: f# i* S% V( n
%%----- convert to internal numbering, remove out-of-service stuff -----
/ j5 F6 L8 K) g8 N/ i: {mpc = ext2int(mpc);6 D2 |/ U0 b2 v( \! l6 _' V. T
0 ~$ S! X k" u# G%%----- construct OPF model object -----6 x, V7 K; d- h% t3 f3 ]
om = opf_setup(mpc, mpopt);
. j1 z. j8 _8 c' ]1 X
$ b% t! F- E5 J6 b- p* i8 C. u& _%%----- execute the OPF -----
; j, b6 x7 |1 t# ]if nargout > 7" I D0 _! {3 ^
mpopt(52) = 1; %% RETURN_RAW_DER( H3 g. x7 |- f* p L2 r
end
% w; b+ B; X1 X6 K[results, success, raw] = opf_execute(om, mpopt);
8 n- K( s& M1 e' g
6 [0 T3 y# D4 Q ^ q# v' `% U%%----- revert to original ordering, including out-of-service stuff -----
5 F& j& ?% t# Xresults = int2ext(results);5 j1 e5 ^! U. P- { l! q
- K7 W: Q$ N' ~ r% h6 [ Y%% zero out result fields of out-of-service gens & branches& M- T. z* y5 H7 @$ t+ b+ n
if ~isempty(results.order.gen.status.off): J9 n/ U/ p3 p( s, s1 q( f
results.gen(results.order.gen.status.off, [PG QG MU_PMAX MU_PMIN]) = 0;8 K! D( X0 `, B9 @% E
end* ~$ d% `5 }: x0 z; Q$ v7 |; ~
if ~isempty(results.order.branch.status.off)
: G4 X% \5 i5 ~) p3 y results.branch(results.order.branch.status.off, [PF QF PT QT MU_SF MU_ST MU_ANGMIN MU_ANGMAX]) = 0;
3 a0 T1 a# d, M8 N5 Zend i/ z7 X2 `8 I, H5 _: W8 i
$ e7 V- E9 N2 _2 O, l- ?. @. F: C%%----- finish preparing output -----
7 }$ \1 S& ^% r( |7 ~* let = etime(clock, t0); %% compute elapsed time
& _$ @' T& W4 ^; Q/ zif nargout > 0
# _9 ~, S4 i" B/ i- Z _- r* t if nargout <= 2" Q, Z" J' X( }% H! X. D
results.et = et;
- u0 G+ h+ T# i& D) \ results.success = success;
' b$ @# l9 U8 n c- ? results.raw = raw;
) b% ~. |) d' n, } busout = results;
f) r( O% A4 e J5 D& z. n genout = success;4 A+ ?# g/ G: y% ~. q
else
1 X, {8 L0 U7 T, h# L1 i7 l [busout, genout, branchout, f, info, xr, pimul] = deal(results.bus, ...) s7 |" R4 ]. u3 X* t7 ` Q0 m6 h# p
results.gen, results.branch, results.f, raw.info, raw.xr, raw.pimul);' m: S) r7 h2 k$ g! ?8 M
if isfield(results, 'g')
6 n1 ~) u1 H( p0 F8 S# B g = results.g;
. k3 \; a" u, g* t% ]4 N8 P+ u end
' n; ~1 Q5 H& F5 ` if isfield(results, 'dg'). B2 Y" h! v# @9 Y
jac = results.dg;+ r: m: K8 h( A* _. U
end
+ I4 L) J- z" o* }: @+ b6 U end- x9 _& t# j/ T
elseif success
8 g2 S6 o6 c( M, k, m Q results.et = et;8 ~! P/ K+ S' o; Z
results.success = success;) ?9 E% I' f i0 @* C
printpf(results, 1, mpopt);$ A' w& f" o! `9 k0 H
end |
|