public Individual CorssOver(Individual otherParent) { List <int> childGenes = new List <int>(); var x = random.Next(1, otherParent.Genes.Length - 1); var pGenes = Genes.Take(x).ToArray(); childGenes.AddRange(pGenes); for (int i = 0; i < otherParent.Genes.Length; i++) { if (!childGenes.Contains(otherParent.Genes[i])) { childGenes.Add(otherParent.Genes[i]); } } var child = new Individual(size, random); childGenes.CopyTo(child.Genes, 0); childGenes = null; return(child); }
public virtual Individuo Cruce(Individuo Padre) { var genesPadre = Padre.Genes; int n = Genes.Count(); var genes = (n % 2 == 0) ? Genes.Take(n / 2).Concat(genesPadre.Skip(n / 2)) : Genes.Take((n / 2) + 1).Concat(genesPadre.Skip(n / 2)); return(getNuevoIndividuo(genes.ToList())); }