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

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

Added original make3d

File size: 4.0 KB
Line 
1function output = callglpk(interfacedata)
2
3% Author Johan Löfberg
4% $Id: callglpk.m,v 1.18 2005/09/20 11:27:32 joloef Exp $
5
6% Retrieve needed data
7options = interfacedata.options;
8F_struc = interfacedata.F_struc;
9c       = interfacedata.c;
10K       = interfacedata.K;
11integer_variables = interfacedata.integer_variables;
12binary_variables = interfacedata.binary_variables;
13ub      = interfacedata.ub;
14lb      = interfacedata.lb;
15interfacedata.gettime = 0;
16n = length(c);
17
18if ~isempty(ub)
19    LB = lb;
20    UB = ub;
21    LB(binary_variables)  = round(LB(binary_variables));
22    UB(binary_variables)  = round(UB(binary_variables));
23    LB(integer_variables) = round(LB(integer_variables));
24    UB(integer_variables) = round(UB(integer_variables));
25
26    if all(isinf(LB))
27        LB=repmat(-1e6,n,1);    % just for sure
28    end
29    if all(isinf(UB))
30        UB=repmat(1e6,n,1);    % just for sure
31    end
32else
33    LB=repmat(-1e6,n,1);    % just for sure
34    UB=repmat(1e6,n,1);
35end
36
37% GLPK does not like lb==ub
38equality_in_bound = find((abs(LB-UB)<1e-12) & ~isinf(LB));
39m = length(equality_in_bound);
40if ~isempty(equality_in_bound)
41    F_struc = [-LB(equality_in_bound) sparse(1:m,equality_in_bound,ones(m,1),m,n);F_struc];
42    UB(equality_in_bound) = UB(equality_in_bound) + 1;
43    K.f = K.f + m;
44end
45
46if options.showprogress;showprogress('Calling GLPK',options.showprogress);end
47
48% GLPK notation for sure...
49SENSE = 1;     % Minimize
50C = full(c);   % Must be full
51B = full(F_struc(:,1));         % Must be full
52A =-F_struc(:,2:end);
53if length(B)==0;
54    A = C';
55    B = 1e6;
56end
57% Optimized code, make a lot of difference when you make this call 10000
58% times in a branch and bound setting...
59CTYPE = [char(ones(K.f,1)*83); char(ones(K.l,1)*85)];
60VARTYPE = char(ones(n,1)*67);
61VARTYPE(integer_variables) = 'I';
62VARTYPE(binary_variables)  = 'I';  % Should not happen except from bmibnb
63
64if options.savedebug
65    save glpkmexdebug
66end
67options.glpk.msglev = options.verbose;
68if options.glpk.msglev==1
69    options.glpk.msglev = 2;
70end
71
72% Call mex-interface
73solvertime = clock;
74[x,FMIN,STATUS,LAMBDA_EXTRA] = glpkmex(SENSE,C,A,B,CTYPE,LB,UB,VARTYPE,options.glpk,options.glpk.lpsolver,options.glpk.save);
75if interfacedata.getsolvertime solvertime = etime(clock,solvertime);else solvertime = 0;end
76problem = 0;
77
78if options.saveduals
79    if isstruct(LAMBDA_EXTRA)
80        LAMBDA = LAMBDA_EXTRA.lambda;
81        EXTRA = LAMBDA_EXTRA;
82    else
83        LAMBDA = LAMBDA_EXTRA;
84        EXTRA = 'Not saved in old GLPKMEX version, update...';
85    end
86    D_struc = -LAMBDA(m+1:end,:);
87else
88    D_struc = [];
89end
90
91% Hack
92if isempty([ub;lb]) & (any(LB==x & C>0) | any(UB==x & C<0))
93    STATUS = 214;
94end
95
96% Check, currently not exhaustive...
97switch STATUS
98    case {171,180,151,200}
99        problem = 0;
100    case {182,173,183,0,213,204,209}
101        problem = 1;
102    case 214
103        problem = 2;
104    case 207
105        problem = 3;
106    case {210,211,212}
107        problem = 4;
108    case 170
109        problem = 11;
110    otherwise
111        problem = -1;
112end
113
114% Save all data sent to solver?
115if options.savesolverinput
116        solverinput.A = A;
117        solverinput.C = C;
118        solverinput.B = B;
119        solverinput.CTYPE = CTYPE;
120        solverinput.LB = LB;
121        solverinput.UB = UB;
122    solverinput.param = options.glpk;
123    solverinput.lpsolver = options.glpk.lpsolver;
124else
125        solverinput = [];
126end
127
128% Save all data from the solver?
129if options.savesolveroutput
130
131    % Stupid redo, but this saves some time in bnb calls
132    if isstruct(LAMBDA_EXTRA)
133        LAMBDA = LAMBDA_EXTRA.lambda;
134        EXTRA = LAMBDA_EXTRA;
135    else
136        LAMBDA = LAMBDA_EXTRA;
137        EXTRA = 'Not saved in old GLPKMEX version, update...';
138    end
139   
140        solveroutput.x = x;
141    solveroutput.FMIN = FMIN;
142    solveroutput.STATUS = STATUS;
143    solveroutput.LAMBDA=LAMBDA;
144    solveroutput.EXTRA = EXTRA;
145else
146        solveroutput = [];
147end
148
149% Standard interface
150output.Primal      = x;
151output.Dual        = D_struc;
152output.Slack       = [];
153output.problem     = problem;
154output.solverinput = solverinput;
155output.solveroutput= solveroutput;
156output.solvertime  = solvertime;
Note: See TracBrowser for help on using the repository browser.