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] = ...% `) d+ ]% B5 R
opf(varargin)
5 l4 L0 ?& Z. W& ^: \6 X/ n%OPF Solves an optimal power flow.3 x# q+ z. r& z: f& K
% [RESULTS, SUCCESS] = OPF(MPC, MPOPT)" {8 a1 P W% Q/ ^* Q' {
%
! O/ M1 P9 r- y% Returns either a RESULTS struct and an optional SUCCESS flag, or individual( M" ~7 O% P6 d
% data matrices, the objective function value and a SUCCESS flag. In the
$ z- [, B+ y0 c) ^; m7 t% latter case, there are additional optional return values. See Examples
$ x8 D8 Q* d0 {' N& y4 M% below for the possible calling syntax options." i- c' `& q$ y1 f! \
%3 {% U) G. _, P5 B9 k$ t
% Examples:$ A* x% `" t# D0 |6 E) c
% Output argument options:7 a8 |: U0 q3 v
%) }" D* {' X% G T, z
% results = opf(...)
2 o2 ]( ]9 | X% [results, success] = opf(...)
- H; p ^4 I- g" v2 D% [bus, gen, branch, f, success] = opf(...)
9 B/ B+ b a$ k/ K& |/ ~; ~; U% [bus, gen, branch, f, success, info, et, g, jac, xr, pimul] = opf(...)3 X9 V+ r$ G- D5 ]) w% p
%
" u% [6 J. i% w/ e% Input arguments options:
9 m, z' o% H v1 ^" K5 K%
$ v) X" l, X0 w; ~, t/ \# L* V% opf(mpc)! Y: q& x1 o6 v5 V8 p5 H& r* c
% opf(mpc, mpopt)1 o) ^4 C2 S" `3 U3 f( {+ ~: ]. z5 i
% opf(mpc, userfcn, mpopt)$ j/ h9 P, D8 [) y' {
% opf(mpc, A, l, u)! h; U1 U& Q; L9 q0 G5 }8 G
% opf(mpc, A, l, u, mpopt)1 @6 f' h2 Y& ~- e. f
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw)2 e* p: l8 X0 {' [5 `9 K+ u
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw, z0, zl, zu). K( M; y' V9 ^; b
%
" m- A$ Q6 V& _$ R! `% opf(baseMVA, bus, gen, branch, areas, gencost)+ d/ k( t- u1 s' ?
% opf(baseMVA, bus, gen, branch, areas, gencost, mpopt)
; V% ~3 t5 K/ ]9 o( p1 D# ?% opf(baseMVA, bus, gen, branch, areas, gencost, userfcn, mpopt)1 M( s/ f3 y5 E- [, C- v
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u)' L8 F# E3 u( L6 p j" G
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, mpopt)
% F$ Z, ~/ c2 l+ w- k: T; W% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, .... |+ Y, J& x/ g9 L _+ @
% mpopt, N, fparm, H, Cw)
5 |. B z# k. M: O' c, h a: G- X% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...
/ d1 d& c* f. }3 d+ u4 [( [8 g# [% mpopt, N, fparm, H, Cw, z0, zl, zu)
9 R* Z+ L) g' m5 Y' M%" S* u) h) T2 g; V* c* I
% The data for the problem can be specified in one of three ways:2 E2 p" u4 M1 P. e) J8 @2 ^6 U% O( I
% (1) a string (mpc) containing the file name of a MATPOWER case% g1 T; h7 \% z
% which defines the data matrices baseMVA, bus, gen, branch, and
, m9 z$ c# s. h4 ]3 g0 }% gencost (areas is not used at all, it is only included for6 K4 _' V2 N7 u( t5 F# f. k8 K' F
% backward compatibility of the API).2 ]5 c+ X8 S1 b) l
% (2) a struct (mpc) containing the data matrices as fields.+ c1 {; J) M( J# q: j; T s! p
% (3) the individual data matrices themselves.
& U, a5 }1 P' `' T: Z7 q% - v7 Q! C* ^9 ?) s0 O! [
% The optional user parameters for user constraints (A, l, u), user costs
/ |: A# a7 T; V- p8 V4 [% (N, fparm, H, Cw), user variable initializer (z0), and user variable/ C& F$ ~' C6 b9 }' r; l
% limits (zl, zu) can also be specified as fields in a case struct,
/ l' i& x2 s" x) E7 Z: j8 E" {% either passed in directly or defined in a case file referenced by name.
+ G$ x8 |& b( e%
2 R/ Q! C: B' v* z, \% When specified, A, l, u represent additional linear constraints on the
( P& d( F8 E& c) c2 n# \4 v% optimization variables, l <= A*[x; z] <= u. If the user specifies an A
6 E. x, y, N+ _- D; O% matrix that has more columns than the number of "x" (OPF) variables,
+ l- p- u6 J J. C( b% B% then there are extra linearly constrained "z" variables. For an' P9 o8 e. Y5 o$ t" S
% explanation of the formulation used and instructions for forming the
6 B! a \1 o* S$ t/ b! m% A matrix, see the manual.1 a i; m" C9 z$ L! D) Y
%
7 Z, G E' Q1 j8 Q2 q: }% A generalized cost on all variables can be applied if input arguments3 t9 I6 b. {* h& R4 q1 {0 ~
% N, fparm, H and Cw are specified. First, a linear transformation6 l4 [6 T! A5 `5 T$ F; ~
% of the optimization variables is defined by means of r = N * [x; z].
) y7 i! ~ F l/ L% Then, to each element of r a function is applied as encoded in the( L- B# j0 J$ x
% fparm matrix (see manual). If the resulting vector is named w,9 ?4 V& l; |8 I" M) x$ [& M- e* m
% then H and Cw define a quadratic cost on w: (1/2)*w'*H*w + Cw * w ." B# {9 h2 z2 V. h6 `
% H and N should be sparse matrices and H should also be symmetric.: x6 Q M; e% F, B+ O( \. K
%
- ^" t0 b0 w* W2 c3 V% The optional mpopt vector specifies MATPOWER options. If the OPF/ W9 n; M! S/ W
% algorithm is not explicitly set in the options MATPOWER will use$ W0 |9 T/ }! R
% the default solver, based on a primal-dual interior point method.
8 ~, r) M/ `: \4 L, ?6 b% For the AC OPF this is OPF_ALG = 560, unless the TSPOPF optional; K* m9 K; V. t5 P! q! [
% package is installed, in which case the default is 540. For the
: j! s% b" V2 P; V+ R* U- A: A% DC OPF, the default is OPF_ALG_DC = 200. See MPOPTION for
0 Q% S, T( q! A L: m b% more details on the available OPF solvers and other OPF options( m3 q: u# i i( F2 H' `, k
% and their default values.: w G% N' D! W. T) q
%2 v: T$ z N9 ~) p& u- T- O
% The solved case is returned either in a single results struct (described3 f( `7 y3 Z2 |
% below) or in the individual data matrices, bus, gen and branch. Also
" r: J( q( f) \. x2 u! S( s% returned are the final objective function value (f) and a flag which is
" A. T1 V* n) _1 M% true if the algorithm was successful in finding a solution (success).
, E! f$ r. p3 A. t- ]% Additional optional return values are an algorithm specific return status
+ V# K! F( T# M6 l: p/ M% (info), elapsed time in seconds (et), the constraint vector (g), the3 S& F, ^- n- C# H; F# S
% Jacobian matrix (jac), and the vector of variables (xr) as well 9 t. L+ @' q# f2 G
% as the constraint multipliers (pimul).8 g5 q+ E, Q$ u9 F9 w: x
%6 Z0 L$ A# `9 T1 z+ A* I, B
% The single results struct is a MATPOWER case struct (mpc) with the2 m" x9 n$ a& p! J9 U: E
% usual baseMVA, bus, branch, gen, gencost fields, along with the
: t; F1 _: P5 t% following additional fields:, l* e: G% m0 X" g
%
5 q$ E+ s3 ^! e% .order see 'help ext2int' for details of this field
% ` U \: `5 b% .et elapsed time in seconds for solving OPF6 r4 v# h, `7 a/ s. p% s9 P
% .success 1 if solver converged successfully, 0 otherwise
9 f/ D2 u4 }2 X, Q% .om OPF model object, see 'help opf_model'# E. w) t) x; ~8 @2 M3 M+ l: T
% .x final value of optimization variables (internal order)
1 I0 t3 Y# M* _% f! q; H+ L% .f final objective function value0 p$ r. ~8 i8 x
% .mu shadow prices on ...0 R6 I& N# i0 f" b _! T2 \/ l/ a
% .var
2 U' r- L- L6 K; g: i% .l lower bounds on variables+ w8 Q k# N9 s7 x2 }
% .u upper bounds on variables
1 ]$ ^ F% r( X% m+ s- e$ v7 [% .nln8 {/ N; _8 v3 C" k0 \4 o( v; f
% .l lower bounds on nonlinear constraints: ?) V, L: _' X3 S& g# \ _2 R. g
% .u upper bounds on nonlinear constraints M _' R/ o; a* W
% .lin2 @: p7 u7 f( P% J
% .l lower bounds on linear constraints8 P. C1 w4 ~; k
% .u upper bounds on linear constraints5 H- G1 `& b- @* Y9 @$ j8 i" }& m
% .raw raw solver output in form returned by MINOS, and more
- s: ?+ R/ P5 o! J# d. u% .xr final value of optimization variables
! g$ O" n& w# _4 ]. Y% .pimul constraint multipliers
; K/ w O+ `2 o2 y( _% .info solver specific termination code- B8 I* ~# K/ I- l) |" E
% .output solver specific output information5 W3 j' k- e4 ^5 N" J7 d; _
% .alg algorithm code of solver used1 I. r# T: l/ O" k! j
% .g (optional) constraint values3 Q" l: d. A5 `& G" n, ^# E
% .dg (optional) constraint 1st derivatives; a* Q! J* |1 t7 i2 \! f0 i
% .df (optional) obj fun 1st derivatives (not yet implemented)+ r& J8 B4 h' m' w0 g
% .d2f (optional) obj fun 2nd derivatives (not yet implemented)$ o* g; c& D! I4 L' s
% .var
0 m7 M+ k/ Z5 j% .val optimization variable values, by named block* U) n% s) F" ?4 P& p
% .Va voltage angles' M. H2 n0 V0 ~: G* c$ }
% .Vm voltage magnitudes (AC only)* D4 x9 I, q% T5 H( v
% .Pg real power injections) \* t" \; |+ Z- Z g; \3 K; z
% .Qg reactive power injections (AC only)& L8 i* ]: q; T2 D
% .y constrained cost variable (only if have pwl costs)
6 g$ W3 n4 l$ i! x, r* z0 H; t% (other) any user defined variable blocks6 n9 @9 i2 @* K* W! V+ }" Q! y
% .mu variable bound shadow prices, by named block$ O3 ]2 n8 ` E" Z2 R! u
% .l lower bound shadow prices; M/ ], y( e8 L8 a
% .Va, Vm, Pg, Qg, y, (other); a- w- N1 L7 `4 n) u3 |
% .u upper bound shadow prices& R0 N5 u$ {7 a; P( ^
% .Va, Vm, Pg, Qg, y, (other)- f: V7 r* i9 J8 x# X2 Y/ R" T
% .nln (AC only)
9 b6 o, J* C s% .mu shadow prices on nonlinear constraints, by named block3 ?6 d9 @& G- U
% .l lower bounds d* K% H, E/ ^+ p1 O
% .Pmis real power mismatch equations
1 `( Q* R; X1 j( ~% .Qmis reactive power mismatch equations. Z+ S: R. v" }* Y! t$ Y8 ?0 ~8 {
% .Sf flow limits at "from" end of branches$ T U0 z' @3 F" K$ y
% .St flow limits at "to" end of branches
- W6 f. D5 ?0 R& ]. y# G) E% .u upper bounds
) S+ a4 O, N# y( Z) [8 F% .Pmis, Qmis, Sf, St+ l3 l( E6 G5 D. p) |& e
% .lin
6 W9 ~7 T! x2 J% H' U9 K) \% .mu shadow prices on linear constraints, by named block
8 u+ `% G) v& z3 @; r# h, x% .l lower bounds# o W9 i# {% O# {* F/ F" o/ n
% .Pmis real power mistmatch equations (DC only)
% |6 f6 X6 i! X% .Pf flow limits at "from" end of branches (DC only) y1 x/ q5 m, R( ]7 X
% .Pt flow limits at "to" end of branches (DC only)7 y3 n+ O4 {2 K8 t# C
% .PQh upper portion of gen PQ-capability curve (AC only)3 W& u; p( H" K
% .PQl lower portion of gen PQ-capability curve (AC only)- o9 s E. t8 `" T, a1 O& V* Z
% .vl constant power factor constraint for loads (AC only); l7 p! ^- X1 M0 V, l
% .ycon basin constraints for CCV for pwl costs' @3 L/ J. Y9 C$ S8 D! x7 I
% (other) any user defined constraint blocks2 H( G* G1 N* E( E% Y- w/ `! t: o& H4 ?. `
% .u upper bounds
; W+ A" U: I V: q: @% .Pmis, Pf, Pf, PQh, PQl, vl, ycon, (other)
6 U; f. l/ }6 i/ X# i% .cost user defined cost values, by named block
1 Q ?( _5 J8 T" p) H; i" \%
5 O0 |! w: t6 u7 P" u% See also RUNOPF, DCOPF, UOPF, CASEFORMAT.4 B' z# E ~0 m
6 \6 s, `( [ h5 E
% MATPOWER0 c! q2 T' m3 w( k
% $Id: opf.m,v 1.73 2010/06/09 14:56:58 ray Exp $# F/ T5 Q& G/ i
% by Ray Zimmerman, PSERC Cornell4 s1 o; Z/ l( V9 C8 O( G
% and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales
0 c) P5 }2 N' [) l2 }5 J/ `" b+ |% Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
- `" m$ b, m d0 Q%4 L1 B6 h( n/ `4 D9 {% v
% This file is part of MATPOWER.5 L- h! U! Q2 f
% See http://www.pserc.cornell.edu/matpower/ for more info.- B! d3 J# E; S5 D
%
3 i( ~2 k4 k/ i' u; ~, p% MATPOWER is free software: you can redistribute it and/or modify
: @9 K( w; ~+ z' F9 R# @) u' r% it under the terms of the GNU General Public License as published
. K% V6 ]# ]9 w5 Z* N1 j& T% by the Free Software Foundation, either version 3 of the License,8 |) V! |( i$ Z1 B3 S# t
% or (at your option) any later version.; K. }& u2 o+ h: Y
%
& @! H9 [9 M# A: T$ O% MATPOWER is distributed in the hope that it will be useful,
8 A( L, c' s6 F% n8 X, W5 f% but WITHOUT ANY WARRANTY; without even the implied warranty of
9 V$ M! u [: j) S9 A+ d3 l% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
) G; |8 [( s$ L( q7 _% GNU General Public License for more details.) h2 s: m( Y8 y: O1 Q# _0 K3 D
%) \" R6 ^, q1 v5 F& k- [3 W- P
% You should have received a copy of the GNU General Public License
6 a8 z* B6 F& p2 c, d ^+ w- V( g% along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.& J* m. _% s. u0 U4 X0 }8 T
%& g; O' _' h( S& ? R0 Y- ?/ D
% Additional permission under GNU GPL version 3 section 7
2 P) H N" R0 o0 d5 H%2 ?. ^. u2 Z1 y; O
% If you modify MATPOWER, or any covered work, to interface with- W% i/ n- q/ `3 @2 A
% other modules (such as MATLAB code and MEX-files) available in a O5 s( T. U; Y6 {8 }! k1 A
% MATLAB(R) or comparable environment containing parts covered& d6 a" O4 r0 Z+ h
% under other licensing terms, the licensors of MATPOWER grant
5 z/ ]; _; n+ f% c/ Z4 E p% you additional permission to convey the resulting work.
9 q; {: M: t/ e& g3 P/ N& x; f6 p+ K: k$ D Y; g6 K
%%----- initialization -----4 Y' ~ h1 o( j; Z% O9 H8 E' E
t0 = clock; %% start timer C6 `8 p" J. O7 X8 b
! A6 U: P/ r* ~%% define named indices into data matrices" M0 t8 @( h! |) \4 @( h
[PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
5 i4 }& W2 q- q, g; C VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;" ]( U& ~, T3 G- C
[GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...* S% J. q v m, L+ ?4 N% c& f
MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
; z( O( ~4 e) x+ T& }6 u1 ^/ ~ QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;/ _/ e* b. [& ^6 b1 ~0 ` J
[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...8 e, X; a; n! z5 O4 K! U
TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
5 K" c4 ]% @: t0 c, t' `% ` ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;, P5 V/ a s' A2 Z q! v. g
[PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
2 ~* H! X' I0 |, R8 x( `% Z7 |1 Z. r1 ^+ A
%% process input arguments+ Z% i1 B& W6 b' X7 f2 N
[mpc, mpopt] = opf_args(varargin{:});
/ `% X4 z; Q0 s% Y& B+ N: k. F/ A5 q. m: S% m* g: T# Z. p
%% add zero columns to bus, gen, branch for multipliers, etc if needed
5 y4 g- E8 }3 f( H7 J' onb = size(mpc.bus, 1); %% number of buses3 C% T6 M9 F& l/ w$ [) U* Z# v# B
nl = size(mpc.branch, 1); %% number of branches% Q$ j$ D; J1 C( R
ng = size(mpc.gen, 1); %% number of dispatchable injections& e$ U2 G1 s6 N* ?/ r7 s- `6 }/ R
if size(mpc.bus,2) < MU_VMIN& c9 i3 k) I7 i1 |9 v" g) m$ n" C
mpc.bus = [mpc.bus zeros(nb, MU_VMIN-size(mpc.bus,2)) ];* T, T$ k) m; v1 M- c+ t
end
w0 I3 Z; C6 T- u; |. Zif size(mpc.gen,2) < MU_QMIN
6 k! t: s9 I5 X mpc.gen = [ mpc.gen zeros(ng, MU_QMIN-size(mpc.gen,2)) ];3 l2 G+ N9 I9 H1 A& u7 ?/ Y
end
; {+ z5 D/ m4 Z$ lif size(mpc.branch,2) < MU_ANGMAX7 J1 z7 N8 l4 r: ]! P
mpc.branch = [ mpc.branch zeros(nl, MU_ANGMAX-size(mpc.branch,2)) ];
4 K& }: n# j7 a6 f& Fend
7 s/ L% @& t0 l/ ?- _0 b
# \2 r# Y8 b) L1 B: X- a0 O%%----- convert to internal numbering, remove out-of-service stuff -----
' B; l% X' E8 P% m8 k7 x( W& Nmpc = ext2int(mpc);
$ T1 i* W& ?* x7 R Z3 m1 E) w
8 f. r @; S. i3 P. |%%----- construct OPF model object -----
4 M/ c) E1 Z2 ~) g3 {4 w/ i$ W5 m' Som = opf_setup(mpc, mpopt);
! ?, x, T/ h& V9 O' D3 J8 Y; V. \4 M
%%----- execute the OPF -----
0 K8 h; F$ D L( F6 m/ M0 ~, |if nargout > 7) \ O3 Q# ?+ ]! `; _) q
mpopt(52) = 1; %% RETURN_RAW_DER/ y! n# O3 _% w/ u. y% @
end; v5 _4 Q! S8 `3 I
[results, success, raw] = opf_execute(om, mpopt);
( z' |' H1 a0 |6 i( c# S- `& E, X% w7 d" K, `
%%----- revert to original ordering, including out-of-service stuff -----
) N6 J1 B6 Y7 Y! R) lresults = int2ext(results);5 }/ v0 z' ~4 r2 ]: {4 _0 D
/ C9 p% L0 u% M6 N% X/ o" [1 W%% zero out result fields of out-of-service gens & branches
" V, d0 `% m0 p' a1 V( n' D# j8 I0 Hif ~isempty(results.order.gen.status.off)8 R( K9 j2 d' F
results.gen(results.order.gen.status.off, [PG QG MU_PMAX MU_PMIN]) = 0;
7 K. }! g* {& E2 vend4 Y/ o1 T1 u: R; }9 f# c; Q
if ~isempty(results.order.branch.status.off)6 a \/ O$ E+ f
results.branch(results.order.branch.status.off, [PF QF PT QT MU_SF MU_ST MU_ANGMIN MU_ANGMAX]) = 0;9 M3 n: H) i( K' q* t, D! A! F3 ?
end9 @3 M) z) e- d+ C: o
$ Y$ i# X& B# _) D" E6 H* t%%----- finish preparing output -----) U; J# |' }% ]6 t2 \- x
et = etime(clock, t0); %% compute elapsed time% n% S' J& z! N6 e6 e Y* l" ^. Q
if nargout > 0( O8 @" N) J) v1 ^* O2 x* t0 d
if nargout <= 2" |* Z5 K/ [9 U# x) W, m+ E
results.et = et;
5 Y0 @5 I, Y9 c# T# x7 E3 G results.success = success;& z# K! e8 u8 z0 `; _: Q0 q: x3 @) o
results.raw = raw;
0 O: {; q# G& t3 n busout = results;
8 E( j, L% \- ?7 R- l genout = success;! X: ^5 g7 {9 q1 z; k" J
else
2 [ l( @: i% X [busout, genout, branchout, f, info, xr, pimul] = deal(results.bus, ...# E1 X2 L" [7 n3 Q. O7 R3 g
results.gen, results.branch, results.f, raw.info, raw.xr, raw.pimul);" H% \" V# L6 }2 a; i6 O' l+ H+ u
if isfield(results, 'g'): R3 v4 a9 r" Y8 F7 J3 V: R
g = results.g;
, B) i9 h0 D' y0 }0 T2 l/ W5 ` end" b7 Q) k* H# j. N
if isfield(results, 'dg')! L2 t' M7 d1 B5 y3 K" T
jac = results.dg;2 t B) u& A+ x- j4 ?: g
end
, W: v+ w2 ~( g2 ] end# K) v- P, Y: {6 a$ j0 H
elseif success2 k: Q0 G5 I- I" K4 [% ]
results.et = et; o' f( [" L! c" A( ] C# ]
results.success = success;
# }: H) F; x8 E- b, S( Q printpf(results, 1, mpopt);$ L; S; @. ~9 x+ u/ x3 ]
end |
|