最优潮流
刚刚上研一,想写最优潮流,有sb有最优潮流的matlab程序吗?谢谢哦~ 你可以看看matpower。基于matlab的潮流计算。里面有OPF。希望能帮到你 Matpower 回复 2# helton8221大哥,是可以在matpower里面直接看到最优潮流的matlab程序吗? 楼主,你的帖子里“sb”是啥意思呀,小心删贴处罚你 我咋记得PSAT里面有呢, 还是MATPOWER来着, 反正其中有一个有OPF的按钮. function = ...
opf(varargin)
%OPFSolves an optimal power flow.
% = OPF(MPC, MPOPT)
%
% Returns either a RESULTS struct and an optional SUCCESS flag, or individual
% data matrices, the objective function value and a SUCCESS flag. In the
% latter case, there are additional optional return values. See Examples
% below for the possible calling syntax options.
%
% Examples:
% Output argument options:
%
% results = opf(...)
% = opf(...)
% = opf(...)
% = opf(...)
%
% Input arguments options:
%
% opf(mpc)
% opf(mpc, mpopt)
% opf(mpc, userfcn, mpopt)
% opf(mpc, A, l, u)
% opf(mpc, A, l, u, mpopt)
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw)
% opf(mpc, A, l, u, mpopt, N, fparm, H, Cw, z0, zl, zu)
%
% opf(baseMVA, bus, gen, branch, areas, gencost)
% opf(baseMVA, bus, gen, branch, areas, gencost, mpopt)
% opf(baseMVA, bus, gen, branch, areas, gencost, userfcn, mpopt)
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u)
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, mpopt)
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...
% mpopt, N, fparm, H, Cw)
% opf(baseMVA, bus, gen, branch, areas, gencost, A, l, u, ...
% mpopt, N, fparm, H, Cw, z0, zl, zu)
%
% The data for the problem can be specified in one of three ways:
% (1) a string (mpc) containing the file name of a MATPOWER case
% which defines the data matrices baseMVA, bus, gen, branch, and
% gencost (areas is not used at all, it is only included for
% backward compatibility of the API).
% (2) a struct (mpc) containing the data matrices as fields.
% (3) the individual data matrices themselves.
%
% The optional user parameters for user constraints (A, l, u), user costs
% (N, fparm, H, Cw), user variable initializer (z0), and user variable
% limits (zl, zu) can also be specified as fields in a case struct,
% either passed in directly or defined in a case file referenced by name.
%
% When specified, A, l, u represent additional linear constraints on the
% optimization variables, l <= A* <= u. If the user specifies an A
% matrix that has more columns than the number of "x" (OPF) variables,
% then there are extra linearly constrained "z" variables. For an
% explanation of the formulation used and instructions for forming the
% A matrix, see the manual.
%
% A generalized cost on all variables can be applied if input arguments
% N, fparm, H and Cw are specified.First, a linear transformation
% of the optimization variables is defined by means of r = N * .
% Then, to each element of r a function is applied as encoded in the
% fparm matrix (see manual). If the resulting vector is named w,
% then H and Cw define a quadratic cost on w: (1/2)*w'*H*w + Cw * w .
% H and N should be sparse matrices and H should also be symmetric.
%
% The optional mpopt vector specifies MATPOWER options. If the OPF
% algorithm is not explicitly set in the options MATPOWER will use
% the default solver, based on a primal-dual interior point method.
% For the AC OPF this is OPF_ALG = 560, unless the TSPOPF optional
% package is installed, in which case the default is 540. For the
% DC OPF, the default is OPF_ALG_DC = 200. See MPOPTION for
% more details on the available OPF solvers and other OPF options
% and their default values.
%
% The solved case is returned either in a single results struct (described
% below) or in the individual data matrices, bus, gen and branch. Also
% returned are the final objective function value (f) and a flag which is
% true if the algorithm was successful in finding a solution (success).
% Additional optional return values are an algorithm specific return status
% (info), elapsed time in seconds (et), the constraint vector (g), the
% Jacobian matrix (jac), and the vector of variables (xr) as well
% as the constraint multipliers (pimul).
%
% The single results struct is a MATPOWER case struct (mpc) with the
% usual baseMVA, bus, branch, gen, gencost fields, along with the
% following additional fields:
%
% .order see 'help ext2int' for details of this field
% .et elapsed time in seconds for solving OPF
% .success 1 if solver converged successfully, 0 otherwise
% .om OPF model object, see 'help opf_model'
% .x final value of optimization variables (internal order)
% .f final objective function value
% .mu shadow prices on ...
% .var
% .llower bounds on variables
% .uupper bounds on variables
% .nln
% .llower bounds on nonlinear constraints
% .uupper bounds on nonlinear constraints
% .lin
% .llower bounds on linear constraints
% .uupper bounds on linear constraints
% .raw raw solver output in form returned by MINOS, and more
% .xr final value of optimization variables
% .pimulconstraint multipliers
% .info solver specific termination code
% .output solver specific output information
% .alg algorithm code of solver used
% .g (optional) constraint values
% .dg (optional) constraint 1st derivatives
% .df (optional) obj fun 1st derivatives (not yet implemented)
% .d2f (optional) obj fun 2nd derivatives (not yet implemented)
% .var
% .val optimization variable values, by named block
% .Va voltage angles
% .Vm voltage magnitudes (AC only)
% .Pg real power injections
% .Qg reactive power injections (AC only)
% .y constrained cost variable (only if have pwl costs)
% (other) any user defined variable blocks
% .mu variable bound shadow prices, by named block
% .llower bound shadow prices
% .Va, Vm, Pg, Qg, y, (other)
% .uupper bound shadow prices
% .Va, Vm, Pg, Qg, y, (other)
% .nln (AC only)
% .mu shadow prices on nonlinear constraints, by named block
% .llower bounds
% .Pmis real power mismatch equations
% .Qmis reactive power mismatch equations
% .Sf flow limits at "from" end of branches
% .St flow limits at "to" end of branches
% .uupper bounds
% .Pmis, Qmis, Sf, St
% .lin
% .mu shadow prices on linear constraints, by named block
% .llower bounds
% .Pmis real power mistmatch equations (DC only)
% .Pf flow limits at "from" end of branches (DC only)
% .Pt flow limits at "to" end of branches (DC only)
% .PQh upper portion of gen PQ-capability curve (AC only)
% .PQl lower portion of gen PQ-capability curve (AC only)
% .vl constant power factor constraint for loads (AC only)
% .ycon basin constraints for CCV for pwl costs
% (other) any user defined constraint blocks
% .uupper bounds
% .Pmis, Pf, Pf, PQh, PQl, vl, ycon, (other)
% .cost user defined cost values, by named block
%
% See also RUNOPF, DCOPF, UOPF, CASEFORMAT.
% MATPOWER
% $Id: opf.m,v 1.73 2010/06/09 14:56:58 ray Exp $
% by Ray Zimmerman, PSERC Cornell
% and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales
% Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
%
% This file is part of MATPOWER.
% See http://www.pserc.cornell.edu/matpower/ for more info.
%
% MATPOWER is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published
% by the Free Software Foundation, either version 3 of the License,
% or (at your option) any later version.
%
% MATPOWER is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
%
% Additional permission under GNU GPL version 3 section 7
%
% If you modify MATPOWER, or any covered work, to interface with
% other modules (such as MATLAB code and MEX-files) available in a
% MATLAB(R) or comparable environment containing parts covered
% under other licensing terms, the licensors of MATPOWER grant
% you additional permission to convey the resulting work.
%%----- initialization -----
t0 = clock; %% start timer
%% define named indices into data matrices
[PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
[GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
= idx_cost;
%% process input arguments
= opf_args(varargin{:});
%% add zero columns to bus, gen, branch for multipliers, etc if needed
nb = size(mpc.bus, 1); %% number of buses
nl = size(mpc.branch, 1); %% number of branches
ng = size(mpc.gen, 1); %% number of dispatchable injections
if size(mpc.bus,2) < MU_VMIN
mpc.bus = ;
end
if size(mpc.gen,2) < MU_QMIN
mpc.gen = [ mpc.gen zeros(ng, MU_QMIN-size(mpc.gen,2)) ];
end
if size(mpc.branch,2) < MU_ANGMAX
mpc.branch = [ mpc.branch zeros(nl, MU_ANGMAX-size(mpc.branch,2)) ];
end
%%-----convert to internal numbering, remove out-of-service stuff-----
mpc = ext2int(mpc);
%%-----construct OPF model object-----
om = opf_setup(mpc, mpopt);
%%-----execute the OPF-----
if nargout > 7
mpopt(52) = 1; %% RETURN_RAW_DER
end
= opf_execute(om, mpopt);
%%-----revert to original ordering, including out-of-service stuff-----
results = int2ext(results);
%% zero out result fields of out-of-service gens & branches
if ~isempty(results.order.gen.status.off)
results.gen(results.order.gen.status.off, ) = 0;
end
if ~isempty(results.order.branch.status.off)
results.branch(results.order.branch.status.off, ) = 0;
end
%%-----finish preparing output-----
et = etime(clock, t0); %% compute elapsed time
if nargout > 0
if nargout <= 2
results.et = et;
results.success = success;
results.raw = raw;
busout = results;
genout = success;
else
= deal(results.bus, ...
results.gen, results.branch, results.f, raw.info, raw.xr, raw.pimul);
if isfield(results, 'g')
g = results.g;
end
if isfield(results, 'dg')
jac = results.dg;
end
end
elseif success
results.et = et;
results.success = success;
printpf(results, 1, mpopt);
end PSAT里有直接算最优潮流的按钮,不用编程,很方便的 。。。坛子里有 回复 6# 白萝卜
在psat中可以直接画模型,基本上opf潮流计算(稳态)是没问题。进一步讨论得具体分析
页:
[1]
2
