1 | function pen = sedumi2penbmi(F_struc,c,Q,K,monomtable,options,x0) |
---|
2 | |
---|
3 | % Linear before bilinearize |
---|
4 | temp = sum(monomtable,2)>1; |
---|
5 | tempnonlinearindicies = find(temp); |
---|
6 | templinearindicies = find(~temp); |
---|
7 | |
---|
8 | if isempty(monomtable) |
---|
9 | monomtable = eye(length(c)); |
---|
10 | end |
---|
11 | |
---|
12 | temp = sum(monomtable,2)>1; |
---|
13 | nonlinearindicies = find(temp); |
---|
14 | linearindicies = find(~temp); |
---|
15 | c0 = c; |
---|
16 | c = c(linearindicies); |
---|
17 | Q = Q(linearindicies,linearindicies); |
---|
18 | nonlinear_scalars = []; |
---|
19 | |
---|
20 | % Any non-linear scalar inequalities? |
---|
21 | % Move these to the BMI part |
---|
22 | if K.l>0 |
---|
23 | nonlinear_scalars = find(any(full(F_struc(1:K.l,[nonlinearindicies(:)'+1])),2)); |
---|
24 | if ~isempty(nonlinear_scalars) |
---|
25 | Kold = K; |
---|
26 | linear_scalars = setdiff(1:K.l,nonlinear_scalars); |
---|
27 | F_struc = [F_struc(linear_scalars,:);F_struc(nonlinear_scalars,:);F_struc(K.l+1:end,:)]; |
---|
28 | K.l = K.l-length(nonlinear_scalars); |
---|
29 | if (length(K.s)==1) & (K.s==0) |
---|
30 | K.s = [repmat(1,1,length(nonlinear_scalars))]; |
---|
31 | K.rank = repmat(1,1,length(nonlinear_scalars)); |
---|
32 | else |
---|
33 | K.s = [repmat(1,1,length(nonlinear_scalars)) K.s]; |
---|
34 | K.rank = [repmat(1,1,length(nonlinear_scalars)) K.rank]; |
---|
35 | end |
---|
36 | end |
---|
37 | end |
---|
38 | |
---|
39 | if ~isempty(F_struc) |
---|
40 | pen = sedumi2pen(F_struc(:,[1 linearindicies(:)'+1]),K,c,x0); |
---|
41 | else |
---|
42 | pen = sedumi2pen([],K,c,x0); |
---|
43 | end |
---|
44 | |
---|
45 | if ~isempty(nonlinearindicies) |
---|
46 | bmi = sedumi2pen(F_struc(:,[nonlinearindicies(:)'+1]),K,[],[]); |
---|
47 | pen.ki_dim = bmi.ai_dim; |
---|
48 | % Nonlinear index |
---|
49 | pen.ki_dim = bmi.ai_dim; |
---|
50 | pen.ki_row = bmi.ai_row; |
---|
51 | pen.ki_col = bmi.ai_col; |
---|
52 | pen.ki_nzs = bmi.ai_nzs; |
---|
53 | pen.ki_val = bmi.ai_val; |
---|
54 | for i = 1:length(bmi.ai_idx) |
---|
55 | nl = nonlinearindicies(1+bmi.ai_idx(i)); |
---|
56 | v = find(monomtable(nl,:)); |
---|
57 | if length(v)==1 |
---|
58 | v(2)=v(1); |
---|
59 | end |
---|
60 | pen.ki_idx(i)=find(linearindicies == v(1)); |
---|
61 | pen.kj_idx(i)=find(linearindicies == v(2)); |
---|
62 | end |
---|
63 | else |
---|
64 | pen.ki_dim = 0*pen.ai_dim; |
---|
65 | pen.ki_row = 0; |
---|
66 | pen.ki_col = 0; |
---|
67 | pen.ki_nzs = 0; |
---|
68 | pen.ki_idx = 0; |
---|
69 | pen.kj_idx = 0; |
---|
70 | pen.kj_val = 0; |
---|
71 | end |
---|
72 | |
---|
73 | if nnz(Q)>0 |
---|
74 | [row,col,vals] = find(triu(Q)); |
---|
75 | pen.q_nzs = length(row); |
---|
76 | pen.q_val = vals'; |
---|
77 | pen.q_col = col'-1; |
---|
78 | pen.q_row = row'-1; |
---|
79 | else |
---|
80 | pen.q_nzs = 0; |
---|
81 | pen.q_val = 0; |
---|
82 | pen.q_col = 0; |
---|
83 | pen.q_row = 0; |
---|
84 | end |
---|
85 | |
---|
86 | ops = struct2cell(options.penbmi);ops = [ops{1:end}]; |
---|
87 | pen.ioptions = ops(1:12); |
---|
88 | pen.foptions = ops(13:end); |
---|
89 | pen.ioptions(4) = max(0,min(3,options.verbose+1)); |
---|
90 | if pen.ioptions(4)==1 |
---|
91 | pen.ioptions(4)=0; |
---|
92 | end |
---|
93 | |
---|
94 | % **************************************** |
---|
95 | % UNCOMMENT THIS FOR PENBMI version 1 |
---|
96 | % **************************************** |
---|
97 | %pen.ioptions = pen.ioptions(1:8); |
---|
98 | %pen.foptions = pen.foptions(1:8); |
---|
99 | |
---|
100 | if ~isempty(x0) |
---|
101 | pen.x0(isnan(pen.x0)) = 0; |
---|
102 | pen.x0 = x0(linearindicies); |
---|
103 | pen.x0 = pen.x0(:)'; |
---|
104 | end |
---|