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

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

Added original make3d

File size: 4.6 KB
Line 
1function 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
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
20switch 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';
27end
28
29% *********************************
30% What type of variables do we have
31% *********************************
32linear_variables = find((sum(abs(mt),2)==1) & (any(mt==1,2)));
33nonlinear_variables = setdiff((1:size(mt,1))',linear_variables);
34sigmonial_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
40if 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
50end
51
52if 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
123else
124    x = [];
125    solvertime = 0;
126end
127
128% Internal format for duals (currently not supported in GP)
129D_struc = [];
130
131infostr = yalmiperror(problem,interfacedata.solver.tag);
132
133if options.savesolverinput
134    solverinput.A = [];
135    solverinput.b = [];
136    solverinput.Aeq = [];
137    solverinput.beq = [];
138    solverinput.options = options.fmincon;
139else
140    solverinput = [];
141end
142
143% Save all data from the solver?
144if options.savesolveroutput
145    solveroutput.x = x;
146    solveroutput.fmin = fmin;
147    solveroutput.flag = flag;
148    solveroutput.output=output;
149    solveroutput.lambda=lambda;
150else
151    solveroutput = [];
152end
153
154% Standard interface
155output.Primal      = x;
156output.Dual        = D_struc;
157output.Slack       = [];
158output.problem     = problem;
159output.infostr     = infostr;
160output.solverinput = solverinput;
161output.solveroutput= solveroutput;
162output.solvertime  = solvertime;
Note: See TracBrowser for help on using the repository browser.