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 = 'qdc' => quadratic cost set SET_TYPE = 'nlc' => nonlinear 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 and ADD_NLN_COST.
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 = 'qdc' => quadratic cost set 0017 % SET_TYPE = 'nlc' => nonlinear cost set 0018 % 0019 % Indexed Named Sets 0020 % 0021 % A variable, constraint or cost set can be identified by a single NAME, 0022 % such as 'Pmismatch', or by a name that is indexed by one or more indices, 0023 % such as 'Pmismatch(3,4)'. For an indexed named set, before adding the 0024 % indexed variable, constraint or cost sets themselves, the dimensions of 0025 % the indexed set must be set by calling INIT_INDEXED_NAME, where 0026 % DIM_LIST is a cell array of the dimensions. 0027 % 0028 % Examples: 0029 % %% linear constraints with indexed named set 'R(i,j)' 0030 % om.init_indexed_name('lin', 'R', {2, 3}); 0031 % for i = 1:2 0032 % for j = 1:3 0033 % om.add_lin_constraint('R', {i, j}, A{i,j}, ...); 0034 % end 0035 % end 0036 % 0037 % See also OPT_MODEL, ADD_VAR, ADD_LIN_CONSTRAINT, ADD_NLN_CONSTRAINT, 0038 % ADD_QUAD_COST and ADD_NLN_COST. 0039 0040 % MP-Opt-Model 0041 % Copyright (c) 2008-2020, Power Systems Engineering Research Center (PSERC) 0042 % by Ray Zimmerman, PSERC Cornell 0043 % 0044 % This file is part of MP-Opt-Model. 0045 % Covered by the 3-clause BSD License (see LICENSE file for details). 0046 % See https://github.com/MATPOWER/mp-opt-model for more info. 0047 0048 %% use column vector if single dimension 0049 if length(dim_list) == 1 0050 dim_list = {dim_list{:}, 1}; 0051 end 0052 0053 %% call parent method (also checks for valid type for named set) 0054 om = init_indexed_name@mp_idx_manager(om, set_type, name, dim_list); 0055 0056 %% add type-specific info about this named set 0057 empty_cell = cell(dim_list{:}); 0058 switch set_type 0059 case 'var' %% variable set 0060 om.var.data.v0.(name) = empty_cell; %% initial value 0061 om.var.data.vl.(name) = empty_cell; %% lower bound 0062 om.var.data.vu.(name) = empty_cell; %% upper bound 0063 om.var.data.vt.(name) = empty_cell; %% variable type 0064 case 'lin' %% linear constraint set 0065 om.lin.data.A.(name) = empty_cell; 0066 om.lin.data.l.(name) = empty_cell; 0067 om.lin.data.u.(name) = empty_cell; 0068 om.lin.data.vs.(name) = empty_cell; 0069 case 'nle' %% nonlinear equality constraint set 0070 om.nle.data.fcn.(name) = empty_cell; 0071 om.nle.data.hess.(name) = empty_cell; 0072 om.nle.data.vs.(name) = empty_cell; 0073 case 'nli' %% nonlinear inequality constraint set 0074 om.nli.data.fcn.(name) = empty_cell; 0075 om.nli.data.hess.(name) = empty_cell; 0076 om.nli.data.vs.(name) = empty_cell; 0077 case 'nlc' %% nonlinear cost set 0078 om.nlc.data.fcn.(name) = empty_cell; 0079 om.nlc.data.vs.(name) = empty_cell; 0080 case 'qdc' %% quadratic cost set 0081 om.qdc.data.Q.(name) = empty_cell; 0082 om.qdc.data.c.(name) = empty_cell; 0083 om.qdc.data.k.(name) = empty_cell; 0084 om.qdc.data.vs.(name) = empty_cell; 0085 end