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] = ...; C- k& _" x" C$ s, N
opf(varargin)
3 e- k0 h4 F6 M$ V+ F% O( c%OPF Solves an optimal power flow.
# _0 ]; C) z F5 L% b; V0 s( j; R% [RESULTS, SUCCESS] = OPF(MPC, MPOPT)
; b1 Q' h+ s4 U4 g* R1 _ m5 N7 B% n%
& ]4 A0 m4 d' k D3 b/ L3 w% Returns either a RESULTS struct and an optional SUCCESS flag, or individual7 u3 S6 ]7 `0 N7 `2 _
% data matrices, the objective function value and a SUCCESS flag. In the1 m {# h( |. N) D' D% J/ D
% latter case, there are additional optional return values. See Examples
' v6 n1 W' ` @8 A4 e' ^% below for the possible calling syntax options.
0 n- m/ k3 c% p3 m: o: C* {' H4 z%
) p; u! F2 k* O% Examples:
. e0 p" u, p2 K& z% C% Output argument options:/ a5 b, H1 a5 j6 Q
%
2 X% e3 I/ O8 K8 L3 \0 k% results = opf(...)
( K5 T+ c# V8 } `2 A% f7 r% [results, success] = opf(...)( ^3 O+ f! U! R1 ~0 @$ H
% [bus, gen, branch, f, success] = opf(...)
0 s) m& q7 ^( j) k6 }! W) ~% [bus, gen, branch, f, success, info, et, g, jac, xr, pimul] = opf(...)9 z, V" v' x8 a$ ~6 d
%
! ?1 Q9 |, H1 N, A7 i% Input arguments options:( J o/ s/ X t4 X8 G
%
- F! ^" u8 l' ?) M0 l" z! ] `% opf(mpc)% \- f0 w7 ]( R, h9 N* Z
% opf(mpc, mpopt)
+ |$ N: a6 w) u$ M; S% opf(mpc, userfcn, mpopt)6 G: a% `5 r" P- Q" W1 ]
% opf(mpc, A, l, u)& \; B% z8 Z# ]% {' \& X# S& F
% opf(mpc, A, l, u, mpopt)' U' S" T: p& L+ V3 e
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw)1 K3 J% o, ^- ~
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw, z0, zl, zu)
/ ^# R n+ ^' \: m2 S' K+ Z%
. Z9 b6 S; e* n- \" T% opf(baseMVA, bus, gen, branch, areas, gencost)8 W9 u. K7 E7 q2 `! \: Y3 U
% opf(baseMVA, bus, gen, branch, areas, gencost, mpopt)7 p7 X* g3 ^& Q# E* `1 z$ x/ H% i
% opf(baseMVA, bus, gen, branch, areas, gencost, userfcn, mpopt)
' s& K, t# `' H7 S: X0 K0 _& `% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u)
' X) r x) i- u) ]1 o+ \% L+ R7 g& W% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, mpopt)8 f% ^8 v- l* E% m
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...
+ k5 N' M. Z+ G, P ~% mpopt, N, fparm, H, Cw)4 }2 {5 t+ Z6 a3 G6 L* |$ D( [$ f
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...
3 q/ Z2 o0 a. r6 `' G9 g% mpopt, N, fparm, H, Cw, z0, zl, zu)* L' b3 O# O1 a4 ?
%
! ]3 L" |$ j2 M% The data for the problem can be specified in one of three ways:0 y1 p" I5 ?3 n6 h
% (1) a string (mpc) containing the file name of a MATPOWER case
/ q5 x4 p/ U5 k; p8 Z% which defines the data matrices baseMVA, bus, gen, branch, and
, H% h* w4 l1 F6 U% gencost (areas is not used at all, it is only included for
# N: O! [. Z2 A; Z% backward compatibility of the API).
' ^8 l; ^( C# \+ O/ ~% (2) a struct (mpc) containing the data matrices as fields.
7 s& r- ~# ^4 a% G/ h% (3) the individual data matrices themselves.
" u/ [1 f( P7 w4 d2 M% 8 p+ z( y. W" Z( g+ A" [
% The optional user parameters for user constraints (A, l, u), user costs3 a! n1 V; ^8 ~
% (N, fparm, H, Cw), user variable initializer (z0), and user variable; F) ]2 C" S( r7 R7 E
% limits (zl, zu) can also be specified as fields in a case struct,+ }( A) _4 l. r, U7 H6 }' Z
% either passed in directly or defined in a case file referenced by name.
: y9 V2 ?/ V. n* n- Z4 z% ! K6 b5 z9 ?/ [* I
% When specified, A, l, u represent additional linear constraints on the% l# j6 s' f: D
% optimization variables, l <= A*[x; z] <= u. If the user specifies an A
' ~( y( G9 E3 Q1 ]% matrix that has more columns than the number of "x" (OPF) variables,9 ~; i; A8 z8 Q6 i/ y* H+ E8 P
% then there are extra linearly constrained "z" variables. For an: W4 o) Q1 J: g5 e( _
% explanation of the formulation used and instructions for forming the
! r( n. ?0 W9 I% A matrix, see the manual." n) m% v, Z1 N
%( Y& n. P# Q, c% w- [* ^4 }3 H9 d
% A generalized cost on all variables can be applied if input arguments
) a0 v z. E6 a: M* n* `4 A6 `% N, fparm, H and Cw are specified. First, a linear transformation
3 }4 w, B* l" y. |% of the optimization variables is defined by means of r = N * [x; z].
/ d) B( p; M: J& @, b% Then, to each element of r a function is applied as encoded in the
5 C( D2 ?% g( C1 T% }; V# @% fparm matrix (see manual). If the resulting vector is named w,1 c- H6 Q/ m) \. u# e( r# A6 V" [
% then H and Cw define a quadratic cost on w: (1/2)*w'*H*w + Cw * w .' [ P% g$ P3 C5 Q7 |
% H and N should be sparse matrices and H should also be symmetric.
9 V) z. z8 ]4 y5 _+ C%6 Q, J' a$ |% _, y; C
% The optional mpopt vector specifies MATPOWER options. If the OPF
0 {$ n+ j9 F! k" j6 {" I6 h1 {% algorithm is not explicitly set in the options MATPOWER will use$ o) ~. I1 E/ j$ |) P5 J
% the default solver, based on a primal-dual interior point method.
9 L8 v% `8 Q2 F% For the AC OPF this is OPF_ALG = 560, unless the TSPOPF optional7 k. ?: J0 }2 u. w9 f- H) p' }
% package is installed, in which case the default is 540. For the3 r8 E2 j7 h# a- x7 v0 k8 z$ |* y
% DC OPF, the default is OPF_ALG_DC = 200. See MPOPTION for; Y5 W A7 `2 D9 Z; q8 \6 q" U
% more details on the available OPF solvers and other OPF options* Z- ]. r* M) Q7 J6 r1 }
% and their default values.
& o P) E- g( B7 P%6 g/ T9 x8 S3 q6 K& t9 q; J
% The solved case is returned either in a single results struct (described/ D2 C: i2 E! m
% below) or in the individual data matrices, bus, gen and branch. Also
" \' M6 x1 n/ W0 o% returned are the final objective function value (f) and a flag which is( F* x' j% b. _
% true if the algorithm was successful in finding a solution (success).' x' {! j$ ?1 k
% Additional optional return values are an algorithm specific return status1 ]' M0 {( C$ {# l
% (info), elapsed time in seconds (et), the constraint vector (g), the
: g9 g+ x P+ {3 L0 l% Jacobian matrix (jac), and the vector of variables (xr) as well
" K# ?* |* j h1 }: ?6 X/ s/ e4 o* w% as the constraint multipliers (pimul).
- A# b, p O# M%
1 C9 I7 l) y, u% The single results struct is a MATPOWER case struct (mpc) with the3 t. R; W6 e. e. |5 r
% usual baseMVA, bus, branch, gen, gencost fields, along with the
' [$ F b! P1 V) W% following additional fields:& K" i8 d9 e# _
%- x* m/ s' [2 g. Z! K) |: F2 I! G
% .order see 'help ext2int' for details of this field: n* }9 B$ f: T' Q; Q
% .et elapsed time in seconds for solving OPF4 @/ o3 b% N/ n$ u+ a* d1 f) S& _
% .success 1 if solver converged successfully, 0 otherwise
8 ~$ ]; u2 X; G# `% .om OPF model object, see 'help opf_model'
. m+ y2 Q {$ { I7 _$ R4 D/ ^% .x final value of optimization variables (internal order)! ? [* X2 T- R8 |- A
% .f final objective function value
# x% p! ]5 M1 f5 T1 H. @% .mu shadow prices on ...8 K2 P; E/ m/ C) m n: [
% .var
4 {1 h$ l/ e% P5 ]) }4 _- b3 l% .l lower bounds on variables
2 i* b+ L: B) \7 l; B% .u upper bounds on variables
& n% B$ X& q5 H% .nln
0 I# c8 J. K* E' v j1 s5 c% .l lower bounds on nonlinear constraints- ?8 U6 g% m$ q+ D
% .u upper bounds on nonlinear constraints
6 O$ L& x. M: D8 N: {+ A% .lin* }' d* s6 d$ L! y0 B
% .l lower bounds on linear constraints
/ ~% t5 y q2 a; k) t% .u upper bounds on linear constraints
5 u! G6 v$ k6 w8 t5 K& z ?4 @: W4 H% .raw raw solver output in form returned by MINOS, and more
" m7 z- b* T, [, ^$ W% .xr final value of optimization variables! u1 X& W" {: @5 J; {8 @3 l
% .pimul constraint multipliers5 b& ~* `. ~/ L+ }# [# r: D) P$ C
% .info solver specific termination code
. H/ N5 `$ A V& R, F! u% s% .output solver specific output information
8 [( z) d# h6 @1 j+ n/ D- J5 H2 x% .alg algorithm code of solver used: O# a9 C) W& Z" m
% .g (optional) constraint values8 E* C& H0 D8 E8 n8 }' ^: T7 K
% .dg (optional) constraint 1st derivatives; F, W2 f, c% T" R/ e
% .df (optional) obj fun 1st derivatives (not yet implemented)8 p9 C& H# {. o) S X
% .d2f (optional) obj fun 2nd derivatives (not yet implemented)4 l1 Q$ V8 B$ E! Z7 P
% .var
3 L% Z# _% l' V3 v5 r! b% .val optimization variable values, by named block( F& x3 Y6 j& P9 \9 Q
% .Va voltage angles
' t% e& Q, {, L% e6 T% .Vm voltage magnitudes (AC only)2 ]' `& z: X. h! @# H, X) }
% .Pg real power injections0 t7 s% K" h: O9 }
% .Qg reactive power injections (AC only) y2 Y8 s6 V7 R. ]; ~
% .y constrained cost variable (only if have pwl costs)
]: \* e% U0 c6 d% (other) any user defined variable blocks' I' H) C& J( G' c' Z+ u
% .mu variable bound shadow prices, by named block
7 |! t* @& Y) j) o/ a& w# b% .l lower bound shadow prices
& {7 d3 Z3 D6 U- v% .Va, Vm, Pg, Qg, y, (other)
/ w/ y* x7 J- E* Z1 \% .u upper bound shadow prices p1 h3 A5 M g. g5 O
% .Va, Vm, Pg, Qg, y, (other)
. W; F, H% L1 f% .nln (AC only)
0 E! T7 d& ` i6 e# i% .mu shadow prices on nonlinear constraints, by named block7 I O9 k( k% Y- i" T0 S
% .l lower bounds. C% s$ P# m; E( [: E
% .Pmis real power mismatch equations
/ i' T! @# N; }( a3 n) b, k; j* }% .Qmis reactive power mismatch equations' c2 M3 Y6 Q5 \3 Y
% .Sf flow limits at "from" end of branches$ e" F1 h H# d: l$ v3 H/ P
% .St flow limits at "to" end of branches- k9 x0 p2 z$ z' Q. Y* J
% .u upper bounds
; w8 A; T6 a% T. \% .Pmis, Qmis, Sf, St B4 X& c/ \4 \2 v7 u7 ^
% .lin
2 w4 O7 I2 d6 w( p7 h& I% .mu shadow prices on linear constraints, by named block+ L& f# [9 ^% E' r# V: H
% .l lower bounds
& l* R+ V9 o9 B0 U3 x! C" Y% .Pmis real power mistmatch equations (DC only)+ m# R2 @# X3 D! X6 d& Y
% .Pf flow limits at "from" end of branches (DC only)' C, f8 Y, J* X' y8 L# x1 d
% .Pt flow limits at "to" end of branches (DC only)
/ @& o3 j2 y( U: B8 {$ M) a6 h% .PQh upper portion of gen PQ-capability curve (AC only)4 y" p4 T3 Z7 k/ o
% .PQl lower portion of gen PQ-capability curve (AC only); I" `0 p: G2 w. c1 ^
% .vl constant power factor constraint for loads (AC only)
+ m7 } J Q4 s6 P% .ycon basin constraints for CCV for pwl costs6 C& V2 B+ L* Q, L; s* d4 }
% (other) any user defined constraint blocks
% g8 \, d$ P! B1 k% .u upper bounds- w8 [& _$ j; k
% .Pmis, Pf, Pf, PQh, PQl, vl, ycon, (other)
4 P) N% d7 T! ^8 Y5 v' D% .cost user defined cost values, by named block
# R( _2 s8 G @# f: U%. @0 n% B7 h0 F9 @9 C- C
% See also RUNOPF, DCOPF, UOPF, CASEFORMAT.& ~9 t* W4 k% ^+ f& m6 H
8 N9 K/ v7 I/ P% MATPOWER; F' x) v3 U D4 I% G5 \
% $Id: opf.m,v 1.73 2010/06/09 14:56:58 ray Exp $6 ~6 u; @ ]/ V) l0 K% {
% by Ray Zimmerman, PSERC Cornell
" C7 K- E) C, G5 z2 o; o& i5 l% and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales# |6 u% Y3 D9 I; s$ n9 Q
% Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)2 j* v j8 ] R7 Q
%! L9 P$ e3 b7 j
% This file is part of MATPOWER.
" k$ h9 k- n* n% U% See http://www.pserc.cornell.edu/matpower/ for more info.! _0 ]% ~' d& ^4 O. e. W
%
' J4 x. R# ^/ h% MATPOWER is free software: you can redistribute it and/or modify
. D/ M8 e* m% U! e1 _% it under the terms of the GNU General Public License as published: C S( x8 @9 j# W
% by the Free Software Foundation, either version 3 of the License,9 W1 {* L) f) A/ Z+ L+ G
% or (at your option) any later version.
+ J) p) E3 y# V' ?8 ]3 [%
9 c; K8 |9 U5 y/ V" m% MATPOWER is distributed in the hope that it will be useful,
7 s; L* X! C1 b# K% but WITHOUT ANY WARRANTY; without even the implied warranty of' m8 \4 w$ ~) D7 b9 [+ @9 H
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the: ]3 a5 |5 Y: F1 ?8 L* z) z: Z
% GNU General Public License for more details.2 |7 M' I) C: ^; p
%8 C; {! t3 n% ~. y, `8 e) y
% You should have received a copy of the GNU General Public License
2 P( W& v" Q" d& k' X% along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.( M# W0 I4 ~* w& @) ^: U# i$ j- a
%
; f y" f: H! F# r O5 p# h% Additional permission under GNU GPL version 3 section 7
{: x, f" {& g5 x G%) g4 C, a/ }7 S& ?2 E t
% If you modify MATPOWER, or any covered work, to interface with
5 z5 d5 S* T) I8 \! a M3 Y% other modules (such as MATLAB code and MEX-files) available in a) _2 Y' J3 t' |7 J
% MATLAB(R) or comparable environment containing parts covered
$ ]- b4 \ H0 I' [. n% under other licensing terms, the licensors of MATPOWER grant
( a/ e4 L6 V2 j3 e" V8 P6 S% you additional permission to convey the resulting work.
! L+ V5 f1 R, @+ X1 ^
, B! p! Z2 N4 E# ~9 M K%%----- initialization ------ D+ p; z: G. r
t0 = clock; %% start timer, [' B- h+ a* i ~
% C/ W" C+ ]; D1 ]4 i, c4 w7 e
%% define named indices into data matrices
* G- S/ r8 y9 }2 G& |# e/ v1 ?[PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
! B. @& R( A- o6 T* h$ t/ t VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;% K2 |: J) V1 D2 a! a
[GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...$ X5 m5 S' Y6 z# G+ a
MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
9 \7 ~9 X$ c c1 `* I! U QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
6 C3 Y+ [; F, m: G7 m6 s+ ?[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
- C+ I* h. K; ^ TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
$ D' w9 N6 a, U9 c2 w, f ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
, ~2 J8 t G3 q; s# x+ M[PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
, t( _# c; U) G. F! j. l' ]3 C9 t8 [- C" N; J' H, X
%% process input arguments
& c0 Z6 W( J! V2 i[mpc, mpopt] = opf_args(varargin{:});
" b. h) A- r2 F, `- h' S1 ?" F2 t/ M/ {. n ^
%% add zero columns to bus, gen, branch for multipliers, etc if needed- V! C7 ~- H6 T* j s9 Q/ ^8 S
nb = size(mpc.bus, 1); %% number of buses
. o* ]2 o1 V8 X! e- b( D3 o/ k" qnl = size(mpc.branch, 1); %% number of branches
6 W q* v% `; Y2 w# D4 P1 g' @6 Qng = size(mpc.gen, 1); %% number of dispatchable injections
! A, p, m/ ?: `4 F. m8 I" yif size(mpc.bus,2) < MU_VMIN9 N4 P5 m! a) }8 N' J
mpc.bus = [mpc.bus zeros(nb, MU_VMIN-size(mpc.bus,2)) ];
( [0 e+ c5 P# T/ u% Pend6 @( g$ G* [; N7 N5 a$ T7 h, X9 ^
if size(mpc.gen,2) < MU_QMIN
" m! n3 v) W- @! ~5 a4 Z* K mpc.gen = [ mpc.gen zeros(ng, MU_QMIN-size(mpc.gen,2)) ];- ? ~4 ?+ t# \/ l1 \6 Z
end
) j7 o$ G6 X2 E5 zif size(mpc.branch,2) < MU_ANGMAX
`7 e/ O/ G0 K4 A$ k$ | e mpc.branch = [ mpc.branch zeros(nl, MU_ANGMAX-size(mpc.branch,2)) ];6 N8 { D& l! f# D, E8 {
end
& U) {+ F- q% b) l5 u7 H6 C0 P, h! k/ I7 _
%%----- convert to internal numbering, remove out-of-service stuff -----
/ C3 @0 A0 d( I6 M9 _. U, X* smpc = ext2int(mpc);
6 I+ s u/ l! p0 x& f# C1 v3 g' o( @4 Q
%%----- construct OPF model object -----, n( k; Q2 B8 c1 T' e6 y$ _
om = opf_setup(mpc, mpopt);) T6 }4 f$ A& @
) n, Y! e c p8 }$ W
%%----- execute the OPF -----
7 _ z& E/ J4 e5 W: d" O+ i# }if nargout > 7
# d5 ~+ U0 a& @" @9 f mpopt(52) = 1; %% RETURN_RAW_DER
& T6 v% A {9 K% [5 C# O* A9 Nend
A; T$ S) S9 k* X7 f J7 y5 ~[results, success, raw] = opf_execute(om, mpopt);) D' O5 p7 R8 W9 o
: O/ E$ M) Z o; B- l
%%----- revert to original ordering, including out-of-service stuff -----
' G1 M( w0 k+ P" Dresults = int2ext(results);: M: d, c& K) @" L% Q
, {* R+ _$ k/ b5 ~4 Y. a( ?, ~
%% zero out result fields of out-of-service gens & branches* \6 {: e" @7 F# n, t
if ~isempty(results.order.gen.status.off)
% h$ A/ ^+ y$ [, I5 R8 f7 X& U results.gen(results.order.gen.status.off, [PG QG MU_PMAX MU_PMIN]) = 0;
0 p: U" k8 U$ s1 N3 ^9 M6 Dend& r& i. q0 F9 w
if ~isempty(results.order.branch.status.off)
7 }) D( k1 q" M% \1 O results.branch(results.order.branch.status.off, [PF QF PT QT MU_SF MU_ST MU_ANGMIN MU_ANGMAX]) = 0;
3 O$ Z$ c7 `+ }5 ~) m+ G0 O" Qend
0 Q' N* Q, U/ r1 y) R
& p0 t |/ a7 H. N; J C%%----- finish preparing output -----' A7 `+ y) K2 Y' c6 x7 a1 R
et = etime(clock, t0); %% compute elapsed time
6 G4 t8 F4 \. t/ D0 N3 Kif nargout > 0
# f$ x$ X3 y; G3 j" J9 e if nargout <= 2
9 ?; P1 G: x, O. m) q results.et = et;% D% F" e! k* _& v
results.success = success;
* y: W0 c' J6 f2 _ X+ a3 u6 h results.raw = raw;6 l7 g( ~# m0 r- N- L: @5 w
busout = results;) Z0 y2 l( j* y8 P4 v) b+ x
genout = success;
5 j* ^9 p2 H8 ^+ v else v) ]' g. w7 a
[busout, genout, branchout, f, info, xr, pimul] = deal(results.bus, ...
$ p) O* f3 u; q: b results.gen, results.branch, results.f, raw.info, raw.xr, raw.pimul);
, v) O8 S+ _7 b+ g8 _: V6 |% B if isfield(results, 'g')
6 m+ O6 `* b0 w I g = results.g;
, Z5 w7 {- P( g. ?( b end
& t8 K8 ?& M- G3 `8 P0 x if isfield(results, 'dg')7 R3 A1 \$ m- L- E+ g. {& B3 C
jac = results.dg;
" r: r2 N; n' U2 E$ K end3 P/ N( ^- z g: r8 w1 O9 k: e
end/ T7 F; h, ~* z/ n
elseif success+ d' D. |) O* Q! m, q
results.et = et;
& _0 Y8 l6 C- [; C& J m; x/ g results.success = success;- z$ u6 K0 q: |7 T% n
printpf(results, 1, mpopt);- N+ m3 {9 K# j1 M6 ]
end |
|