public override Chromosome ImplementationClone() { RealValuedChromosome chromosome = new RealValuedChromosome((double[])Values.Clone(), Min, Max, MutationSize); chromosome.Fitness = Fitness; return(chromosome); }
public override Tuple <Chromosome, Chromosome> Crossover(Chromosome pair) { RealValuedChromosome p = (RealValuedChromosome)pair; if (useOnePointCrossover) { return(OnePointCrossover(p)); } else { return(BlendAlphaCrossover(p)); } }
public override double Evaluate(Chromosome chromosome) { RealValuedChromosome _chromosome = (RealValuedChromosome)chromosome; double sum = 0; for (int i = 0; i < _chromosome.Values.Length; i++) { sum += Math.Pow(_chromosome.Values[i], 2); } return(sum); }
public override double Evaluate(Chromosome chromosome) { RealValuedChromosome _chromosome = (RealValuedChromosome)chromosome; double sum = 0; double product = 1; for (int i = 0; i < _chromosome.Values.Length; i++) { sum += _chromosome.Values[i] * _chromosome.Values[i]; product *= Math.Cos(_chromosome.Values[i] / Math.Sqrt(i + 1)); } return(1 + sum / 4000 - product); }
private Tuple <Chromosome, Chromosome> OnePointCrossover(RealValuedChromosome p) { int crossOverPoint = r.Next(Length); List <double> firstChild = new List <double>(); List <double> secondChild = new List <double>(); firstChild.AddRange(Values.Take(crossOverPoint)); secondChild.AddRange(p.Values.Take(crossOverPoint)); firstChild.AddRange(p.Values.Skip(crossOverPoint)); secondChild.AddRange(Values.Skip(crossOverPoint)); RealValuedChromosome firstChildChromosome = new RealValuedChromosome(firstChild.ToArray(), Min, Max, MutationSize); RealValuedChromosome secondChildChromosome = new RealValuedChromosome(secondChild.ToArray(), Min, Max, MutationSize); return(new Tuple <Chromosome, Chromosome>(firstChildChromosome, secondChildChromosome)); }
private Tuple <Chromosome, Chromosome> BlendAlphaCrossover(RealValuedChromosome p) { List <double> firstChild = new List <double>(); List <double> secondChild = new List <double>(); for (int i = 0; i < Values.Length; i++) { double d = Math.Abs(Values[i] - p.Values[i]); double min = Math.Min(Values[i], p.Values[i]); double max = Math.Max(Values[i], p.Values[i]); double u1 = RandomDoubleRange(min - alpha * d, max + alpha * d); double u2 = RandomDoubleRange(min - alpha * d, max + alpha * d); firstChild.Add(u1); secondChild.Add(u2); } RealValuedChromosome firstChildChromosome = new RealValuedChromosome(firstChild.ToArray(), Min, Max, MutationSize); RealValuedChromosome secondChildChromosome = new RealValuedChromosome(secondChild.ToArray(), Min, Max, MutationSize); return(new Tuple <Chromosome, Chromosome>(firstChildChromosome, secondChildChromosome)); }