/// <summary> /// Raises the Mutated event. /// </summary> /// <param name="e"></param> protected virtual void OnMutated(MutatedEventArgs e) { if (Mutated != null) { Mutated(this, e); } }
static void OnMutated(object o, MutatedEventArgs e) { Console.WriteLine("Chromosome was mutated:"); Console.WriteLine( e.Chromosome.ToString() ); for(int i=0;i<e.MutationPoint;i++) { Console.Write(" "); } Console.WriteLine("^"); }
void Mutate(Chromosome[] cs) { foreach (Chromosome c in cs) { // // Mutate a gene's value in this chromosome. // if (Utils.Rand.NextDouble() < GeneMutationProbability) { int mutationPoint = Utils.Rand.Next(c.Genes.Length); Gene gene = c.Genes[mutationPoint]; // // A globally installed valuemutator takes precedence over the // default gene mutator. // if (ValueMutator != null) { c.Genes[mutationPoint] = ValueMutator(gene); } else { // this is the Custom case c.Genes[mutationPoint] = gene.Descriptor.Mutate(gene); } // // Raise the Mutated event. // MutatedEventArgs e = new MutatedEventArgs(); e.Chromosome = c; e.MutationPoint = mutationPoint; e.OldGene = gene; e.NewGene = c.Genes[mutationPoint]; OnMutated(e); } #if NOTDEF if (Utils.Rand.NextDouble() < OrderMutationProbability) { if (OrderMutator != null) { OrderMutator(c); } } #endif } }
void Mutate(Chromosome[] cs) { foreach(Chromosome c in cs) { // // Mutate a gene's value in this chromosome. // if ( Utils.Rand.NextDouble() < GeneMutationProbability ) { int mutationPoint = Utils.Rand.Next( c.Genes.Length ); Gene gene = c.Genes[mutationPoint]; // // A globally installed valuemutator takes precedence over the // default gene mutator. // if ( ValueMutator != null ) { c.Genes[mutationPoint] = ValueMutator(gene); } else { // this is the Custom case c.Genes[mutationPoint] = gene.Descriptor.Mutate(gene); } // // Raise the Mutated event. // MutatedEventArgs e = new MutatedEventArgs(); e.Chromosome = c; e.MutationPoint = mutationPoint; e.OldGene = gene; e.NewGene = c.Genes[mutationPoint]; OnMutated( e ); } #if NOTDEF if ( Utils.Rand.NextDouble() < OrderMutationProbability ) { if ( OrderMutator != null ) { OrderMutator(c); } } #endif } }
/// <summary> /// Raises the Mutated event. /// </summary> /// <param name="e"></param> protected virtual void OnMutated(MutatedEventArgs e) { if ( Mutated != null ) { Mutated(this, e); } }