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

opf_model

PURPOSE ^

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 classdef opf_model < opt_model
0002 %OPF_MODEL  Constructor for OPF model class.
0003 %   OM = OPF_MODEL(MPC)
0004 %
0005 %   This class implements the OPF model object used to encapsulate
0006 %   a given OPF problem formulation. It allows for access to optimization
0007 %   variables, constraints and costs in named blocks, keeping track of the
0008 %   ordering and indexing of the blocks as variables, constraints and costs
0009 %   are added to the problem.
0010 %
0011 %   This class is a sub-class of OPT_MODEL that adds the 'mpc'
0012 %   field for storing the MATPOWER case struct used to build the object
0013 %   along with the get_mpc() method.
0014 %
0015 %   It also add the 'cost' field and the following three methods for
0016 %   implementing the legacy user-defined OPF costs:
0017 %       add_legacy_cost
0018 %       params_legacy_cost
0019 %       eval_legacy_cost
0020 %
0021 %   The following deprecated OPT_MODEL methods, from an older OPF_MODEL
0022 %   implementation have also been moved back to OPF_MODEL:
0023 %       add_costs (use add_quad_cost, add_nln_cost or add_legacy_cost)
0024 %       add_constraints (use add_lin_constraint or add_nln_constraint)
0025 %       add_vars (use add_var)
0026 %       getv (use params_var)
0027 %       linear_constraints (use params_lin_constraint)
0028 %       build_cost_params (use params_legacy_cost)
0029 %       compute_cost (use eval_legacy_cost)
0030 %
0031 %   The following is the structure of the data in the OPF model object.
0032 %
0033 %   om
0034 %       <opt_model fields> - see OPT_MODEL for details
0035 %       .cost       - data for legacy user-defined costs
0036 %           .idx
0037 %               .i1 - starting row index within full N matrix
0038 %               .iN - ending row index within full N matrix
0039 %               .N  - number of rows in this cost block in full N matrix
0040 %           .N      - total number of rows in full N matrix
0041 %           .NS     - number of cost blocks
0042 %           .data   - data for each user-defined cost block
0043 %               .N  - see help for ADD_LEGACY_COST for details
0044 %               .H  -               "
0045 %               .Cw -               "
0046 %               .dd -               "
0047 %               .rr -               "
0048 %               .kk -               "
0049 %               .mm -               "
0050 %               .vs - cell array of variable sets that define xx for this
0051 %                     cost block, where the N for this block multiplies xx
0052 %           .order  - struct array of names/indices for cost blocks in the
0053 %                     order they appear in the rows of the full N matrix
0054 %               .name   - name of the block, e.g. R
0055 %               .idx    - indices for name, {2,3} => R(2,3)
0056 %       .mpc        - MATPOWER case struct used to create this model object
0057 %           .baseMVA
0058 %           .bus
0059 %           .branch
0060 %           .gen
0061 %           .gencost
0062 %           .A  (if present, must have l, u)
0063 %           .l
0064 %           .u
0065 %           .N  (if present, must have fparm, H, Cw)
0066 %           .fparm
0067 %           .H
0068 %           .Cw
0069 %
0070 %   See also OPT_MODEL.
0071 
0072 %   MATPOWER
0073 %   Copyright (c) 2008-2020, Power Systems Engineering Research Center (PSERC)
0074 %   by Ray Zimmerman, PSERC Cornell
0075 %
0076 %   This file is part of MATPOWER.
0077 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0078 %   See https://matpower.org for more info.
0079 
0080     properties
0081         cost = [];
0082         mpc = struct();
0083     end     %% properties
0084 
0085     methods
0086         %% constructor
0087         function om = opf_model(mpc)
0088             args = {};
0089             have_mpc = 0;
0090             if nargin > 0
0091                 if isa(mpc, 'opf_model')
0092                     args = { mpc };
0093                 elseif isstruct(mpc)
0094                     have_mpc = 1;
0095                 end
0096             end
0097 
0098             %% call parent constructor
0099             om@opt_model(args{:});
0100 
0101             if isempty(om.cost) && strcmp(class(om), 'opf_model')
0102                 %% skip if it's a sub-class or being constructed from existing object
0103                 om.init_set_types();    %% Should be called in mp_idx_manager
0104                                         %% constructor, if not for:
0105                                         %% https://savannah.gnu.org/bugs/?52614
0106             end
0107 
0108             if have_mpc
0109                 om.mpc = mpc;
0110             end
0111         end
0112 
0113         function om = def_set_types(om)
0114             om.set_types = struct(...
0115                     'var', 'variable', ...
0116                     'lin', 'linear constraint', ...
0117                     'nle', 'nonlinear equality constraint', ...
0118                     'nli', 'nonlinear inequality constraint', ...
0119                     'qdc', 'quadratic cost', ...
0120                     'nlc', 'general nonlinear cost', ...
0121                     'cost', 'legacy cost' ...
0122                 );
0123         end
0124 
0125         function om = init_set_types(om)
0126             %% call parent to create base data structures for each type
0127             init_set_types@opt_model(om);
0128 
0129             %% finish initializing data structures for each type
0130             es = struct();  %% empty struct
0131             om.cost.data = struct( ...
0132                 'N', es, ...
0133                 'H', es, ...
0134                 'Cw', es, ...
0135                 'dd', es, ...
0136                 'rh', es, ...
0137                 'kk', es, ...
0138                 'mm', es, ...
0139                 'vs', es );
0140             om.cost.params = [];
0141         end
0142     end     %% methods
0143 end         %% classdef

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