-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmutation.m
More file actions
26 lines (26 loc) · 1.08 KB
/
mutation.m
File metadata and controls
26 lines (26 loc) · 1.08 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
% random mutation
function [individual_1, individual_2] = mutation(individual_1, individual_2, probabillity_of_mutation)
drawn_probabillity = randi([0, 100]);
if drawn_probabillity <= probabillity_of_mutation
indiv_index = randi(2);
chromosome_index = randi(3);
allel_index = randi(10);
if indiv_index == 1
chromosome = individual_1(chromosome_index);
allel = chromosome{1}(allel_index);
allelDouble = str2double(allel);
allelDouble = num2str(~allelDouble);
allelStr = string(allelDouble);
chromosome{1}(allel_index) = allelStr;
individual_1(chromosome_index) = chromosome;
else
chromosome = individual_2(chromosome_index);
allel = chromosome{1}(allel_index);
allelDouble = str2double(allel);
allelDouble = num2str(~allelDouble);
allelStr = string(allelDouble);
chromosome{1}(allel_index) = allelStr;
individual_2(chromosome_index) = chromosome;
end
end
end