I'm making a genetic algorithm and I'm having trouble with the mutation. What I want to do is generate 30 random characters which will act as 10 states in my finite state machine (10 sets of 3 digits), the first digit of each 3 must be between 1-4, while the other 2 digits must be between 0-9.
Once I've generated my numbers I have to convert them into a 30 character string. I'd like to only mutate something like every fifth digit too.
This is what I'm currently trying:
% mutate probability 0.2
if (rand < 0.2)
% pick best chromosome to mutate
mut = combo{10};
for t = 3:30
mut(t) = num2str(randi([0,9]));
end
end
What I currently can't do is mutate only every nth digit or make sure that the first of every 3 digits is between 1-4 while keeping the others between 0-9.
In case it's helpful: combo{10}
represents 110202132224154246176368198100
Not fully understand what you by mutating the strings, but to get a string of 30 random numbers, you can simply do as follows:
Example result
str_r
is: