0001 function [A, l, u] = linear_constraints(om)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 nnzA = 0;
0025 s = struct('type', {'.', '{}'}, 'subs', {'', 1});
0026 for k = 1:om.lin.NS
0027 name = om.lin.order(k).name;
0028 idx = om.lin.order(k).idx;
0029 if isempty(idx)
0030 nnzA = nnzA + nnz(om.lin.data.A.(name));
0031 else
0032
0033
0034
0035 s(1).subs = name;
0036 s(2).subs = idx;
0037 nnzA = nnzA + nnz(subsref(om.lin.data.A, s));
0038 end
0039 end
0040 At = sparse([], [], [], om.var.N, om.lin.N, nnzA);
0041 u = Inf(om.lin.N, 1);
0042 l = -u;
0043
0044
0045 s2 = s;
0046 s(2).type = '()';
0047 s1 = s;
0048 for k = 1:om.lin.NS
0049 name = om.lin.order(k).name;
0050 idx = om.lin.order(k).idx;
0051 if isempty(idx)
0052 N = om.lin.idx.N.(name);
0053 else
0054
0055
0056
0057
0058 s1(1).subs = name;
0059 s1(2).subs = idx;
0060 s2(1).subs = name;
0061 s2(2).subs = idx;
0062 N = subsref(om.lin.idx.N, s1);
0063 end
0064 if N
0065 if isempty(idx)
0066 Ak = om.lin.data.A.(name);
0067 i1 = om.lin.idx.i1.(name);
0068 iN = om.lin.idx.iN.(name);
0069 vsl = om.lin.data.vs.(name);
0070 else
0071 Ak = subsref(om.lin.data.A, s2);
0072 i1 = subsref(om.lin.idx.i1, s1);
0073 iN = subsref(om.lin.idx.iN, s1);
0074 vsl = subsref(om.lin.data.vs, s2);
0075 end
0076 if isempty(vsl)
0077 if size(Ak,2) == om.var.N
0078 At(:, i1:iN) = Ak';
0079 else
0080
0081 At(1:size(Ak,2), i1:iN) = Ak';
0082 end
0083 else
0084 kN = 0;
0085 Ai = sparse(N, om.var.N);
0086 for v = 1:length(vsl)
0087
0088
0089
0090 s(1).subs = vsl(v).name;
0091 s(2).subs = vsl(v).idx;
0092 j1 = subsref(om.var.idx.i1, s);
0093 jN = subsref(om.var.idx.iN, s);
0094 k1 = kN + 1;
0095 kN = kN + subsref(om.var.idx.N, s);
0096 Ai(:, j1:jN) = Ak(:, k1:kN);
0097 end
0098 At(:, i1:iN) = Ai';
0099 end
0100
0101 if isempty(idx)
0102 l(i1:iN) = om.lin.data.l.(name);
0103 u(i1:iN) = om.lin.data.u.(name);
0104 else
0105 l(i1:iN) = subsref(om.lin.data.l, s2);
0106 u(i1:iN) = subsref(om.lin.data.u, s2);
0107 end
0108 end
0109 end
0110 A = At';