forked from MATPOWER/matpower
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathopf_consfcn.m
57 lines (55 loc) · 2.52 KB
/
opf_consfcn.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function [h, g, dh, dg] = opf_consfcn(x, om, Ybus, Yf, Yt, mpopt, il, varargin)
%OPF_CONSFCN Evaluates nonlinear constraints and their Jacobian for OPF.
% [H, G, DH, DG] = OPF_CONSFCN(X, OM, YBUS, YF, YT, MPOPT, IL)
%
% Constraint evaluation function for AC optimal power flow, suitable
% for use with MIPS or FMINCON. Computes constraint vectors and their
% gradients.
%
% Inputs:
% X : optimization vector
% OM : OPF model object
% YBUS : bus admittance matrix
% YF : admittance matrix for "from" end of constrained branches
% YT : admittance matrix for "to" end of constrained branches
% MPOPT : MATPOWER options struct
% IL : (optional) vector of branch indices corresponding to
% branches with flow limits (all others are assumed to be
% unconstrained). The default is [1:nl] (all branches).
% YF and YT contain only the rows corresponding to IL.
%
% Outputs:
% H : vector of inequality constraint values (flow limits)
% where the flow can be apparent power, real power, or
% current, depending on the value of opf.flow_lim in MPOPT
% (only for constrained lines), normally expressed as
% (limit^2 - flow^2), except when opf.flow_lim == 'P',
% in which case it is simply (limit - flow).
% G : vector of equality constraint values (power balances)
% DH : (optional) inequality constraint gradients, column j is
% gradient of H(j)
% DG : (optional) equality constraint gradients
%
% Examples:
% [h, g] = opf_consfcn(x, om, Ybus, Yf, Yt, mpopt);
% [h, g, dh, dg] = opf_consfcn(x, om, Ybus, Yf, Yt, mpopt);
% [h, g, dh, dg] = opf_consfcn(x, om, Ybus, Yf, Yt, mpopt, il);
%
% See also OPF_COSTFCN, OPF_HESSFCN.
% MATPOWER
% Copyright (c) 1996-2017, Power Systems Engineering Research Center (PSERC)
% by Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Nacional de Colombia
% and Ray Zimmerman, PSERC Cornell
%
% This file is part of MATPOWER.
% Covered by the 3-clause BSD License (see LICENSE file for details).
% See http://www.pserc.cornell.edu/matpower/ for more info.
if nargout == 2 %% contraints only
g = om.eval_nln_constraint(x, 1); %% equalities (power flow)
h = om.eval_nln_constraint(x, 0); %% inequalities (branch flow limits)
else %% constraints and derivatives
[g, dg] = om.eval_nln_constraint(x, 1); %% equalities (power flow)
[h, dh] = om.eval_nln_constraint(x, 0); %% inequalities (branch flow limits)
dg = dg';
dh = dh';
end