Ejemplo n.º 1
0
        public override IGenotype CrossoverWith(IGenotype other, CrossoverType crossover, IRandomNumberGenerator random)
        {
            var newgeno = new StringGenotype(null);
            var og      = other as StringGenotype;

            switch (crossover)
            {
            case CrossoverType.Uniform:
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < Math.Min(str.Length, og.str.Length); i++)
                {
                    sb.Append(random.NextBool() ? str[i] : og.str[i]);
                }
                newgeno.str = sb.ToString();
                break;

            case CrossoverType.OnePoint:
                var point = random.Next(Math.Min(str.Length, og.str.Length));
                newgeno.str = str.Substring(0, point) + og.str.Substring(point);
                break;

            default: throw new NotImplementedException(crossover.ToString());
            }
            return(newgeno);
        }
Ejemplo n.º 2
0
        public override IGenotype Clone()
        {
            var geno = new StringGenotype(string.Copy(str));

            return(geno);
        }
Ejemplo n.º 3
0
 public HammingPhenotype(IGenotype genotype) : base(genotype)
 {
     geno = genotype as StringGenotype;
 }