Example #1
0
        /// <summary>
        /// Add an attribute to this individual
        /// </summary>
        /// <param name="tag">Attribute label</param>
        /// <param name="value">Value to set or change</param>
        public void Add(string tag, IIndividualAttribute value = null)
        {
            if (attributes is null)
            {
                attributes = new Dictionary <string, IIndividualAttribute>();
            }

            if (!attributes.ContainsKey(tag))
            {
                attributes.Add(tag, value);
            }
            else
            {
                attributes[tag] = value;
            }
        }
Example #2
0
        private void SetFemaleMateAttributes(RuminantFemale female, KeyValuePair <string, IIndividualAttribute> femaleAttribute, IIndividualAttribute maleAttribute)
        {
            if (maleAttribute != null)
            {
                if (femaleAttribute.Value != null && femaleAttribute.Value.InheritanceStyle != maleAttribute.InheritanceStyle)
                {
                    string errorMsg;
                    if (useControlledMating)
                    {
                        errorMsg = $"provided from [a={controlledMating.NameWithParent}]";
                    }
                    else
                    {
                        errorMsg = $"from the herd in [a={NameWithParent}]";
                    }
                    throw new ApsimXException(this, $"The inheritance style for attribute [{femaleAttribute.Key}] differs between the breeder [{femaleAttribute.Value.InheritanceStyle}] and breeding male [{maleAttribute.InheritanceStyle}] {errorMsg}");
                }

                if (femaleAttribute.Value != null)
                {
                    femaleAttribute.Value.StoredMateValue = maleAttribute.StoredValue;
                }
            }
            else
            {
                if (femaleAttribute.Value != null)
                {
                    femaleAttribute.Value.StoredMateValue = null;
                }
                if (female.BreedParams.IsMandatoryAttribute(femaleAttribute.Key))
                {
                    string errorMsg;
                    if (useControlledMating)
                    {
                        errorMsg = $"Cannot locate the madatory attribute [{femaleAttribute.Key}] in [a={controlledMating.NameWithParent}]{Environment.NewLine}Add a [SetAttribute] component below the [a=RuminantnActivityControlledMating]";
                    }
                    else
                    {
                        errorMsg = $"Cannot locate the madatory attribute [{femaleAttribute.Key}] in from the breeding male selected from the herd in [a={NameWithParent}]{Environment.NewLine}Ensure all sires in initial herd or purchased provide the appropriate [SetAttribute] component";
                    }
                    throw new ApsimXException(this, errorMsg);
                }
            }
        }