2
$\begingroup$

I'm working on GA coding to optimize the locators position in fixturing system to minimize the error in precision manufacturing.I need a code for mutation (genetic algorithm) in Mathematica. Here, I am sharing the code which I tried to made. Kindly, help me if possible. Thanks in advance.

string = {1, 0, 0, 0, 1, 1}
mutataionrate = .01;
domutation[string_] :=
 Module[{tempstring, i},
  tempstring = string;
  Do[If[Random[] < mutationrate,
    tempstring[[i]] = 1 - tempstring[[i]]],
   {i, StringLength}];
  Return[{tempstring}]]
$\endgroup$
  • $\begingroup$ Have you taken a look at (How can I speed up the classic GA for graph coloring?)[mathematica.stackexchange.com/q/13454/27951]? The question and answers contain a possible implementation of mutation. $\endgroup$ – MarcoB May 28 '15 at 17:22
2
$\begingroup$

Since it looks like your search space is binary strings, you can take advantage of BitXor which is popular in GAs for toggling genes:

doMutation[string_, geneMutateProb_] := 
 BitXor[string, RandomVariate[BernoulliDistribution[geneMutateProb], Length[string]]]
|improve this answer|||||
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.