1 | function output = callfmincongp(interfacedata) |
---|
2 | |
---|
3 | % Author Johan Löfberg |
---|
4 | % $Id: callfmincongp.m,v 1.15 2006/07/28 06:27:01 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 | x0 = interfacedata.x0; |
---|
13 | integer_variables = interfacedata.integer_variables; |
---|
14 | binary_variables = interfacedata.binary_variables; |
---|
15 | extended_variables = interfacedata.extended_variables; |
---|
16 | ub = interfacedata.ub; |
---|
17 | lb = interfacedata.lb; |
---|
18 | mt = interfacedata.monomtable; |
---|
19 | |
---|
20 | switch options.verbose |
---|
21 | case 0 |
---|
22 | options.fmincon.Display = 'off'; |
---|
23 | case 1 |
---|
24 | options.fmincon.Display = 'final'; |
---|
25 | otherwise |
---|
26 | options.fmincon.Display = 'iter'; |
---|
27 | end |
---|
28 | |
---|
29 | % ********************************* |
---|
30 | % What type of variables do we have |
---|
31 | % ********************************* |
---|
32 | linear_variables = find((sum(abs(mt),2)==1) & (any(mt==1,2))); |
---|
33 | nonlinear_variables = setdiff((1:size(mt,1))',linear_variables); |
---|
34 | sigmonial_variables = find(any(0>mt,2) | any(mt-fix(mt),2)); |
---|
35 | |
---|
36 | % Convert to common format for fmincon, mosek and gpposy |
---|
37 | [prob,problem] = yalmip2geometric(options,F_struc,c,Q,K,ub,lb,mt,linear_variables,extended_variables); |
---|
38 | |
---|
39 | %something failed, perhaps a QP |
---|
40 | if problem & isempty(sigmonial_variables) |
---|
41 | % This is an LP or QP! |
---|
42 | % Go to standard fmincon |
---|
43 | if options.verbose |
---|
44 | disp('Conversion to geometric program failed. Trying general non-convex model in fmincon'); |
---|
45 | disp(' '); |
---|
46 | end |
---|
47 | interfacedata.solver.tag = strrep(interfacedata.solver.tag,'-geometric',''); |
---|
48 | output = callfmincon(interfacedata); |
---|
49 | return |
---|
50 | end |
---|
51 | |
---|
52 | if problem == 0 |
---|
53 | |
---|
54 | fmincon_fungp([],[],[],prob); % initialize persistent |
---|
55 | fmincon_congp([],[],[],prob); % initialize persistent |
---|
56 | |
---|
57 | if isempty(x0) |
---|
58 | x0 = zeros(length(linear_variables),1); |
---|
59 | else |
---|
60 | x0 = x0(linear_variables); |
---|
61 | end |
---|
62 | |
---|
63 | % Fake logarithm (extend linearly for small values) |
---|
64 | ind = find(x0<1e-2); |
---|
65 | x0(ind) = exp(log(1e-2)+(x0(ind)-1e-2)/1e-2); |
---|
66 | x0 = log(x0); |
---|
67 | |
---|
68 | % Clean up the bounds (from branch and bound) |
---|
69 | % Note, these bounds are in the |
---|
70 | % logarithmic variables. |
---|
71 | if ~isempty(lb) |
---|
72 | lb = lb(linear_variables); |
---|
73 | ind = find(lb<1e-2); |
---|
74 | lb(ind) = exp(log(1e-2)+(lb(ind)-1e-2)/1e-2); |
---|
75 | lb = log(lb+sqrt(eps)); |
---|
76 | end |
---|
77 | if ~isempty(ub) |
---|
78 | ub = ub(linear_variables); |
---|
79 | ind = find(ub<1e-2); |
---|
80 | ub(ind) = exp(log(1e-2)+(ub(ind)-1e-2)/1e-2); |
---|
81 | ub = log(ub+sqrt(eps)); |
---|
82 | end |
---|
83 | |
---|
84 | if options.savedebug |
---|
85 | ops = options.fmincon; |
---|
86 | save fmincongpdebug prob x0 ops lb ub |
---|
87 | end |
---|
88 | |
---|
89 | solvertime = clock; |
---|
90 | options.fmincon.GradObj = 'on'; |
---|
91 | options.fmincon.GradConstr = 'off'; |
---|
92 | if isfield(options.fmincon,'tlprob') |
---|
93 | [xout,fmin,flag,output,lambda] = fmincon('fmincon_fungp',x0,[],[],[],[],lb,ub,'fmincon_congp',options.fmincon,options.fmincon.tlprob); |
---|
94 | else |
---|
95 | [xout,fmin,flag,output,lambda] = fmincon('fmincon_fungp',x0,[],[],[],[],lb,ub,'fmincon_congp',options.fmincon); |
---|
96 | end |
---|
97 | solvertime = etime(clock,solvertime); |
---|
98 | |
---|
99 | x = zeros(length(c),1); |
---|
100 | x(linear_variables) = exp(xout); |
---|
101 | problem = 0; |
---|
102 | % Check, currently not exhaustive... |
---|
103 | if flag==0 |
---|
104 | problem = 3; |
---|
105 | else |
---|
106 | if flag>0 |
---|
107 | problem = 0; |
---|
108 | else |
---|
109 | if isempty(x) |
---|
110 | x = repmat(nan,length(c),1); |
---|
111 | end |
---|
112 | if 0%any((A*x-b)>sqrt(eps)) | any( abs(Aeq*x-beq)>sqrt(eps)) |
---|
113 | problem = 1; % Likely to be infeasible |
---|
114 | else |
---|
115 | if c'*x<-1e10 % Likely unbounded |
---|
116 | problem = 2; |
---|
117 | else % Probably convergence issues |
---|
118 | problem = 5; |
---|
119 | end |
---|
120 | end |
---|
121 | end |
---|
122 | end |
---|
123 | else |
---|
124 | x = []; |
---|
125 | solvertime = 0; |
---|
126 | end |
---|
127 | |
---|
128 | % Internal format for duals (currently not supported in GP) |
---|
129 | D_struc = []; |
---|
130 | |
---|
131 | infostr = yalmiperror(problem,interfacedata.solver.tag); |
---|
132 | |
---|
133 | if options.savesolverinput |
---|
134 | solverinput.A = []; |
---|
135 | solverinput.b = []; |
---|
136 | solverinput.Aeq = []; |
---|
137 | solverinput.beq = []; |
---|
138 | solverinput.options = options.fmincon; |
---|
139 | else |
---|
140 | solverinput = []; |
---|
141 | end |
---|
142 | |
---|
143 | % Save all data from the solver? |
---|
144 | if options.savesolveroutput |
---|
145 | solveroutput.x = x; |
---|
146 | solveroutput.fmin = fmin; |
---|
147 | solveroutput.flag = flag; |
---|
148 | solveroutput.output=output; |
---|
149 | solveroutput.lambda=lambda; |
---|
150 | else |
---|
151 | solveroutput = []; |
---|
152 | end |
---|
153 | |
---|
154 | % Standard interface |
---|
155 | output.Primal = x; |
---|
156 | output.Dual = D_struc; |
---|
157 | output.Slack = []; |
---|
158 | output.problem = problem; |
---|
159 | output.infostr = infostr; |
---|
160 | output.solverinput = solverinput; |
---|
161 | output.solveroutput= solveroutput; |
---|
162 | output.solvertime = solvertime; |
---|