-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmutate_pop.m
72 lines (61 loc) · 1.74 KB
/
mutate_pop.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
function popm = mutate_pop(pop, n_mutation, X, Y, Fl)
% mutation operation
individual.position = [];
individual.cost = [];
popm = repmat(individual, n_mutation, 1);
parfor k = 1:n_mutation
max_retry = 3;
for t = 1:max_retry
p = pop(randi(numel(pop)));
position = quick_bit_mutate(p.position);
cost = fitness(X, Y, position);
if ~is_dominated(cost, Fl)
break;
end
end
% no mutation retry
% p = pop(randi(numel(pop)));
% position = quick_bit_mutate(p.position);
% cost = fitness(X, Y, position);
popm(k).position = position;
popm(k).cost = cost;
% if mod(k, 100) == 0
% logger(['mutate ', num2str(k), '/', num2str(n_mutation), ', cost = ', num2str(pop(k).cost')]);
% end
end
end
function new_position = quick_bit_mutate(position)
mu = 0.1;
r = rand;
index_one = find(position == true);
index_zero = find(position == false);
n_one = numel(index_one);
n_zero = numel(index_zero);
n_mu = ceil(min(n_one, n_zero) * mu);
new_position = repmat(position, 1);
if r > 0.5
index = randsample(index_one, n_mu);
new_position(index) = false;
else
index = randsample(index_zero, n_mu);
new_position(index) = true;
end
end
function b = is_dominated(cost, Fl)
b = false;
for i = 1:numel(Fl)
if dominates(Fl(i).cost, cost)
b = true;
break;
end
end
end
% function b = inpop(position, pop)
% b = false;
% for i = 1:numel(pop)
% if all(pop(i).position == position)
% b = true;
% break;
% end
% end
% end