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, bounds and type for optimization variables: getv 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 .vt - scalar or vector of variable types 'C' = continuous 'I' = integer 'B' = binary .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)
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, bounds and type for optimization variables: 0026 % getv 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 % .vt - scalar or vector of variable types 0075 % 'C' = continuous 0076 % 'I' = integer 0077 % 'B' = binary 0078 % .order - struct array of names/indices for variable 0079 % blocks in the order they appear in x 0080 % .name - name of the block, e.g. Pg 0081 % .idx - indices for name, {2,3} => Pg(2,3) 0082 % .nln - data for nonlinear constraints that make up the 0083 % full set of nonlinear constraints ghn(x) 0084 % .idx 0085 % .i1 - starting index within ghn(x) 0086 % .iN - ending index within ghn(x) 0087 % .N - number of elements in this constraint set 0088 % .N - total number of elements in ghn(x) 0089 % .NS - number of nonlinear constraint sets or named blocks 0090 % .order - struct array of names/indices for nonlinear constraint 0091 % blocks in the order they appear in ghn(x) 0092 % .name - name of the block, e.g. Pmis 0093 % .idx - indices for name, {2,3} => Pmis(2,3) 0094 % .lin - data for linear constraints that make up the 0095 % full set of linear constraints ghl(x) 0096 % .idx 0097 % .i1 - starting index within ghl(x) 0098 % .iN - ending index within ghl(x) 0099 % .N - number of elements in this constraint set 0100 % .N - total number of elements in ghl(x) 0101 % .NS - number of linear constraint sets or named blocks 0102 % .data - data for l <= A*xx <= u linear constraints 0103 % .A - sparse linear constraint matrix 0104 % .l - left hand side vector, bounding A*x below 0105 % .u - right hand side vector, bounding A*x above 0106 % .vs - cell array of variable sets that define the xx for 0107 % this constraint block 0108 % .order - struct array of names/indices for linear constraint 0109 % blocks in the order they appear in ghl(x) 0110 % .name - name of the block, e.g. Pmis 0111 % .idx - indices for name, {2,3} => Pmis(2,3) 0112 % .cost - data for user-defined costs 0113 % .idx 0114 % .i1 - starting row index within full N matrix 0115 % .iN - ending row index within full N matrix 0116 % .N - number of rows in this cost block in full N matrix 0117 % .N - total number of rows in full N matrix 0118 % .NS - number of cost blocks 0119 % .data - data for each user-defined cost block 0120 % .N - see help for ADD_COSTS for details 0121 % .H - " 0122 % .Cw - " 0123 % .dd - " 0124 % .rr - " 0125 % .kk - " 0126 % .mm - " 0127 % .vs - cell array of variable sets that define xx for this 0128 % cost block, where the N for this block multiplies xx 0129 % .order - struct array of names/indices for cost blocks in the 0130 % order they appear in the rows of the full N matrix 0131 % .name - name of the block, e.g. R 0132 % .idx - indices for name, {2,3} => R(2,3) 0133 % .userdata - any user defined data added via USERDATA 0134 % .(user defined fields) 0135 0136 % MATPOWER 0137 % Copyright (c) 2008-2016, Power Systems Engineering Research Center (PSERC) 0138 % by Ray Zimmerman, PSERC Cornell 0139 % 0140 % This file is part of MATPOWER. 0141 % Covered by the 3-clause BSD License (see LICENSE file for details). 0142 % See http://www.pserc.cornell.edu/matpower/ for more info. 0143 0144 es = struct(); 0145 if nargin == 0 0146 om.var.idx.i1 = es; 0147 om.var.idx.iN = es; 0148 om.var.idx.N = es; 0149 om.var.N = 0; 0150 om.var.NS = 0; 0151 om.var.order = struct('name', [], 'idx', []); 0152 om.var.data.v0 = es; 0153 om.var.data.vl = es; 0154 om.var.data.vu = es; 0155 om.var.data.vt = es; 0156 0157 om.nln.idx.i1 = es; 0158 om.nln.idx.iN = es; 0159 om.nln.idx.N = es; 0160 om.nln.N = 0; 0161 om.nln.NS = 0; 0162 om.nln.order = struct('name', [], 'idx', []); 0163 0164 om.lin.idx.i1 = es; 0165 om.lin.idx.iN = es; 0166 om.lin.idx.N = es; 0167 om.lin.N = 0; 0168 om.lin.NS = 0; 0169 om.lin.order = struct('name', [], 'idx', []); 0170 om.lin.data.A = es; 0171 om.lin.data.l = es; 0172 om.lin.data.u = es; 0173 om.lin.data.vs = es; 0174 0175 om.cost.idx.i1 = es; 0176 om.cost.idx.iN = es; 0177 om.cost.idx.N = es; 0178 om.cost.N = 0; 0179 om.cost.NS = 0; 0180 om.cost.order = struct('name', [], 'idx', []); 0181 om.cost.data.N = es; 0182 om.cost.data.H = es; 0183 om.cost.data.Cw = es; 0184 om.cost.data.dd = es; 0185 om.cost.data.rh = es; 0186 om.cost.data.kk = es; 0187 om.cost.data.mm = es; 0188 om.cost.data.vs = es; 0189 om.cost.params = es; 0190 0191 om.userdata = es; 0192 0193 om = class(om, 'opt_model'); 0194 elseif isa(s,'opt_model') 0195 om = s; 0196 elseif isfield(s, 'var') && isfield(s, 'nln') && ... 0197 isfield(s, 'lin') && isfield(s, 'cost') && isfield(s, 'userdata') 0198 om = class(s, 'opt_model'); 0199 else 0200 error('@opt_model/opt_model: input must be an OPT_MODEL object or struct with corresponding fields'); 0201 end