📄 mopf.m
字号:
function [busout, genout, branchout, f, success, info, et, g, jac, xr, pimul]... = mopf(baseMVA, bus, gen, branch, areas, gencost, Au, lbu, ubu, mpopt, ... N, fparm, H, Cw, z0, zl, zu)%MOPF Solves an AC optimal power flow using MINOS solver.%% [bus, gen, branch, f, success] = mopf(casefile, mpopt)%% [bus, gen, branch, f, success] = mopf(casefile, A, l, u, mpopt)%% [bus, gen, branch, f, success] = mopf(baseMVA, bus, gen, branch, ...% areas, gencost, mpopt)%% [bus, gen, branch, f, success] = mopf(baseMVA, bus, gen, branch, ...% areas, gencost, A, l, u, mpopt)%% [bus, gen, branch, f, success] = mopf(baseMVA, bus, gen, branch, ...% areas, gencost, A, l, u, mpopt, ...% N, fparm, H, Cw)%% [bus, gen, branch, f, success] = mopf(baseMVA, bus, gen, branch, ...% areas, gencost, A, l, u, mpopt, ...% N, fparm, H, Cw, z0, zl, zu)%% [bus, gen, branch, f, success, info, et, g, jac, xr, pimul] = mopf(casefile)%% The data for the problem can be specified in one of 3 ways: (1) the name of% a case file which defines the data matrices baseMVA, bus, gen, branch,% areas and gencost, (2) a struct containing the data matrices as fields, or% (3) the data matrices themselves.%% When specified, A, l, u represent additional linear constraints on the% optimization variables, l <= A*[x; z] <= u. For an explanation of the% formulation used and instructions for forming the A matrix, type% 'help genform'.%% 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 * [x; z].% Then, to each element of r a function is applied as encoded in the% fparm matrix (see manual or type 'help generalcost'). If the% resulting vector is now 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. Type 'help mpoption'% for details and default values.%% The solved case is returned in the 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 and slacks (xr) as well % as the constraint multipliers from MINOS (pimul); see the MINOS 5.5 manual % for details.%% Rules for A matrix: 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.% MINOPF for MATPOWER% $Id: mopf.m,v 1.26 2007/08/14 15:14:10 ray Exp $% by Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales% Copyright (c) 2000-2006 by Power System Engineering Research Center (PSERC)% See http://www.pserc.cornell.edu/minopf/ for more info.% Sort out input argumentst1 = clock;if isstr(baseMVA) | isstruct(baseMVA) % passing filename or struct %---- mopf(baseMVA, bus, gen, branch, areas, gencost, Au, lbu, ubu, mpopt, N, fparm, H, Cw, z0, zl, zu) % 12 mopf(casefile, Au, lbu, ubu, mpopt, N, fparm, H, Cw, z0, zl, zu) % 9 mopf(casefile, Au, lbu, ubu, mpopt, N, fparm, H, Cw) % 5 mopf(casefile, Au, lbu, ubu, mpopt) % 4 mopf(casefile, Au, lbu, ubu) % 2 mopf(casefile, mpopt) % 1 mopf(casefile) if any(nargin == [1, 2, 4, 5, 9, 12]) casefile = baseMVA; if nargin == 12 zu = fparm; zl = N; z0 = mpopt; Cw = ubu; H = lbu; fparm = Au; N = gencost; mpopt = areas; ubu = branch; lbu = gen; Au = bus; elseif nargin == 9 zu = []; zl = []; z0 = []; Cw = ubu; H = lbu; fparm = Au; N = gencost; mpopt = areas; ubu = branch; lbu = gen; Au = bus; elseif nargin == 5 zu = []; zl = []; z0 = []; Cw = []; H = []; fparm = []; N = []; mpopt = areas; ubu = branch; lbu = gen; Au = bus; elseif nargin == 4 zu = []; zl = []; z0 = []; Cw = []; H = []; fparm = []; N = []; mpopt = mpoption; ubu = branch; lbu = gen; Au = bus; elseif nargin == 2 zu = []; zl = []; z0 = []; Cw = []; H = []; fparm = []; N = []; mpopt = bus; ubu = []; lbu = []; Au = sparse(0,0); elseif nargin == 1 zu = []; zl = []; z0 = []; Cw = []; H = []; fparm = []; N = []; mpopt = mpoption; ubu = []; lbu = []; Au = sparse(0,0); end else error('mopf.m: Incorrect input parameter order, number or type'); end [baseMVA, bus, gen, branch, areas, gencost] = loadcase(casefile);else % passing individual data matrices %---- mopf(baseMVA, bus, gen, branch, areas, gencost, Au, lbu, ubu, mpopt, N, fparm, H, Cw, z0, zl, zu) % 17 mopf(baseMVA, bus, gen, branch, areas, gencost, Au, lbu, ubu, mpopt, N, fparm, H, Cw, z0, zl, zu) % 14 mopf(baseMVA, bus, gen, branch, areas, gencost, Au, lbu, ubu, mpopt, N, fparm, H, Cw) % 10 mopf(baseMVA, bus, gen, branch, areas, gencost, Au, lbu, ubu, mpopt) % 9 mopf(baseMVA, bus, gen, branch, areas, gencost, Au, lbu, ubu) % 7 mopf(baseMVA, bus, gen, branch, areas, gencost, mpopt) % 6 mopf(baseMVA, bus, gen, branch, areas, gencost) if any(nargin == [6, 7, 9, 10, 14, 17]) if nargin == 14 zu = []; zl = []; z0 = []; elseif nargin == 10 zu = []; zl = []; z0 = []; Cw = []; H = []; fparm = []; N = []; elseif nargin == 9 zu = []; zl = []; z0 = []; Cw = []; H = []; fparm = []; N = []; mpopt = mpoption; elseif nargin == 7 zu = []; zl = []; z0 = []; Cw = []; H = []; fparm = []; N = []; mpopt = Au; ubu = []; lbu = []; Au = sparse(0,0); elseif nargin == 6 zu = []; zl = []; z0 = []; Cw = []; H = []; fparm = []; N = []; mpopt = mpoption; ubu = []; lbu = []; Au = sparse(0,0); end else error('mopf.m: Incorrect input parameter order, number or type'); endendif size(N, 1) > 0 if size(N, 1) ~= size(fparm, 1) | size(N, 1) ~= size(H, 1) | ... size(N, 1) ~= size(H, 2) | size(N, 1) ~= length(Cw) error('mopf.m: wrong dimensions in generalized cost parameters'); end if size(Au, 1) > 0 & size(N, 2) ~= size(Au, 2) error('mopf.m: A and N must have the same number of columns'); end % make sure N and H are sparse to keep from crashing MINOPF if ~issparse(N) N = sparse(N); end if ~issparse(H) H = sparse(H); endendif isempty(mpopt) mpopt = mpoption;end% check for active power or current line flow limitif mpopt(24) == 1 | mpopt(24) == 2 error('mopf.m: options OPF_FLOW_LIM == 1 or 2 not yet supported by MINOPF');endif strcmp(computer, 'PCWIN') mpopt(70) = 0; % The DLL incarnation of minopf was born mute and deaf,end % probably because of acute shock after realizing its fate. % Can't be allowed to try to speak or its universe crumbles.% Load column indexes for case tables.[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;[PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;% If tables do not have multiplier/extra columns, append zero cols.% Update whenever the data format changes!if size(bus,2) < MU_VMIN bus = [bus zeros(size(bus,1),MU_VMIN-size(bus,2)) ];endif size(gen,2) < MU_QMIN gen = [ gen zeros(size(gen,1),MU_QMIN-size(gen,2)) ];endif size(branch,2) < MU_ANGMAX branch = [ branch zeros(size(branch,1),MU_ANGMAX-size(branch,2)) ];end% Filter out inactive generators and branches; save original bus & branchcomgen = find(gen(:,GEN_STATUS) > 0);offgen = find(gen(:,GEN_STATUS) <= 0);onbranch = find(branch(:,BR_STATUS) ~= 0);offbranch = find(branch(:,BR_STATUS) == 0);genorg = gen;branchorg = branch;ng = size(gen,1); % original size(gen), at least temporallygen = gen(comgen, :);branch = branch(onbranch, :);if size(gencost,1) == ng gencost = gencost(comgen, :);else gencost = gencost( [comgen; comgen+ng], :);end% Renumber buses consecutively[i2e, bus, gen, branch, areas] = ext2int(bus, gen, branch, areas);[ref, pv, pq] = bustypes(bus, gen);% Sort generators in order of increasing bus number;ng = size(gen,1);[tmp, igen] = sort(gen(:, GEN_BUS));[tmp, inv_gen_ord] = sort(igen); % save for inverse reordering at the endgen = gen(igen, :);if ng == size(gencost,1) gencost = gencost(igen, :);else gencost = gencost( [igen; igen+ng], :);end% Print a warning if there is more than one reference busif size(find(bus(:, BUS_TYPE) == REF), 1) > 1 errstr = ['\nmopf: Warning: more than one reference bus detected in bus table data.\n', ... ' For a system with islands, a reference bus in each island\n', ... ' might help convergence but in a fully connected system such\n', ... ' a situation is probably not reasonable.\n\n' ]; fprintf(errstr);end% Find out if any of these "generators" are actually dispatchable loads.% (see 'help isload' for details on what constitutes a dispatchable load)% Dispatchable loads are modeled as generators with an added constant% power factor constraint. The power factor is derived from the original% value of Pmin and either Qmin (for inductive loads) or Qmax (for capacitive% loads). If both Qmin and Qmax are zero, this implies a unity power factor% without the need for an additional constraint.vload = find( isload(gen) & (gen(:, QMIN) ~= 0 | gen(:, QMAX) ~= 0) );% At least one of the Q limits must be zero (corresponding to Pmax == 0)if any( gen(vload, QMIN) ~= 0 & gen(vload, QMAX) ~= 0 ) error('mopf.m: Either Qmin or Qmax must be equal to zero for each dispatchable load.');end% Initial values of PG and QG must be consistent with specified power factor% This is to prevent a user from unknowingly using a case file which would% have defined a different power factor constraint under a previous version% which used PG and QG to define the power factor.Qlim = (gen(vload, QMIN) == 0) .* gen(vload, QMAX) + ... (gen(vload, QMAX) == 0) .* gen(vload, QMIN);if any( abs( gen(vload, QG) - gen(vload, PG) .* Qlim ./ gen(vload, PMIN) ) > 1e-4 ) errstr = sprintf('%s\n', ... 'For a dispatchable load, PG and QG must be consistent', ... 'with the power factor defined by PMIN and the Q limits.' ); error(errstr);end% Find out which generators require additional linear constraints% (as opposed to simple box constraints) on (Pg,Qg) to correctly% model their PQ capability curvesipqh = find( hasPQcap(gen, 'U') );ipql = find( hasPQcap(gen, 'L') );% Find out which branches require angle constraintsif mpopt(25) % OPF_IGNORE_ANG_LIM nang = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -