-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPartitions_opt_4.m
46 lines (46 loc) · 2.22 KB
/
Partitions_opt_4.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
function [set_part, time_part, time_opt] = Partitions_opt_4(value_opt, init_state, targets, sub_nu)
tic;
nu = double(targets);
time_opt=[];
time_part = [];
sub_n_c_ag = [];
sub_nu_l = cellfun('length',sub_nu);
cover_time_opt = -value_opt;
time = cover_time_opt(init_state,:);
for i=1:size(sub_nu,1)
rem_l_j = length(nu) - sub_nu_l(i);
to_sub_j = find(sub_nu_l<=rem_l_j);
for c_j=1:length(to_sub_j)
j = to_sub_j(c_j);
rem_l_k = length(nu) - sub_nu_l(i) - sub_nu_l(j);
to_sub_k = find(sub_nu_l<=rem_l_k);
for c_k=1:length(to_sub_k)
k = to_sub_k(c_k);
rem_l_l = length(nu) - sub_nu_l(i) - sub_nu_l(j) - sub_nu_l(k);
to_sub_l = find(sub_nu_l==rem_l_l);
for c_l=1:length(to_sub_l)
l = to_sub_l(c_l);
if(length(unique([sub_nu{i,1}(1:sub_nu_l(i)),sub_nu{j,1}(1:sub_nu_l(j)),sub_nu{k,1}(1:sub_nu_l(k)),sub_nu{l,1}(1:sub_nu_l(l))]))==length(nu))
if(isempty(time_opt))
time_opt = max([time(i),time(j),time(k),time(l)]);
time_part = [time(i),time(j),time(k),time(l)];
set_part_1 = sub_nu{i,1}(1:sub_nu_l(i));
set_part_2 = sub_nu{j,1}(1:sub_nu_l(j));
set_part_3 = sub_nu{k,1}(1:sub_nu_l(k));
set_part_4 = sub_nu{l,1}(1:sub_nu_l(l));
elseif(max([time(i),time(j),time(k)]) < time_opt)
time_opt = max([time(i),time(j),time(k),time(l)]);
time_part = [time(i),time(j),time(k),time(l)];
set_part_1 = sub_nu{i,1}(1:sub_nu_l(i));
set_part_2 = sub_nu{j,1}(1:sub_nu_l(j));
set_part_3 = sub_nu{k,1}(1:sub_nu_l(k));
set_part_4 = sub_nu{l,1}(1:sub_nu_l(l));
end
end
end
end
end
end
set_part = {set_part_1; set_part_2; set_part_3; set_part_4};
toc;
end