/// <summary> /// RuleBook側で扱えるゲノムを作成 /// </summary> /// <returns></returns> public Genome CreateGenome() { var genome = new Genome(NumberDNA.Make(this.dnaMax, this.seed, this.Min, this.Max), new NumberMutant(this.seed, this.Min, this.Max), new NumberCrossover(this.seed, this.Min, this.Max)); this.seed += 1; return(genome); }
/// <summary> /// ゲノムのDNAから新しいDNAを生成 /// </summary> /// <param name="aMyDna"></param> /// <param name="aSomeOneDNA"></param> /// <returns></returns> private (DNA[], DNA[]) NCrossPoint(DNA[] aMyDna, DNA[] aSomeOneDNA) { Random rand = new Random(this.seed++); int[] cutPoint = this.MkCutPoint(rand.Next(1, aMyDna.Length), 0, aMyDna.Length); Array.Resize(ref cutPoint, cutPoint.Length + 1); // memo: Length+1して拡張した要素に元のDNA最大数を入れているが意味あるのか? cutPoint[cutPoint.Length - 1] = aMyDna.Length; DNA[] ch1 = new NumberDNA[aMyDna.Length]; { for (int i = 0; i < ch1.Length; ++i) { ch1[i] = new NumberDNA(0); } } DNA[] ch2 = new NumberDNA[aMyDna.Length]; { for (int i = 0; i < ch2.Length; ++i) { ch2[i] = new NumberDNA(0); } } int IX = 0; var st = 0; foreach (var pt in cutPoint) { // pt >= stにならないと入れ替えが発生しない // st ~ pt - stの範囲内で値の入れ替えをしている if (IX++ % 2 == 0) { for (int i = st; i < pt - st; ++i) { ch1[i].Copy(aMyDna[i]); ch2[i].Copy(aSomeOneDNA[i]); } } else { for (int i = st; i < pt - st; ++i) { ch2[i].Copy(aMyDna[i]); ch1[i].Copy(aSomeOneDNA[i]); } } st = pt; } return(ch1, ch2); }
public void Copy(DNA org) { NumberDNA numberDNA = org as NumberDNA; this.num = numberDNA.num; }