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()); } }
public void PutRandom() { if (Vocab.vocabs != null) { Exp.Add(Vocab.Random()); } }
public static Vocab Random() { Vocab result = null; if (vocabs != null) { result = new Vocab(vocabs[random.Next(vocabs.Length)], random.Next(quantifiers.Length)); } return(result); }
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); }