1 | function output = callgpposy(interfacedata) |
---|
2 | |
---|
3 | % Author Johan Löfberg |
---|
4 | % $Id: callgpposy.m,v 1.10 2006/03/27 15:11:17 joloef Exp $ |
---|
5 | |
---|
6 | % Retrieve needed data |
---|
7 | options = interfacedata.options; |
---|
8 | F_struc = interfacedata.F_struc; |
---|
9 | c = interfacedata.c; |
---|
10 | Q = interfacedata.Q; |
---|
11 | K = interfacedata.K; |
---|
12 | extended_variables = interfacedata.extended_variables; |
---|
13 | ub = interfacedata.ub; |
---|
14 | lb = interfacedata.lb; |
---|
15 | mt = interfacedata.monomtable; |
---|
16 | variabletype = interfacedata.variabletype; |
---|
17 | |
---|
18 | % ********************************* |
---|
19 | % What type of variables do we have |
---|
20 | % ********************************* |
---|
21 | if isempty(variabletype) |
---|
22 | linear_variables = find((sum(abs(mt),2)==1) & (any(mt==1,2))); |
---|
23 | else |
---|
24 | linear_variables = find(variabletype == 0); |
---|
25 | end |
---|
26 | |
---|
27 | % Same for fmincon,mosek,gpposy (for gpposy, we do not add bound constraints) |
---|
28 | [prob,problem] = yalmip2geometric(options,F_struc,c,Q,K,[],[],mt,linear_variables,extended_variables); |
---|
29 | |
---|
30 | if problem == 0 |
---|
31 | |
---|
32 | % Account for numerical problems in gpposy |
---|
33 | if ~isempty(lb); |
---|
34 | lb=lb(linear_variables); |
---|
35 | lb(lb<0)=1e-100; |
---|
36 | lb(lb==0) = 1e-100; |
---|
37 | end |
---|
38 | if ~isempty(ub); |
---|
39 | ub=ub(linear_variables); |
---|
40 | ub(isinf(ub))=1e100; |
---|
41 | end |
---|
42 | |
---|
43 | % Convert to gpposy |
---|
44 | A=prob.A; |
---|
45 | b=prob.b; |
---|
46 | G = prob.G; |
---|
47 | h = prob.h; |
---|
48 | szs=[]; |
---|
49 | for i=0:max(prob.map) |
---|
50 | szs=[szs;nnz(find(i==prob.map))]; |
---|
51 | end |
---|
52 | |
---|
53 | if szs(1) == 0 |
---|
54 | % Feasibility problem not supported by GPPOSY |
---|
55 | % Just minimize sum of all variables |
---|
56 | A = [eye(size(A,2));A]; |
---|
57 | b = [ones(size(A,2),1);b]; |
---|
58 | szs(1) = size(A,2); |
---|
59 | end |
---|
60 | |
---|
61 | if options.savedebug |
---|
62 | save gpposydebug A b szs |
---|
63 | end |
---|
64 | |
---|
65 | if interfacedata.getsolvertime solvertime = clock; end |
---|
66 | [x,status,lambda,nu] = gpposy(A,b,szs,G,h,lb,ub,double(options.verbose)==0); |
---|
67 | if interfacedata.getsolvertime solvertime = etime(clock,solvertime);else solvertime = 0;end |
---|
68 | |
---|
69 | Primal = zeros(length(c),1); |
---|
70 | |
---|
71 | % Check, currently not exhaustive... |
---|
72 | switch lower(status) |
---|
73 | case 'solved' |
---|
74 | problem = 0; |
---|
75 | Primal(linear_variables) = x; |
---|
76 | case 'infeasible' |
---|
77 | problem = 1; |
---|
78 | case 'failed' |
---|
79 | problem = 4; |
---|
80 | otherwise |
---|
81 | problem = 9; |
---|
82 | end |
---|
83 | else |
---|
84 | Primal = []; |
---|
85 | solvertime = []; |
---|
86 | end |
---|
87 | |
---|
88 | |
---|
89 | % Internal format for duals |
---|
90 | Dual = []; |
---|
91 | |
---|
92 | |
---|
93 | infostr = yalmiperror(problem,interfacedata.solver.tag); |
---|
94 | |
---|
95 | if options.savesolverinput |
---|
96 | solverinput.A = A; |
---|
97 | solverinput.b = b; |
---|
98 | solverinput.szs = szs; |
---|
99 | else |
---|
100 | solverinput = []; |
---|
101 | end |
---|
102 | |
---|
103 | % Save all data from the solver? |
---|
104 | if options.savesolveroutput |
---|
105 | solveroutput.x = x; |
---|
106 | solveroutput.status = status; |
---|
107 | else |
---|
108 | solveroutput = []; |
---|
109 | end |
---|
110 | |
---|
111 | % Standard interface |
---|
112 | output.Primal = Primal; |
---|
113 | output.Dual = Dual; |
---|
114 | output.Slack = []; |
---|
115 | output.problem = problem; |
---|
116 | output.infostr = infostr; |
---|
117 | output.solverinput = solverinput; |
---|
118 | output.solveroutput= solveroutput; |
---|
119 | output.solvertime = solvertime; |
---|