Example #1
0
        /// <summary>
        /// Generates a gene value from the domain that results from mutating the given gene value.
        /// </summary>
        /// <param name="allele">The value to base the mutated value on. Has to be part of the domain.</param>
        /// <param name="variancePercentage">
        /// Mutation might utilize Gaussian distributions.
        /// This parameter defines the respective variance as a certain percentage of the variable's domain.
        /// Needs to be positive and at most 1.
        /// </param>
        /// <returns>The generated gene value.</returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown if the given value is not part of the domain
        /// or the given percentage is not a positive value at most 1.
        /// </exception>
        public IAllele MutateGeneValue(IAllele allele, double variancePercentage)
        {
            if (!this.ContainsGeneValue(allele))
            {
                throw new ArgumentOutOfRangeException(
                          $"{allele.GetValue().GetType()} {allele} is not part of the {typeof(T)} domain {this}.");
            }

            var typedValue = (T)allele.GetValue();

            return(new Allele <T>(this.Mutate(typedValue, variancePercentage)));
        }
Example #2
0
        /// <summary>
        /// Checks if the given gene value is part of the domain.
        /// </summary>
        /// <param name="allele">Gene value to check.</param>
        /// <returns>Whether or not the given gene value is part of the domain.</returns>
        public bool ContainsGeneValue(IAllele allele)
        {
            // Check given value's type.
            if (!(allele.GetValue() is T))
            {
                return(false);
            }

            // Check if it is contained in domain.
            var typedValue = (T)allele.GetValue();

            return(this.Contains(typedValue));
        }
Example #3
0
        public void GeneIsSetCorrectly()
        {
            this._genome.SetGene("a", new Allele <int>(5));

            IAllele geneValue = this._genome.GetGeneValue("a");

            Assert.Equal(5, geneValue.GetValue());
        }
Example #4
0
        /// <summary>
        /// Converts the given <paramref name="member"/> of this <see cref="IDomain"/> into a double value.
        /// </summary>
        /// <param name="member">A member of the current domain.</param>
        /// <returns>A double that represents the <paramref name="member"/>.</returns>
        public virtual double ConvertToDouble(IAllele member)
        {
            // check if this is a member
            if (this.ContainsGeneValue(member))
            {
                return(this.ConvertMemberToDouble((T)member.GetValue()));
            }

            throw new ArgumentException($"Allele {member} is not a member of this Domain.", nameof(member));
        }
Example #5
0
 /// <summary>
 /// Check if override of <see cref="ParameterReplacementDefinition.IndicatorParameterIdentifier"/> is required.
 /// </summary>
 /// <param name="indicatorInCurrentTree">
 /// The indicator's value in the current tree.
 /// </param>
 /// <param name="replacementDefinitionWithOverride">
 /// The wrapper with override.
 /// </param>
 /// <returns>
 /// True, if <paramref name="indicatorInCurrentTree"/>.GetValue().Equals(<see cref="ParameterReplacementDefinition.IndicatorParameterValue"/>).
 /// </returns>
 private static bool CheckIfOverrideIsRequired(
     IAllele indicatorInCurrentTree,
     ParameterReplacementDefinition replacementDefinitionWithOverride)
 {
     return(object.Equals(indicatorInCurrentTree.GetValue(), replacementDefinitionWithOverride.IndicatorParameterValue));
 }