Esempio n. 1
0
        internal GenePool CreateChild(DNAPool father, DNAPool mother)
        {
            GenePool child = new GenePool();
            EnumBase dominant;
            EnumBase recessive;
            Gene     gc;

            foreach (Gene f in father.GetGenes)
            {
                Type trait = f.Trait;

                Gene m = mother.GetGenes.FindByTrait(trait);

                EnumBase allele1 = GetAllele(f.Dominant, m.Dominant);
                EnumBase allele2 = GetAllele(f.Recessive, m.Recessive);

                if (allele1.Dominancy >= allele2.Dominancy)
                {
                    dominant  = allele2;
                    recessive = allele1;
                }
                else
                {
                    dominant  = allele1;
                    recessive = allele2;
                }

                gc = new Gene(trait, dominant, recessive);
                child.Add(gc);
            }

            return(child);
        }
Esempio n. 2
0
        public static TAttribute GetAttribute <TAttribute>(EnumBase @this) where TAttribute : Attribute
        {
            var field = @this.GetType().GetField(
                @this.ToString(),
                // BindingFlags is yet another flags enum!
                BindingFlags.Public | BindingFlags.Static
                );

            return(field.GetCustomAttribute <TAttribute>());
        }
Esempio n. 3
0
        private EnumBase GetAllele(EnumBase father, EnumBase mother)
        {
            decimal cutOff = father.Probability;
            decimal total  = father.Probability + mother.Probability;

            NextCheck(cutOff, total);

            while (!changed)
            {
            }

            changed = false;

            if (random)
            {
                return(father);
            }
            else
            {
                return(mother);
            }
        }
Esempio n. 4
0
 public Gene(Type _t, EnumBase _d, EnumBase _r)
 {
     Trait     = _t;
     Dominant  = _d;
     Recessive = _r;
 }