PARAMS_NLN_CONSTRAINT Returns parameters for general nonlinear constraints. N = OM.PARAMS_NLN_CONSTRAINT(ISEQ, NAME) N = OM.PARAMS_NLN_CONSTRAINT(ISEQ, NAME, IDX_LIST) [N, FCN] = OM.PARAMS_NLN_CONSTRAINT(...) [N, FCN, HESS] = OM.PARAMS_NLN_CONSTRAINT(...) [N, FCN, HESS, VS] = OM.PARAMS_NLN_CONSTRAINT(...) [N, FCN, HESS, VS, INCLUDE] = OM.PARAMS_NLN_CONSTRAINT(...) Returns the parameters N, and optionally FCN, and HESS provided when the corresponding named nonlinear constraint set was added to the model. Likewise for indexed named sets specified by NAME and IDX_LIST. The ISEQ input should be set to 1 for equality constrainst and to 0 for inequality constraints. An optional 4th output argument VS indicates the variable sets used by this constraint set.
0001 function [N, fcn, hess, vs, include] = params_nln_constraint(om, iseq, name, idx) 0002 %PARAMS_NLN_CONSTRAINT Returns parameters for general nonlinear constraints. 0003 % N = OM.PARAMS_NLN_CONSTRAINT(ISEQ, NAME) 0004 % N = OM.PARAMS_NLN_CONSTRAINT(ISEQ, NAME, IDX_LIST) 0005 % [N, FCN] = OM.PARAMS_NLN_CONSTRAINT(...) 0006 % [N, FCN, HESS] = OM.PARAMS_NLN_CONSTRAINT(...) 0007 % [N, FCN, HESS, VS] = OM.PARAMS_NLN_CONSTRAINT(...) 0008 % [N, FCN, HESS, VS, INCLUDE] = OM.PARAMS_NLN_CONSTRAINT(...) 0009 % 0010 % Returns the parameters N, and optionally FCN, and HESS provided when 0011 % the corresponding named nonlinear constraint set was added to the 0012 % model. Likewise for indexed named sets specified by NAME and IDX_LIST. 0013 % The ISEQ input should be set to 1 for equality constrainst and to 0 0014 % for inequality constraints. 0015 % 0016 % An optional 4th output argument VS indicates the variable sets used by 0017 % this constraint set. 0018 0019 % And, for constraint sets whose functions compute the constraints for 0020 % another set, an optional 5th output argument returns a struct with a 0021 % cell array of set names in the 'name' field and an array of 0022 % corresponding dimensions in the 'N' field. 0023 % 0024 % See also OPT_MODEL, ADD_NLN_CONSTRAINT, EVAL_NLN_CONSTRAINT. 0025 0026 % MP-Opt-Model 0027 % Copyright (c) 2017-2020, Power Systems Engineering Research Center (PSERC) 0028 % by Ray Zimmerman, PSERC Cornell 0029 % 0030 % This file is part of MP-Opt-Model. 0031 % Covered by the 3-clause BSD License (see LICENSE file for details). 0032 % See https://github.com/MATPOWER/mp-opt-model for more info. 0033 0034 %% get constraint type 0035 if iseq %% equality constraints 0036 om_nlx = om.nle; 0037 else %% inequality constraints 0038 om_nlx = om.nli; 0039 end 0040 0041 if nargin < 4 0042 idx = {}; 0043 end 0044 0045 if isempty(idx) 0046 dims = size(om_nlx.idx.i1.(name)); 0047 if prod(dims) ~= 1 0048 error('@opt_model/params_nln_constraint: nonlinear constraint set ''%s'' requires an IDX_LIST arg', name) 0049 end 0050 N = om_nlx.idx.N.(name); 0051 if nargout > 1 0052 if isfield(om_nlx.data.fcn, name) 0053 fcn = om_nlx.data.fcn.(name); 0054 else 0055 fcn = ''; 0056 end 0057 if nargout > 2 0058 if isfield(om_nlx.data.hess, name) 0059 hess = om_nlx.data.hess.(name); 0060 else 0061 hess = ''; 0062 end 0063 if nargout > 3 0064 if isfield(om_nlx.data.vs, name) 0065 vs = om_nlx.data.vs.(name); 0066 else 0067 vs = {}; 0068 end 0069 if nargout > 4 0070 if isfield(om_nlx.data.include, name) 0071 include = om_nlx.data.include.(name); 0072 else 0073 include = ''; 0074 end 0075 end 0076 end 0077 end 0078 end 0079 else 0080 %% calls to substruct() are relatively expensive, so we pre-build the 0081 %% structs for addressing cell and numeric array fields 0082 %% sn = substruct('.', name, '()', idx); 0083 %% sc = substruct('.', name, '{}', idx); 0084 sc = struct('type', {'.', '{}'}, 'subs', {name, idx}); %% cell array field 0085 sn = sc; sn(2).type = '()'; %% num array field 0086 0087 N = subsref(om_nlx.idx.N, sn); 0088 if nargout > 1 0089 if isfield(om_nlx.data.fcn, name) 0090 fcn = subsref(om_nlx.data.fcn, sc); 0091 else 0092 fcn = ''; 0093 end 0094 if nargout > 2 0095 if isfield(om_nlx.data.hess, name) 0096 hess = subsref(om_nlx.data.hess, sc); 0097 else 0098 hess = ''; 0099 end 0100 if nargout > 3 0101 if isfield(om_nlx.data.vs, name) 0102 vs = subsref(om_nlx.data.vs, sc); 0103 else 0104 vs = {}; 0105 end 0106 if nargout > 4 0107 error('@opt_model/params_nln_constraint: nonlinear constraint set ''%s'' cannot return INCLUDE, since a nonlinear constraint set computed by another set is currently only implemented for simple named sets, not yet for indexed named sets', name) 0108 end 0109 end 0110 end 0111 end 0112 end