1 | function 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 |
---|
7 | options = interfacedata.options; |
---|
8 | F_struc = interfacedata.F_struc; |
---|
9 | c = interfacedata.c; |
---|
10 | K = interfacedata.K; |
---|
11 | Q = interfacedata.Q; |
---|
12 | lb = interfacedata.lb; |
---|
13 | ub = interfacedata.ub; |
---|
14 | x0 = interfacedata.x0; |
---|
15 | binary_variables = interfacedata.binary_variables; |
---|
16 | integer_variables = interfacedata.integer_variables; |
---|
17 | |
---|
18 | showprogress('Calling BINTPROG',options.showprogress); |
---|
19 | |
---|
20 | if isempty(F_struc) |
---|
21 | Aeq = []; |
---|
22 | beq = []; |
---|
23 | A = []; |
---|
24 | b = []; |
---|
25 | else |
---|
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); |
---|
30 | end |
---|
31 | solvertime = clock; |
---|
32 | |
---|
33 | % Any continuous varialbles |
---|
34 | if 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 |
---|
45 | end |
---|
46 | |
---|
47 | if 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; |
---|
78 | else |
---|
79 | H = 1; |
---|
80 | xbase = 0; |
---|
81 | end |
---|
82 | |
---|
83 | switch options.verbose |
---|
84 | case 0 |
---|
85 | options.bintprog.Display = 'off'; |
---|
86 | case 1 |
---|
87 | options.bintprog.Display = 'final'; |
---|
88 | otherwise |
---|
89 | options.bintprog.Display = 'iter'; |
---|
90 | end |
---|
91 | |
---|
92 | c = full(c); |
---|
93 | A = full(A); |
---|
94 | b = full(b); |
---|
95 | Aeq = full(Aeq); |
---|
96 | beq = full(beq); |
---|
97 | ops = options.bintprog; |
---|
98 | if options.savedebug |
---|
99 | save bintprogdebug c A b Aeq beq ops |
---|
100 | end |
---|
101 | |
---|
102 | [x,fmin,flag,output] = bintprog(c, A, b, Aeq, beq, x0,ops); |
---|
103 | |
---|
104 | % Go back to integer variables |
---|
105 | if ~isempty(x) |
---|
106 | x = xbase + H*x; |
---|
107 | end |
---|
108 | |
---|
109 | solvertime = etime(clock,solvertime); |
---|
110 | problem = 0; |
---|
111 | |
---|
112 | % No duals |
---|
113 | D_struc = []; |
---|
114 | |
---|
115 | % Check, currently not exhaustive... |
---|
116 | switch flag |
---|
117 | case 1 |
---|
118 | problem = 0; |
---|
119 | case {0,-4,-5,-6} |
---|
120 | problem = 3; |
---|
121 | case -2 |
---|
122 | problem = 1; |
---|
123 | otherwise |
---|
124 | problem = -1; |
---|
125 | end |
---|
126 | |
---|
127 | infostr = yalmiperror(problem,'BINTPROG'); |
---|
128 | |
---|
129 | % Save all data sent to solver? |
---|
130 | if 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; |
---|
137 | else |
---|
138 | solverinput = []; |
---|
139 | end |
---|
140 | |
---|
141 | % Save all data from the solver? |
---|
142 | if options.savesolveroutput |
---|
143 | solveroutput.x = x; |
---|
144 | solveroutput.fmin = fmin; |
---|
145 | solveroutput.flag = flag; |
---|
146 | solveroutput.output=output; |
---|
147 | else |
---|
148 | solveroutput = []; |
---|
149 | end |
---|
150 | |
---|
151 | % Standard interface |
---|
152 | output.Primal = x; |
---|
153 | output.Dual = D_struc; |
---|
154 | output.Slack = []; |
---|
155 | output.problem = problem; |
---|
156 | output.infostr = infostr; |
---|
157 | output.solverinput = solverinput; |
---|
158 | output.solveroutput= solveroutput; |
---|
159 | output.solvertime = solvertime; |
---|