-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathSelectLeader.m
More file actions
38 lines (26 loc) · 759 Bytes
/
SelectLeader.m
File metadata and controls
38 lines (26 loc) · 759 Bytes
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
function leader = SelectLeader(rep, beta)
% Grid Index of All Repository Members
GI = [rep.GridIndex];
% Occupied Cells
OC = unique(GI); % unique() find and sort unique values in an array
% Number of Particles in Occupied Cells
N = zeros(size(OC));
for k = 1:numel(OC)
N(k) = numel(find(GI == OC(k)));
end
% Selection Probabilities
P = exp(-beta*N);
P = P/sum(P);
% Selected Cell Index
sci = RouletteWheelSelection(P);
% Selected Cell
sc = OC(sci);
% Selected Cell Members
SCM = find(GI == sc);
% Selected Member Index
smi = randi([1 numel(SCM)]);
% Selected Member
sm = SCM(smi);
% Leader
leader = rep(sm);
end