GET_COST_PARAMS Returns the cost parameter struct for user-defined costs. ----- DEPRECATED - use PARAMS_LEGACY_COST instead ----- CP = OM.GET_COST_PARAMS() CP = OM.GET_COST_PARAMS(NAME) CP = OM.GET_COST_PARAMS(NAME, IDX) Returns the full cost parameter struct for all user-defined costs that incorporates all of the named cost sets added via ADD_COSTS, or, if a NAME is provided it returns the cost struct corresponding to the named set of cost rows (N still has full number of columns). The cost parameters are returned in a struct with the following fields: N - nw x nx sparse matrix Cw - nw x 1 vector H - nw x nw sparse matrix (optional, all zeros by default) dd, mm - nw x 1 vectors (optional, all ones by default) rh, kk - nw x 1 vectors (optional, all zeros by default) See also OPT_MODEL, ADD_COSTS, COMPUTE_COST.
0001 function cp = get_cost_params(om, name, idx) 0002 %GET_COST_PARAMS Returns the cost parameter struct for user-defined costs. 0003 % 0004 % ----- DEPRECATED - use PARAMS_LEGACY_COST instead ----- 0005 % 0006 % CP = OM.GET_COST_PARAMS() 0007 % CP = OM.GET_COST_PARAMS(NAME) 0008 % CP = OM.GET_COST_PARAMS(NAME, IDX) 0009 % 0010 % Returns the full cost parameter struct for all user-defined 0011 % costs that incorporates all of the named cost sets added via ADD_COSTS, 0012 % or, if a NAME is provided it returns the cost struct corresponding to 0013 % the named set of cost rows (N still has full number of columns). 0014 % 0015 % The cost parameters are returned in a struct with the following fields: 0016 % N - nw x nx sparse matrix 0017 % Cw - nw x 1 vector 0018 % H - nw x nw sparse matrix (optional, all zeros by default) 0019 % dd, mm - nw x 1 vectors (optional, all ones by default) 0020 % rh, kk - nw x 1 vectors (optional, all zeros by default) 0021 % 0022 % See also OPT_MODEL, ADD_COSTS, COMPUTE_COST. 0023 0024 % MATPOWER 0025 % Copyright (c) 2008-2017, Power Systems Engineering Research Center (PSERC) 0026 % by Ray Zimmerman, PSERC Cornell 0027 % 0028 % This file is part of MATPOWER. 0029 % Covered by the 3-clause BSD License (see LICENSE file for details). 0030 % See https://matpower.org for more info. 0031 0032 cp = om.params_legacy_cost(); 0033 0034 if nargin > 1 0035 if getN(om, 'cost', name) 0036 if nargin < 3 || isempty(idx) 0037 if prod(size(om.cost.idx.i1.(name))) == 1 0038 i1 = om.cost.idx.i1.(name); 0039 iN = om.cost.idx.iN.(name); 0040 else 0041 error('@opt_model/get_cost_params: cost set ''%s'' requires an idx arg', name); 0042 end 0043 else 0044 %% calls to substruct() are relatively expensive, so we pre-build the 0045 %% structs for addressing cell and numeric array fields 0046 %% sn = substruct('.', name, '()', idx); 0047 sn = struct('type', {'.', '()'}, 'subs', {name, idx}); %% num array field 0048 i1 = subsref(om.cost.idx.i1, sn); 0049 iN = subsref(om.cost.idx.iN, sn); 0050 end 0051 cp.N = cp.N(i1:iN,:); 0052 cp.Cw = cp.Cw(i1:iN); 0053 cp.H = cp.H(i1:iN,i1:iN); 0054 cp.dd = cp.dd(i1:iN); 0055 cp.rh = cp.rh(i1:iN); 0056 cp.kk = cp.kk(i1:iN); 0057 cp.mm = cp.mm(i1:iN); 0058 end 0059 end