Home > matpower7.0 > extras > misc > check_feasibility.m

check_feasibility

PURPOSE ^

CHECK_FEASIBILITY Returns the maximum constraint violation in p.u.

SYNOPSIS ^

function [v, f, hn, gn, Al, Au, xl, xu] = check_feasibility(mpc, mpopt)

DESCRIPTION ^

CHECK_FEASIBILITY  Returns the maximum constraint violation in p.u.
   V = CHECK_FEASIBILITY(MPC)
   [V, F, HN, GN, AL, AU, XL, XU] = CHECK_FEASIBILITY(MPC, MPOPT)

   Not thoroughly tested.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [v, f, hn, gn, Al, Au, xl, xu] = check_feasibility(mpc, mpopt)
0002 %CHECK_FEASIBILITY  Returns the maximum constraint violation in p.u.
0003 %   V = CHECK_FEASIBILITY(MPC)
0004 %   [V, F, HN, GN, AL, AU, XL, XU] = CHECK_FEASIBILITY(MPC, MPOPT)
0005 %
0006 %   Not thoroughly tested.
0007 
0008 %   MATPOWER
0009 %   Copyright (c) 2010-2018, Power Systems Engineering Research Center (PSERC)
0010 %   by Ray Zimmerman, PSERC Cornell
0011 %
0012 %   This file is part of MATPOWER Extras.
0013 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0014 %   See https://github.com/MATPOWER/matpower-extras for more info.
0015 
0016 %%----- initialization -----
0017 %% define named indices into data matrices
0018 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0019     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0020 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0021     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0022     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0023 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0024     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0025     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0026 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0027 
0028 if nargin < 2
0029     mpopt = mpoption;
0030 end
0031 
0032 [mpc, mpopt] = opf_args(mpc, mpopt);
0033 mpc = ext2int(mpc);
0034 om = opf_setup(mpc, mpopt);
0035 om = om.build_cost_params();
0036 
0037 %% unpack data
0038 mpc = om.get_mpc();
0039 vv = om.get_idx();
0040 
0041 %% problem dimensions
0042 nb = size(mpc.bus, 1);      %% number of buses
0043 nl = size(mpc.branch, 1);   %% number of branches
0044 ny = om.getN('var', 'y');   %% number of piece-wise linear costs
0045 
0046 %% linear constraints
0047 [A, l, u] = om.params_lin_constraint();
0048 
0049 %% bounds on optimization vars
0050 [x, xmin, xmax] = om.params_var();
0051 
0052 %% build admittance matrices
0053 [Ybus, Yf, Yt] = makeYbus(mpc.baseMVA, mpc.bus, mpc.branch);
0054 
0055 %% set y variables (ONLY IMPLEMENTED FOR PG)
0056 if ny > 0
0057     ipwl = find(mpc.gencost(:, MODEL) == PW_LINEAR);
0058     ig = vv.i1.Pg:vv.iN.Pg;
0059     x(vv.i1.y:vv.iN.y) = totcost(mpc.gencost(ipwl, :), x(ig(ipwl)) * mpc.baseMVA);
0060 end
0061 
0062 %% find branches with flow limits
0063 il = find(mpc.branch(:, RATE_A) ~= 0 & mpc.branch(:, RATE_A) < 1e10);
0064 nl2 = length(il);           %% number of constrained lines
0065 
0066 %% evaluate OPF constraints
0067 f_fcn = @(x)opf_costfcn(x, om);
0068 gh_fcn = @(x)opf_consfcn(x, om, Ybus, Yf(il,:), Yt(il,:), mpopt, il);
0069 hess_fcn = @(x, lambda, cost_mult)opf_hessfcn(x, lambda, cost_mult, om, Ybus, Yf(il,:), Yt(il,:), mpopt, il);
0070 
0071 [f, df, d2f] = f_fcn(x);
0072 [hn, gn, dhn, dgn] = gh_fcn(x);
0073 
0074 Ax = A * x;
0075 Au = Ax - u;
0076 Al = l - Ax;
0077 
0078 xu = x - xmax;
0079 xl = xmin - x;
0080 
0081 v = max([hn; abs(gn); Au; Al; xu; xl]);

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005