1 | function [sol,dgn,Z,J] = mpbbmilp(F,obj,options,parametric) |
---|
2 | |
---|
3 | % Figure out binary variables |
---|
4 | binary = recover(intersect(getvariables(F),yalmip('binvariables'))); |
---|
5 | |
---|
6 | if isempty(options) |
---|
7 | options = sdpsettings('relax',1); |
---|
8 | else |
---|
9 | options = sdpsettings(options,'relax',1); |
---|
10 | end |
---|
11 | |
---|
12 | % Solve relaxed problem recursively |
---|
13 | [sol,dgn,Z,J] = sub_mpmilp(F,obj,options,parametric,binary,[]) |
---|
14 | |
---|
15 | function [sol,dgn,Z,J] = sub_mpmilp(F,obj,options,parametric,binary,fixed) |
---|
16 | |
---|
17 | % Solve relaxed problem, extract only binary solution |
---|
18 | disp(['-> Fixed variables : ' num2str(fixed)]); |
---|
19 | |
---|
20 | [sol,dgn,Z,J] = solvemp(F,obj,options,parametric,binary); |
---|
21 | if isempty(sol) |
---|
22 | return |
---|
23 | end |
---|
24 | |
---|
25 | % Find parametrically integer solutions |
---|
26 | not_integer = find((sum(abs([sol{1}.Fi{:}]),2) >1e-8) | sum(abs([sol{1}.Gi{:}]-round([sol{1}.Gi{:}])),2)>1e-8); |
---|
27 | |
---|
28 | if ~isempty(not_integer) |
---|
29 | |
---|
30 | j = not_integer(1); |
---|
31 | |
---|
32 | sol_down = sub_mpmilp(F+set(binary(j) == 0),obj,options,parametric,binary,[fixed -j]); |
---|
33 | sol_up = sub_mpmilp(F+set(binary(j) == 1),obj,options,parametric,binary,[fixed j]); |
---|
34 | |
---|
35 | if isempty(sol_down) |
---|
36 | sol = sol_up; |
---|
37 | elseif isempty(sol_up) |
---|
38 | sol = sol_down; |
---|
39 | else |
---|
40 | sol = {rmovlps({sol_down{1},sol_up{1}})}; |
---|
41 | end |
---|
42 | else |
---|
43 | disp('-> Integer node found') |
---|
44 | end |
---|
45 | |
---|
46 | |
---|
47 | |
---|