public IGenome Copy() { Dictionary <Guid, INode> nodeReplacements = new Dictionary <Guid, INode>(); List <IGene> genes = Genes.Select(g => g.Copy()).ToList(); genes.ToList().ForEach(g => { if (!nodeReplacements.Any(nr => nr.Key == g.NodeIn.Id)) { nodeReplacements.Add(g.NodeIn.Id, g.NodeIn.Copy()); } if (!nodeReplacements.Any(nr => nr.Key == g.NodeOut.Id)) { nodeReplacements.Add(g.NodeOut.Id, g.NodeOut.Copy()); } g.NodeIn = nodeReplacements[g.NodeIn.Id]; g.NodeOut = nodeReplacements[g.NodeOut.Id]; }); return(new Genome() { Id = Id, Genes = genes, Nodes = nodeReplacements.Select(nr => nr.Value).ToList() }); }
public DNA <T> Crossover(DNA <T> otherParent) { DNA <T> child = new DNA <T>(Genes.Length, random, getRandomGene, determineFitness, InitializeGenes: false); child.Genes = Genes.Select((g, i) => random.NextDouble() < 0.5 ? g : otherParent.Genes[i]).ToArray(); return(child); }
public Generation(DirectoryInfo d) { RootPath = d.FullName; Name = d.Name; Genes = d.GetDirectories().Select(x => new Gene(x)).OrderByDescending(x => x.Score).ToList(); AverageScore = Genes.Select(x => x.Score).Where(x => x != double.MinValue).DefaultIfEmpty().Average(); MaxScore = Genes.Select(x => x.Score).Where(x => x != double.MinValue).DefaultIfEmpty().Max(); }
public ChromosomeType Clone() { var result = new ChromosomeType(Size); result.Genes = Genes .Select(x => x) .ToArray(); return(result); }
public override void Evaluar() { int valor = 0; var genes = Genes.Select(gen => new { Horario = gen.Horario, Asignatura = gen.Asignatura.Nombre, Aula = gen.Aula.Nombre, Profesor = gen.Asignatura.NombreProfesor }); valor += 10 * genes .GroupBy(gen => new { CodigoProf = gen.Profesor, Horario = gen.Horario }) .Where(gen => gen.Count() > 1) .Count(); valor += 10 * genes .GroupBy(gen => new { Horario = gen.Horario, Aula = gen.Aula }) .Where(res => res.Count() > 1) .Count(); valor += 5 * genes. GroupBy(gen => new { Asignatura = gen.Asignatura, Aula = gen.Aula }) .Where(res => res.Count() != 4) .Count(); valor += 3 * genes .GroupBy(gen => new { Asignatura = gen.Asignatura, Aula = gen.Aula, Dia = HorarioHelper.Dia(gen.Horario) }) .Where(res => res.Count() > 1) .Count(); this.Fitness = valor; }
public virtual IGenome <T> CreateNew(bool copyGenes = true) { IList <Gene <T> > genes; if (copyGenes) { genes = Genes.Select(x => new Gene <T>(x)).ToArray(); } else { genes = Genes; } return(new GenomeBase <T>(genes)); }
public override IGenome <Synapse> CreateNew(bool copyGenes = true) { IList <Gene <Synapse> > genes; IList <Neuron> neurons; if (copyGenes) { genes = Genes.Select(x => new Gene <Synapse>(x)).ToArray(); } else { genes = Genes; } neurons = NeuronLst.Select(x => new Neuron(x)).ToArray(); return(new NeuralGenomeBase(neurons, genes, ActivationF)); }
public override void Evaluar() { return; int valor = 0; //se sumará el coste de los horarios asignados //valor += Genes // .Select(gen => gen.Coste) // .Sum(); var genes = Genes.Select(gen => new { Profesor = gen.Asignatura.NombreProfesor, Horario = gen.Horario, Asignatura = gen.Asignatura.Nombre, Aula = gen.Aula.Nombre }); //se calcula el número de apariciones del profesor //en el mismo horario valor += 5 * genes .GroupBy(gen => new { CodigoProf = gen.Profesor, Horario = gen.Horario }) .Where(gen => gen.Count() > 1) .Count(); //se calcula el número de apariciones del profesor //en el mismo horario valor += 5 * Genes .GroupBy(gen => new { Horario = gen.Horario, Aula = gen.Aula.Nombre }) .Where(res => res.Count() > 1) .Count(); this.Fitness = valor; }
public override List <Individual> getNeighbourhood() { var individuos = new List <Individual>(); for (int i = 0; i < 10; i++) { var genes = Genes .Select(gen => { return(new Gen() { Asignatura = gen.Asignatura, Coste = 0, Horario = gen.Horario, Aula = AulaHelper.Aleatorea(gen.Asignatura.TipoAula, gen.Horario) }); }).ToList(); individuos.Add(new IndividuoUniversidad(genes)); } return(individuos); }
public override List <Individual> getNeighbourhood() { individuos.Clear(); int horarios = HorarioHelper.NumHorarios(); for (int i = 0; i < 5; i++) { var genes = Genes .Select(gen => { return(new Gen() { Asignatura = AsignaturaHelper.Aleatorea(), Coste = 0, Horario = gen.Horario, Aula = gen.Aula }); }); individuos.Add(new IndividuoPrescolar(genes)); } return(individuos); }
public void Mutate(double MutationRate) { Genes = Genes.Select(g => random.NextDouble() < MutationRate ? getRandomGene(random) : g).ToArray(); }
public override string ToString() { return(string.Join(" ", Genes.Select(g => g.Allele))); }
public string GetPath() { return(string.Join("\n\t", Genes.Select(c => c.Name))); }
// Set weights to genes public double[] getWeights() { // Set each weight in the neural net to its gene representation return(Genes.Select(gene => gene.Allele).ToArray()); }