public static ISorterGenome ToSorterGenome( this IRando randy, int keyCount, int keyPairCount) { var keyPairSetSize = (uint)KeyPairRepository.KeyPairSetSizeForKeyCount(keyCount); return(new SorterGenomeImpl ( guid: randy.NextGuid(), parentGuid: Guid.Empty, chromosome: randy .ToUintEnumerator(keyPairSetSize) .Take(keyPairCount) .ToList() .ToChromosomeUint ( maxVal: keyPairSetSize ), keyCount: keyCount, keyPairCount: keyPairCount )); }
public static ISwitchableGroupGenome ToSwitchableGroupGenome( this IRando rando, SwitchableGroupGenomeType switchableGroupGenomeType, int keyCount, int groupSize ) { switch (switchableGroupGenomeType) { case SwitchableGroupGenomeType.UInt: return(new SwitchableGroupGenomeImpl ( guid: rando.NextGuid(), parentGuid: Guid.Empty, keyCount: keyCount, chromosome: rando.ToUintEnumerator(((uint)1) << (keyCount - 1)) .Take(groupSize) .ToList() .ToChromosomeUint(((uint)1) << keyCount), groupCount: groupSize )); case SwitchableGroupGenomeType.ULong: return(new SwitchableGroupGenomeImpl ( guid: rando.NextGuid(), parentGuid: Guid.Empty, keyCount: keyCount, chromosome: rando.ToUlongEnumerator(((ulong)1) << (keyCount - 1)) .Take(groupSize) .ToUints() .ToList() .ToChromosomeUlongN(((ulong)1) << keyCount), groupCount: groupSize )); case SwitchableGroupGenomeType.BitArray: return(new SwitchableGroupGenomeImpl ( guid: rando.NextGuid(), parentGuid: Guid.Empty, keyCount: keyCount, chromosome: rando.ToUintEnumerator(2) .Take(groupSize * keyCount) .ToList() .ToChromosomeBits(rando.NextGuid(), keyCount), groupCount: groupSize )); case SwitchableGroupGenomeType.IntArray: return(new SwitchableGroupGenomeImpl ( guid: rando.NextGuid(), parentGuid: Guid.Empty, keyCount: keyCount, chromosome: Enumerable .Range(0, groupSize) .SelectMany(i => Enumerable .Range(0, keyCount) .Select(t => (uint)t) .ToList() .FisherYatesShuffle(rando) ) .ToList() .ToChromosomePermutation(rando.NextGuid(), keyCount, 0.2), groupCount: groupSize )); default: throw new Exception(); } }