Esempio n. 1
0
        public void Mutate()
        {
            int rand = random.Next(1000);

            int[] rates = { 10, 140, 15 };
            if (rand < rates[0])
            {
                Exp.Add(Vocab.Random());
            }
            else
            if (rand < rates[0] + rates[1])
            {
                if (Exp.Count > 1)
                {
                    Exp.RemoveAt(random.Next(0, Exp.Count));
                }
            }
            else
            if (rand < rates[0] + rates[1] + rates[2])
            {
                int index = random.Next(0, Exp.Count);
                Exp.RemoveAt(index);
                Exp.Insert(index, Vocab.Random());
            }
        }
Esempio n. 2
0
 public void PutRandom()
 {
     if (Vocab.vocabs != null)
     {
         Exp.Add(Vocab.Random());
     }
 }
Esempio n. 3
0
        public static Vocab Random()
        {
            Vocab result = null;

            if (vocabs != null)
            {
                result = new Vocab(vocabs[random.Next(vocabs.Length)], random.Next(quantifiers.Length));
            }

            return(result);
        }
Esempio n. 4
0
        public Expression Crossover(Expression other)
        {
            Expression child = new Expression();

            for (int i = 0; i < this.Exp.Count; i++)
            {
                int rand = random.Next(5);
                if (rand < 2)
                {
                    child.Exp.Add(this.Exp[i]);
                }
                else if (rand < 4)
                {
                    if (i < other.Exp.Count)
                    {
                        child.Exp.Add(other.Exp[i]);
                    }
                }
            }
            child.Exp.Add(Vocab.Random());
            return(child);
        }