Exemplo n.º 1
0
Arquivo: ga.cs Projeto: mykwillis/genX
 /// <summary>
 /// Raises the Mutated event.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnMutated(MutatedEventArgs e)
 {
     if (Mutated != null)
     {
         Mutated(this, e);
     }
 }
Exemplo n.º 2
0
 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("^");
 }
Exemplo n.º 3
0
Arquivo: ga.cs Projeto: mykwillis/genX
        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
            }
        }
Exemplo n.º 4
0
Arquivo: ga.cs Projeto: mykwillis/genX
        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
            }
        }
Exemplo n.º 5
0
Arquivo: ga.cs Projeto: mykwillis/genX
 /// <summary>
 /// Raises the Mutated event.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnMutated(MutatedEventArgs e)
 {
     if ( Mutated != null )
     {
         Mutated(this, e);
     }
 }