/// <summary> /// Adds a mutation function to the chain at a random gene location. /// </summary> /// <param name="fnInitializer">Mutation function.</param> /// <param name="copies">Number of copies, at random positions, to append to the chain.</param> /// <returns>MutationChain.</returns> public MutationChain AddRandom <T>(Func <T> fnInitializer, int copies = 1) where T : MutationBase { MutationChain chain = this; for (int i = 0; i < copies; i++) { chain = chain.Add(fnInitializer, Sampling.GetUniform(0, this.SequenceLength - 1)); } return(chain); }
/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="fnInitializer"></param> /// <param name="index"></param> /// <returns></returns> public MutationChain Add <T>(Func <T> fnInitializer, int index) where T : MutationBase { if (index >= this.SequenceLength) { throw new ArgumentOutOfRangeException(nameof(index), "Index for gene mutation was greater than the sequence length."); } if (index < 0) { throw new ArgumentOutOfRangeException(nameof(index), "Index was less than zero"); } T mutator = fnInitializer(); mutator.N = index; MutationChain result = this.Add(mutator); return(result); }