public static ISwitchableGroupGenome Make ( Guid guid, Guid parentGuid, int keyCount, IChromosome chromosome, SwitchableGroupGenomeType switchableGroupGenomeType, int groupCount ) { switch (switchableGroupGenomeType) { case SwitchableGroupGenomeType.UInt: return(new SwitchableGroupGenomeImpl(guid, parentGuid, keyCount, (IChromosomeUint)chromosome, groupCount)); case SwitchableGroupGenomeType.ULong: return(new SwitchableGroupGenomeImpl(guid, parentGuid, keyCount, (IChromosomeUlongN)chromosome, groupCount)); case SwitchableGroupGenomeType.BitArray: return(new SwitchableGroupGenomeImpl(guid, parentGuid, keyCount, (IChromosomeBits)chromosome, groupCount)); case SwitchableGroupGenomeType.IntArray: return(new SwitchableGroupGenomeImpl(guid, parentGuid, keyCount, (IChromosomePermutation)chromosome, groupCount)); default: throw new Exception("SwitchableGroupGenomeType not handled"); } }
public static ISorterCompParaPoolWorkflow Make( int seed, SwitchableGroupGenomeType switchableGroupGenomeType, int keyCount, int keyPairCount, int switchableGroupSize, SorterCompParaPoolParams sorterCompParaPoolParams ) { var randy = Rando.Fast(seed); return(new SorterCompParaPoolWorkflowImpl ( sorterLayer: SorterLayer.Create ( seed: randy.NextInt(), genomeCount: sorterCompParaPoolParams.PopulationSize, keyCount: keyCount, keyPairCount: keyPairCount ), switchableGroupLayer: SwitchableLayer.Create ( seed: randy.NextInt(), switchableGroupGenomeType: switchableGroupGenomeType, genomeCount: sorterCompParaPoolParams.SwitchableLayerStartingGenomeCount, keyCount: keyCount, groupSize: switchableGroupSize ), sorterCompParaPoolParams: sorterCompParaPoolParams, generation: 0 )); }
static Func <int, ISwitchableGroupGenome> CreateFunc ( SwitchableGroupGenomeType switchableGroupGenomeType, int keyCount, int groupSize ) { return(i => Rando.Fast(i).ToSwitchableGroupGenome ( switchableGroupGenomeType: switchableGroupGenomeType, keyCount: keyCount, groupSize: groupSize )); }
public static ILayer <ISwitchableGroupGenome> Create ( int seed, SwitchableGroupGenomeType switchableGroupGenomeType, int genomeCount, int keyCount, int groupSize ) { return(Layer.Create ( seed: seed, createFunc: CreateFunc(switchableGroupGenomeType, keyCount, groupSize), genomeCount: genomeCount )); }
public void TestRandomSwitchableGroupGenomeIntArray() { const int cSeed = 1234; const int cGroupSize = 100; const int cKeyCount = 16; const SwitchableGroupGenomeType cSwitchableGroupGenomeType = SwitchableGroupGenomeType.IntArray; var switchableGroupGenome = Rando.Fast(cSeed).ToSwitchableGroupGenome ( switchableGroupGenomeType: cSwitchableGroupGenomeType, keyCount: cKeyCount, groupSize: cGroupSize ); Assert.AreEqual(switchableGroupGenome.KeyCount, cKeyCount); Assert.AreEqual(switchableGroupGenome.Chromosome.Sequence.Count, cGroupSize * cKeyCount); Assert.AreEqual(switchableGroupGenome.SwitchableGroupGenomeType, cSwitchableGroupGenomeType); }
public void TestToSwitchableGroupBitArray() { const int cSeed = 1234; const int cGroupSize = 100; const int cKeyCount = 60; const SwitchableGroupGenomeType cSwitchableGroupGenomeType = SwitchableGroupGenomeType.BitArray; var switchableGroupGenome = Rando.Fast(cSeed).ToSwitchableGroupGenome ( switchableGroupGenomeType: cSwitchableGroupGenomeType, keyCount: cKeyCount, groupSize: cGroupSize ); var switchableGroup = switchableGroupGenome.ToSwitchableGroup(); Assert.AreEqual(switchableGroup.KeyCount, cKeyCount); Assert.AreEqual(switchableGroup.SwitchableCount, cGroupSize); Assert.AreEqual(switchableGroup.SwitchableDataType, cSwitchableGroupGenomeType.ToSwitchableGroupDataType()); }
public static Type ToSwitchableGroupDataType ( this SwitchableGroupGenomeType switchableGroupGenomeType ) { switch (switchableGroupGenomeType) { case SwitchableGroupGenomeType.UInt: return(typeof(uint)); case SwitchableGroupGenomeType.ULong: return(typeof(ulong)); case SwitchableGroupGenomeType.BitArray: return(typeof(bool[])); case SwitchableGroupGenomeType.IntArray: return(typeof(uint[])); default: throw new Exception(string.Format("SwitchableGroupGenomeType: {0} unkown", switchableGroupGenomeType)); } }
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(); } }