public Chromosome(Chromosome chromosome) { this.Genes = new List <Gene>(chromosome.Genes).ToArray(); this.MutationTracker = chromosome.MutationTracker; this.neuralChromosome = chromosome.neuralChromosome; this.Parameters = chromosome.Parameters; }
public Chromosome(Gene[] genes, NeuralChromosome neuralChromosome, string mutationTracker, ChromosomeParameters parameters) { this.Genes = new List <Gene>(genes).ToArray(); this.MutationTracker = mutationTracker; this.neuralChromosome = neuralChromosome; this.Parameters = parameters; }
public Chromosome(SerializationInfo info, StreamingContext context) { Genes = (Gene[])info.GetValue("Genes", typeof(Gene[])); MutationTracker = (string)info.GetValue("MutationTracker", typeof(string)); neuralChromosome = (NeuralChromosome)info.GetValue("neuralChromosome", typeof(NeuralChromosome)); Parameters = (ChromosomeParameters)info.GetValue("Parameters", typeof(ChromosomeParameters)); }
private static ChromosomeParameters MutateParameters(ChromosomeParameters parameters) { double[] param = parameters.ToArray(); for (int i = 0; i < param.Length; i++) { param[i] = MutateParameter(param[i], 0, 1); } return(new ChromosomeParameters(param)); }
public static ChromosomeParameters CrossParameters(ChromosomeParameters parameters1, ChromosomeParameters parameters2) { double[] p1 = parameters1.ToArray(); double[] p2 = parameters2.ToArray(); double[] res = new double[p1.Length]; for (int i = 0; i < p1.Length; i++) { if (GenesManager.r.Next(2) == 0) { res[i] = p1[i]; } else { res[i] = p2[i]; } } return(new ChromosomeParameters(res)); }
public static Chromosome CreateCrossover(Chromosome ch1, Chromosome ch2) { Gene[] genes = CrossoverManager.Crossover(ch1.Genes, ch2.Genes); var neuralComparableGenes = CrossoverManager.Crossover(ch1.neuralChromosome.GetComparableGenes(), ch2.neuralChromosome.GetComparableGenes()); DendriteGene[] dendriteGenes = new DendriteGene[neuralComparableGenes.Length]; for (int i = 0; i < dendriteGenes.Length; i++) { dendriteGenes[i] = neuralComparableGenes[i].GetGene(); } NeuralChromosome neuralChromosome = new NeuralChromosome(dendriteGenes); ChromosomeParameters parameters = CrossoverManager.CrossParameters(ch1.Parameters, ch2.Parameters); Chromosome chromosome = new Chromosome(genes, neuralChromosome, ch1.MutationTracker + "CR", parameters); return(chromosome); }