[37] | 1 | function output = callsdplr(interfacedata) |
---|
| 2 | |
---|
| 3 | % Author Johan Löfberg |
---|
| 4 | % $Id: callsdplr.m,v 1.8 2005/12/15 13:21:16 joloef Exp $ |
---|
| 5 | |
---|
| 6 | % Retrieve needed data |
---|
| 7 | options = interfacedata.options; |
---|
| 8 | F_struc = interfacedata.F_struc; |
---|
| 9 | c = interfacedata.c; |
---|
| 10 | K = interfacedata.K; |
---|
| 11 | ub = interfacedata.ub; |
---|
| 12 | lb = interfacedata.lb; |
---|
| 13 | lowrankdetails = interfacedata.lowrankdetails; |
---|
| 14 | |
---|
| 15 | % Create the parameter structure |
---|
| 16 | pars = options.sdplr; |
---|
| 17 | pars.printlevel = options.verbose; |
---|
| 18 | |
---|
| 19 | % ********************************************* |
---|
| 20 | % Bounded variables converted to constraints |
---|
| 21 | % N.B. Only happens when caller is BNB |
---|
| 22 | % ********************************************* |
---|
| 23 | if ~isempty(ub) |
---|
| 24 | [F_struc,K] = addbounds(F_struc,K,ub,lb); |
---|
| 25 | end |
---|
| 26 | |
---|
| 27 | % rmfield is slow... |
---|
| 28 | Knew.l = K.l; |
---|
| 29 | Knew.s = K.s; |
---|
| 30 | K = Knew; |
---|
| 31 | |
---|
| 32 | if options.savedebug |
---|
| 33 | save sdplrdebug F_struc c K pars -V6 |
---|
| 34 | end |
---|
| 35 | |
---|
| 36 | % ********************************************* |
---|
| 37 | %FIND LOW RANK STRUCTURES |
---|
| 38 | % ********************************************* |
---|
| 39 | problem = 0; |
---|
| 40 | lrA = []; |
---|
| 41 | if ~isempty(lowrankdetails) | (options.sdplr.maxrank>0 & (K.s(1)>0)) |
---|
| 42 | showprogress('Detecting low rank data',options.showprogress); |
---|
| 43 | sdploc = K.l+cumsum([1 K.s.^2]); |
---|
| 44 | k = 1; |
---|
| 45 | % FIX : Lazy code copy... |
---|
| 46 | [ix,jx,sx] = find(F_struc); |
---|
| 47 | if isempty(lowrankdetails) |
---|
| 48 | % Okay, this means we have to go through everything... |
---|
| 49 | % Get all data in F_struc for later |
---|
| 50 | for lmiid = 1:length(K.s) |
---|
| 51 | removethese = zeros(1,size(F_struc,2)-1); |
---|
| 52 | for i = 1:size(F_struc,2)-1 |
---|
| 53 | Fi = reshape(F_struc(sdploc(lmiid):sdploc(lmiid+1)-1,i+1),K.s(lmiid),K.s(lmiid)); |
---|
| 54 | if nnz(Fi)>0 |
---|
| 55 | [D,V] = getfactors(Fi); |
---|
| 56 | if length(D) <= options.sdplr.maxrank |
---|
| 57 | lrA(k).cons = i; |
---|
| 58 | lrA(k).start = sdploc(lmiid); |
---|
| 59 | lrA(k).D = D; |
---|
| 60 | lrA(k).V = V; |
---|
| 61 | k = k+1; |
---|
| 62 | removethese(i) = 1; |
---|
| 63 | end |
---|
| 64 | end |
---|
| 65 | end |
---|
| 66 | removethese = find(removethese); |
---|
| 67 | if ~isempty(removethese) |
---|
| 68 | these = find((sdploc(lmiid+1)-1>= ix) & (ix>=sdploc(lmiid)) & ismember(jx,1+removethese)); |
---|
| 69 | sx(these) = 0; |
---|
| 70 | end |
---|
| 71 | end |
---|
| 72 | else |
---|
| 73 | % Just check those constraints declared low-rank by user |
---|
| 74 | for lrdef = 1:length(lowrankdetails) |
---|
| 75 | for lrconstraint = 1:length(lowrankdetails{lrdef}.id) |
---|
| 76 | lmiid = lowrankdetails{lrdef}.id(lrconstraint); |
---|
| 77 | removethese = zeros(1,size(F_struc,2)-1); |
---|
| 78 | checkthese = lowrankdetails{lrdef}.variables; |
---|
| 79 | if isempty(checkthese) |
---|
| 80 | checkthese = 1:size(F_struc,2)-1; |
---|
| 81 | end |
---|
| 82 | for i = checkthese |
---|
| 83 | Fi = reshape(F_struc(sdploc(lmiid):sdploc(lmiid+1)-1,i+1),K.s(lmiid),K.s(lmiid)); |
---|
| 84 | if nnz(Fi)>0 |
---|
| 85 | [D,V] = getfactors(Fi); |
---|
| 86 | if (options.sdplr.maxrank == 0) | (options.sdplr.maxrank ~= 0 & (length(D) <= options.sdplr.maxrank)) |
---|
| 87 | lrA(k).cons = i; |
---|
| 88 | lrA(k).start = sdploc(lmiid); |
---|
| 89 | lrA(k).D = D; |
---|
| 90 | lrA(k).V = V; |
---|
| 91 | k = k+1; |
---|
| 92 | removethese(i) = 1; |
---|
| 93 | end |
---|
| 94 | end |
---|
| 95 | end |
---|
| 96 | removethese = find(removethese); |
---|
| 97 | if ~isempty(removethese) |
---|
| 98 | these = find((sdploc(lmiid+1)-1>= ix) & (ix>=sdploc(lmiid)) & ismember(jx,1+removethese)); |
---|
| 99 | sx(these) = 0; |
---|
| 100 | %F_struc(sdploc(lmiid):sdploc(lmiid+1)-1,1+removethese) = 0; |
---|
| 101 | end |
---|
| 102 | end |
---|
| 103 | end |
---|
| 104 | F_struc = sparse(ix,jx,sx,size(F_struc,1),size(F_struc,2)); |
---|
| 105 | end |
---|
| 106 | end |
---|
| 107 | |
---|
| 108 | % ********************************************* |
---|
| 109 | % CALL SDPLR |
---|
| 110 | % ********************************************* |
---|
| 111 | if options.showprogress;showprogress(['Calling ' interfacedata.solver.tag],options.showprogress);end |
---|
| 112 | solvertime = clock; |
---|
| 113 | if isempty(lrA) |
---|
| 114 | [x_s,y_s,info] = sdplr(F_struc(:,2:end),c,F_struc(:,1),K,pars); |
---|
| 115 | else |
---|
| 116 | [x_s,y_s,info] = sdplr(F_struc(:,2:end),c,F_struc(:,1),K,pars,lrA); |
---|
| 117 | end |
---|
| 118 | solvertime = etime(clock,solvertime); |
---|
| 119 | |
---|
| 120 | % YALMIP format |
---|
| 121 | D_struc = x_s; |
---|
| 122 | x = -y_s; |
---|
| 123 | |
---|
| 124 | % No error codes currently... |
---|
| 125 | problem = 0; |
---|
| 126 | |
---|
| 127 | infostr = yalmiperror(problem,interfacedata.solver.tag); |
---|
| 128 | |
---|
| 129 | % Save ALL data sent to solver |
---|
| 130 | if options.savesolverinput |
---|
| 131 | solverinput.A = F_struc(:,2:end); |
---|
| 132 | solverinput.c = F_struc(:,1); |
---|
| 133 | solverinput.b = c; |
---|
| 134 | solverinput.K = K; |
---|
| 135 | solverinput.pars = pars; |
---|
| 136 | else |
---|
| 137 | solverinput = []; |
---|
| 138 | end |
---|
| 139 | |
---|
| 140 | % Save ALL data from the solution? |
---|
| 141 | if options.savesolveroutput |
---|
| 142 | solveroutput.x = x_s; |
---|
| 143 | solveroutput.y = y_s; |
---|
| 144 | solveroutput.info = info; |
---|
| 145 | else |
---|
| 146 | solveroutput = []; |
---|
| 147 | end |
---|
| 148 | |
---|
| 149 | % Standard interface |
---|
| 150 | output.Primal = x(:); |
---|
| 151 | output.Dual = D_struc; |
---|
| 152 | output.Slack = []; |
---|
| 153 | output.problem = problem; |
---|
| 154 | output.infostr = infostr; |
---|
| 155 | output.solverinput = solverinput; |
---|
| 156 | output.solveroutput= solveroutput; |
---|
| 157 | output.solvertime = solvertime; |
---|
| 158 | |
---|
| 159 | function [D,V] = getfactors(Fi) |
---|
| 160 | if nnz(Fi)>0 |
---|
| 161 | [v,d] = eig(full(Fi)); |
---|
| 162 | d = diag(d); |
---|
| 163 | keep = find(abs(d)>1e-6); |
---|
| 164 | V = v(:,keep); |
---|
| 165 | D = d(keep); |
---|
| 166 | % lrA(k).cons = i; |
---|
| 167 | % lrA(k).start = sdploc(j); |
---|
| 168 | % lrA(k).D = D; |
---|
| 169 | % lrA(k).V = V; |
---|
| 170 | % k = k+1; |
---|
| 171 | else |
---|
| 172 | D = []; |
---|
| 173 | V = []; |
---|
| 174 | end |
---|
| 175 | |
---|
| 176 | |
---|