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] = ...
. m( E8 e& V+ l5 Q/ V! G" h opf(varargin)
/ z( u; b9 a v6 {4 y%OPF Solves an optimal power flow.
8 |: v. @4 O) {8 R& f4 o% [RESULTS, SUCCESS] = OPF(MPC, MPOPT), V7 S- w+ q& B+ X
%
; d4 W' J2 y# L4 X- `- m. B- l% Returns either a RESULTS struct and an optional SUCCESS flag, or individual
7 `5 y4 {! f' @2 E q+ h% data matrices, the objective function value and a SUCCESS flag. In the3 i9 H+ J* G \" ]; b* a
% latter case, there are additional optional return values. See Examples6 I# r, }% S E+ z! Z0 ?
% below for the possible calling syntax options.. e# r. N3 F) ?7 E
%
+ h6 ~0 {; J- t! s; a& o% Examples:
$ s8 F5 C2 Y$ E% z# V% Output argument options:
+ g; S" u* [1 o+ _! x%9 m3 b, [6 X9 H, S, d* f( q5 a
% results = opf(...)
9 t: N& j: p& Q+ v b% v& [! b% P: r% [results, success] = opf(...)
% Y" g+ _; X0 g% [bus, gen, branch, f, success] = opf(...)% O9 ^. `; D; d% B5 {1 B
% [bus, gen, branch, f, success, info, et, g, jac, xr, pimul] = opf(...)
% T. O. h+ d9 R$ O8 i% @%7 s% B6 }. s2 B: O
% Input arguments options:
5 z$ ~1 _0 N I5 y%4 e5 Y6 A) L7 k' N; D
% opf(mpc)
+ u, S1 i4 \2 D' e% opf(mpc, mpopt)
: d# ~4 z8 g4 u2 _ J% opf(mpc, userfcn, mpopt)3 R' l, }8 d" i. K1 C2 k3 C- P
% opf(mpc, A, l, u)- t% ]/ |( s+ N7 j% a- ^8 e/ \3 P( j
% opf(mpc, A, l, u, mpopt)+ P: I7 w$ Q, s3 r Y3 }; F( l y
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw): }, X3 t8 ^+ ]3 T7 C1 @% C& a
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw, z0, zl, zu)
; k: j5 D4 q( C%
, {2 `4 A/ N7 K6 @, b l/ J% opf(baseMVA, bus, gen, branch, areas, gencost)
+ U" B: O/ N$ L+ [. `% opf(baseMVA, bus, gen, branch, areas, gencost, mpopt)
% \2 M& b8 F/ I% m& W2 }% S* V8 E% opf(baseMVA, bus, gen, branch, areas, gencost, userfcn, mpopt)" z* H% K% d: X% j- j! k$ j- i' |$ n
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u)
4 e: k: G' o* D& j. a1 G) y% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, mpopt)7 f0 ?8 J) a. Q! h. ?4 p* I
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...
- r! d$ F: q' |* f1 g9 w9 N% mpopt, N, fparm, H, Cw)
( g$ v5 F& ?1 [: n, U1 Y7 Q9 D% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...9 M" V g, u+ W+ W7 y7 b
% mpopt, N, fparm, H, Cw, z0, zl, zu)
( d3 e1 ]; i" d8 A+ K* S; ]% A/ @3 F) O7 A* w" k8 k' W
% The data for the problem can be specified in one of three ways:& l$ H6 N X4 Z1 h& ^3 i' G
% (1) a string (mpc) containing the file name of a MATPOWER case
4 Y2 [; B# _/ T% P1 B Q1 D0 ]9 j5 j! n( `% which defines the data matrices baseMVA, bus, gen, branch, and0 [. {; r6 k0 Y" S
% gencost (areas is not used at all, it is only included for
5 E' S! v+ K k& K7 y! S& J% backward compatibility of the API).
o8 }9 o4 w# f+ i" R% Y; [2 U% (2) a struct (mpc) containing the data matrices as fields.
1 e( b7 Y6 L( E/ C1 b8 N! E' U% (3) the individual data matrices themselves.2 h* E3 }+ K4 f* \
% / x8 H/ k+ x0 k9 V# z
% The optional user parameters for user constraints (A, l, u), user costs x/ o& O2 U2 w6 {$ u
% (N, fparm, H, Cw), user variable initializer (z0), and user variable
4 K6 E, {, I4 B$ e% limits (zl, zu) can also be specified as fields in a case struct,
) C% @* C; H1 R2 u! ^% either passed in directly or defined in a case file referenced by name.
: T" p% W7 ~& i%
5 Y6 D3 l' f! m6 s# F; t% When specified, A, l, u represent additional linear constraints on the
# F2 {1 n! U5 m& D$ c% optimization variables, l <= A*[x; z] <= u. If the user specifies an A
4 l2 z1 i8 q( s" w% matrix that has more columns than the number of "x" (OPF) variables,
3 w: F- | W0 i% x% then there are extra linearly constrained "z" variables. For an2 H, p2 s, I& c/ P- y
% explanation of the formulation used and instructions for forming the
6 u; _. H8 {( j, {: S+ I% A matrix, see the manual.# _& [: | L' F& {/ B& z2 E- Z. `
%! n; U4 W/ Q$ z! |, W( {
% A generalized cost on all variables can be applied if input arguments5 j2 m% @, Y( L$ Q7 R% k" ^
% N, fparm, H and Cw are specified. First, a linear transformation1 B) z0 }( b: N$ y1 O
% of the optimization variables is defined by means of r = N * [x; z].
- }4 t/ T5 |9 V( `& }% Then, to each element of r a function is applied as encoded in the: \; R3 y) T+ k
% fparm matrix (see manual). If the resulting vector is named w,4 L4 Z& q/ W/ g
% then H and Cw define a quadratic cost on w: (1/2)*w'*H*w + Cw * w .
- a* f- o0 _0 Y% H and N should be sparse matrices and H should also be symmetric.
3 X1 p1 W! f: {) Q; k%
3 q E( R" \9 R* i% The optional mpopt vector specifies MATPOWER options. If the OPF
' x; S; M- k7 t0 z$ G% algorithm is not explicitly set in the options MATPOWER will use3 G0 `- L1 E& U) `% H* T8 q7 v
% the default solver, based on a primal-dual interior point method.
& g9 Y2 C) n! j3 M% For the AC OPF this is OPF_ALG = 560, unless the TSPOPF optional
$ h) l" a a: C" \! r5 C- ]4 N# N5 B% package is installed, in which case the default is 540. For the" U5 ?* q/ m) i6 f( i
% DC OPF, the default is OPF_ALG_DC = 200. See MPOPTION for
1 [! r2 L$ P% u T; O f% more details on the available OPF solvers and other OPF options' `( d& @0 g- U- \7 `; _
% and their default values.
3 {" ~3 K- x) f%6 Q% O( J' \) ~5 u0 Y
% The solved case is returned either in a single results struct (described7 d+ L" `: |/ s* y ]1 t
% below) or in the individual data matrices, bus, gen and branch. Also
+ \5 t; t) Z: n; w! A, G5 n3 W% returned are the final objective function value (f) and a flag which is/ |, ]% L( H- O2 M
% true if the algorithm was successful in finding a solution (success).- a3 a, e0 H$ V3 }
% Additional optional return values are an algorithm specific return status; |8 L5 V0 n* [7 o( d# O: e, @ F
% (info), elapsed time in seconds (et), the constraint vector (g), the* ]2 W3 z6 o, S4 g
% Jacobian matrix (jac), and the vector of variables (xr) as well & Z2 v* s3 c0 N# d( E0 [3 g
% as the constraint multipliers (pimul).- b2 K, n8 k% ]0 h' ^
%
" P, u- d& s% W" Q: s5 }% The single results struct is a MATPOWER case struct (mpc) with the
/ n( ^) n8 M# k8 [2 I+ L% usual baseMVA, bus, branch, gen, gencost fields, along with the; j; A: b" H3 F3 x: I/ k+ X! `
% following additional fields:
\( Y {1 Y/ ~$ E" I1 k( I%
, d4 R k4 I) ]% {' N' e: Q" \8 j7 R+ @% .order see 'help ext2int' for details of this field5 V, c( ~; K/ r. G7 ^8 y' `* E
% .et elapsed time in seconds for solving OPF3 p/ G8 {5 b* B6 B
% .success 1 if solver converged successfully, 0 otherwise
8 f% W/ ]$ Y9 h% r, b% .om OPF model object, see 'help opf_model'
" a9 Y; R( i+ h2 X" @$ _% .x final value of optimization variables (internal order)8 G* D: b7 k' F( D( s- |& Z- z/ I
% .f final objective function value: x8 @; m, _3 ~: I1 }$ t
% .mu shadow prices on ...
/ |) E9 e3 ]( d/ p% .var0 m5 A6 H* X! L( d& W+ j
% .l lower bounds on variables3 K& ^- |! j" { i8 d& L9 h8 Y& a2 q* _
% .u upper bounds on variables
8 C8 R, T) `0 @5 w# s5 I% .nln$ r T6 b; J) W8 R" t
% .l lower bounds on nonlinear constraints/ o- w& l+ L& n6 W& c5 c
% .u upper bounds on nonlinear constraints. b5 J# t' b g& M! `# t. {# n
% .lin+ B/ [: N+ z) i9 u5 j$ q& v
% .l lower bounds on linear constraints
0 \8 }5 O' G% m. `! [% .u upper bounds on linear constraints
# x4 b. W2 V( [( Z6 N- y5 o% .raw raw solver output in form returned by MINOS, and more
+ f' {2 E3 s1 w% .xr final value of optimization variables- d& [$ b8 L+ g$ G3 k
% .pimul constraint multipliers
# h* b. B) {. D" l# p3 S& g( _% .info solver specific termination code
- o. b1 {+ q- }3 @% .output solver specific output information
# f6 \1 L, J7 O- c- `: K! A$ U7 i% .alg algorithm code of solver used) J8 c( U) `$ `" W" V: j+ o' F, y/ c0 w
% .g (optional) constraint values
: a$ q6 m7 P3 S& \% .dg (optional) constraint 1st derivatives, ]$ V! p2 i# [' [- s
% .df (optional) obj fun 1st derivatives (not yet implemented), l8 a+ N: {: s$ ]4 B c. Z+ S
% .d2f (optional) obj fun 2nd derivatives (not yet implemented)
. {8 p5 l( J) n: i% .var
# ?1 u( K V4 B! L5 A4 f! m% .val optimization variable values, by named block
0 [+ J, `! a& o- w x7 @% .Va voltage angles, w6 V+ i3 Z! d) ]8 i
% .Vm voltage magnitudes (AC only)
/ r" K5 T! e+ y' {1 c a% h0 a% .Pg real power injections% s) |, o& t1 R1 A+ x
% .Qg reactive power injections (AC only); S5 B$ P2 L8 D. S8 E; a
% .y constrained cost variable (only if have pwl costs)) O5 s5 e- Y$ R$ ^' Y
% (other) any user defined variable blocks; g# J# |2 }2 {5 r' U; m; _! ?
% .mu variable bound shadow prices, by named block/ c8 Y6 O) L' ] |$ Z( N& V( i- i
% .l lower bound shadow prices9 g4 j. D& Z9 e/ W' Q/ [
% .Va, Vm, Pg, Qg, y, (other)8 |; r+ E9 \& p" r$ e" J" e3 _
% .u upper bound shadow prices4 X: ~7 z3 ]5 H$ g# v c6 ]
% .Va, Vm, Pg, Qg, y, (other); ?( E) D* a; G* O$ Y
% .nln (AC only), R; Z+ ]6 B/ v: \: @3 V
% .mu shadow prices on nonlinear constraints, by named block
* j& G7 K E% p2 e% .l lower bounds
4 y2 E2 Y) F* b8 @9 T' G5 o% .Pmis real power mismatch equations) }0 y/ ?- B: m4 H
% .Qmis reactive power mismatch equations
( P2 |: N$ C/ R( u2 p% V% .Sf flow limits at "from" end of branches' _/ y; _) I* r" y# P: v/ x; ~
% .St flow limits at "to" end of branches* G1 f0 b% u4 N# y. A @. _1 N
% .u upper bounds* |4 r* u& N2 ]; h6 T6 a8 J
% .Pmis, Qmis, Sf, St3 i2 T! M3 t) d# j
% .lin
. X# N1 z+ T+ z0 A @; G* N' e% .mu shadow prices on linear constraints, by named block
! Y+ Y( O; p2 [+ F1 u- u+ N% .l lower bounds) V% Z( e1 h+ V* j/ o
% .Pmis real power mistmatch equations (DC only)
0 u. w$ I0 L# z! P7 P3 Y: w% .Pf flow limits at "from" end of branches (DC only)& y: _5 N" w* U! r F
% .Pt flow limits at "to" end of branches (DC only)% i2 H; X# l0 a3 g+ J
% .PQh upper portion of gen PQ-capability curve (AC only)/ U" m( g+ b* w: o. I( P, t! _. h
% .PQl lower portion of gen PQ-capability curve (AC only)
: s( p2 R! n( [- `; E% .vl constant power factor constraint for loads (AC only)
) F: e3 P f+ G, T. @6 e% .ycon basin constraints for CCV for pwl costs6 |3 B& S' E; U; K0 B/ x' t" m
% (other) any user defined constraint blocks+ i1 S" w' @0 L% L8 @, r
% .u upper bounds) U" d/ I6 F) N* O. \
% .Pmis, Pf, Pf, PQh, PQl, vl, ycon, (other)6 @) z- O# O( C6 X* X0 Q
% .cost user defined cost values, by named block, `' O3 l0 N2 G# x v9 [. `5 ?
%
% w% j# K0 l, Z( `% See also RUNOPF, DCOPF, UOPF, CASEFORMAT.
8 j2 m% u! M A7 o& Z) n( D$ V# @- j+ I) G$ U
% MATPOWER
, L- ]: ~; c( P% a- n7 A/ X% $Id: opf.m,v 1.73 2010/06/09 14:56:58 ray Exp $; n4 ~3 `6 U E4 c2 E3 k3 K
% by Ray Zimmerman, PSERC Cornell
4 h: i% Y: [6 D4 X2 @. k- d. m2 @% and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales
) H0 m- r3 O% M- p% Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)" x$ u/ V" g5 } Q7 x
%
. H2 g9 e* `* i2 @! p% R# s% This file is part of MATPOWER.* T1 ~# x, N$ G( `$ z
% See http://www.pserc.cornell.edu/matpower/ for more info.& `9 ]( p1 h* b+ R+ Z* o
%3 d7 S! R$ f7 N3 j" ^0 ^
% MATPOWER is free software: you can redistribute it and/or modify e3 l! H4 _/ t. n) n
% it under the terms of the GNU General Public License as published! q" T" F% o& W% M* w4 ^
% by the Free Software Foundation, either version 3 of the License,
& @, L" x+ o, {* M; i( e; _/ n% or (at your option) any later version.8 y7 l7 L+ F% }) h, h
%- x2 c0 P0 N3 i; D9 B
% MATPOWER is distributed in the hope that it will be useful,
4 Q2 J4 N* O( x( Y: ]& e4 V1 Y% but WITHOUT ANY WARRANTY; without even the implied warranty of
" [* i; L# r# E/ N* e: T% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5 g6 _) k( x' B, R% GNU General Public License for more details.
n B# ^$ K, ^/ i2 M, R%
+ V8 ^& E' q4 z# j% v% You should have received a copy of the GNU General Public License
: @% i; i; Z8 Y( v5 w% along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
9 W9 S. @( `! i# C# ^%: K0 J% n$ O2 K2 r) L
% Additional permission under GNU GPL version 3 section 7' x; w, ?2 C( F- C& Z# u1 L! m$ A
%' N3 H% s; F F0 {
% If you modify MATPOWER, or any covered work, to interface with$ v1 i8 I$ }- L! ]" k3 |5 ^
% other modules (such as MATLAB code and MEX-files) available in a
/ l$ j6 x) F' e% MATLAB(R) or comparable environment containing parts covered& W/ N/ U) V6 l+ W" v9 ^ r
% under other licensing terms, the licensors of MATPOWER grant
; X* f4 i2 ]& g( A$ z& S% you additional permission to convey the resulting work.
" n$ s( i D: l9 T0 ^: J& g5 _2 }( T, t1 F0 A5 c
%%----- initialization -----
; K# G `0 t8 r' O! Ct0 = clock; %% start timer3 j% N4 Z; @' `6 V1 l+ R0 _% l
1 \& m& `, r, {$ z2 t. L%% define named indices into data matrices7 F* Z; A4 ?: n
[PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...+ M0 }$ C4 y, j4 l" t8 x& @" y2 t9 \
VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
2 Y: `% z5 ?: N: h# ?! G1 q[GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, .../ D& z: Y$ _) M3 h& ?# h E
MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
% h2 E: ^4 M7 f+ j% e QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;: a& R: m; W) Q% I+ v0 V1 g
[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
6 C$ g. P- |( L+ s* J TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...4 T1 Q% [* K `3 {% E% U
ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
. H4 n/ h) j; p$ G/ Q[PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
3 @2 W2 e, O" p# ~; w# g1 O" H+ Y* Z8 v9 g
%% process input arguments* F* U; d. ^. E" `
[mpc, mpopt] = opf_args(varargin{:});
3 ^, v8 u- O$ ?; H6 a7 K( p! W
; v9 Q+ c* n7 A* J/ L' v%% add zero columns to bus, gen, branch for multipliers, etc if needed
8 A0 a, z2 C- l, ?% Mnb = size(mpc.bus, 1); %% number of buses( o8 X% Z& \0 e4 m& j
nl = size(mpc.branch, 1); %% number of branches: ~6 V" O1 K* I% I, d
ng = size(mpc.gen, 1); %% number of dispatchable injections% K2 g6 p$ J7 F( l7 c
if size(mpc.bus,2) < MU_VMIN
) k7 B( [$ p' b" Z mpc.bus = [mpc.bus zeros(nb, MU_VMIN-size(mpc.bus,2)) ];
; d8 W" Y; J" U$ Fend# f9 p# ^5 o1 s6 a4 B, ^3 ~. h2 w
if size(mpc.gen,2) < MU_QMIN
" A# o2 g' E! a0 H/ @5 V. G& K mpc.gen = [ mpc.gen zeros(ng, MU_QMIN-size(mpc.gen,2)) ];
8 j1 ?0 c+ l1 q. f2 Y2 Gend
) s: j7 y0 W1 O! qif size(mpc.branch,2) < MU_ANGMAX
' [$ z/ {1 Y) d4 }1 g! o mpc.branch = [ mpc.branch zeros(nl, MU_ANGMAX-size(mpc.branch,2)) ];
! \5 T& g" v, E( \) A# uend) l, ~9 J9 c0 j/ [
0 l7 L ?; d/ X/ l8 [- l
%%----- convert to internal numbering, remove out-of-service stuff -----4 D m0 c' O$ r6 m6 Z) \" ?3 V
mpc = ext2int(mpc);
" n' l+ {( d, O; l
. P5 o0 H+ B6 U9 W%%----- construct OPF model object -----* }/ A ~4 K5 F
om = opf_setup(mpc, mpopt);' L3 J y) _& g2 n! S8 u) V% ]* e2 K
4 x$ t8 k0 s3 A$ y%%----- execute the OPF -----
5 N1 N9 F s1 c6 |0 j! Dif nargout > 70 V0 p4 Y) L8 [5 I* K
mpopt(52) = 1; %% RETURN_RAW_DER
+ W4 R7 {- y! W! y2 h# Gend
$ Y$ @% q" j9 J/ I |[results, success, raw] = opf_execute(om, mpopt);
6 D' h5 F; t: ^
% D$ W& G* c7 L9 T%%----- revert to original ordering, including out-of-service stuff -----
2 R, \1 P- c) c5 m& zresults = int2ext(results);* w7 f% Q7 v- j
' t* @/ |3 T0 Q' n4 H4 j3 n
%% zero out result fields of out-of-service gens & branches
3 I4 G4 R. x3 T+ X1 C' Vif ~isempty(results.order.gen.status.off)
9 y7 a/ D, W9 v/ }( K9 Q7 s results.gen(results.order.gen.status.off, [PG QG MU_PMAX MU_PMIN]) = 0;* Q! A- f% a# l. R6 n
end
$ L9 S( J1 {- S9 _if ~isempty(results.order.branch.status.off)6 m" D' `( P- h0 w6 b
results.branch(results.order.branch.status.off, [PF QF PT QT MU_SF MU_ST MU_ANGMIN MU_ANGMAX]) = 0;
$ P( [! s1 o- A$ G! ^; f$ |end
4 j; \2 @: ~/ [
$ F' g. ]. @4 @6 D%%----- finish preparing output -----
$ ~; t) a0 f8 Q2 w; U8 aet = etime(clock, t0); %% compute elapsed time
1 K! i8 a# N; P( rif nargout > 0% ~% v+ {5 ~7 s7 J
if nargout <= 2
2 b; v) p2 \' W" O, n4 W g H results.et = et;
3 E/ j3 p9 x$ B7 y( B& M" J results.success = success;
) z9 C9 ?6 \9 F0 J: P results.raw = raw;
`$ U- W1 @1 M/ b3 S' N, [ busout = results;
: ?8 @% ^. {! D1 ?# | genout = success;
9 F+ C" A& X% k4 J0 O$ ^ else
' C; R0 ?% I/ p& |& K& E1 P2 b* K [busout, genout, branchout, f, info, xr, pimul] = deal(results.bus, ...
+ `2 J: V2 b8 \8 ^ results.gen, results.branch, results.f, raw.info, raw.xr, raw.pimul);
- `1 }' H9 y1 h% K: a6 b if isfield(results, 'g'). R) ~+ r: S6 {; z5 y* _8 d' }& A
g = results.g;! {6 d( V7 W( L8 U$ b8 o
end
5 ^% S6 L. ^9 n) x3 f, {; M if isfield(results, 'dg')! R6 G, Z8 [2 N
jac = results.dg;
+ {1 M' [3 l& i( {% ~6 v! e end
. |. v0 Z( ~; L q U3 A' N end; ] k% g( F6 Z
elseif success& a4 X9 {! x( r; U' f
results.et = et;; R5 q. N4 Q, x. x) m& k
results.success = success;
, D- d+ \9 n7 C: @7 P4 X printpf(results, 1, mpopt);: y3 y$ f8 G1 K( s, g- a9 I% Q
end |
|