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 % $Id: get_cost_params.m 2048 2012-05-03 12:59:07Z cvs $ 0024 % by Ray Zimmerman, PSERC Cornell 0025 % Copyright (c) 2008-2012 by Power System Engineering Research Center (PSERC) 0026 % 0027 % This file is part of MATPOWER. 0028 % See http://www.pserc.cornell.edu/matpower/ for more info. 0029 % 0030 % MATPOWER is free software: you can redistribute it and/or modify 0031 % it under the terms of the GNU General Public License as published 0032 % by the Free Software Foundation, either version 3 of the License, 0033 % or (at your option) any later version. 0034 % 0035 % MATPOWER is distributed in the hope that it will be useful, 0036 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0037 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0038 % GNU General Public License for more details. 0039 % 0040 % You should have received a copy of the GNU General Public License 0041 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0042 % 0043 % Additional permission under GNU GPL version 3 section 7 0044 % 0045 % If you modify MATPOWER, or any covered work, to interface with 0046 % other modules (such as MATLAB code and MEX-files) available in a 0047 % MATLAB(R) or comparable environment containing parts covered 0048 % under other licensing terms, the licensors of MATPOWER grant 0049 % you additional permission to convey the resulting work. 0050 0051 if ~isfield(om.cost.params, 'N') 0052 error('@opt_model/get_cost_params: must call build_cost_params first'); 0053 end 0054 0055 cp = om.cost.params; 0056 0057 if nargin > 1 0058 if getN(om, 'cost', name) 0059 if nargin < 3 || isempty(idx) 0060 if prod(size(om.cost.idx.i1.(name))) == 1 0061 i1 = om.cost.idx.i1.(name); 0062 iN = om.cost.idx.iN.(name); 0063 else 0064 error('@opt_model/get_cost_params: cost set ''%s'' requires an idx arg', name); 0065 end 0066 else 0067 s1 = substruct('.', name, '()', idx); 0068 i1 = subsref(om.cost.idx.i1, s1); 0069 iN = subsref(om.cost.idx.iN, s1); 0070 end 0071 cp.N = cp.N(i1:iN,:); 0072 cp.Cw = cp.Cw(i1:iN); 0073 cp.H = cp.H(i1:iN,i1:iN); 0074 cp.dd = cp.dd(i1:iN); 0075 cp.rh = cp.rh(i1:iN); 0076 cp.kk = cp.kk(i1:iN); 0077 cp.mm = cp.mm(i1:iN); 0078 end 0079 end