Home > matpower7.1 > mp-opt-model > lib > @mp_idx_manager > init_indexed_name.m

init_indexed_name

PURPOSE ^

INIT_INDEXED_NAME Initializes the dimensions for an indexed named set.

SYNOPSIS ^

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

DESCRIPTION ^

INIT_INDEXED_NAME  Initializes the dimensions for an indexed named set.

   OBJ.INIT_INDEXED_NAME(SET_TYPE, NAME, DIM_LIST)

   Initializes the dimensions for an indexed named set.

   For example, variables and linear constraints could be referenced in
   terms of named sets, where the 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

   Indexed Named Sets

   In this case a variable or constraint 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 or constraint 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)'
       obj.init_indexed_name('lin', 'R', {2, 3});
       for i = 1:2
         for j = 1:3
           obj.add_lin_constraint('R', {i, j}, A{i,j}, ...);
         end
       end

   See also OPT_MODEL, and its methods INIT_INDEXED_NAME, ADD_VAR,
           ADD_LIN_CONSTRAINT, ADD_NLN_CONSTRAINT, ADD_QUAD_COST and
           ADD_NLN_COST.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function obj = init_indexed_name(obj, set_type, name, dim_list)
0002 %INIT_INDEXED_NAME  Initializes the dimensions for an indexed named set.
0003 %
0004 %   OBJ.INIT_INDEXED_NAME(SET_TYPE, NAME, DIM_LIST)
0005 %
0006 %   Initializes the dimensions for an indexed named set.
0007 %
0008 %   For example, variables and linear constraints could be referenced in
0009 %   terms of named sets, where the type of named set being referenced is
0010 %   given by SET_TYPE, with the following valid options:
0011 %       SET_TYPE = 'var'   => variable set
0012 %       SET_TYPE = 'lin'   => linear constraint set
0013 %
0014 %   Indexed Named Sets
0015 %
0016 %   In this case a variable or constraint set can be identified by a single
0017 %   NAME, such as 'Pmismatch', or by a name that is indexed by one or more
0018 %   indices, such as 'Pmismatch(3,4)'. For an indexed named set, before adding
0019 %   the indexed variable or constraint sets themselves, the dimensions of
0020 %   the indexed set must be set by calling INIT_INDEXED_NAME, where DIM_LIST
0021 %   is a cell array of the dimensions.
0022 %
0023 %   Examples:
0024 %       %% linear constraints with indexed named set 'R(i,j)'
0025 %       obj.init_indexed_name('lin', 'R', {2, 3});
0026 %       for i = 1:2
0027 %         for j = 1:3
0028 %           obj.add_lin_constraint('R', {i, j}, A{i,j}, ...);
0029 %         end
0030 %       end
0031 %
0032 %   See also OPT_MODEL, and its methods INIT_INDEXED_NAME, ADD_VAR,
0033 %           ADD_LIN_CONSTRAINT, ADD_NLN_CONSTRAINT, ADD_QUAD_COST and
0034 %           ADD_NLN_COST.
0035 
0036 %   MP-Opt-Model
0037 %   Copyright (c) 2008-2020, Power Systems Engineering Research Center (PSERC)
0038 %   by Ray Zimmerman, PSERC Cornell
0039 %
0040 %   This file is part of MP-Opt-Model.
0041 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0042 %   See https://github.com/MATPOWER/mp-opt-model for more info.
0043 
0044 %% check for valid type for named set
0045 st_label = obj.valid_named_set_type(set_type);
0046 if st_label
0047     ff = set_type;
0048 else
0049     ff = fieldnames(obj.set_types);
0050     stypes = sprintf('\n  ''%s''', ff{:});
0051     error('@mp_idx_manager/init_indexed_name: ''%s'' is not a valid SET_TYPE, must be one of the following:%s', set_type, stypes);
0052 end
0053 
0054 %% prevent duplicate name in set of specified type
0055 if isfield(obj.(ff).idx.N, name)
0056     error('@mp_idx_manager/init_indexed_name: %s set named ''%s'' already exists', ...
0057         st_label, name);
0058 end
0059 
0060 %% use column vector if single dimension
0061 if length(dim_list) == 1
0062     dim_list = {dim_list{:}, 1};
0063 end
0064 
0065 %% add general info about this named set
0066 zero_vector = zeros(dim_list{:});
0067 obj.(ff).idx.i1.(name)  = zero_vector;  %% starting index
0068 obj.(ff).idx.iN.(name)  = zero_vector;  %% ending index
0069 obj.(ff).idx.N.(name)   = zero_vector;  %% number of vars/constraints/costs

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005