PARAMS_NLN_COST Returns cost parameters for general nonlinear costs. [N, FCN] = OM.PARAMS_NLN_COST(NAME) [N, FCN] = OM.PARAMS_NLN_COST(NAME, IDX_LIST) [N, FCN, VS] = OM.PARAMS_NLN_COST(...) Returns the parameters N and FCN provided when the corresponding named general nonlinear cost set was added to the model. Likewise for indexed named sets specified by NAME and IDX_LIST. An optional 3rd output argument VS indicates the variable sets used by this cost set. See also OPT_MODEL, ADD_NLN_COST, EVAL_NLN_COST.
0001 function [N, fcn, vs] = params_nln_cost(om, name, idx) 0002 %PARAMS_NLN_COST Returns cost parameters for general nonlinear costs. 0003 % [N, FCN] = OM.PARAMS_NLN_COST(NAME) 0004 % [N, FCN] = OM.PARAMS_NLN_COST(NAME, IDX_LIST) 0005 % [N, FCN, VS] = OM.PARAMS_NLN_COST(...) 0006 % 0007 % Returns the parameters N and FCN provided when the corresponding 0008 % named general nonlinear cost set was added to the model. Likewise 0009 % for indexed named sets specified by NAME and IDX_LIST. 0010 % 0011 % An optional 3rd output argument VS indicates the variable sets used by 0012 % this cost set. 0013 % 0014 % See also OPT_MODEL, ADD_NLN_COST, EVAL_NLN_COST. 0015 0016 % MP-Opt-Model 0017 % Copyright (c) 2017-2020, Power Systems Engineering Research Center (PSERC) 0018 % by Ray Zimmerman, PSERC Cornell 0019 % 0020 % This file is part of MP-Opt-Model. 0021 % Covered by the 3-clause BSD License (see LICENSE file for details). 0022 % See https://github.com/MATPOWER/mp-opt-model for more info. 0023 0024 nlc = om.nlc; 0025 if nargin < 3 0026 idx = {}; 0027 end 0028 0029 if isempty(idx) 0030 dims = size(nlc.idx.i1.(name)); 0031 if prod(dims) ~= 1 0032 error('@opt_model/params_nln_cost: general nonlinear cost set ''%s'' requires an IDX_LIST arg', name) 0033 end 0034 N = nlc.idx.N.(name); 0035 fcn = nlc.data.fcn.(name); 0036 vs = nlc.data.vs.(name); 0037 else 0038 %% calls to substruct() are relatively expensive, so we pre-build the 0039 %% structs for addressing cell and numeric array fields 0040 %% sn = substruct('.', name, '()', idx); 0041 %% sc = substruct('.', name, '{}', idx); 0042 sc = struct('type', {'.', '{}'}, 'subs', {name, idx}); %% cell array field 0043 sn = sc; sn(2).type = '()'; %% num array field 0044 0045 N = subsref(nlc.idx.N, sn); 0046 fcn = subsref(nlc.data.fcn, sc); 0047 vs = subsref(nlc.data.vs, sc); 0048 end