Home > matpower4.0 > @opf_model > build_cost_params.m

build_cost_params

PURPOSE ^

BUILD_COST_PARAMS Builds and saves the full generalized cost parameters.

SYNOPSIS ^

function om = build_cost_params(om)

DESCRIPTION ^

BUILD_COST_PARAMS  Builds and saves the full generalized cost parameters.
   OM = BUILD_COST_PARAMS(OM)
   OM = BUILD_COST_PARAMS(OM, 'force')

   Builds the full set of cost parameters from the individual named
   sub-sets added via ADD_COST. Skips the building process if it has
   already been done, unless a second input argument is present.

   These cost parameters can be retrieved by calling GET_COST_PARAMS
   and the user-defined costs evaluated by calling COMPUTE_COST.

   See also OPF_MODEL, ADD_COST, GET_COST_PARAMS, COMPUTE_COST.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function om = build_cost_params(om)
0002 %BUILD_COST_PARAMS  Builds and saves the full generalized cost parameters.
0003 %   OM = BUILD_COST_PARAMS(OM)
0004 %   OM = BUILD_COST_PARAMS(OM, 'force')
0005 %
0006 %   Builds the full set of cost parameters from the individual named
0007 %   sub-sets added via ADD_COST. Skips the building process if it has
0008 %   already been done, unless a second input argument is present.
0009 %
0010 %   These cost parameters can be retrieved by calling GET_COST_PARAMS
0011 %   and the user-defined costs evaluated by calling COMPUTE_COST.
0012 %
0013 %   See also OPF_MODEL, ADD_COST, GET_COST_PARAMS, COMPUTE_COST.
0014 
0015 %   MATPOWER
0016 %   $Id: build_cost_params.m,v 1.9 2010/04/26 19:45:25 ray Exp $
0017 %   by Ray Zimmerman, PSERC Cornell
0018 %   Copyright (c) 2008-2010 by Power System Engineering Research Center (PSERC)
0019 %
0020 %   This file is part of MATPOWER.
0021 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0022 %
0023 %   MATPOWER is free software: you can redistribute it and/or modify
0024 %   it under the terms of the GNU General Public License as published
0025 %   by the Free Software Foundation, either version 3 of the License,
0026 %   or (at your option) any later version.
0027 %
0028 %   MATPOWER is distributed in the hope that it will be useful,
0029 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0030 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0031 %   GNU General Public License for more details.
0032 %
0033 %   You should have received a copy of the GNU General Public License
0034 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0035 %
0036 %   Additional permission under GNU GPL version 3 section 7
0037 %
0038 %   If you modify MATPOWER, or any covered work, to interface with
0039 %   other modules (such as MATLAB code and MEX-files) available in a
0040 %   MATLAB(R) or comparable environment containing parts covered
0041 %   under other licensing terms, the licensors of MATPOWER grant
0042 %   you additional permission to convey the resulting work.
0043 
0044 if nargin > 1 || ~isfield(om.cost.params, 'N')
0045     %% initialize parameters
0046     nw = om.cost.N;
0047     nnzN = 0;
0048     nnzH = 0;
0049     for k = 1:om.cost.NS
0050         name = om.cost.order{k};
0051         nnzN = nnzN + nnz(om.cost.data.N.(name));
0052         if isfield(om.cost.data.H, name)
0053             nnzH = nnzH + nnz(om.cost.data.H.(name));
0054         end
0055     end
0056     N = sparse([], [], [], nw, om.var.N, nnzN);
0057     Cw = zeros(nw, 1);
0058     H = sparse([], [], [], nw, nw, nnzH);   %% default => no quadratic term
0059     dd = ones(nw, 1);                       %% default => linear
0060     rh = Cw;                                %% default => no shift
0061     kk = Cw;                                %% default => no dead zone
0062     mm = dd;                                %% default => no scaling
0063     
0064     %% fill in each piece
0065     for k = 1:om.cost.NS
0066         name = om.cost.order{k};
0067         Nk = om.cost.data.N.(name);          %% N for kth cost set
0068         i1 = om.cost.idx.i1.(name);          %% starting row index
0069         iN = om.cost.idx.iN.(name);          %% ending row index
0070         if om.cost.idx.N.(name)              %% non-zero number of rows to add
0071             vsl = om.cost.data.vs.(name);       %% var set list
0072             kN = 0;                             %% initialize last col of Nk used
0073             for v = 1:length(vsl)
0074                 j1 = om.var.idx.i1.(vsl{v});    %% starting column in N
0075                 jN = om.var.idx.iN.(vsl{v});    %% ending column in N
0076                 k1 = kN + 1;                    %% starting column in Nk
0077                 kN = kN + om.var.idx.N.(vsl{v});%% ending column in Nk
0078                 N(i1:iN, j1:jN) = Nk(:, k1:kN);
0079             end
0080             Cw(i1:iN) = om.cost.data.Cw.(name);
0081             if isfield(om.cost.data.H, name)
0082                 H(i1:iN, i1:iN) = om.cost.data.H.(name);
0083             end
0084             if isfield(om.cost.data.dd, name)
0085                 dd(i1:iN) = om.cost.data.dd.(name);
0086             end
0087             if isfield(om.cost.data.rh, name)
0088                 rh(i1:iN) = om.cost.data.rh.(name);
0089             end
0090             if isfield(om.cost.data.kk, name)
0091                 kk(i1:iN) = om.cost.data.kk.(name);
0092             end
0093             if isfield(om.cost.data.mm, name)
0094                 mm(i1:iN) = om.cost.data.mm.(name);
0095             end
0096         end
0097     end
0098 
0099     %% save in object
0100     om.cost.params = struct( ...
0101         'N', N, 'Cw', Cw, 'H', H, 'dd', dd, 'rh', rh, 'kk', kk, 'mm', mm );
0102 end

Generated on Mon 26-Jan-2015 14:56:45 by m2html © 2005