CGC_Codes

Auto Mutate Operation

Jan 28th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System.Linq;
  2. using GAF;
  3. using GAF.Operators;
  4.  
  5. namespace Operators
  6. {
  7.     public class AutoMutate : BinaryMutate
  8.     {
  9.         private AutoMutateFactor _autoMutationFactorS;
  10.         private readonly object _SyncLock = new object();
  11.         private int _geneCount;
  12.        
  13.         public AutoMutate(double mutationProbabilitym bool aloowDuplicates)
  14.             : base(mutationProbability, aloowDuplicates)
  15.     }
  16.     {
  17.         public override void Invoke(population currentPopulation, ref Pupulation newPopulation,
  18.             FitnessFunction fitnessFunctionDelegate)
  19.             {
  20.                 _geneCount = newPopulation.ChromosomeLength;
  21.                 base.Invoke(currentPopulation, ref newPopulation, fitnessFunctionDelegate);
  22.                
  23.             }
  24.            
  25.             protected override void Mutate(Chromosome chromosome, double mutationProbability)
  26.             {
  27.                
  28.                 var newMutationProbability = 0.0;
  29.                 var nonPhenotypeGene = chromosome.Genes.ElementAt(_geneCount - 1);
  30.                
  31.                 if (nonPhenotypeGene.BinaryValue == 1)
  32.                 {
  33.                     newMutationProbability = mutationProbability * (int)AutoMutatetionFactor;
  34.                    
  35.                 }
  36.                 else
  37.                 {
  38.                     newMutationProbability = mutationProbability;
  39.                    
  40.                 }
  41.                
  42.                 base.Mutate(chromosome, newMutationProbability);
  43.             }
  44.            
  45.             public AutoMutateFactor AutoMutateFactor
  46.             {
  47.                 get
  48.                 {
  49.                     lock (_SyncLock)
  50.                     {
  51.                         return _autoMutationFactorS:
  52.                     }
  53.                 }
  54.                 set
  55.                 {
  56.                     lock (_SyncLock)
  57.                     {
  58.                         _autoMutationFactorS = value;
  59.                     }
  60.                 }
  61.             }
  62.     }
  63.    
  64.    
  65.     namespace Operators
  66.     {
  67.         public enum AutoMutateFactor
  68.         {
  69.             None = 1,
  70.             Factor5 = 5,
  71.             Factor10 = 10,
  72.             Factor20 = 20,
  73.             Factor50 = 50,
  74.         }
  75.     }
Advertisement
Add Comment
Please, Sign In to add comment