Home > matpower7.0 > lib > @opt_model > init_indexed_name.m

init_indexed_name

PURPOSE ^

INIT_INDEXED_NAME Initializes the dimensions for an indexed named set.

SYNOPSIS ^

function om = init_indexed_name(om, set_type, name, dim_list)

DESCRIPTION ^

INIT_INDEXED_NAME  Initializes the dimensions for an indexed named set.

   OM.INIT_INDEXED_NAME(SET_TYPE, NAME, DIM_LIST)

   Initializes the dimensions for an indexed named variable, constraint
   or cost set.

   Variables, constraints and costs are referenced in OPT_MODEL in terms
   of named sets. The specific type of named set being referenced is
   given by SET_TYPE, with the following valid options:
       SET_TYPE = 'var'   => variable set
       SET_TYPE = 'lin'   => linear constraint set
       SET_TYPE = 'nle'   => nonlinear equality constraint set
       SET_TYPE = 'nli'   => nonlinear inequality constraint set
       SET_TYPE = 'cost'  => cost set

   Indexed Named Sets

   A variable, constraint or cost set can be identified by a single NAME,
   such as 'Pmismatch', or by a name that is indexed by one or more indices,
   such as 'Pmismatch(3,4)'. For an indexed named set, before adding the
   indexed variable, constraint or cost sets themselves, the dimensions of
   the indexed set must be set by calling INIT_INDEXED_NAME, where
   DIM_LIST is a cell array of the dimensions.

   Examples:
       %% linear constraints with indexed named set 'R(i,j)'
       om.init_indexed_name('lin', 'R', {2, 3});
       for i = 1:2
         for j = 1:3
           om.add_lin_constraint('R', {i, j}, A{i,j}, ...);
         end
       end

   See also OPT_MODEL, ADD_VAR, ADD_LIN_CONSTRAINT, ADD_NLN_CONSTRAINT,
            ADD_QUAD_COST, ADD_NLN_COST and ADD_LEGACY_COST.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function om = init_indexed_name(om, set_type, name, dim_list)
0002 %INIT_INDEXED_NAME  Initializes the dimensions for an indexed named set.
0003 %
0004 %   OM.INIT_INDEXED_NAME(SET_TYPE, NAME, DIM_LIST)
0005 %
0006 %   Initializes the dimensions for an indexed named variable, constraint
0007 %   or cost set.
0008 %
0009 %   Variables, constraints and costs are referenced in OPT_MODEL in terms
0010 %   of named sets. The specific type of named set being referenced is
0011 %   given by SET_TYPE, with the following valid options:
0012 %       SET_TYPE = 'var'   => variable set
0013 %       SET_TYPE = 'lin'   => linear constraint set
0014 %       SET_TYPE = 'nle'   => nonlinear equality constraint set
0015 %       SET_TYPE = 'nli'   => nonlinear inequality constraint set
0016 %       SET_TYPE = 'cost'  => cost set
0017 %
0018 %   Indexed Named Sets
0019 %
0020 %   A variable, constraint or cost set can be identified by a single NAME,
0021 %   such as 'Pmismatch', or by a name that is indexed by one or more indices,
0022 %   such as 'Pmismatch(3,4)'. For an indexed named set, before adding the
0023 %   indexed variable, constraint or cost sets themselves, the dimensions of
0024 %   the indexed set must be set by calling INIT_INDEXED_NAME, where
0025 %   DIM_LIST is a cell array of the dimensions.
0026 %
0027 %   Examples:
0028 %       %% linear constraints with indexed named set 'R(i,j)'
0029 %       om.init_indexed_name('lin', 'R', {2, 3});
0030 %       for i = 1:2
0031 %         for j = 1:3
0032 %           om.add_lin_constraint('R', {i, j}, A{i,j}, ...);
0033 %         end
0034 %       end
0035 %
0036 %   See also OPT_MODEL, ADD_VAR, ADD_LIN_CONSTRAINT, ADD_NLN_CONSTRAINT,
0037 %            ADD_QUAD_COST, ADD_NLN_COST and ADD_LEGACY_COST.
0038 
0039 %   MATPOWER
0040 %   Copyright (c) 2008-2017, Power Systems Engineering Research Center (PSERC)
0041 %   by Ray Zimmerman, PSERC Cornell
0042 %
0043 %   This file is part of MATPOWER.
0044 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0045 %   See https://matpower.org for more info.
0046 
0047 %% check for valid type for named set
0048 st_label = om.valid_named_set_type(set_type);
0049 if st_label
0050     ff = set_type;
0051 else
0052     error('@opt_model/init_indexed_name: ''%s'' is not a valid SET_TYPE, must be one of ''var'', ''lin'', ''nle'', ''nli'', ''cost''', set_type);
0053 end
0054 
0055 %% prevent duplicate name in set of specified type
0056 if isfield(om.(ff).idx.N, name)
0057     error('@opt_model/init_indexed_name: %s set named ''%s'' already exists', ...
0058         st_label, name);
0059 end
0060 
0061 %% use column vector if single dimension
0062 if length(dim_list) == 1
0063     dim_list = {dim_list{:}, 1};
0064 end
0065 
0066 %% add general info about this named set
0067 zero_vector = zeros(dim_list{:});
0068 empty_cell  = cell(dim_list{:});
0069 om.(ff).idx.i1.(name)    = zero_vector; %% starting index
0070 om.(ff).idx.iN.(name)    = zero_vector; %% ending index
0071 om.(ff).idx.N.(name)     = zero_vector; %% number of vars/constraints/costs
0072 
0073 %% add type-specific info about this named set
0074 switch ff
0075     case 'var'          %% variable set
0076         om.var.data.v0.(name)   = empty_cell;   %% initial value
0077         om.var.data.vl.(name)   = empty_cell;   %% lower bound
0078         om.var.data.vu.(name)   = empty_cell;   %% upper bound
0079         om.var.data.vt.(name)   = empty_cell;   %% variable type
0080     case 'lin'          %% linear constraint set
0081         om.lin.data.A.(name)   = empty_cell;
0082         om.lin.data.l.(name)   = empty_cell;
0083         om.lin.data.u.(name)   = empty_cell;
0084         om.lin.data.vs.(name)  = empty_cell;
0085     case {'nle', 'nli'} %% nonlinear constraint set
0086         om.(ff).data.fcn.(name) = empty_cell;
0087         om.(ff).data.hess.(name)= empty_cell;
0088         om.(ff).data.vs.(name)  = empty_cell;
0089     case 'cost'         %% cost set
0090         om.cost.data.N.(name)   = empty_cell;
0091         om.cost.data.Cw.(name)  = empty_cell;
0092         om.cost.data.vs.(name)  = empty_cell;
0093 end

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005