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] = ...4 c' `8 }; B9 K" ]
opf(varargin)
3 L; u5 |: Q d2 }: a; L%OPF Solves an optimal power flow.- [' V$ p5 z7 h4 E3 s5 i5 `, c
% [RESULTS, SUCCESS] = OPF(MPC, MPOPT)
. N7 o# b8 M+ L$ i( _( d%3 D4 o! w$ |2 m" y6 K* Y; h U. k
% Returns either a RESULTS struct and an optional SUCCESS flag, or individual
, Z1 }9 O) B* M& O1 }/ A% data matrices, the objective function value and a SUCCESS flag. In the
& e- _3 G, x v( Z: Y% F- I4 d9 h7 J% latter case, there are additional optional return values. See Examples
# ]5 ]# R+ g, D; @- c% below for the possible calling syntax options.# Y) p! J6 Q" S; U% q% m
%
2 O7 C1 Z1 D( L/ a% Examples:; A6 P+ E" w/ R+ z
% Output argument options:' g5 f) g: }8 E1 Z4 U8 E& I3 K2 \/ n
%
3 t1 J' b+ L8 g9 M: p% results = opf(...)
6 n$ ?/ f8 E5 n% [results, success] = opf(...)
4 G j. ]$ B) [, V% [bus, gen, branch, f, success] = opf(...) X2 J+ [+ p* K3 f( }# t
% [bus, gen, branch, f, success, info, et, g, jac, xr, pimul] = opf(...)" l" P7 f1 R: p+ i) Z
%
8 _8 N. f% |) u" s9 n0 n% Input arguments options:
$ A4 s. b8 \* P( b- d; t) a5 o1 [%
" Z- w8 T: c2 p) L0 t8 F, ]% opf(mpc)) ^9 |/ X8 s0 E& n( {
% opf(mpc, mpopt)* t5 T% K+ a/ V! Y& I. U% q
% opf(mpc, userfcn, mpopt)
' {+ o. Z8 g- D" i% opf(mpc, A, l, u)
" [# t" H F9 e. c1 J% opf(mpc, A, l, u, mpopt)
, s p$ |" c1 G1 Y7 n% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw) r% d" e9 ^. H7 y9 y( A! m6 D" c
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw, z0, zl, zu)7 e c( _& f3 j0 B! C+ \2 S
%- ]- Q; }# j0 _/ [5 s. z' l
% opf(baseMVA, bus, gen, branch, areas, gencost)
7 W) T! ]+ {5 b$ l% opf(baseMVA, bus, gen, branch, areas, gencost, mpopt)% b5 ?( O9 c, W- k0 u/ z! v
% opf(baseMVA, bus, gen, branch, areas, gencost, userfcn, mpopt), L5 o+ v7 G" u: g) m3 Z1 ]
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u)# k: R& J/ B4 j) b! O
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, mpopt)& a" W( q& X* L9 i z8 N
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...# }" J, q3 ~9 r' a/ G, l& u
% mpopt, N, fparm, H, Cw)" [/ j, i, r, D
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...
; @8 I5 {0 _( y# Z% mpopt, N, fparm, H, Cw, z0, zl, zu)
' X5 O) E9 |$ a5 T% C' f5 x4 y%
- Z+ _# R9 N1 z" y% D) O% The data for the problem can be specified in one of three ways:/ @$ `* e2 ]' Y5 J/ D$ U7 U, m/ D
% (1) a string (mpc) containing the file name of a MATPOWER case8 K5 P- p3 l' _* N u
% which defines the data matrices baseMVA, bus, gen, branch, and* j# B- c) g+ e; ?
% gencost (areas is not used at all, it is only included for2 S. v. N& a( {8 A
% backward compatibility of the API).
' E- P" L9 |4 r+ ?4 p* ~) x. m2 V% (2) a struct (mpc) containing the data matrices as fields.
: P0 e S# ^! |# L9 s- d% (3) the individual data matrices themselves.
* t; t: u5 c* F%
; C4 l9 C- J6 g; Z M1 b+ l- D$ ~% The optional user parameters for user constraints (A, l, u), user costs/ A* ]9 R+ }3 _" x7 \
% (N, fparm, H, Cw), user variable initializer (z0), and user variable
( b+ ?; O7 m) H$ L* K% limits (zl, zu) can also be specified as fields in a case struct,: B L+ O& d& e9 f
% either passed in directly or defined in a case file referenced by name.
: ?; V4 S5 z* c% d1 {% 0 ?9 |! c5 ?. ]
% When specified, A, l, u represent additional linear constraints on the
9 S8 D8 k" h! w) Q% optimization variables, l <= A*[x; z] <= u. If the user specifies an A) M: d$ g) i; m+ S5 L3 e( \
% matrix that has more columns than the number of "x" (OPF) variables,# Z/ j$ W4 C5 s0 ]1 V+ j/ {4 |
% then there are extra linearly constrained "z" variables. For an& f/ J: n8 c' D
% explanation of the formulation used and instructions for forming the
5 J# {! l6 h$ m& S/ m4 @% A matrix, see the manual.
, P9 ]* c& a0 Z- m+ ^* n& @9 M, w%
0 G2 |* D# V% e8 R5 A8 T% p; e% A generalized cost on all variables can be applied if input arguments9 K8 }4 i; B) m5 k0 e/ ]
% N, fparm, H and Cw are specified. First, a linear transformation
1 S5 h4 z0 I+ S# n* o% @/ k, j$ u2 V% of the optimization variables is defined by means of r = N * [x; z].- N5 [ Z t( Y/ F
% Then, to each element of r a function is applied as encoded in the
1 H* k5 S! @; F. R+ `# X% fparm matrix (see manual). If the resulting vector is named w,* M& `1 M3 i0 n; X8 k
% then H and Cw define a quadratic cost on w: (1/2)*w'*H*w + Cw * w ., l/ U0 H- @! {/ u4 S' Y
% H and N should be sparse matrices and H should also be symmetric.
; F s$ f6 d! l, p- n! Z8 s+ Y6 X%
! ]/ ?. o4 L% E% ]' t$ _& h% The optional mpopt vector specifies MATPOWER options. If the OPF0 ]6 l, k. _2 ~/ `0 k# W' c0 E
% algorithm is not explicitly set in the options MATPOWER will use& r0 Q/ p. ?7 N# D" V$ l$ z
% the default solver, based on a primal-dual interior point method.% h4 p" c" z' X0 U' w* w* j8 ^: t0 B
% For the AC OPF this is OPF_ALG = 560, unless the TSPOPF optional
( O) n/ D& s! k: V/ Y" J% package is installed, in which case the default is 540. For the$ f. h8 P' h1 y; r' Z* r
% DC OPF, the default is OPF_ALG_DC = 200. See MPOPTION for
- }* t4 A% f" C5 q# Y, D3 C) `% more details on the available OPF solvers and other OPF options5 A1 U/ r% `: {# m6 _% q2 J$ |5 D
% and their default values.( F9 a& e0 z0 [# e
%
! _6 n4 P, T( e5 R. Q9 r% The solved case is returned either in a single results struct (described6 O0 U6 ]- s4 g, N- D- I- w
% below) or in the individual data matrices, bus, gen and branch. Also0 C# p/ ~4 [0 r. O
% returned are the final objective function value (f) and a flag which is" o+ U1 z8 a6 {$ b: _# j! s7 @- Q
% true if the algorithm was successful in finding a solution (success).
6 G; W4 w% D1 p' W& i8 M1 l/ X% Additional optional return values are an algorithm specific return status ^3 V9 @2 j. z
% (info), elapsed time in seconds (et), the constraint vector (g), the
4 U. o; Q7 Z7 Y& H7 M. L n% Jacobian matrix (jac), and the vector of variables (xr) as well
& g( @$ b1 r' X, c* U% as the constraint multipliers (pimul).
8 H, _9 y( V( b" N @9 U% W) y%7 }$ @$ }5 W; r8 k1 ~+ x
% The single results struct is a MATPOWER case struct (mpc) with the# m$ t( x0 I" k m, m: i+ x6 J _* D
% usual baseMVA, bus, branch, gen, gencost fields, along with the
$ Q! E+ Y( @+ `4 h. P% following additional fields:6 v9 L% n# \/ c: N: N
%
8 D. ~+ X4 k9 _9 o4 \1 N% p% .order see 'help ext2int' for details of this field
+ Z7 Z' I" L: v# B% .et elapsed time in seconds for solving OPF& O4 J+ H4 g! e2 |) V
% .success 1 if solver converged successfully, 0 otherwise5 g" {3 B& R) H6 @0 R8 M
% .om OPF model object, see 'help opf_model'
" r2 u/ n7 V) o( ]% .x final value of optimization variables (internal order)
& l: K5 N; Q* x- X% B8 Z6 F+ M% .f final objective function value
0 r W. v" w/ G. _% s2 Y$ E% .mu shadow prices on ...
/ p5 \( n% }0 H- Y- k% .var# c% t0 O2 \8 @" v" I/ @6 k& J
% .l lower bounds on variables
1 Q9 ~3 C" I! ?$ y% .u upper bounds on variables
$ o y$ T! j" r/ V% .nln) O! U: }4 n6 D
% .l lower bounds on nonlinear constraints# q. V- {, w( b% O8 h4 V
% .u upper bounds on nonlinear constraints6 A$ Q0 M) P# e: N: I; y" T
% .lin( ]6 q. H: K3 K7 s
% .l lower bounds on linear constraints0 O5 g& J `: o( `9 D
% .u upper bounds on linear constraints9 G9 l. B3 m! E, R8 t. k1 Y
% .raw raw solver output in form returned by MINOS, and more
* }8 d* s6 N3 i6 m$ S% .xr final value of optimization variables. t& p, c' {9 s
% .pimul constraint multipliers
- ^/ A" n# H9 g# O! n1 E% .info solver specific termination code G2 C$ Y0 a: B/ @, i
% .output solver specific output information) ~: D6 q, w! c; O' N
% .alg algorithm code of solver used
& I+ g4 `' O$ h" r' N% .g (optional) constraint values/ S8 k& x* c3 B+ [, i _% K
% .dg (optional) constraint 1st derivatives3 U$ |3 N$ C3 ?" G* Y6 K
% .df (optional) obj fun 1st derivatives (not yet implemented)) N7 U" l0 V/ h$ M# v
% .d2f (optional) obj fun 2nd derivatives (not yet implemented)
& k6 S; r/ c2 Y; G7 ^7 G% .var9 Z4 d( S) G! f+ f* n( l& e& Q
% .val optimization variable values, by named block: \1 l1 f9 W# E! r. n( k2 K
% .Va voltage angles
9 s) }% W$ q, L$ k) Y% .Vm voltage magnitudes (AC only)
; h8 Y1 m! t6 ^) h$ K8 \% .Pg real power injections0 w& \" S! p& y# J/ D2 v
% .Qg reactive power injections (AC only)
9 d0 S4 S& q Y- O' F% .y constrained cost variable (only if have pwl costs)
. Z7 s( ]# z. i% (other) any user defined variable blocks! J8 O- ~+ X' ^ }# l
% .mu variable bound shadow prices, by named block x9 R; n O% f1 v4 l1 Y
% .l lower bound shadow prices5 V- s' U2 Y6 h% u3 G
% .Va, Vm, Pg, Qg, y, (other)# B% e) ?" [7 _! ^
% .u upper bound shadow prices
1 S% }* L% @" p( u. Y5 d# a% v% .Va, Vm, Pg, Qg, y, (other)& R) n$ }7 H! J4 D
% .nln (AC only), {" R, [( P/ G- [% a8 y: f$ L- r
% .mu shadow prices on nonlinear constraints, by named block
' S- i1 m; B1 O; \) x& k& B7 w% .l lower bounds: O0 N& M3 i6 i
% .Pmis real power mismatch equations
, _( Z4 `4 a# F2 F% .Qmis reactive power mismatch equations I q: |4 k+ [& K6 }7 o, V
% .Sf flow limits at "from" end of branches
9 e. q" {3 X: j; n% T: S m$ j6 |3 \' B* |% .St flow limits at "to" end of branches: t1 B6 T* m4 P: m+ {0 K C
% .u upper bounds
# t9 \6 F( I" h9 l/ p2 H: I$ D% .Pmis, Qmis, Sf, St% M) y4 \ K7 v
% .lin
* r9 h" i( L5 ^( [2 l6 @% .mu shadow prices on linear constraints, by named block) k4 J8 M L/ }9 o, b9 ~
% .l lower bounds
0 Q- x2 s6 m: W) ]# K0 p3 ~9 N% ]4 P) |% .Pmis real power mistmatch equations (DC only)
5 P% A, ?2 A& ~5 q, S/ d% .Pf flow limits at "from" end of branches (DC only)+ @- Q( `) d4 |3 {; G6 i
% .Pt flow limits at "to" end of branches (DC only)6 \7 I+ M" J0 Q9 G; {8 }" R6 U0 j/ h
% .PQh upper portion of gen PQ-capability curve (AC only)4 L% ]* ]; `* y" _3 j4 d
% .PQl lower portion of gen PQ-capability curve (AC only)1 r1 l4 j. j: o* `
% .vl constant power factor constraint for loads (AC only)$ o* `2 N* k$ u0 F# a& B* U! W
% .ycon basin constraints for CCV for pwl costs
9 J) U" p1 A: O% (other) any user defined constraint blocks! H! S4 j* m8 V# m# e) `2 I4 U* c
% .u upper bounds6 y, V X t1 J0 ?7 V/ o& u* b4 e
% .Pmis, Pf, Pf, PQh, PQl, vl, ycon, (other)- e' U6 r) ?+ R7 D. H; P9 F' l
% .cost user defined cost values, by named block
/ o9 p- u- a1 {& S, n8 @- S%1 ~# |3 \. ?$ O7 L9 Y3 i
% See also RUNOPF, DCOPF, UOPF, CASEFORMAT.
: T# {2 w2 z1 _% U E' `( O# |- O1 w5 P: D+ Q+ q
% MATPOWER. f0 A1 S, b( M( P3 s% l" a& k
% $Id: opf.m,v 1.73 2010/06/09 14:56:58 ray Exp $1 D" P4 b% S2 [6 I$ Y9 V# r& l
% by Ray Zimmerman, PSERC Cornell Z4 X5 Y# E# Y) j( s7 w8 e
% and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales
. f8 D. F5 H/ F% k* z! ]7 Q2 t% Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)8 e$ t: r% h# a0 b4 h/ ?% y
%
/ k* J1 m8 Z# x; F) x% This file is part of MATPOWER.
% Y y4 q2 [7 }. Q. {+ k9 U+ ^% See http://www.pserc.cornell.edu/matpower/ for more info.
; U/ E3 h/ r9 V @5 z9 A0 X; U%
9 Y3 [6 n( i4 b. `% MATPOWER is free software: you can redistribute it and/or modify* |1 G3 p2 }% ]# {
% it under the terms of the GNU General Public License as published
$ U8 v% k3 T% U* O ?3 o# ?1 W0 ~% by the Free Software Foundation, either version 3 of the License,6 p9 N# F6 X! z2 S9 K T! I: {
% or (at your option) any later version." T+ [8 s; b4 n
%
9 F( U3 f/ L% U7 E( O3 H- g2 [+ K% MATPOWER is distributed in the hope that it will be useful,# t' c z' r2 [' b# W; ^3 g
% but WITHOUT ANY WARRANTY; without even the implied warranty of$ \4 n, y& e) X2 w7 P6 r" g* d e
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the3 @# Z- i' f2 g; Z1 F( Z0 C( ~
% GNU General Public License for more details." ~1 O+ c( q- n- k; O
%8 @2 S- o1 X7 J* p
% You should have received a copy of the GNU General Public License; {! X u S, [3 e- x
% along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.5 Z2 Q5 S7 n( }$ q/ R! P0 e
%& s! H# h# w( q1 V1 ^' C+ u# C
% Additional permission under GNU GPL version 3 section 7
: M( @9 O& L% G; Z) a& e# D% q%
7 V9 i( n8 m: u" Q% If you modify MATPOWER, or any covered work, to interface with3 a% w: a( T3 @& }- j
% other modules (such as MATLAB code and MEX-files) available in a+ _: a8 L. x. m3 i; G( f0 v9 I
% MATLAB(R) or comparable environment containing parts covered
& X, O2 v/ D0 y% under other licensing terms, the licensors of MATPOWER grant5 Q# ]- T" W7 {3 [% g" t( r( A) n
% you additional permission to convey the resulting work.
: l. @! |( L* D" }3 ~
: D- E% x* h0 M3 Q8 A%%----- initialization -----6 W G. u/ [, E/ r' {
t0 = clock; %% start timer# O1 m7 n5 J; f! w7 l* H
) R+ X$ b* N+ N
%% define named indices into data matrices
b/ w% |" F; Y+ z[PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
. T9 Y) y# e u. _5 W# s VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
# g ^* t( f( X0 Q h% Y1 n9 F[GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...: l6 l5 x8 K' i* Q, O
MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...% s `4 S/ y& M" A" Z
QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
- z, Y# b! n" _$ k[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...; l8 W! W) K+ _4 s" X
TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...; z0 R% @5 H" q2 u( V' v& _
ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;- i' G& {2 Z2 x: G4 b# G+ s
[PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;" w. c1 ? V E0 E1 V$ c
1 R `4 t4 W& Z; h5 X%% process input arguments
* ~% @ e% i8 Z1 v. v[mpc, mpopt] = opf_args(varargin{:}); L0 a( r% L6 T- o0 }7 ^
& a* {6 A' g' U) N%% add zero columns to bus, gen, branch for multipliers, etc if needed
' l- n$ j4 G3 e, ~1 W* |; v, b5 f' znb = size(mpc.bus, 1); %% number of buses
/ C7 K' K1 w1 V4 y9 [nl = size(mpc.branch, 1); %% number of branches
% f0 ^0 D* j5 B- b4 ~ng = size(mpc.gen, 1); %% number of dispatchable injections
* ~& d- [6 p1 |0 l; I9 xif size(mpc.bus,2) < MU_VMIN Z8 V8 j! h3 I0 @& B5 n- o5 M' g
mpc.bus = [mpc.bus zeros(nb, MU_VMIN-size(mpc.bus,2)) ];- d1 p3 J1 f E
end- i+ s( s' c! s ~
if size(mpc.gen,2) < MU_QMIN9 d' l) i( Q9 n4 P
mpc.gen = [ mpc.gen zeros(ng, MU_QMIN-size(mpc.gen,2)) ];6 M- G I6 O) V& o7 i" q$ Z6 F( }5 x
end w1 x$ L0 W/ Z" ?
if size(mpc.branch,2) < MU_ANGMAX8 |" @* p, F/ Q- Q5 q, ?- [3 ^
mpc.branch = [ mpc.branch zeros(nl, MU_ANGMAX-size(mpc.branch,2)) ];; y* }! W. T$ ]9 X6 R# S% p% B
end
+ V7 W( I3 @2 a& c* ~$ I5 s: y# i; ^" p$ ]
%%----- convert to internal numbering, remove out-of-service stuff -----! r3 w8 \( |! N7 Y5 ?
mpc = ext2int(mpc);
+ d; ]/ R! X% n$ f, F: z# A5 L( T% k; u" \+ X6 s9 H# s, o2 A' u( W
%%----- construct OPF model object -----/ S$ x2 q( B; V! n
om = opf_setup(mpc, mpopt);% v2 h; C; A, z6 z2 ^
/ [$ s7 B* a5 {: G; Q. K2 M5 m0 d
%%----- execute the OPF -----
- J0 x! r- } E, V1 @) q( zif nargout > 7: l4 x* E+ C7 K1 P! N: y
mpopt(52) = 1; %% RETURN_RAW_DER1 r1 P( t# J' p; ~ z. w
end* R6 K. Q3 V/ z1 A1 c5 ~: i
[results, success, raw] = opf_execute(om, mpopt);
) ~3 g/ R, y3 H9 L" H+ u5 n6 ?
/ H) V( j( Z) Y) w! |- x%%----- revert to original ordering, including out-of-service stuff -----5 ^ N. E8 L* U1 J
results = int2ext(results);" K8 m9 I- u5 T( G' X% Z
" @. v5 w: z4 B0 ]# _%% zero out result fields of out-of-service gens & branches
5 W5 S8 Y7 y& y4 g+ O3 ^ ` Iif ~isempty(results.order.gen.status.off)4 P T/ A+ h* k' I* y; h
results.gen(results.order.gen.status.off, [PG QG MU_PMAX MU_PMIN]) = 0;* ^: M8 K# }" e0 h. _2 i
end( a/ u) t( {* l, N$ ~2 V# x
if ~isempty(results.order.branch.status.off)4 [5 P9 Q( ^! \1 s3 z: d
results.branch(results.order.branch.status.off, [PF QF PT QT MU_SF MU_ST MU_ANGMIN MU_ANGMAX]) = 0;( S$ ~7 s! u3 m2 Z7 N( }* c) [
end$ e" v$ o' V( }4 ^
" s# p Y9 j8 g1 b% M
%%----- finish preparing output -----
& i* C, d! @9 ?3 h& X# met = etime(clock, t0); %% compute elapsed time6 u7 n* h/ k! n6 ]+ Y
if nargout > 0
" U8 \% A# Q! L) w6 n if nargout <= 2
' a6 C! p I8 D- O5 ~% b results.et = et;) V$ Z- g0 o" C$ s) a9 r. J& d
results.success = success;
; e* k% F# w7 C( }' G' z results.raw = raw;/ K1 e4 C$ ~9 C& h9 Z
busout = results;9 P. C. y: R) ^
genout = success;' y L1 b4 g$ ?& F0 m I
else& q$ W9 n1 q6 B8 E
[busout, genout, branchout, f, info, xr, pimul] = deal(results.bus, ...& i+ r2 o* @6 d. T
results.gen, results.branch, results.f, raw.info, raw.xr, raw.pimul);
; e; ]$ \! O A$ Z if isfield(results, 'g')
3 b" x+ [: M' c! n, Q g = results.g;& \. i! A7 W+ H& w, Y6 ^ x
end. [& H' Q' e, k8 X
if isfield(results, 'dg')
7 Z. e5 S8 @( m e, `3 G& y9 `0 p jac = results.dg;
: m2 W( N I5 ?+ h' c end
6 o/ E+ @6 F" K4 u3 M; A end2 i* s$ W; `+ H2 N9 n; ^# c
elseif success
/ r% O4 s8 P# f. a4 k7 ]8 F results.et = et;7 Z5 M( i- L/ Z% R! D- S
results.success = success;; j: |2 B) H5 v# e
printpf(results, 1, mpopt);2 F% \; {; |/ K$ }8 c$ z; Q! ]
end |
|