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 m9 n* ]+ _. o& i3 a/ S& b
opf(varargin)% @0 _2 q" }! ]0 V
%OPF Solves an optimal power flow.
6 X4 N8 l+ m' F; t/ p4 s' S9 X% [RESULTS, SUCCESS] = OPF(MPC, MPOPT)8 p# F$ _6 x# p: w; B7 P$ `
%
% W3 F2 Y& j7 t/ D8 ` C9 r% Returns either a RESULTS struct and an optional SUCCESS flag, or individual
$ Q4 G. Z( x$ j% data matrices, the objective function value and a SUCCESS flag. In the
8 d6 @1 }, f) B# ]4 i! f. y% latter case, there are additional optional return values. See Examples2 b% x& T% H, a7 Z
% below for the possible calling syntax options.1 w" s! J" C9 z& |5 S/ Z
%
( }3 {" F* I3 R+ Z/ \' F3 U( o, _% Examples:
( L! T" d* k; N7 ^5 _# c* s% Output argument options:' c" g4 o S" U0 @, y% x* G& |# L
%' k' E8 D! z$ @4 V- A2 {2 e# d+ w
% results = opf(...)' \( d+ K2 ~/ H
% [results, success] = opf(...)9 a0 H. M+ _! s# J' S
% [bus, gen, branch, f, success] = opf(...)! t7 v. K% h5 H# A
% [bus, gen, branch, f, success, info, et, g, jac, xr, pimul] = opf(...)
) e2 q* j1 g% F/ O; D9 r%
3 W% p7 _& J, Y; {. R% z% Input arguments options:+ ^+ b$ @1 \! |3 o8 X% l$ ^( x
%
. f9 @% u; g! K$ r% opf(mpc)9 g5 V; a1 T6 L( h3 e
% opf(mpc, mpopt)
: ?. ?4 O9 P& K7 p% opf(mpc, userfcn, mpopt)6 w- L G3 S Q, t! i
% opf(mpc, A, l, u)5 X2 U1 B( l9 p6 |' O5 J
% opf(mpc, A, l, u, mpopt)
, @( J% ~* F8 l+ j* Q6 u% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw)
( Y; W* D& \8 }- |/ T% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw, z0, zl, zu)
3 X) i2 c; U" l* p( f/ W%
0 ^3 ^: b* n/ ^; h4 [! U0 W% opf(baseMVA, bus, gen, branch, areas, gencost)! p0 l: _4 S- _$ ~
% opf(baseMVA, bus, gen, branch, areas, gencost, mpopt)$ [6 l" j; H- R( Z+ }5 b5 ^& N
% opf(baseMVA, bus, gen, branch, areas, gencost, userfcn, mpopt)+ Z" B6 |) ?. X$ B1 T/ [
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u)- ? M9 ]9 Y" c% A
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, mpopt)3 d$ ?3 G; c) i5 P5 d" ^
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...7 P' y# J$ ~. P: i
% mpopt, N, fparm, H, Cw)
! Q$ n' u) m6 I% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ... l/ |: i5 c! b! T6 B2 P
% mpopt, N, fparm, H, Cw, z0, zl, zu)7 q. ^* w$ P- [. O( a, ^
%. Q" b& g) {0 E: y6 \5 o* i! b# V
% The data for the problem can be specified in one of three ways:
! e+ k3 J* I* x% (1) a string (mpc) containing the file name of a MATPOWER case
$ r$ u% ^* U. l8 w V! y4 i; T) R% which defines the data matrices baseMVA, bus, gen, branch, and
, c; N, g( Z; Y( ?% gencost (areas is not used at all, it is only included for& V3 T* {0 K8 U8 L% m
% backward compatibility of the API).* l# A' _6 o6 T6 }5 @
% (2) a struct (mpc) containing the data matrices as fields.6 T( F) |) t9 X# M4 w. }7 [
% (3) the individual data matrices themselves.
9 E# p! G2 P$ E% ^- d% / M, O1 N5 Z7 w" x
% The optional user parameters for user constraints (A, l, u), user costs
0 ^& m# A( i" k8 c$ p% (N, fparm, H, Cw), user variable initializer (z0), and user variable
D3 `5 [4 A9 f* }) l* t7 }% limits (zl, zu) can also be specified as fields in a case struct,
N; X+ m3 \6 w2 k! Z% either passed in directly or defined in a case file referenced by name.
' {+ k# [5 O1 `8 n% 5 H8 |8 P' y5 g) }7 L
% When specified, A, l, u represent additional linear constraints on the6 x5 F. b& K+ i' Y
% optimization variables, l <= A*[x; z] <= u. If the user specifies an A6 l( E2 D' z; t# ]
% matrix that has more columns than the number of "x" (OPF) variables,
7 p2 M* }- B9 C. a% then there are extra linearly constrained "z" variables. For an& d/ R2 }- w! P/ D
% explanation of the formulation used and instructions for forming the
9 q- J# I i; k+ k3 X6 @% A matrix, see the manual.; G3 X* ?; g* J* a
%3 O9 T& l( k0 D5 S
% A generalized cost on all variables can be applied if input arguments$ u3 x% H; Z" l2 {
% N, fparm, H and Cw are specified. First, a linear transformation
7 B; f( N5 x3 ~& G. @% of the optimization variables is defined by means of r = N * [x; z].
- X5 n$ r% M" x% Then, to each element of r a function is applied as encoded in the5 G. z' H( S1 x( ?! [) K9 _
% fparm matrix (see manual). If the resulting vector is named w,/ \& M( r) Y0 l V9 r6 S
% then H and Cw define a quadratic cost on w: (1/2)*w'*H*w + Cw * w .% t/ Q- j: s0 j, \
% H and N should be sparse matrices and H should also be symmetric.
. @+ {4 J* o9 K! h4 b/ [+ {' x%5 C( T @5 \6 }) _& Z6 l8 D4 I
% The optional mpopt vector specifies MATPOWER options. If the OPF
- O3 {1 ~2 ?1 P" N* N4 [) Q, `: K% algorithm is not explicitly set in the options MATPOWER will use% Q8 ^+ ^# j# l5 i3 u
% the default solver, based on a primal-dual interior point method.
' [" X5 ?% Q3 h& u/ L% For the AC OPF this is OPF_ALG = 560, unless the TSPOPF optional' p# | m I" h n* q: @
% package is installed, in which case the default is 540. For the0 |- T: U. R8 I" k; R
% DC OPF, the default is OPF_ALG_DC = 200. See MPOPTION for! Y$ r5 \& a# o( C
% more details on the available OPF solvers and other OPF options9 H, s, t6 }1 g& @& f1 i) s% ^" G
% and their default values.8 B7 U. E7 K$ X- z6 S: r
%# K# D [, i! z4 u
% The solved case is returned either in a single results struct (described
0 N3 _ T D' V0 h* z1 J( J" i% below) or in the individual data matrices, bus, gen and branch. Also0 T0 D/ v* t) }3 u: j& ^
% returned are the final objective function value (f) and a flag which is
0 p& x1 E/ u: M" W) t% true if the algorithm was successful in finding a solution (success).
. F) a* d" n! R0 ]- S% Additional optional return values are an algorithm specific return status) \$ U1 c4 n0 N+ Z0 A2 u8 ~! v% T0 a
% (info), elapsed time in seconds (et), the constraint vector (g), the
! V3 Y7 ]5 ?# q/ w" T2 U# _% s O, ]- Y% Jacobian matrix (jac), and the vector of variables (xr) as well 7 ^1 J( U' R& q& a
% as the constraint multipliers (pimul).3 m, Q( h5 s5 V
%( s! g2 C/ ^: f: o8 a2 F
% The single results struct is a MATPOWER case struct (mpc) with the
& X' T5 G# Y4 ~4 f# t% usual baseMVA, bus, branch, gen, gencost fields, along with the
6 V. F- R6 F) K9 Q% following additional fields:5 h9 {5 H% {, v) |$ ^+ }7 \" J0 c! s
%/ c2 y Q& U1 R
% .order see 'help ext2int' for details of this field. O6 Z& q5 N5 E7 \: K) `) [+ q% t
% .et elapsed time in seconds for solving OPF) d8 X) B2 p6 S
% .success 1 if solver converged successfully, 0 otherwise, N$ k, F# u3 k! N4 v6 p' U
% .om OPF model object, see 'help opf_model'
7 P7 }4 V2 L: }1 v& a% ?% .x final value of optimization variables (internal order), n" t1 A/ I: ?" g3 X
% .f final objective function value! l: l; T/ [# U% g& G
% .mu shadow prices on ...7 v' Z; s/ D1 H8 A$ a/ {3 ]: M
% .var- b4 G, c* @. w; b) m& l( u
% .l lower bounds on variables
; @% ]$ S3 B8 Y% N5 w; t* `% .u upper bounds on variables* Q) a: ^/ ^$ K2 \. p4 ?
% .nln6 k- `3 W( b) }' S/ r
% .l lower bounds on nonlinear constraints! s# q+ W' O" S8 {4 w D( O9 L
% .u upper bounds on nonlinear constraints
6 F/ a% `* P; A. y% .lin$ d3 I+ F/ ~4 y* v8 D
% .l lower bounds on linear constraints
$ h6 R+ @3 V5 C. C% .u upper bounds on linear constraints: l0 Q+ K, u# D! p# x
% .raw raw solver output in form returned by MINOS, and more
. u+ e# _. Q! }8 L3 l/ ^% .xr final value of optimization variables! x% f! w1 A# `+ N0 Y3 K1 [
% .pimul constraint multipliers
. i" H% U! e- N& }7 V% k. C% .info solver specific termination code/ O: I+ v, D9 I; v8 w) [- A: V2 R% t
% .output solver specific output information
0 _1 o% W9 a- m6 Z. Y1 q% .alg algorithm code of solver used' ]0 `, t" d) [* F
% .g (optional) constraint values/ \. \: x, ^- P8 e# b) b3 D
% .dg (optional) constraint 1st derivatives1 r5 j* F; M" ?) u2 V4 }& z3 O5 p/ {# |
% .df (optional) obj fun 1st derivatives (not yet implemented)( u9 }# Z) F& [8 }
% .d2f (optional) obj fun 2nd derivatives (not yet implemented)
: H6 e2 I7 V% p9 j* ?0 B% .var
& j D' P* Q i% j% .val optimization variable values, by named block; x, `! i! @) C; W q/ Z O/ w
% .Va voltage angles( Q6 C1 j9 e \$ ?/ `
% .Vm voltage magnitudes (AC only)
, _8 Z3 R7 `! q; N) U1 z% .Pg real power injections
' Q# \/ n) ~! _1 G; x+ h7 n- I% .Qg reactive power injections (AC only)) D# q3 Y b; d2 l
% .y constrained cost variable (only if have pwl costs)
' t5 h1 e I, m: x$ N) I3 `/ n% (other) any user defined variable blocks& H+ T. h- `; a: q q$ ]: w p
% .mu variable bound shadow prices, by named block
' {$ p4 _* W: I+ E9 o% .l lower bound shadow prices
! h3 k6 g! G; {# \% .Va, Vm, Pg, Qg, y, (other)8 J9 a# D$ w3 x; i6 O- N
% .u upper bound shadow prices; t) j' d! _" Z! O6 \
% .Va, Vm, Pg, Qg, y, (other)
8 \% |9 _* Y( n2 T8 I! z& ]% .nln (AC only)& u$ X& K) j7 ~4 j) z6 N* u
% .mu shadow prices on nonlinear constraints, by named block
* I6 w" s4 ]2 ?1 n% .l lower bounds8 s1 X- w3 C0 K# R, P
% .Pmis real power mismatch equations
3 A! D% C' E; w1 u% .Qmis reactive power mismatch equations) ]0 C! y, {. v1 R( x& J o
% .Sf flow limits at "from" end of branches
) ^; s% \# S/ N; a4 B% .St flow limits at "to" end of branches+ F; C; p5 p8 N1 @! P
% .u upper bounds/ E8 a% g1 Q- }8 f% f( ^
% .Pmis, Qmis, Sf, St
9 q7 N9 U i+ }7 }, f% .lin
: I0 g3 h; W& l6 p' z) }+ D) ~% _# L% W% .mu shadow prices on linear constraints, by named block0 ]3 s' h7 s0 j
% .l lower bounds
0 ?$ y' x& i" Q% .Pmis real power mistmatch equations (DC only)
' f" l* T' O5 R: f- |% .Pf flow limits at "from" end of branches (DC only)
( s# j) l& Q @4 b- M" t* X' F- G9 n% .Pt flow limits at "to" end of branches (DC only)7 N! E* z" W+ U) B( }
% .PQh upper portion of gen PQ-capability curve (AC only)
3 J0 e- P* ?6 w/ ~% .PQl lower portion of gen PQ-capability curve (AC only)5 j2 v/ s' U' r5 v6 D' w) g, i
% .vl constant power factor constraint for loads (AC only)
* Y0 E% w9 v' ~9 A3 K5 j" ?% .ycon basin constraints for CCV for pwl costs; N4 y, t+ p2 ?+ P# Z5 \! n0 l
% (other) any user defined constraint blocks" F8 ]; w) |+ {1 |2 w, P; Y
% .u upper bounds: B7 o C5 u$ W& ?
% .Pmis, Pf, Pf, PQh, PQl, vl, ycon, (other)
+ |' Y/ X$ r6 w: X% .cost user defined cost values, by named block$ G1 M7 E. x, y. a0 c
%
w2 Q0 Z( t) ? l. W% See also RUNOPF, DCOPF, UOPF, CASEFORMAT." A' Z2 b' R1 ]( Z
- e9 ]. V9 D% C% MATPOWER5 L P; z, E% O# Y
% $Id: opf.m,v 1.73 2010/06/09 14:56:58 ray Exp $
) P: a: N& J* J# ` w; ?6 s% by Ray Zimmerman, PSERC Cornell3 Q7 H& O% y" B$ i
% and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales
9 C) [& D! C% N* c( D% Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
) m2 N* ~0 z3 p E$ G/ [%& @" B( |$ Y5 j+ I
% This file is part of MATPOWER.
" h6 Y; t7 P- y1 Z4 `9 H% See http://www.pserc.cornell.edu/matpower/ for more info.6 c }* Z, C/ n" H1 h
%
. {, k+ t* e% m5 L% MATPOWER is free software: you can redistribute it and/or modify
1 }; c9 y1 V/ X6 H! A8 ^% g. q3 v% it under the terms of the GNU General Public License as published$ v- \8 S; H# s
% by the Free Software Foundation, either version 3 of the License,5 o; T6 k6 Z: n' B; a8 w
% or (at your option) any later version.; \: p1 I9 ^6 D1 j( x0 C+ @
%. M6 e7 K7 E5 Z, d6 i$ c
% MATPOWER is distributed in the hope that it will be useful,8 E! W4 h( x& V: \ N) l( @' G! u
% but WITHOUT ANY WARRANTY; without even the implied warranty of4 r, ] e2 s: V+ Z1 t
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the& `) b7 `$ ^3 }* x0 t& p8 y1 k" _
% GNU General Public License for more details.& b! k+ `6 k4 g" `8 z
%; ?# d0 b' s% c' J: @! P) A
% You should have received a copy of the GNU General Public License" ^0 Q9 t8 S+ Q/ s1 `
% along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.' k; P$ |+ e* T$ X/ f2 _& l
%
9 F' X, A ]. F8 R% Additional permission under GNU GPL version 3 section 7
d6 A# ]$ w2 _4 g%% Z) F3 \* w+ C
% If you modify MATPOWER, or any covered work, to interface with
( t# m/ M# ]( `- E, ^- }, t% other modules (such as MATLAB code and MEX-files) available in a7 Z! R& m/ J/ a$ t6 `$ Z
% MATLAB(R) or comparable environment containing parts covered
$ @! S) t1 |, e2 u% s# D+ y% under other licensing terms, the licensors of MATPOWER grant
8 T1 ?; q* _8 P8 N8 i% you additional permission to convey the resulting work.
' i% N' R; G+ i
% ?% _% k( F; Z% i0 C% e$ g9 B%%----- initialization -----
. J( H% r; R' O0 K0 O% Yt0 = clock; %% start timer
- h! B+ C Y. I/ L% i4 d
1 W1 P: d* X/ ]%% define named indices into data matrices
+ L0 e+ k- v& `/ R" }2 T9 [7 N% N# g[PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0 e! m5 u) a& g- n7 u n VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
z4 X8 N) x; m. x! P[GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
! {( d a/ ]) U MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
7 m) P/ ~- ~ w, n QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;6 U3 ~1 ?0 x* Z4 U, c1 o* L
[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...* B0 ]' D+ |4 p9 v
TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...' j; D# R0 m9 f
ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;& a$ {6 N( M5 }2 x9 r. l X5 v
[PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;# @3 t" J$ C8 a; u! ]
- b0 Y# x- |; l9 w6 ]3 ^
%% process input arguments$ C% |1 {" ?0 E k( K, d# U
[mpc, mpopt] = opf_args(varargin{:});$ }8 e2 i0 p# i1 U
' x1 l& Y% c! p: T; E%% add zero columns to bus, gen, branch for multipliers, etc if needed
5 ]9 W3 p) \6 N' Pnb = size(mpc.bus, 1); %% number of buses5 d: s+ G2 @: g1 V& M% n* s: ^3 ?4 p# K
nl = size(mpc.branch, 1); %% number of branches
8 g2 H A- Z* ^. r ?ng = size(mpc.gen, 1); %% number of dispatchable injections
& k5 t$ T# _. s* E# `if size(mpc.bus,2) < MU_VMIN
& {: s, d9 Y* `' i mpc.bus = [mpc.bus zeros(nb, MU_VMIN-size(mpc.bus,2)) ];
& q2 n6 s( f8 ?! s. l4 b. xend* o; Z7 p9 B6 w6 d4 l
if size(mpc.gen,2) < MU_QMIN
# @$ X* s7 O3 {+ Q1 J+ ^, t mpc.gen = [ mpc.gen zeros(ng, MU_QMIN-size(mpc.gen,2)) ];' v* o* l/ F* L* E" f
end
" Z* `/ c1 B2 S" A$ Z2 R: Sif size(mpc.branch,2) < MU_ANGMAX8 d# M$ B1 W5 d8 }" E; y8 a
mpc.branch = [ mpc.branch zeros(nl, MU_ANGMAX-size(mpc.branch,2)) ];
: }0 w4 `+ O# E# _end. s6 P& G' b, f
+ D d5 h3 j! x' w
%%----- convert to internal numbering, remove out-of-service stuff -----
8 x6 x1 B+ [% a. b5 Tmpc = ext2int(mpc);
0 }: m+ }5 s- z0 y/ i0 g" t8 S# e- r- i
%%----- construct OPF model object -----
6 ?5 E; d" h/ o1 P l3 G+ vom = opf_setup(mpc, mpopt);) R- u* B$ @9 D% Q) h# s+ k& \
# G& W0 I0 \, S5 T; L8 Q3 r
%%----- execute the OPF -----
+ F2 }0 d7 r: E8 Q7 H6 Wif nargout > 7
z" o- r1 I g% d! x3 z. [ mpopt(52) = 1; %% RETURN_RAW_DER% k& [2 C7 r% K+ u3 i# d5 c ?) k* j
end
% [& K X' j) @* @% D0 }[results, success, raw] = opf_execute(om, mpopt);% Y. x7 o* f+ `. c$ W& _ c0 _/ V" W
+ E/ r+ f. x3 @2 x6 U%%----- revert to original ordering, including out-of-service stuff -----" b. X1 D5 y. K$ @8 P
results = int2ext(results);
! [+ a/ E' @6 V+ a! X7 l" x9 A! G1 V- F7 v% f' u
%% zero out result fields of out-of-service gens & branches
; t) E; T7 F; P( N8 N" F* F3 wif ~isempty(results.order.gen.status.off), V- C4 {6 E- U+ w W0 q
results.gen(results.order.gen.status.off, [PG QG MU_PMAX MU_PMIN]) = 0;
# v/ j. m/ y8 d; j/ H Gend
8 \% Z' Y7 o x7 x! ^. z. z+ z' fif ~isempty(results.order.branch.status.off)
6 _6 L! [: @3 U& I5 D$ e results.branch(results.order.branch.status.off, [PF QF PT QT MU_SF MU_ST MU_ANGMIN MU_ANGMAX]) = 0;7 c/ K( i9 B$ j' n% j* W
end
* o/ I9 Q8 A' Z; n' t+ W5 ^2 Q* ]- O/ R* [- J P" ?
%%----- finish preparing output -----8 y; d( a# x3 u t! s
et = etime(clock, t0); %% compute elapsed time
; a6 g V' I: e9 _if nargout > 0
, Q, |' f% T% a5 h( L: Y. o if nargout <= 2
9 @/ r) O8 K- P: V2 P: j results.et = et;
) D3 W* I {/ w9 {" y3 ] J results.success = success;7 H* R5 u2 n7 c3 l
results.raw = raw;; V7 s; Q$ L! w; {$ L0 N+ I) e$ B
busout = results;
7 e m- l6 {2 @, |/ M genout = success;5 p2 Z7 x4 J' W' D$ R6 j9 @: Z3 m
else
* f0 k/ ^: g% X* G& q7 N [busout, genout, branchout, f, info, xr, pimul] = deal(results.bus, ..., x3 j8 D7 W5 Y. n
results.gen, results.branch, results.f, raw.info, raw.xr, raw.pimul);
6 U5 T5 _5 ?9 G4 G, Y: l$ H$ h if isfield(results, 'g')8 w* H( I V% {. e
g = results.g;
, z. x2 a( [: g; `) P. j end
' |- Q; y, }+ |0 J n6 ` if isfield(results, 'dg'): y" w. C: J7 ^1 ]( ~8 c% d$ f
jac = results.dg;8 A% m2 X/ d/ ]1 I
end2 j/ Y6 q$ f. r, l: [# }' P. u9 v+ g# Q
end# H2 ?9 s' j$ j% n5 F" G
elseif success) \4 _& B z2 F4 ~
results.et = et;
1 _! m# ?; N5 K results.success = success;
4 ? X/ G4 P" F6 b7 c6 I printpf(results, 1, mpopt); L8 T7 H. z- O$ D/ ?
end |
|