-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgetRandomChainNode.m
More file actions
48 lines (43 loc) · 1.53 KB
/
Copy pathgetRandomChainNode.m
File metadata and controls
48 lines (43 loc) · 1.53 KB
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
function node = getRandomChainNode(sol, nextClass, conflicting, blacklist)
% function node = getRandomChainNode(sol, nextClass, conflicting, blacklist)
%
% Advanced method to get a random conflicting node:
% renvoit, si possible, le nth (n choisi aléatoirement) vertex qui est
% conflicting, not blacklisted et de la même classe de couleur que
% 'nextClass'
% si nextClass n'est pas définie ou qu'un tel node n'exite pas renvoi,
% si possible, l nth (n choisi aléatoirement) vertex qui est
% conflicting et not blacklisted.
if (nargin < 4)
blacklist = false(1, length(sol));
end
% Color class defined
if (nextClass ~= -1)
% count conflicting nodes in nextClass color class
% cc = countColorConflicting(sol, nC, nextClass, conflicting, blacklist);
temp = (sol == nextClass) & conflicting & ~blacklist;
cc = sum(temp);
if (cc > 0) % s'il y a des conflits dans la color class nextClass
% renvoyer le nth node qui est (color==nextClass, conflicting,
% ~blacklist)
nth = randi(cc);
inds = find(temp);
node = inds(nth);
return;
end
end
% If the search end with unsuccess then try to find both conflicting and not
% blacklisted node with undefined color
temp = conflicting & ~blacklist;
cc = sum(temp);
if (cc > 0) % s'il y a des conflits non blacklisted
% renvoyer le nth node qui est (conflicting, ~blacklist)
nth = randi(cc);
inds = find(temp);
node = inds(nth);
return;
end
% there aren't available nodes, return to the caller that the chain can't
% continue
node = -1;
end