public void InvertMutate() { // Select a region of the Genome and invert it // Mutation equation Vm = V * s * r * 2^(-uk) // where s = sign = {-1, +1) uniform random // r = range // u = [0..1] uniform random // k = precision double resolution = 1; // The smallest number of steps double range = genes.Count - 1; double k = -Math.Log(resolution / range) / Math.Log(2.0); double u = Rng.ContinuousUniformZeroToOne(); double s = range * Math.Pow(2.0, -u * k); int steps = (int)Math.Round(s); int length = 1 + steps; Debug.Assert(length >= 2); Debug.Assert(length <= genes.Count); int start = (length < genes.Count) ? start = Rng.DiscreteUniformZeroToN(genes.Count - length) : 0; Debug.Assert(start < genes.Count - 1); int i = start; int j = start + steps; while (i < j) { Gene temp = genes[i]; genes[i] = genes[j]; genes[j] = temp; i++; j--; } }
public override double Mutate(double value) { // Mutation equation Vm = V * s * r * 2^(-uk) // where s = sign = {-1, +1) uniform random // r = range // u = [0..1] uniform random // k = precision int toss = Rng.DiscreteUniformZeroOrOne(); int sign = (toss == 0) ? -1 : +1; double u = Rng.ContinuousUniformZeroToOne(); value += sign * r * Math.Pow(2.0, -u * k); return(value); }
private void Mutate() { // Value mutations foreach (Individual individual in members) { double u = Rng.ContinuousUniformZeroToOne(); if (u > (1.0 - valueMutationRate)) { individual.Mutate(); } } // Structural mutations foreach (Individual individual in members) { double u = Rng.ContinuousUniformZeroToOne(); if (u > (1.0 - inversionMutationRate)) { individual.InvertMutate(); } } // Duplication mutations foreach (Individual individual in members) { double u = Rng.ContinuousUniformZeroToOne(); if (u > (1.0 - duplicationMutationRate)) { individual.DuplicateMutate(); } } // Deletion mutations foreach (Individual individual in members) { double u = Rng.ContinuousUniformZeroToOne(); if (u > (1.0 - deletionMutationRate)) { individual.DeleteMutate(); } } }