GET_COST_PARAMS Returns the cost parameter struct for user-defined costs. CP = GET_COST_PARAMS(OM) CP = GET_COST_PARAMS(OM, NAME) CP = GET_COST_PARAMS(OM, NAME, IDX) Requires calling BUILD_COST_PARAMS first to build the full set of parameters. 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, BUILD_COST_PARAMS, 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 % CP = GET_COST_PARAMS(OM) 0004 % CP = GET_COST_PARAMS(OM, NAME) 0005 % CP = GET_COST_PARAMS(OM, NAME, IDX) 0006 % 0007 % Requires calling BUILD_COST_PARAMS first to build the full set of 0008 % parameters. Returns the full cost parameter struct for all user-defined 0009 % costs that incorporates all of the named cost sets added via ADD_COSTS, 0010 % or, if a name is provided it returns the cost struct corresponding to 0011 % the named set of cost rows (N still has full number of columns). 0012 % 0013 % The cost parameters are returned in a struct with the following fields: 0014 % N - nw x nx sparse matrix 0015 % Cw - nw x 1 vector 0016 % H - nw x nw sparse matrix (optional, all zeros by default) 0017 % dd, mm - nw x 1 vectors (optional, all ones by default) 0018 % rh, kk - nw x 1 vectors (optional, all zeros by default) 0019 % 0020 % See also OPT_MODEL, ADD_COSTS, BUILD_COST_PARAMS, COMPUTE_COST. 0021 0022 % MATPOWER 0023 % Copyright (c) 2008-2016, Power Systems Engineering Research Center (PSERC) 0024 % by Ray Zimmerman, PSERC Cornell 0025 % 0026 % This file is part of MATPOWER. 0027 % Covered by the 3-clause BSD License (see LICENSE file for details). 0028 % See http://www.pserc.cornell.edu/matpower/ for more info. 0029 0030 if ~isfield(om.cost.params, 'N') 0031 error('@opt_model/get_cost_params: must call build_cost_params first'); 0032 end 0033 0034 cp = om.cost.params; 0035 0036 if nargin > 1 0037 if getN(om, 'cost', name) 0038 if nargin < 3 || isempty(idx) 0039 if prod(size(om.cost.idx.i1.(name))) == 1 0040 i1 = om.cost.idx.i1.(name); 0041 iN = om.cost.idx.iN.(name); 0042 else 0043 error('@opt_model/get_cost_params: cost set ''%s'' requires an idx arg', name); 0044 end 0045 else 0046 s1 = substruct('.', name, '()', idx); 0047 i1 = subsref(om.cost.idx.i1, s1); 0048 iN = subsref(om.cost.idx.iN, s1); 0049 end 0050 cp.N = cp.N(i1:iN,:); 0051 cp.Cw = cp.Cw(i1:iN); 0052 cp.H = cp.H(i1:iN,i1:iN); 0053 cp.dd = cp.dd(i1:iN); 0054 cp.rh = cp.rh(i1:iN); 0055 cp.kk = cp.kk(i1:iN); 0056 cp.mm = cp.mm(i1:iN); 0057 end 0058 end