Home > matpower7.1 > lib > @opf_model > add_named_set.m

add_named_set

PURPOSE ^

ADD_NAMED_SET Adds a named set of variables/constraints/costs to the model.

SYNOPSIS ^

function om = add_named_set(om, set_type, name, idx, N, varargin)

DESCRIPTION ^

ADD_NAMED_SET  Adds a named set of variables/constraints/costs to the model.

   -----  PRIVATE METHOD  -----

   This method is intended to be a private method, used internally by
   the public methods ADD_VAR, ADD_LIN_CONSTRAINT, ADD_NLN_CONSTRAINT
   ADD_QUAD_COST, ADD_NLN_COST and ADD_LEGACY_COST.

   Variable Set
       OM.ADD_NAMED_SET('var', NAME, IDX_LIST, N, V0, VL, VU, VT);

   Linear Constraint Set
       OM.ADD_NAMED_SET('lin', NAME, IDX_LIST, N, A, L, U, VARSETS);

   Nonlinear Inequality Constraint Set
       OM.ADD_NAMED_SET('nle', NAME, IDX_LIST, N, FCN, HESS, COMPUTED_BY, VARSETS);

   Nonlinear Inequality Constraint Set
       OM.ADD_NAMED_SET('nli', NAME, IDX_LIST, N, FCN, HESS, COMPUTED_BY, VARSETS);

   Quadratic Cost Set
       OM.ADD_NAMED_SET('qdc', NAME, IDX_LIST, N, CP, VARSETS);

   General Nonlinear Cost Set
       OM.ADD_NAMED_SET('nlc', NAME, IDX_LIST, N, FCN, VARSETS);

   Legacy Cost Set
       OM.ADD_NAMED_SET('cost', NAME, IDX_LIST, N, CP, VARSETS);

   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 = add_named_set(om, set_type, name, idx, N, varargin)
0002 %ADD_NAMED_SET  Adds a named set of variables/constraints/costs to the model.
0003 %
0004 %   -----  PRIVATE METHOD  -----
0005 %
0006 %   This method is intended to be a private method, used internally by
0007 %   the public methods ADD_VAR, ADD_LIN_CONSTRAINT, ADD_NLN_CONSTRAINT
0008 %   ADD_QUAD_COST, ADD_NLN_COST and ADD_LEGACY_COST.
0009 %
0010 %   Variable Set
0011 %       OM.ADD_NAMED_SET('var', NAME, IDX_LIST, N, V0, VL, VU, VT);
0012 %
0013 %   Linear Constraint Set
0014 %       OM.ADD_NAMED_SET('lin', NAME, IDX_LIST, N, A, L, U, VARSETS);
0015 %
0016 %   Nonlinear Inequality Constraint Set
0017 %       OM.ADD_NAMED_SET('nle', NAME, IDX_LIST, N, FCN, HESS, COMPUTED_BY, VARSETS);
0018 %
0019 %   Nonlinear Inequality Constraint Set
0020 %       OM.ADD_NAMED_SET('nli', NAME, IDX_LIST, N, FCN, HESS, COMPUTED_BY, VARSETS);
0021 %
0022 %   Quadratic Cost Set
0023 %       OM.ADD_NAMED_SET('qdc', NAME, IDX_LIST, N, CP, VARSETS);
0024 %
0025 %   General Nonlinear Cost Set
0026 %       OM.ADD_NAMED_SET('nlc', NAME, IDX_LIST, N, FCN, VARSETS);
0027 %
0028 %   Legacy Cost Set
0029 %       OM.ADD_NAMED_SET('cost', NAME, IDX_LIST, N, CP, VARSETS);
0030 %
0031 %   See also OPT_MODEL, ADD_VAR, ADD_LIN_CONSTRAINT, ADD_NLN_CONSTRAINT
0032 %            ADD_QUAD_COST, ADD_NLN_COST and ADD_LEGACY_COST.
0033 
0034 %   MATPOWER
0035 %   Copyright (c) 2008-2020, Power Systems Engineering Research Center (PSERC)
0036 %   by Ray Zimmerman, PSERC Cornell
0037 %
0038 %   This file is part of MATPOWER.
0039 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0040 %   See https://matpower.org for more info.
0041 
0042 %% call parent method (also checks for valid type for named set)
0043 om = add_named_set@opt_model(om, set_type, name, idx, N, varargin{:});
0044 
0045 switch set_type
0046     case 'cost'         %% cost set
0047         %% add type-specific data for named set
0048         om_ff = om.cost;
0049         om.cost = [];
0050 
0051         [cp, varsets] = deal(varargin{:});
0052 
0053         if isempty(idx)
0054             om_ff.data.N.(name)  = cp.N;
0055             om_ff.data.Cw.(name) = cp.Cw;
0056             om_ff.data.vs.(name) = varsets;
0057             if isfield(cp, 'H')
0058                 om_ff.data.H.(name)  = cp.H;
0059             end
0060             if isfield(cp, 'dd')
0061                 om_ff.data.dd.(name) = cp.dd;
0062             end
0063             if isfield(cp, 'rh')
0064                 om_ff.data.rh.(name) = cp.rh;
0065             end
0066             if isfield(cp, 'kk')
0067                 om_ff.data.kk.(name) = cp.kk;
0068             end
0069             if isfield(cp, 'mm')
0070                 om_ff.data.mm.(name) = cp.mm;
0071             end
0072         else
0073             %% calls to substruct() are relatively expensive, so we pre-build the
0074             %% struct for addressing cell array fields
0075             %% sc = substruct('.', name, '{}', idx);
0076             sc = struct('type', {'.', '{}'}, 'subs', {name, idx});  %% cell array field
0077 
0078             om_ff.data.N  = subsasgn(om_ff.data.N,  sc, cp.N);
0079             om_ff.data.Cw = subsasgn(om_ff.data.Cw, sc, cp.Cw);
0080             om_ff.data.vs = subsasgn(om_ff.data.vs, sc, varsets);
0081             if isfield(cp, 'H')
0082                 om_ff.data.H = subsasgn(om_ff.data.H, sc, cp.H);
0083             end
0084             if isfield(cp, 'dd')
0085                 om_ff.data.dd = subsasgn(om_ff.data.dd, sc, cp.dd);
0086             end
0087             if isfield(cp, 'rh')
0088                 om_ff.data.rh = subsasgn(om_ff.data.rh, sc, cp.rh);
0089             end
0090             if isfield(cp, 'kk')
0091                 om_ff.data.kk = subsasgn(om_ff.data.kk, sc, cp.kk);
0092             end
0093             if isfield(cp, 'mm')
0094                 om_ff.data.mm = subsasgn(om_ff.data.mm, sc, cp.mm);
0095             end
0096         end
0097         if ~isempty(om_ff.params)       %% clear cache of aggregated params
0098             om_ff.params = [];
0099         end
0100         om.cost = om_ff;
0101 end

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