public static ISorter ToSorter(this ISorterGenome sorterGenome) { return(KeyPairRepository.KeyPairSet(sorterGenome.KeyCount) .KeyPairs.ToSorter ( keyPairChoices: sorterGenome.Chromosome.Sequence, keyCount: sorterGenome.KeyCount, guid: sorterGenome.Guid )); }
public void ConvertSorterTest() { const int keyCount = 16; const int sequenceLength = 100; var keyPairSet = KeyPairRepository.KeyPairSet(keyCount); var guid = Guid.NewGuid(); var keyPairs = Enumerable.Range(0, KeyPairRepository.KeyPairSetSizeForKeyCount(keyCount)) .Select(i => keyPairSet[i]) .ToArray(); var sorter = keyPairs.ToSorter(guid: guid, keyCount: keyCount); var serialized = JsonConvert.SerializeObject(sorter.ToJsonAdapter(), Formatting.Indented); var newSorter = serialized.ToSorter(); Assert.AreEqual(newSorter.Guid, guid); Assert.AreEqual(newSorter.KeyCount, keyCount); Assert.IsTrue(newSorter.KeyPairs.IsSameAs(keyPairs)); }
public static IEnumerable <ISorter> Mutate(this ISorter sorter, IRando rando, double mutationRate) { var randoK = rando.Spawn(); var keyPairList = KeyPairRepository.KeyPairSet(sorter.KeyCount).KeyPairs; var newb = randoK.Pick(keyPairList).ToMoveNext(); while (true) { yield return(new SorterImpl ( keyPairs: sorter.KeyPairs.MutateInsertDelete ( rando.Spawn().ToBoolEnumerator(mutationRate), rando.Spawn().ToBoolEnumerator(mutationRate), rando.Spawn().ToBoolEnumerator(mutationRate), T => newb.Next(), T => newb.Next(), T => newb.Next() ), guid: randoK.NextGuid(), keyCount: sorter.KeyCount )); } }
public static ISorter ToSorter2(this IRando rando, int keyCount, int keyPairCount, Guid guid) { var keyPairSet = KeyPairRepository.KeyPairSet(keyCount); return(rando.ToSorter2(keyPairSet.KeyPairs, keyPairCount, keyCount, guid)); }