0001 function om = add_named_set(om, set_type, name, idx, N, varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 om = add_named_set@mp_idx_manager(om, set_type, name, idx, N, varargin{:});
0038
0039 if ~isempty(idx)
0040
0041
0042
0043 sc = struct('type', {'.', '{}'}, 'subs', {name, idx});
0044 end
0045
0046
0047 om_ff = om.(set_type);
0048 om.(set_type) = [];
0049 switch set_type
0050 case 'var'
0051 [v0, vl, vu, vt] = deal(varargin{:});
0052 if isempty(idx)
0053 om_ff.data.v0.(name) = v0;
0054 om_ff.data.vl.(name) = vl;
0055 om_ff.data.vu.(name) = vu;
0056 om_ff.data.vt.(name) = vt;
0057 else
0058 om_ff.data.v0 = subsasgn(om_ff.data.v0, sc, v0);
0059 om_ff.data.vl = subsasgn(om_ff.data.vl, sc, vl);
0060 om_ff.data.vu = subsasgn(om_ff.data.vu, sc, vu);
0061 om_ff.data.vt = subsasgn(om_ff.data.vt, sc, vt);
0062 end
0063 case 'lin'
0064 [A, l, u, varsets] = deal(varargin{:});
0065 if isempty(idx)
0066 om_ff.data.A.(name) = A;
0067 om_ff.data.l.(name) = l;
0068 om_ff.data.u.(name) = u;
0069 om_ff.data.vs.(name) = varsets;
0070 else
0071 om_ff.data.A = subsasgn(om_ff.data.A, sc, A);
0072 om_ff.data.l = subsasgn(om_ff.data.l, sc, l);
0073 om_ff.data.u = subsasgn(om_ff.data.u, sc, u);
0074 om_ff.data.vs = subsasgn(om_ff.data.vs, sc, varsets);
0075 end
0076 if ~isempty(om_ff.params)
0077 om_ff.params = [];
0078 end
0079 case {'nle', 'nli'}
0080 [fcn, hess, computed_by, varsets] = deal(varargin{:});
0081 if isempty(idx)
0082 if isempty(computed_by)
0083 if ~isempty(fcn)
0084 om_ff.data.fcn.(name) = fcn;
0085 om_ff.data.hess.(name) = hess;
0086 end
0087 else
0088 if isfield(om_ff.data.include, computed_by)
0089 om_ff.data.include.(computed_by).name{end+1} = name;
0090 om_ff.data.include.(computed_by).N(end+1) = N;
0091 else
0092 om_ff.data.include.(computed_by).name = {name};
0093 om_ff.data.include.(computed_by).N = N;
0094 end
0095 end
0096 om_ff.data.vs.(name) = varsets;
0097 else
0098 if ~isempty(computed_by)
0099 error('add_named_set: a nonlinear constraint set computed by another set is currently only implemented for simple named sets, not yet for indexed named sets');
0100 end
0101 om_ff.data.fcn = subsasgn(om_ff.data.fcn, sc, fcn);
0102 om_ff.data.hess = subsasgn(om_ff.data.hess, sc, hess);
0103 om_ff.data.vs = subsasgn(om_ff.data.vs, sc, varsets);
0104 end
0105 case 'qdc'
0106 [Q, c, k, varsets] = deal(varargin{:});
0107 if isempty(idx)
0108 om_ff.data.Q.(name) = Q;
0109 om_ff.data.c.(name) = c;
0110 om_ff.data.k.(name) = k;
0111 om_ff.data.vs.(name) = varsets;
0112 else
0113 om_ff.data.Q = subsasgn(om_ff.data.Q, sc, Q);
0114 om_ff.data.c = subsasgn(om_ff.data.c, sc, c);
0115 om_ff.data.k = subsasgn(om_ff.data.k, sc, k);
0116 om_ff.data.vs = subsasgn(om_ff.data.vs, sc, varsets);
0117 end
0118 if ~isempty(om_ff.params)
0119 om_ff.params = [];
0120 end
0121 case 'nlc'
0122 [fcn, varsets] = deal(varargin{:});
0123 if isempty(idx)
0124 om_ff.data.fcn.(name) = fcn;
0125 om_ff.data.vs.(name) = varsets;
0126 else
0127 om_ff.data.fcn = subsasgn(om_ff.data.fcn, sc, fcn);
0128 om_ff.data.vs = subsasgn(om_ff.data.vs, sc, varsets);
0129 end
0130 end
0131 om.(set_type) = om_ff;