public static IEnumerable <ISwitchableGroup <T> > Mutate <T>(this ISwitchableGroup <T> switchableGroup, IRando rando, double mutationRate, IEnumerable <Guid> newGuids) { var mutationSource = rando.MakeSwitchables <T>(switchableGroup.KeyCount).ToMoveNext(); foreach (var newGuid in newGuids) { var switchables = switchableGroup.Switchables.Mutate(rando.ToBoolEnumerator(mutationRate), t => mutationSource.Next()); yield return(new SwitchableGroupImpl <T> ( guid: newGuid, keyCount: switchableGroup.KeyCount, switchables: switchables )); } }
public static IEnumerable <ISwitchable <T> > MakeSwitchables <T>(this IRando random, int keyCount) { if (typeof(T) == typeof(uint)) { return((IEnumerable <ISwitchable <T> >)random.ToUintEnumerator(((uint)1) << (keyCount - 1)).ToUintSwitchable(keyCount)); } if (typeof(T) == typeof(ulong)) { return((IEnumerable <ISwitchable <T> >)random.ToUlongEnumerator(((ulong)1) << (keyCount - 1)).ToUlongSwitchable(keyCount)); } if (typeof(T) == typeof(bool[])) { return((IEnumerable <ISwitchable <T> >)random.ToBoolEnumerator(0.5).Chunk(keyCount).Select(b => b.ToSwitchableBitArray())); } if (typeof(T) == typeof(int[])) { return((IEnumerable <ISwitchable <T> >)random.ToRandomEnumerator().Select(r => r.ToSwitchableIntArray(keyCount))); } throw new Exception("unhandled switchable type"); }
public override IGeneBits NewBlock(IRando rando) { return(rando.ToBoolEnumerator(0.5).Take(BitCount) .ToGeneBits()); }
public IGene Mutate(IRando rando) { return(rando.ToBoolEnumerator(0.5).Take(Bits.Count) .ToGeneBits()); }