Home > matpower5.0 > @opt_model > opt_model.m

opt_model

PURPOSE ^

OPT_MODEL Constructor for optimization model class.

SYNOPSIS ^

function om = opt_model(s)

DESCRIPTION ^

OPT_MODEL  Constructor for optimization model class.
   OM = OPT_MODEL
   OM = OPT_MODEL(S)

   This class implements the optimization model object used to encapsulate
   a given optimization problem formulation. It allows for access to
   optimization variables, constraints and costs in named blocks, keeping
   track of the ordering and indexing of the blocks as variables,
   constraints and costs are added to the problem.

   Below are the list of available methods for use with the Opt Model class.
   Please see the help on each individual method for more details:

   Modify the OPF formulation by adding named blocks of constraints, costs
   or variables:
       add_constraints
       add_costs
       add_vars

   Return the number of linear constraints, nonlinear constraints,
   variables or cost rows, optionally for a single named block:
       getN

   Return the intial values and bounds for optimization variables:
       get_v

   Build and return full set of linear constraints:
       linear_constraints

   Return index structure for variables, linear and nonlinear constraints
   and costs:
       get_idx

   Build and return cost parameters and evaluate user-defined costs:
       build_cost_params
       get_cost_params
       compute_cost

   Save/retreive user data in the model object:
       userdata

   Display the object (called automatically when you omit the semicolon
   at the command-line):
       display

   Return the value of an individual field:
       get

   Indentify variable, constraint or cost row indices:
       describe_idx

   The following is the structure of the data in the OPF model object.
   Each field of .idx or .data is a struct whose field names are the names
   of the corresponding blocks of vars, constraints or costs (found in
   order in the corresponding .order field). The description next to these
   fields gives the meaning of the value for each named sub-field.
   E.g. om.var.data.v0.Pg contains a vector of initial values for the 'Pg'
   block of variables.

   om
       .var        - data for optimization variable sets that make up
                     the full optimization variable x
           .idx
               .i1 - starting index within x
               .iN - ending index within x
               .N  - number of elements in this variable set
           .N      - total number of elements in x
           .NS     - number of variable sets or named blocks
           .data   - bounds and initial value data
               .v0 - vector of initial values
               .vl - vector of lower bounds
               .vu - vector of upper bounds
           .order  - struct array of names/indices for variable
                     blocks in the order they appear in x
               .name   - name of the block, e.g. Pg
               .idx    - indices for name, {2,3} => Pg(2,3)
       .nln        - data for nonlinear constraints that make up the
                     full set of nonlinear constraints ghn(x)
           .idx
               .i1 - starting index within ghn(x)
               .iN - ending index within ghn(x)
               .N  - number of elements in this constraint set
           .N      - total number of elements in ghn(x)
           .NS     - number of nonlinear constraint sets or named blocks
           .order  - struct array of names/indices for nonlinear constraint
                     blocks in the order they appear in ghn(x)
               .name   - name of the block, e.g. Pmis
               .idx    - indices for name, {2,3} => Pmis(2,3)
       .lin        - data for linear constraints that make up the
                     full set of linear constraints ghl(x)
           .idx
               .i1 - starting index within ghl(x)
               .iN - ending index within ghl(x)
               .N  - number of elements in this constraint set
           .N      - total number of elements in ghl(x)
           .NS     - number of linear constraint sets or named blocks
           .data   - data for l <= A*xx <= u linear constraints
               .A  - sparse linear constraint matrix
               .l  - left hand side vector, bounding A*x below
               .u  - right hand side vector, bounding A*x above
               .vs - cell array of variable sets that define the xx for
                     this constraint block
           .order  - struct array of names/indices for linear constraint
                     blocks in the order they appear in ghl(x)
               .name   - name of the block, e.g. Pmis
               .idx    - indices for name, {2,3} => Pmis(2,3)
       .cost       - data for user-defined costs
           .idx
               .i1 - starting row index within full N matrix
               .iN - ending row index within full N matrix
               .N  - number of rows in this cost block in full N matrix
           .N      - total number of rows in full N matrix
           .NS     - number of cost blocks
           .data   - data for each user-defined cost block
               .N  - see help for ADD_COSTS for details
               .H  -               "
               .Cw -               "
               .dd -               "
               .rr -               "
               .kk -               "
               .mm -               "
               .vs - cell array of variable sets that define xx for this
                     cost block, where the N for this block multiplies xx
           .order  - struct array of names/indices for cost blocks in the
                     order they appear in the rows of the full N matrix
               .name   - name of the block, e.g. R
               .idx    - indices for name, {2,3} => R(2,3)
       .userdata   - any user defined data added via USERDATA
           .(user defined fields)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function om = opt_model(s)
