source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/solvers/callmosek.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 7.7 KB
Line 
1function output = callmosek(interfacedata)
2
3% Author Johan Löfberg
4% $Id: callmosek.m,v 1.15 2006/05/22 09:58:52 joloef Exp $
5
6% Retrieve needed data
7options = interfacedata.options;
8F_struc = interfacedata.F_struc;
9c       = interfacedata.c;
10Q       = interfacedata.Q;
11K       = interfacedata.K;
12x0      = interfacedata.x0;
13integer_variables = interfacedata.integer_variables;
14binary_variables = interfacedata.binary_variables;
15extended_variables = interfacedata.extended_variables;
16ub      = interfacedata.ub;
17lb      = interfacedata.lb;
18mt      = interfacedata.monomtable;
19
20% *********************************
21% What type of variables do we have
22% *********************************
23linear_variables = find((sum(abs(mt),2)==1) & (any(mt==1,2)));
24nonlinear_variables = setdiff((1:size(mt,1))',linear_variables);
25sigmonial_variables = find(any(0>mt,2) | any(mt-fix(mt),2));
26
27if ~isempty(sigmonial_variables) | isequal(interfacedata.solver.version,'GEOMETRIC')
28    [x,D_struc,problem,res,solvertime,prob] = call_mosek_geometric(options,F_struc,c,Q,K,ub,lb,mt,linear_variables,extended_variables);         
29else
30    [x,D_struc,problem,res,solvertime,prob] = call_mosek_lpqp(options,F_struc,c,Q,K,ub,lb,mt,linear_variables,integer_variables);       
31end
32
33infostr = yalmiperror(problem,'MOSEK');
34
35% Save all data sent to solver?
36if options.savesolverinput
37    solverinput.prob = prob;
38else
39    solverinput = [];
40end
41
42% Save all data from the solver?
43if options.savesolveroutput
44    solveroutput.res = res;
45else
46    solveroutput = [];
47end
48
49% Standard interface
50output.Primal      = x;
51output.Dual        = D_struc;
52output.Slack       = [];
53output.problem     = problem;
54output.infostr     = infostr;
55output.solverinput = solverinput;
56output.solveroutput= solveroutput;
57output.solvertime  = solvertime;
58
59
60function [x,D_struc,problem,res,solvertime,prob] = call_mosek_lpqp(options,F_struc,c,Q,K,ub,lb,mt,linear_variables,integer_variables);
61
62prob.c = c;
63if ~isempty(F_struc)
64    prob.a = -F_struc(:,2:end);
65    prob.buc = full(F_struc(:,1));
66    prob.blc = repmat(-inf,length(prob.buc),1);
67else
68    prob.a = sparse(ones(1,length(c))); % Dummy constraint
69    prob.buc = inf;
70    prob.blc = -inf;
71end
72if isempty(lb)
73    prob.blx = repmat(-inf,1,length(c));
74else
75    prob.blx = lb;
76end
77if isempty(ub)
78    prob.bux = repmat(inf,1,length(c));
79else
80    prob.bux = ub;
81end
82
83
84if K.f>0
85    prob.blc(1:K.f) = prob.buc(1:K.f);
86end
87
88[prob.qosubi,prob.qosubj,prob.qoval] = find(tril(sparse(2*Q)));   
89
90if K.q(1)>0
91    nof_new = sum(K.q);
92    prob.a = [prob.a [zeros(K.f,nof_new);zeros(K.l,nof_new);eye(nof_new)]];
93    prob.a(1+K.f+K.l:end,1:length(c)) = prob.a(1+K.f+K.l:end,1:length(c));
94    prob.blc(1+K.f+K.l:end) = prob.buc(1+K.f+K.l:end);
95    prob.buc(1+K.f+K.l:end) = prob.buc(1+K.f+K.l:end);   
96    prob.c = [prob.c;zeros(nof_new,1)];
97    top = size(F_struc,2)-1;
98    for i = 1:length(K.q)
99        prob.cones{i}.type = 'MSK_CT_QUAD';
100        prob.cones{i}.sub  = top+1:top+K.q(i);
101        prob.blx(top+1:top+K.q(i)) = -inf;
102        prob.bux(top+1:top+K.q(i)) = inf;       
103        top = top + K.q(i);
104    end   
105end
106
107if ~isempty(integer_variables)
108    prob.ints.sub = integer_variables;
109end
110
111prob.param = options.mosek.param;
112
113% Debug?
114if options.savedebug
115    save mosekdebug prob
116end
117
118% Call MOSEK
119solvertime = clock;
120showprogress('Calling MOSEK',options.showprogress);
121if options.verbose == 0
122    [r,res] = mosekopt('minimize echo(0)',prob);
123else
124    [r,res] = mosekopt('minimize',prob);     
125end
126solvertime = etime(clock,solvertime);
127
128if (r == 1010) | (r == 1011)
129    problem = -5;
130    x = [];
131    D_struc = [];
132elseif r == 1200
133    problem = 7;
134    x = [];
135    D_struc = [];
136else
137    % Recover solutions
138    sol = res.sol;
139    if isempty(integer_variables)
140        x = sol.itr.xx(1:length(c)); % Might have added new ones               
141        D_struc = (sol.itr.suc-sol.itr.slc);       
142        error_message = sol.itr.prosta;
143    else       
144        x = sol.int.xx(1:length(c)); % Might have added new ones
145        D_struc = [];
146        error_message = sol.int.prosta;
147    end
148   
149    switch error_message
150    case {'PRIMAL_AND_DUAL_FEASIBLE','PRIMAL_FEASIBLE'}
151        problem = 0;
152    case 'PRIMAL_INFEASIBLE'
153        problem = 1;
154    case 'DUAL_INFEASIBLE'       
155        problem = 2;
156    case 'PRIMAL_INFEASIBLE_OR_UNBOUNDED'
157        problem = 12;
158    otherwise
159        problem = -1;
160    end
161end
162
163
164
165function [x,D_struc,problem,res,solvertime,prob] = call_mosek_qclp(options,F_struc,c,Q,K,ub,lb,mt,linear_variables);
166
167nonlinear_variables =setdiff(1:length(c),linear_variables);
168var_prod = [];
169for i = 1:length(nonlinear_variables)
170    vars = find(mt(nonlinear_variables(i),:));
171    if length(vars)==1
172        var_prod = [var_prod;vars vars];
173    else
174        var_prod = [var_prod;sort(vars)];
175    end
176end
177
178A = -F_struc(:,1+linear_variables);
179u_c = full(F_struc(:,1));
180l_c = repmat(-inf,length(u_c),1);
181l_x = lb;
182u_x = ub;
183
184if K.f>0
185    l_c(1:K.f) = u_c(1:K.f);
186end
187
188prob.c = c(linear_variables);;
189qcsubk = [];
190qcsubi = [];
191qcsubj = [];
192qcval = [];
193for k = 1:size(F_struc,1)
194    nonlins = find(F_struc(k,nonlinear_variables+1));
195    for i = 1:length(nonlins)
196        qcsubk = [qcsubk;k];
197        qcsubi = [qcsubi;var_prod(nonlins(i),1)];
198        qcsubj = [qcsubj;var_prod(nonlins(i),2)];
199        if var_prod(nonlins(i),2)==var_prod(nonlins(i),1)
200            qcval = [qcval;-2*F_struc(k,1+nonlinear_variables(nonlins(i)))];
201        else
202            qcval = [qcval;-F_struc(k,1+nonlinear_variables(nonlins(i)))];
203        end
204    end
205end
206prob.qcsubk = qcsubk;
207prob.qcsubi = qcsubi;
208prob.qcsubj = qcsubj;
209prob.qcval = qcval;
210prob.a = A;
211prob.buc = u_c;
212
213
214% For debugging
215if options.savedebug
216    save mosekdebug prob
217end
218
219% Call MOSEK
220solvertime = clock;
221showprogress('Calling MOSEK',options.showprogress);
222solvertime = clock;
223if options.verbose == 0
224    [r,res] = mosekopt('minimize echo(0)',prob);
225else
226    [r,res] = mosekopt('minimize',prob);     
227end
228solvertime = etime(clock,solvertime);
229
230x = zeros(length(c),1);
231x(linear_variables)=res.sol.itr.xx;
232D_struc = res.sol.itr.suc;
233if K.f>0
234    D_struc(1:K.f) = (sol.itr.suc(1:K.f)-sol.itr.slc(1:K.f));
235end
236% Check, currently not exhaustive...
237switch res.sol.itr.prosta
238case 'PRIMAL_AND_DUAL_FEASIBLE'
239    problem = 0;
240case 'PRIMAL_INFEASIBLE'
241    problem = 1;
242case 'DUAL_INFEASIBLE'
243    problem = 2;
244otherwise
245    problem = -1;
246end
247
248function [x,D_struc,problem,res,solvertime,prob] = call_mosek_geometric(options,F_struc,c,Q,K,ub,lb,mt,linear_variables,extended_variables);
249   
250x = [];
251D_struc = [];
252res = [];
253solvertime = 0;
254[prob,problem] = yalmip2geometric(options,F_struc,c,Q,K,ub,lb,mt,linear_variables,extended_variables);
255if problem == 0
256
257    % Mosek does not support equalities
258    if ~isempty(prob.G)
259        prob.A = [prob.A;prob.G;-prob.G];
260        prob.b = [prob.b;prob.h;1./prob.h];
261        prob.map = [prob.map;max(prob.map) + (1:2*length(prob.h))'];
262    end
263    if options.savedebug
264        save mosekdebug prob
265    end
266
267    prob.param = options.mosek.param;
268
269    % Call MOSEK
270    solvertime = clock;
271    showprogress('Calling MOSEK',options.showprogress);
272    solvertime = clock;
273    if options.verbose == 0 
274        res = mskgpopt(prob.b,prob.A,prob.map,[],'minimize echo(0)');
275    else
276        res = mskgpopt(prob.b,prob.A,prob.map,[],'minimize');     
277    end
278    sol = res.sol;
279    solvertime = etime(clock,solvertime);
280
281    x = zeros(length(c),1);
282    x(linear_variables)=exp(res.sol.itr.xx);
283    D_struc = [];%exp(res.sol.itr.suc);
284
285    % Check, currently not exhaustive...
286    switch res.sol.itr.prosta
287        case 'PRIMAL_AND_DUAL_FEASIBLE'
288            problem = 0;
289        case 'PRIMAL_INFEASIBLE'
290            problem = 1;
291        case 'DUAL_INFEASIBLE'
292            problem = 2;
293        case 'UNKNOWN'
294            problem = 9;
295        otherwise
296            problem = -1;
297    end
298end
Note: See TracBrowser for help on using the repository browser.