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] = ...7 L0 B5 P- P9 G3 b& B. G+ ^
opf(varargin)- G; ~ d/ d% }3 Q
%OPF Solves an optimal power flow.% F* _0 Q5 l, Y; V6 z/ s* o
% [RESULTS, SUCCESS] = OPF(MPC, MPOPT)
' E0 S% a# L; X% f* e%
2 |+ O7 J$ q2 Q$ h/ p% Returns either a RESULTS struct and an optional SUCCESS flag, or individual
7 H ` \3 n9 y9 C9 R( \% data matrices, the objective function value and a SUCCESS flag. In the
+ C& M0 f0 S5 ^$ m% latter case, there are additional optional return values. See Examples" r+ L0 A4 n/ ?
% below for the possible calling syntax options.
; A# C: N* c# C0 e$ V* d: y%8 G4 N2 S* d8 I) b R/ K8 e% k6 E6 @
% Examples:
& t' P: l) \2 q0 l% Output argument options:2 ^& C( x; L2 j* @' O7 L
%
6 f9 N, Y: V9 O0 Z% results = opf(...) W0 o0 U. y" o1 j2 @5 `3 E% B9 Q
% [results, success] = opf(...)
+ `# F0 o% \+ ?/ ^2 u% [bus, gen, branch, f, success] = opf(...)+ }! h. s- g- e( o( f
% [bus, gen, branch, f, success, info, et, g, jac, xr, pimul] = opf(...)
g0 }8 D1 ]3 z+ H$ g2 z% a; X) k%2 d. U" Q- h( i: O
% Input arguments options:9 b6 r* m0 B+ Q1 D. o1 c! ^
%
1 S5 p7 z; Q( D6 q: E# ?% opf(mpc)
* K6 i# p0 E! n3 L2 o: y% opf(mpc, mpopt)( ]: ]9 b" H6 x! F
% opf(mpc, userfcn, mpopt)/ h$ K, `$ p, G& J" V
% opf(mpc, A, l, u)
* v5 T, ?7 j! ]8 j+ u4 g% opf(mpc, A, l, u, mpopt)
0 G. c% b, m' Q% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw)
9 D% U: E& W# o* g# b3 e) N- p% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw, z0, zl, zu)5 V# ?( N" S8 K2 W S
%$ I$ `% I" L/ ]0 E9 f8 Z8 T
% opf(baseMVA, bus, gen, branch, areas, gencost)
0 e: S! ^: Z' g% G% opf(baseMVA, bus, gen, branch, areas, gencost, mpopt)
5 j4 }8 P! n9 e% opf(baseMVA, bus, gen, branch, areas, gencost, userfcn, mpopt)
7 W! M6 ]- j; Z- I/ h8 ]* K% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u)
4 o; s$ N8 F& b& J% v' y- O% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, mpopt)
# e+ {$ E) u8 q9 l( v1 M* w% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...& s) j z& p, H
% mpopt, N, fparm, H, Cw)
) e& t) ?& N! g% B% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...! k' K" F" d7 ~
% mpopt, N, fparm, H, Cw, z0, zl, zu)
! A6 L# u; L4 o* v3 Y# r%
7 i7 ^9 Z- v8 Z) `$ G8 ] P+ u, y% The data for the problem can be specified in one of three ways:
$ U0 H( n! t4 D( _% (1) a string (mpc) containing the file name of a MATPOWER case, ^% A5 O U/ ? [( O* I
% which defines the data matrices baseMVA, bus, gen, branch, and
7 A8 n( l! j6 R2 B4 ] K; ^% gencost (areas is not used at all, it is only included for
& `# e) I1 c: e( k! M( h; }% backward compatibility of the API).( w7 H6 ^7 ?9 w- k, I
% (2) a struct (mpc) containing the data matrices as fields.- y* @& e5 B4 z0 t+ x# G; Y
% (3) the individual data matrices themselves.0 j& \! a8 f, C! |$ a
% $ ^8 b; h$ H, l0 R3 q4 e* N
% The optional user parameters for user constraints (A, l, u), user costs
& [& T) g3 n5 q& @% (N, fparm, H, Cw), user variable initializer (z0), and user variable
! `* C) P5 a; A; G5 [6 V! w7 y! T% limits (zl, zu) can also be specified as fields in a case struct,/ `( j$ c& w W( _/ H
% either passed in directly or defined in a case file referenced by name.6 I6 q4 z% j6 V" w4 c2 T
% " ]# u! } V0 D* ^" a
% When specified, A, l, u represent additional linear constraints on the
# X% x( H: _3 D% l5 d- L7 m% optimization variables, l <= A*[x; z] <= u. If the user specifies an A: s5 L! R, `0 Q" _
% matrix that has more columns than the number of "x" (OPF) variables,/ V& ?8 A3 E) Q& Z% X' e2 g
% then there are extra linearly constrained "z" variables. For an
# r( T' K2 N/ U4 j+ c% explanation of the formulation used and instructions for forming the3 F/ \* z `- i
% A matrix, see the manual.8 v; O0 Q8 p* u) F5 d! [
%' [' ~- H: g1 Z) T
% A generalized cost on all variables can be applied if input arguments: e5 v p$ @7 `1 y
% N, fparm, H and Cw are specified. First, a linear transformation4 f7 @* b/ y7 v0 P
% of the optimization variables is defined by means of r = N * [x; z].
6 d* k1 M7 u! r1 [ L% Then, to each element of r a function is applied as encoded in the
7 V7 \- S' l( B Y/ B" @3 p+ _4 S6 p% fparm matrix (see manual). If the resulting vector is named w,
5 v8 |6 @* a" I% then H and Cw define a quadratic cost on w: (1/2)*w'*H*w + Cw * w . w5 C0 g9 N$ Y7 M, R
% H and N should be sparse matrices and H should also be symmetric.' q8 C$ Y% B; q
%( y: y3 y# a, j6 x9 m7 r
% The optional mpopt vector specifies MATPOWER options. If the OPF2 R, {( ?- |, P$ d' V. @1 K
% algorithm is not explicitly set in the options MATPOWER will use
& g/ d) ~/ _3 ?0 P/ J% the default solver, based on a primal-dual interior point method.7 J: o% z2 F) N* O1 t
% For the AC OPF this is OPF_ALG = 560, unless the TSPOPF optional" E+ {6 x) B r- V
% package is installed, in which case the default is 540. For the
" O0 p# z9 r$ }4 Q0 ]% DC OPF, the default is OPF_ALG_DC = 200. See MPOPTION for" m9 H" z9 `# @% ?
% more details on the available OPF solvers and other OPF options
% V6 W9 ^( i3 w4 c# o6 g% and their default values.
8 R% C' B7 q! s%
- ~$ e9 e) {7 H% ?& j% The solved case is returned either in a single results struct (described7 F$ s& P$ [2 o+ Y/ V
% below) or in the individual data matrices, bus, gen and branch. Also8 ]6 }9 \/ r; }* x. C; C3 y% E
% returned are the final objective function value (f) and a flag which is% B4 S+ r$ H2 B H8 t1 |
% true if the algorithm was successful in finding a solution (success).
# B8 ^5 W! z X+ X$ T) [/ G% Additional optional return values are an algorithm specific return status2 O( Q0 C+ L0 k4 d. \
% (info), elapsed time in seconds (et), the constraint vector (g), the0 N2 i% x8 q8 W' {- ]! s; o
% Jacobian matrix (jac), and the vector of variables (xr) as well
' o6 X) e8 K/ r. Z% as the constraint multipliers (pimul).
# Y9 ^8 q6 b! Z%
( U4 k# s- C) A% The single results struct is a MATPOWER case struct (mpc) with the) w% a! d! q: K3 G' u/ r: T
% usual baseMVA, bus, branch, gen, gencost fields, along with the7 D& _! Z9 w' @9 V& n* C
% following additional fields:9 T, I1 T$ U- ]
%
! G$ `! V( [4 [( C6 G6 A! M- M7 F' R% .order see 'help ext2int' for details of this field9 [8 K/ G% m0 Q3 j- q4 s( }* {1 y: a
% .et elapsed time in seconds for solving OPF
4 \5 M9 _- f* g% .success 1 if solver converged successfully, 0 otherwise
0 A+ X' F% w( C! q6 ^( j& @% .om OPF model object, see 'help opf_model', D1 t' x3 l# r& b- w$ r
% .x final value of optimization variables (internal order): O: S% t$ Z6 z2 Q
% .f final objective function value
( N" g; A, j7 e/ t1 k; i: w$ `% .mu shadow prices on ...% Q% @5 b6 X: P7 O
% .var
4 r) j& j5 p" c8 N' Z% .l lower bounds on variables
, z, a+ y8 r8 E7 U" | z. Z$ i% .u upper bounds on variables( @& \" g: A" d/ o, i% v
% .nln
' W9 z$ l9 R1 L+ p6 A8 E7 a% .l lower bounds on nonlinear constraints( y% @' a8 R7 d( z( g
% .u upper bounds on nonlinear constraints \ S3 h* F5 b- m% V
% .lin- F8 [" R9 H6 V- i. _
% .l lower bounds on linear constraints, H4 a3 L, N# y, M
% .u upper bounds on linear constraints2 J8 F5 N. d. d# ^ S
% .raw raw solver output in form returned by MINOS, and more
: h* n* l3 E* h% R% .xr final value of optimization variables
# K! K: B" c* ` h/ H% l% .pimul constraint multipliers0 n1 Y; [; Y7 C" l
% .info solver specific termination code7 S+ R4 e% L8 s0 X+ Z) S
% .output solver specific output information
, G( O3 O" o3 @, v* x; d8 a% .alg algorithm code of solver used
0 r$ a* \; J1 g* h% .g (optional) constraint values
2 e2 r. u" y, I. Z) S! R3 v% .dg (optional) constraint 1st derivatives
; g5 U. U1 e$ e% L, x4 D: N; @& ~7 y" b% .df (optional) obj fun 1st derivatives (not yet implemented)
x2 s" |" G" ]/ v( a% .d2f (optional) obj fun 2nd derivatives (not yet implemented)
" N9 U* X0 j/ i# r% .var
; I7 ?, X q1 c) E' K( V% .val optimization variable values, by named block. U, R- j5 W, L0 p# \/ j4 D
% .Va voltage angles9 K/ P4 n: n, E& w; d
% .Vm voltage magnitudes (AC only)7 D1 ` Q- p J' ~
% .Pg real power injections
, W" f1 a, I8 ?3 h% .Qg reactive power injections (AC only)
7 w3 P3 } b0 }) C! a* d# r% .y constrained cost variable (only if have pwl costs)0 U7 _- x; H% Q7 f& e
% (other) any user defined variable blocks
v& u3 E9 a2 b% .mu variable bound shadow prices, by named block
7 G# d* ]2 z3 @# Q+ Q% .l lower bound shadow prices! E8 z- b6 S; z+ r& x" u2 `) Y# v% |
% .Va, Vm, Pg, Qg, y, (other)
: I# Y9 Z' }" g2 o4 c* W% .u upper bound shadow prices% R4 N, n0 g$ D5 \/ c9 Y$ n) A
% .Va, Vm, Pg, Qg, y, (other)
0 w# }4 r8 G5 i7 ]5 C% .nln (AC only)
) ?5 H2 ^; K+ Q& Y: t& {, Y4 \% .mu shadow prices on nonlinear constraints, by named block
! f" x: h- L1 E9 \5 [0 `# G% .l lower bounds/ D9 R6 Y7 W; w# b, j
% .Pmis real power mismatch equations
- e* R# z4 y( L% B8 V/ @% Z4 C% .Qmis reactive power mismatch equations& F( Y) m$ Y( |8 D. d4 G; S
% .Sf flow limits at "from" end of branches: S+ {! }' m' v( U1 l/ I
% .St flow limits at "to" end of branches
G& }4 [6 ^. l3 S0 Y, d* [% .u upper bounds
2 _! Z& L- _5 ^, z% .Pmis, Qmis, Sf, St" X& h. m- Y2 A; J+ y
% .lin% O7 q5 h' u% v: w# N) t7 j
% .mu shadow prices on linear constraints, by named block
2 o" P1 @: W6 x0 k: U% .l lower bounds& `4 A. e5 e) {5 u; p& y
% .Pmis real power mistmatch equations (DC only)
5 b' W7 I Q- E& d% .Pf flow limits at "from" end of branches (DC only)$ w% r) _; h% y) ^
% .Pt flow limits at "to" end of branches (DC only)
. X' Y7 s& Q% `, V5 R7 z% .PQh upper portion of gen PQ-capability curve (AC only)
+ ]5 u6 ?5 j3 D5 {% .PQl lower portion of gen PQ-capability curve (AC only)& x# G, d \. R! ~
% .vl constant power factor constraint for loads (AC only)
9 Y: p/ @ T3 B) [9 Z$ z: w( m- U7 r% .ycon basin constraints for CCV for pwl costs
4 b3 z, T r" y. c# n3 ~/ h% (other) any user defined constraint blocks2 x% \& b/ L! ~- F- R; X! J3 g
% .u upper bounds
, ]+ D, c+ H$ c6 s% .Pmis, Pf, Pf, PQh, PQl, vl, ycon, (other). C: z; ~( l' p# Z: d2 S
% .cost user defined cost values, by named block
1 g! m4 f& n- e! ?%9 T. K1 V( D2 U: Z @
% See also RUNOPF, DCOPF, UOPF, CASEFORMAT.
* N7 {/ g4 R2 s9 v3 K+ X: o' Y5 S! J
% MATPOWER( k) @( s; j1 G3 q$ _: O
% $Id: opf.m,v 1.73 2010/06/09 14:56:58 ray Exp $. m- t3 c/ Z1 v. J P4 k9 t
% by Ray Zimmerman, PSERC Cornell
0 Z. [% v2 |9 G8 J% and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales! {' Q8 q* N8 o) h# q1 S
% Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
+ f6 b! x- S7 L% n2 M%8 ]* z6 w2 E. R! A W
% This file is part of MATPOWER.; Q2 D2 }5 V! c2 \0 V
% See http://www.pserc.cornell.edu/matpower/ for more info.
- m& ] O: v" a5 p6 ]9 ~- c" ?%. v" S' ^+ ~+ d1 s
% MATPOWER is free software: you can redistribute it and/or modify, Q, d# i: b( B. P* A) W. {: Y
% it under the terms of the GNU General Public License as published
7 h4 {* i" h$ {: E% by the Free Software Foundation, either version 3 of the License,7 E i; y& C" G$ b3 T+ P& P
% or (at your option) any later version.& X7 V+ L/ n. ^9 a5 U5 w
%
& ^8 o# I7 v7 B% MATPOWER is distributed in the hope that it will be useful,# E( [! ]+ z5 ^5 H2 S
% but WITHOUT ANY WARRANTY; without even the implied warranty of: u9 Q: ?1 c g! F$ I* w4 h5 e8 b
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the6 U- S( H; r( Z% U3 z# e) X
% GNU General Public License for more details., m! W, w- |; ?
%
) n/ N) R+ ]- w$ z# h( G- Q% You should have received a copy of the GNU General Public License
0 ?) i2 c; }3 n1 r* @1 `/ e% along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.3 J& i, L5 z" p' l: [
%
+ y% T. I7 j( W8 D% Additional permission under GNU GPL version 3 section 7$ m; j" R- s. q6 m& z
%
0 S; v- \" u4 M$ R2 a% If you modify MATPOWER, or any covered work, to interface with7 y/ I& d+ Z% ?( e; E+ U+ c
% other modules (such as MATLAB code and MEX-files) available in a/ r; X) y. D" L% w" `$ W' b/ e
% MATLAB(R) or comparable environment containing parts covered
: `: W. p) i0 Z+ M8 a1 z% under other licensing terms, the licensors of MATPOWER grant
$ Z" y( s" l4 _8 I1 O1 n8 y% you additional permission to convey the resulting work.5 t( w6 s/ y% m$ W
* e' s! T* G+ o5 n* V2 ~6 d
%%----- initialization -----
- |- p) B u# W# K8 Ot0 = clock; %% start timer
: w, |; D) D7 `& c1 n
% b5 G1 U7 I9 ], p+ W9 Y%% define named indices into data matrices
& i6 }+ z" H9 Z: S) E[PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ..." b1 b' C, k! v
VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;/ ?1 W( V$ d+ J2 H4 ~: e
[GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
/ W3 @4 n! |! g3 w# @% d MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...4 U g3 a: s/ C/ @9 D
QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
: Z: z& r' B. R$ k- G[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...) O& s% W$ E9 y# A. u5 z
TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
* G3 @0 G6 N5 D. g ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;2 Z" e+ P7 D; o7 d/ C) z2 }
[PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
4 Y& }- ?$ s% e; J+ i& [- i, u! q- j
%% process input arguments9 T4 J- X7 L' P
[mpc, mpopt] = opf_args(varargin{:});8 P& x z2 @2 o, a4 N4 f" y
! R: R/ l3 z8 U# A/ `6 T0 a%% add zero columns to bus, gen, branch for multipliers, etc if needed& b- D( e0 h6 Z6 U7 a7 C" M9 J+ M& a
nb = size(mpc.bus, 1); %% number of buses
! Z/ s m7 \2 Y/ K3 t- Nnl = size(mpc.branch, 1); %% number of branches& G0 s% ~5 k/ D+ e7 E
ng = size(mpc.gen, 1); %% number of dispatchable injections' L; S. n; c7 f+ o4 n
if size(mpc.bus,2) < MU_VMIN ~1 o% d" f' v9 ~
mpc.bus = [mpc.bus zeros(nb, MU_VMIN-size(mpc.bus,2)) ];
1 r" l7 V- l# P0 ^end
. M/ J- D( e5 u* jif size(mpc.gen,2) < MU_QMIN7 q5 S5 u4 ]3 R; d2 P( m. t) t# [* m
mpc.gen = [ mpc.gen zeros(ng, MU_QMIN-size(mpc.gen,2)) ];
5 i) h, H/ c5 }; m' [end6 }# f; {: U8 g2 F# S& Z
if size(mpc.branch,2) < MU_ANGMAX
+ G4 C% Z: _ r$ F0 f mpc.branch = [ mpc.branch zeros(nl, MU_ANGMAX-size(mpc.branch,2)) ];
; L3 {0 L: A& W7 R4 R! f" {, Yend( L D& f9 m- k3 o2 l2 d
2 }; k% @% ]3 f3 y9 K) y2 r- p5 @
%%----- convert to internal numbering, remove out-of-service stuff -----' P7 w7 D4 Y6 t7 P# l4 a% \
mpc = ext2int(mpc);/ l+ T; O* F( ]8 p! f+ B8 y
$ d; A/ m+ q8 \, g# v$ S
%%----- construct OPF model object -----
7 A5 P4 x0 q! J6 Z# V! p* ^& g v1 @om = opf_setup(mpc, mpopt);
/ X! u$ w! c/ w; F7 R& r; E% @/ \$ M, L8 f
%%----- execute the OPF -----) u0 l6 L7 ^ g* Y$ @
if nargout > 7
: {" k" |0 q, D/ S" ~( L mpopt(52) = 1; %% RETURN_RAW_DER- O2 b Z0 L# h' |0 q
end
9 w6 B+ @; [- Q9 p3 q2 f[results, success, raw] = opf_execute(om, mpopt);* b4 L: Z. e( X, a K8 f
, ^% h) }" |% W4 }8 s+ [%%----- revert to original ordering, including out-of-service stuff -----
' U, i2 j& R1 s% uresults = int2ext(results);
; x: q9 k0 x$ H# [) e4 {5 b! s) t w A# D$ D/ C/ l
%% zero out result fields of out-of-service gens & branches
( g1 X% s. d( \4 v- n6 \if ~isempty(results.order.gen.status.off)
" e. x1 Z; {- Z) a results.gen(results.order.gen.status.off, [PG QG MU_PMAX MU_PMIN]) = 0;
0 u/ A& W# l5 b) e# m/ r1 Dend- ]# Z) `& Z& s) H9 i
if ~isempty(results.order.branch.status.off)
0 h- v6 s4 P( Q0 g1 U( w% W results.branch(results.order.branch.status.off, [PF QF PT QT MU_SF MU_ST MU_ANGMIN MU_ANGMAX]) = 0;, o1 o, h9 s4 l) P; U
end6 z0 j( T/ s5 y& ^& [* @
/ L6 I" W0 x7 O1 a* y, H' s3 @
%%----- finish preparing output -----
+ f2 l5 Y) Z# c' Z) b$ Ret = etime(clock, t0); %% compute elapsed time: Q9 b( p3 u1 d" S& C8 p+ {
if nargout > 0
" [! ]! a# A* V if nargout <= 20 V0 a8 k4 H5 T& c# O3 r
results.et = et;; f0 L9 J( v6 ?2 B4 y
results.success = success;: ?# W G. d4 N2 Y" r
results.raw = raw;% \+ X& @) O, F) |2 U
busout = results;
0 c* R4 k6 W5 T: m/ ~ genout = success;
/ P. p8 l5 {" o$ D else
- H& _0 R/ C( u. H [busout, genout, branchout, f, info, xr, pimul] = deal(results.bus, ...4 q% t1 q" m# N
results.gen, results.branch, results.f, raw.info, raw.xr, raw.pimul);
2 T5 {4 I) K& X; x if isfield(results, 'g')+ ^0 n0 g( N7 s' T X) ?
g = results.g;
3 V; z, T3 E- K end3 T/ L5 Y! O9 g) h5 Q( l
if isfield(results, 'dg')
O% a4 f8 u5 L. D9 F jac = results.dg;" I: ~* b3 G% b6 Z
end6 |. ^$ I( k4 j5 V
end* r2 D$ Y; q( |
elseif success8 V0 `: L- i7 w- g
results.et = et;
A% j$ A4 ^/ r/ D6 L$ N. ? results.success = success;$ `: @! ~; s* ], o3 U
printpf(results, 1, mpopt);
! @- b6 N2 G6 N( jend |
|