-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst_disjoint_route.m
43 lines (32 loc) · 1.05 KB
/
first_disjoint_route.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
function [route] = first_disjoint_route(visited_nodes_routes)
% Check best combination of disjoint routes
indexes = 1:size(visited_nodes_routes,1);
first_solution_found = 0;
for i= size(visited_nodes_routes,1):-1:2
indexes_matrix = nchoosek(indexes, i);
for j=1:size(indexes_matrix,1)
current_indexes = indexes_matrix(j,:);
possible_pairs = nchoosek(current_indexes, 2);
counter = 0;
for k=1:size(possible_pairs,1)
pair_routes = visited_nodes_routes(possible_pairs(k,:),:);
check = sum(sum(pair_routes) > 1);
if check > 1
break;
else
counter = counter + 1;
end
end
if counter == size(possible_pairs,1)
first_solution_found = 1;
% g = sprintf('%d ', current_indexes);
% fprintf('Valid routes: %s \n', g) % valid route indexes
break;
end
end
if first_solution_found == 1
break;
end
end
route = current_indexes;
end