0002 %OPT_MODEL  Constructor for optimization model class.
0003 %   OM = OPT_MODEL
0004 %   OM = OPT_MODEL(S)
0005 %
0006 %   This class implements the optimization model object used to encapsulate
0007 %   a given optimization problem formulation. It allows for access to
0008 %   optimization variables, constraints and costs in named blocks, keeping
0009 %   track of the ordering and indexing of the blocks as variables,
0010 %   constraints and costs are added to the problem.
0011 %
0012 %   Below are the list of available methods for use with the Opt Model class.
0013 %   Please see the help on each individual method for more details:
0014 %
0015 %   Modify the OPF formulation by adding named blocks of constraints, costs
0016 %   or variables:
0017 %       add_constraints
0018 %       add_costs
0019 %       add_vars
0020 %
0021 %   Return the number of linear constraints, nonlinear constraints,
0022 %   variables or cost rows, optionally for a single named block:
0023 %       getN
0024 %
0025 %   Return the intial values and bounds for optimization variables:
0026 %       get_v
0027 %
0028 %   Build and return full set of linear constraints:
0029 %       linear_constraints
0030 %
0031 %   Return index structure for variables, linear and nonlinear constraints
0032 %   and costs:
0033 %       get_idx
0034 %
0035 %   Build and return cost parameters and evaluate user-defined costs:
0036 %       build_cost_params
0037 %       get_cost_params
0038 %       compute_cost
0039 %
0040 %   Save/retreive user data in the model object:
0041 %       userdata
0042 %
0043 %   Display the object (called automatically when you omit the semicolon
0044 %   at the command-line):
0045 %       display
0046 %
0047 %   Return the value of an individual field:
0048 %       get
0049 %
0050 %   Indentify variable, constraint or cost row indices:
0051 %       describe_idx
0052 %
0053 %   The following is the structure of the data in the OPF model object.
0054 %   Each field of .idx or .data is a struct whose field names are the names
0055 %   of the corresponding blocks of vars, constraints or costs (found in
0056 %   order in the corresponding .order field). The description next to these
0057 %   fields gives the meaning of the value for each named sub-field.
0058 %   E.g. om.var.data.v0.Pg contains a vector of initial values for the 'Pg'
0059 %   block of variables.
0060 %
0061 %   om
0062 %       .var        - data for optimization variable sets that make up
0063 %                     the full optimization variable x
0064 %           .idx
0065 %               .i1 - starting index within x
0066 %               .iN - ending index within x
0067 %               .N  - number of elements in this variable set
0068 %           .N      - total number of elements in x
0069 %           .NS     - number of variable sets or named blocks
0070 %           .data   - bounds and initial value data
0071 %               .v0 - vector of initial values
0072 %               .vl - vector of lower bounds
0073 %               .vu - vector of upper bounds
0074 %           .order  - struct array of names/indices for variable
0075 %                     blocks in the order they appear in x
0076 %               .name   - name of the block, e.g. Pg
0077 %               .idx    - indices for name, {2,3} => Pg(2,3)
0078 %       .nln        - data for nonlinear constraints that make up the
0079 %                     full set of nonlinear constraints ghn(x)
0080 %           .idx
0081 %               .i1 - starting index within ghn(x)
0082 %               .iN - ending index within ghn(x)
0083 %               .N  - number of elements in this constraint set
0084 %           .N      - total number of elements in ghn(x)
0085 %           .NS     - number of nonlinear constraint sets or named blocks
0086 %           .order  - struct array of names/indices for nonlinear constraint
0087 %                     blocks in the order they appear in ghn(x)
0088 %               .name   - name of the block, e.g. Pmis
0089 %               .idx    - indices for name, {2,3} => Pmis(2,3)
0090 %       .lin        - data for linear constraints that make up the
0091 %                     full set of linear constraints ghl(x)
0092 %           .idx
0093 %               .i1 - starting index within ghl(x)
0094 %               .iN - ending index within ghl(x)
0095 %               .N  - number of elements in this constraint set
0096 %           .N      - total number of elements in ghl(x)
0097 %           .NS     - number of linear constraint sets or named blocks
0098 %           .data   - data for l <= A*xx <= u linear constraints
0099 %               .A  - sparse linear constraint matrix
0100 %               .l  - left hand side vector, bounding A*x below
0101 %               .u  - right hand side vector, bounding A*x above
0102 %               .vs - cell array of variable sets that define the xx for
0103 %                     this constraint block
0104 %           .order  - struct array of names/indices for linear constraint
0105 %                     blocks in the order they appear in ghl(x)
0106 %               .name   - name of the block, e.g. Pmis
0107 %               .idx    - indices for name, {2,3} => Pmis(2,3)
0108 %       .cost       - data for user-defined costs
0109 %           .idx
0110 %               .i1 - starting row index within full N matrix
0111 %               .iN - ending row index within full N matrix
0112 %               .N  - number of rows in this cost block in full N matrix
0113 %           .N      - total number of rows in full N matrix
0114 %           .NS     - number of cost blocks
0115 %           .data   - data for each user-defined cost block
0116 %               .N  - see help for ADD_COSTS for details
0117 %               .H  -               "
0118 %               .Cw -               "
0119 %               .dd -               "
0120 %               .rr -               "
0121 %               .kk -               "
0122 %               .mm -               "
0123 %               .vs - cell array of variable sets that define xx for this
0124 %                     cost block, where the N for this block multiplies xx
0125 %           .order  - struct array of names/indices for cost blocks in the
0126 %                     order they appear in the rows of the full N matrix
0127 %               .name   - name of the block, e.g. R
0128 %               .idx    - indices for name, {2,3} => R(2,3)
0129 %       .userdata   - any user defined data added via USERDATA
0130 %           .(user defined fields)
0131 
0132 %   MATPOWER
0133 %   $Id: opt_model.m 2208 2013-10-11 20:19:14Z ray $
0134 %   by Ray Zimmerman, PSERC Cornell
0135 %   Copyright (c) 2008-2012 by Power System Engineering Research Center (PSERC)
0136 %
0137 %   This file is part of MATPOWER.
0138 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0139 %
0140 %   MATPOWER is free software: you can redistribute it and/or modify
0141 %   it under the terms of the GNU General Public License as published
0142 %   by the Free Software Foundation, either version 3 of the License,
0143 %   or (at your option) any later version.
0144 %
0145 %   MATPOWER is distributed in the hope that it will be useful,
0146 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0147 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0148 %   GNU General Public License for more details.
0149 %
0150 %   You should have received a copy of the GNU General Public License
0151 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0152 %
0153 %   Additional permission under GNU GPL version 3 section 7
0154 %
0155 %   If you modify MATPOWER, or any covered work, to interface with
0156 %   other modules (such as MATLAB code and MEX-files) available in a
0157 %   MATLAB(R) or comparable environment containing parts covered
0158 %   under other licensing terms, the licensors of MATPOWER grant
0159 %   you additional permission to convey the resulting work.
0160 
0161 es = struct();
0162 if nargin == 0
0163     om.var.idx.i1 = es;
0164     om.var.idx.iN = es;
0165     om.var.idx.N = es;
0166     om.var.N = 0;
0167     om.var.NS = 0;
0168     om.var.order = struct('name', [], 'idx', []);
0169     om.var.data.v0 = es;
0170     om.var.data.vl = es;
0171     om.var.data.vu = es;
0172 
0173     om.nln.idx.i1 = es;
0174     om.nln.idx.iN = es;
0175     om.nln.idx.N = es;
0176     om.nln.N = 0;
0177     om.nln.NS = 0;
0178     om.nln.order = struct('name', [], 'idx', []);
0179 
0180     om.lin.idx.i1 = es;
0181     om.lin.idx.iN = es;
0182     om.lin.idx.N = es;
0183     om.lin.N = 0;
0184     om.lin.NS = 0;
0185     om.lin.order = struct('name', [], 'idx', []);
0186     om.lin.data.A = es;
0187     om.lin.data.l = es;
0188     om.lin.data.u = es;
0189     om.lin.data.vs = es;
0190     
0191     om.cost.idx.i1 = es;
0192     om.cost.idx.iN = es;
0193     om.cost.idx.N = es;
0194     om.cost.N = 0;
0195     om.cost.NS = 0;
0196     om.cost.order = struct('name', [], 'idx', []);
0197     om.cost.data.N = es;
0198     om.cost.data.H = es;
0199     om.cost.data.Cw = es;
0200     om.cost.data.dd = es;
0201     om.cost.data.rh = es;
0202     om.cost.data.kk = es;
0203     om.cost.data.mm = es;
0204     om.cost.data.vs = es;
0205     om.cost.params = es;
0206     
0207     om.userdata = es;
0208 
0209     om = class(om, 'opt_model');
0210 elseif isa(s,'opt_model') 
0211     om = s;
0212 elseif isfield(s, 'var') && isfield(s, 'nln') && ...
0213         isfield(s, 'lin') && isfield(s, 'cost') && isfield(s, 'userdata')
0214     om = class(s, 'opt_model');
0215 else
0216     error('@opt_model/opt_model: input must be an OPT_MODEL object or struct with corresponding fields');
0217 end

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005