forked from shababo/iit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
complex_search.m
91 lines (72 loc) · 2.8 KB
/
complex_search.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function [Big_phi_MIP MIP Complex M_i_max BFCut Big_phi_MIP_M MIP_M Big_phi_MIP_all_M MIP_all_M BFCut_M] = complex_search(Big_phi_M,M_cell,M_IRR_M,N,prob_M, phi_M,options,concept_MIP_M,network)
%% Find complex
op_extNodes = options(11);
op_console = options(8);
Big_phi_MIP_M = zeros(2^N-1,1);
Big_phi_MIP_all_M = cell(2^N-1,1);
MIP_M = cell(2^N-1,1);
MIP_all_M = cell(2^N-1,1);
if op_console
fprintf('\n')
fprintf('\nBig_phi_MIP in subset M:\n\n')
end
parfor M_i = 1: 2^N-1
M = M_cell{M_i};
if length(M) > 1 && Big_phi_M(M_i) ~= 0 % Larissa: faster like this!
% [Big_phi_MIP_M(M_i) MIP_M{M_i} Big_phi_MIP_all_M{M_i} MIP_all_M{M_i}] = ...
% MIP_search(M,N,Big_phi_M, M_IRR_M, prob_M, phi_M,options);
%For reentry uncomment this and comment the one above!
if op_extNodes == 1 && N ~= numel(M)
rem_network = network.removal_networks{M_i};
[Big_phi_MIP_M(M_i) MIP_M{M_i} Big_phi_MIP_all_M{M_i} MIP_all_M{M_i} BFCut_M{M_i}] = ...
MIP_search_reentry(M,N,Big_phi_M, M_IRR_M, prob_M, phi_M,options,concept_MIP_M, rem_network);
else
[Big_phi_MIP_M(M_i) MIP_M{M_i} Big_phi_MIP_all_M{M_i} MIP_all_M{M_i} BFCut_M{M_i}] = ...
MIP_search_reentry(M,N,Big_phi_M, M_IRR_M, prob_M, phi_M,options,concept_MIP_M, network);
end
else
% 08/23/2013 exclude self loops
Big_phi_MIP_M(M_i) = 0;
%Big_phi_MIP_M(M_i) = Big_phi_M(M_i);
MIP_M{M_i} = M;
Big_phi_MIP_all_M{M_i} = 0;
%Big_phi_MIP_all_M{M_i} = Big_phi_M(M_i);
MIP_all_M{M_i} = M;
BFCut_M{M_i} = 0;
end
end
[Big_phi_MIP M_i_max] = max_complex(Big_phi_MIP_M,M_cell);
Complex = M_cell{M_i_max};
MIP = cell(2,1);
MIP{1} = MIP_M{M_i_max};
Big_phi = Big_phi_M(M_i_max);
BFCut = BFCut_M{M_i_max};
MIP{2} = pick_rest(Complex,MIP{1});
if op_console
fprintf('\n')
fprintf('---------------------------------------------------------------------\n\n')
fprintf('Complex = %s\nBig_phi = %f\nMIP = %s-%s\nBig_phi_MIP = %f\n', ...
mat2str(Complex),Big_phi, mod_mat2str(MIP{1}),mod_mat2str(MIP{2}),Big_phi_MIP);
end
end
function [x_max i_max] = max_complex(x,M_cell)
N = length(x);
epsilon = 10^-6;
x_max = x(1);
i_max = 1;
for i = 2:N %Larissa: This seems fishy
if x(i) ~= 0
dif = x_max - x(i);
if abs(dif) < epsilon
if length(M_cell{i_max}) < length(M_cell{i})
x_max = x(i);
i_max = i;
end
elseif dif < 0
x_max = x(i);
i_max = i;
else
end
end
end
end