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

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

Added original make3d

File size: 3.8 KB
Line 
1function output = calllinprog(interfacedata)
2
3% Author Johan Löfberg
4% $Id: callbintprog.m,v 1.4 2005/05/07 13:53:20 joloef Exp $
5
6% Standard input interface
7options = interfacedata.options;
8F_struc = interfacedata.F_struc;
9c       = interfacedata.c;
10K       = interfacedata.K;
11Q       = interfacedata.Q;
12lb      = interfacedata.lb;
13ub      = interfacedata.ub;
14x0      = interfacedata.x0;
15binary_variables = interfacedata.binary_variables;
16integer_variables = interfacedata.integer_variables;
17
18showprogress('Calling BINTPROG',options.showprogress);
19
20if isempty(F_struc)
21    Aeq = [];
22    beq = [];
23    A = [];
24    b = [];
25else
26    Aeq = -F_struc(1:1:K.f,2:end);
27    beq = F_struc(1:1:K.f,1);       
28    A =-F_struc(K.f+1:end,2:end);
29    b = F_struc(K.f+1:end,1);   
30end
31solvertime = clock;
32
33% Any continuous varialbles
34if length(union(binary_variables,integer_variables)) < length(c)
35    % Standard interface
36    output.Primal      = [];
37    output.Dual        = [];
38    output.Slack       = [];
39    output.problem     = -4;
40    output.infostr     = yalmiperror(-4);
41    output.solverinput = [];
42    output.solveroutput= [];
43    output.solvertime  = 0;
44    return
45end
46
47if any(integer_variables)
48    [lb,ub,used_rows] = findulb(F_struc,K);
49    % Not explicitely bounded not allowed
50    if any(isinf([lb(integer_variables) ub(integer_variables)])) | any(isinf([lb(integer_variables) ub(integer_variables)]))
51        % Standard interface
52        output.Primal      = [];
53        output.Dual        = [];
54        output.Slack       = [];
55        output.problem     = -4;
56        output.infostr     = yalmiperror(-4);
57        output.solverinput = [];
58        output.solveroutput= [];
59        output.solvertime  = 0;
60        return
61    else
62        spread = ub(integer_variables) - lb(integer_variables);
63        bits = ceil(log2(spread+1));
64        H = full(sparse(find(ismember(1:length(c),binary_variables)),1:length(binary_variables),ones(1,length(binary_variables)),length(c),length(binary_variables)));
65        for i = 1:length(integer_variables)
66            j = integer_variables(i);
67            H(j,end+1:end+bits(i)) = 2.^(0:bits(i)-1);
68        end
69    end
70    xbase = zeros(length(c),1);
71    xbase(integer_variables) = lb(integer_variables);
72    Aold = A;
73    A = Aold*H;
74    b = b-Aold*xbase;
75    beq = beq-Aeq*xbase;
76    Aeq = Aeq*H;
77    c = H'*c;
78else
79    H = 1;
80    xbase  = 0;
81end
82
83switch options.verbose
84case 0
85    options.bintprog.Display = 'off';
86case 1
87    options.bintprog.Display = 'final';
88otherwise
89    options.bintprog.Display = 'iter';
90end
91
92c = full(c);
93A = full(A);
94b = full(b);
95Aeq = full(Aeq);
96beq = full(beq);
97ops = options.bintprog;
98if options.savedebug
99    save bintprogdebug c A b Aeq beq ops
100end
101
102[x,fmin,flag,output] = bintprog(c, A, b, Aeq, beq, x0,ops);
103
104% Go back to integer variables
105if ~isempty(x)
106    x = xbase + H*x;
107end
108
109solvertime = etime(clock,solvertime);
110problem = 0;
111
112% No duals
113D_struc = [];
114
115% Check, currently not exhaustive...
116switch flag
117case 1
118    problem = 0;
119case {0,-4,-5,-6}
120    problem = 3;
121case -2
122    problem = 1;
123otherwise
124    problem = -1;
125end
126
127infostr = yalmiperror(problem,'BINTPROG');       
128
129% Save all data sent to solver?
130if options.savesolverinput
131    solverinput.A = A;
132    solverinput.b = b;
133    solverinput.Aeq = Aq;
134    solverinput.beq = beq;
135    solverinput.c = c;
136    solverinput.options = options.linprog;
137else
138    solverinput = [];
139end
140
141% Save all data from the solver?
142if options.savesolveroutput
143    solveroutput.x = x;
144    solveroutput.fmin = fmin;
145    solveroutput.flag = flag;
146    solveroutput.output=output;
147else
148    solveroutput = [];
149end
150
151% Standard interface
152output.Primal      = x;
153output.Dual        = D_struc;
154output.Slack       = [];
155output.problem     = problem;
156output.infostr     = infostr;
157output.solverinput = solverinput;
158output.solveroutput= solveroutput;
159output.solvertime  = solvertime;
Note: See TracBrowser for help on using the repository browser.