Beispiel #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        public Ruminant(double setAge, Sex setGender, double setWeight, RuminantType setParams)
        {
            this.Age = setAge;
            this.AgeEnteredSimulation = setAge;
            this.Gender      = setGender;
            this.BreedParams = setParams;

            if (setWeight <= 0)
            {
                // use normalised weight
                this.Weight = NormalisedAnimalWeight;
            }
            else
            {
                this.Weight = setWeight;
            }

            this.PreviousWeight = this.Weight;
            this.Number         = 1;
            this.Wool           = 0;
            this.Cashmere       = 0;
            this.weaned         = true;
            this.SaleFlag       = HerdChangeReason.None;

            this.Tags = new List <string>();
        }
Beispiel #2
0
        /// <summary>
        /// Provides the closing html tags for object
        /// </summary>
        /// <returns></returns>
        public override string ModelSummaryInnerClosingTags(bool formatForParentControl)
        {
            string html = "";

            if (formatForParentControl)
            {
                RuminantType rumtype      = FindAncestor <RuminantType>();
                Ruminant     newInd       = null;
                string       normWtString = "Unavailable";
                double       normalisedWt = 0;

                if (rumtype != null)
                {
                    newInd       = new Ruminant(this.Age, this.Gender, 0, FindAncestor <RuminantType>());
                    normWtString = newInd.NormalisedAnimalWeight.ToString("#,##0");
                    normalisedWt = newInd.NormalisedAnimalWeight;
                    if (Math.Abs(this.Weight - newInd.NormalisedAnimalWeight) / newInd.NormalisedAnimalWeight > 0.2)
                    {
                        normWtString = "<span class=\"errorlink\">" + normWtString + "</span>";
                        (this.Parent as RuminantInitialCohorts).WeightWarningOccurred = true;
                    }

                    html += "\n<tr><td>" + this.Name + "</td><td><span class=\"setvalue\">" + this.Gender + "</span></td><td><span class=\"setvalue\">" + this.Age.ToString() + "</span></td><td><span class=\"setvalue\">" + this.Weight.ToString() + ((this.WeightSD > 0) ? " (" + this.WeightSD.ToString() + ")" : "") + "</spam></td><td>" + normWtString + "</td><td><span class=\"setvalue\">" + this.Number.ToString() + "</span></td><td" + ((this.Suckling) ? " class=\"fill\"" : "") + "></td><td" + ((this.Sire) ? " class=\"fill\"" : "") + "></td></tr>";
                }
            }
            else
            {
                html += "\n</div>";
            }
            return(html);
        }
Beispiel #3
0
        private void OnCLEMInitialiseResource(object sender, EventArgs e)
        {
            Details      = this.FindAllChildren <RuminantTypeCohort>().FirstOrDefault();
            ruminantType = Resources.GetResourceItem(this.Parent as Model, RuminantTypeName, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop) as RuminantType;

            // create example ruminant
            Details.Number    = 1;
            ExampleIndividual = Details.CreateIndividuals(null, BreedParams).FirstOrDefault();
        }
Beispiel #4
0
 /// <summary>
 /// Factory for creating ruminants based on provided values
 /// </summary>
 public static Ruminant Create(Sex sex, RuminantType parameters, double age = 0, double weight = 0)
 {
     if (sex == Sex.Male)
     {
         return(new RuminantMale(parameters, age, weight));
     }
     else
     {
         return(new RuminantFemale(parameters, age, weight));
     }
 }
Beispiel #5
0
        /// <summary>
        /// Constructor
        /// </summary>
        public Ruminant(RuminantType setParams, double setAge, double setWeight)
        {
            this.BreedParams          = setParams;
            this.Age                  = setAge;
            this.AgeEnteredSimulation = setAge;

            Weight = setWeight <= 0 ? NormalisedAnimalWeight : setWeight;

            this.PreviousWeight = this.Weight;
            this.Number         = 1;
            this.Wool           = 0;
            this.Cashmere       = 0;
            this.weaned         = true;
            this.SaleFlag       = HerdChangeReason.None;
            this.Attributes     = new IndividualAttributeList();
        }
Beispiel #6
0
        /// <summary>
        /// Validate model
        /// </summary>
        /// <param name="validationContext"></param>
        /// <returns></returns>
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            RuminantTypeCohort ruminantCohort = Parent as RuminantTypeCohort;
            var results = new List <ValidationResult>();

            if ((Parent as RuminantTypeCohort).Sex == Sex.Female)
            {
                // get the breed to check gestation
                RuminantType ruminantType = this.FindAncestor <RuminantType>();
                if (ruminantType is null)
                {
                    // find type from a specify ruminant component
                    var specifyRuminant = this.FindAncestor <SpecifyRuminant>();
                    if (specifyRuminant != null)
                    {
                        ruminantType = resources.FindResourceType <RuminantHerd, RuminantType>(this as Model, specifyRuminant.RuminantTypeName, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop);
                    }

                    if (ruminantType != null)
                    {
                        if (NumberMonthsPregnant < ruminantType.GestationLength)
                        {
                            string[] memberNames = new string[] { "Ruminant cohort details" };
                            results.Add(new ValidationResult($"The number of months pregant [{NumberMonthsPregnant}] for [r=SetPreviousConception] must be less than the gestation length of the breed [{ruminantType.GestationLength}]", memberNames));
                        }
                        // get the individual to check female and suitable age for conception supplied.
                        if (ruminantCohort.Age - NumberMonthsPregnant >= ruminantType.MinimumAge1stMating)
                        {
                            string[] memberNames = new string[] { "Ruminant cohort details" };
                            results.Add(new ValidationResult($"The individual specified must be at least [{ruminantType.MinimumAge1stMating}] month old at the time of conception [r=SetPreviousConception]", memberNames));
                        }
                    }
                    else
                    {
                        string[] memberNames = new string[] { "Ruminant cohort details" };
                        results.Add(new ValidationResult($"Cannot locate a [r=RuminantType] in tree structure above [r=SetPreviousConception]", memberNames));
                    }
                }
            }
            else
            {
                string[] memberNames = new string[] { "ActivityHolder" };
                results.Add(new ValidationResult("Previous conception status can only be calculated for female ruminants", memberNames));
            }

            return(results);
        }
Beispiel #7
0
        /// <summary>
        /// Generate the store for tracking individuals in groups for reporting
        /// </summary>
        /// <returns>Dicitonary of ResourceTypes and categories for each</returns>
        public IEnumerable <string> GetReportingGroups(RuminantType ruminantType)
        {
            List <string> catNames = new List <string>();

            switch (TransactionStyle)
            {
            case RuminantTransactionsGroupingStyle.Combined:
                catNames.Add("All");
                break;

            case RuminantTransactionsGroupingStyle.ByPriceGroup:
                var animalPricing = ruminantType.FindAllChildren <AnimalPricing>().FirstOrDefault();
                if (animalPricing != null)
                {
                    catNames.AddRange(animalPricing.FindAllChildren <AnimalPriceGroup>().Select(a => a.Name));
                }
                break;

            case RuminantTransactionsGroupingStyle.ByClass:
                catNames.AddRange(Enum.GetNames(typeof(RuminantClass)));
                break;

            case RuminantTransactionsGroupingStyle.BySexAndClass:
                var classes = Enum.GetNames(typeof(RuminantClass));
                foreach (var item in classes)
                {
                    switch (item)
                    {
                    case "Castrate":
                    case "Sire":
                        catNames.Add($"{item}Male");
                        break;

                    default:
                        catNames.Add($"{item}Female");
                        catNames.Add($"{item}Male");
                        break;
                    }
                }
                break;

            default:
                break;
            }
            return(catNames);
        }
Beispiel #8
0
        /// <summary>
        /// Provides the description of the model settings for summary (GetFullSummary)
        /// </summary>
        /// <param name="formatForParentControl">Use full verbose description</param>
        /// <returns></returns>
        public override string ModelSummary(bool formatForParentControl)
        {
            string html = "";

            if (!formatForParentControl)
            {
                html += "\n<div class=\"activityentry\">";
                if (Number <= 0)
                {
                    html += "<span class=\"errorlink\">" + Number.ToString() + "</span> x ";
                }
                else if (Number > 1)
                {
                    html += "<span class=\"setvalue\">" + Number.ToString() + "</span> x ";
                }
                else
                {
                    html += "A ";
                }
                html += "<span class=\"setvalue\">";
                html += Age.ToString("0") + "</span> month old ";
                html += "<span class=\"setvalue\">" + Gender.ToString() + "</span></div>";
                if (Suckling)
                {
                    html += "\n<div class=\"activityentry\">" + ((Number > 1)?"These individuals are suckling":"This individual is a suckling") + "</div>";
                }
                if (Sire)
                {
                    html += "\n<div class=\"activityentry\">" + ((Number > 1) ? "These individuals are breeding sires" : "This individual is a breeding sire") + "</div>";
                }

                RuminantType rumtype      = FindAncestor <RuminantType>();
                Ruminant     newInd       = null;
                string       normWtString = "Unavailable";

                if (rumtype != null)
                {
                    newInd       = new Ruminant(this.Age, this.Gender, 0, FindAncestor <RuminantType>());
                    normWtString = newInd.NormalisedAnimalWeight.ToString("#,##0");
                }

                if (WeightSD > 0)
                {
                    html += "\n<div class=\"activityentry\">Individuals will be randomally assigned a weight based on a mean " + ((Weight == 0) ? "(using the normalised weight) " : "") + "of <span class=\"setvalue\">" + Weight.ToString("#,##0") + "</span> kg with a standard deviation of <span class=\"setvalue\">" + WeightSD.ToString() + "</span></div>";

                    if (newInd != null && Math.Abs(Weight - newInd.NormalisedAnimalWeight) / newInd.NormalisedAnimalWeight > 0.2)
                    {
                        html += "<div class=\"activityentry\">These individuals should weigh close to the normalised weight of <span class=\"errorlink\">" + normWtString + "</span> kg for their age</div>";
                    }
                }
                else
                {
                    html += "\n<div class=\"activityentry\">" + ((Number > 1) ? "These individuals " : "This individual ") + "weigh" + ((Number > 1) ? "" : "s") + ((Weight == 0)?" the normalised weight of ":"") + " <span class=\"setvalue\">" + Weight.ToString("#,##0") + "</span> kg";
                    if (newInd != null && Math.Abs(Weight - newInd.NormalisedAnimalWeight) / newInd.NormalisedAnimalWeight > 0.2)
                    {
                        html += ", but should weigh close to the normalised weight of <span class=\"errorlink\">" + normWtString + "</span> kg for their age";
                    }
                    html += "</div>";
                }
                html += "</div>";
            }
            else
            {
                if (this.Parent is CLEMActivityBase)
                {
                    // when formatted for parent control. i.e. child fo trade
                    html += "\n<div class=\"resourcebanneralone clearfix\">";
                    html += "Buy ";
                    if (Number > 0)
                    {
                        html += "<span class=\"setvalue\">";
                        html += Number.ToString();
                    }
                    else
                    {
                        html += "<span class=\"errorlink\">";
                        html += "NOT SET";
                    }
                    html += "</span> x ";
                    if (Age > 0)
                    {
                        html += "<span class=\"setvalue\">";
                        html += Number.ToString();
                    }
                    else
                    {
                        html += "<span class=\"errorlink\">";
                        html += "NOT SET";
                    }
                    html += "</span> month old ";
                    html += "<span class=\"setvalue\">";
                    html += Gender.ToString() + ((Number > 1) ? "s" : "");
                    html += "</span> weighing ";
                    if (Weight > 0)
                    {
                        html += "<span class=\"setvalue\">";
                        html += Weight.ToString();
                        html += "</span> kg ";
                        if (WeightSD > 0)
                        {
                            html += "with a standard deviation of <span class=\"setvalue\">";
                            html += WeightSD.ToString();
                            html += "</span>";
                        }
                    }
                    else
                    {
                        html += "<span class=\"setvalue\">";
                        html += "Normalised weight";
                        html += "</span>";
                    }
                    html += "\n</div>";
                }
            }
            return(html);
        }
Beispiel #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 public RuminantFemale(double setAge, Sex setGender, double setWeight, RuminantType setParams) : base(setAge, setGender, setWeight, setParams)
 {
     SucklingOffspringList = new List <Ruminant>();
 }
Beispiel #10
0
 /// <summary>
 /// Constructor
 /// </summary>
 public RuminantMale(double setAge, Sex setGender, double setWeight, RuminantType setParams) : base(setAge, setGender, setWeight, setParams)
 {
     IsSire      = false;
     IsDraught   = false;
     IsCastrated = false;
 }
Beispiel #11
0
        /// <inheritdoc/>
        public override string ModelSummaryInnerClosingTags()
        {
            using (StringWriter htmlWriter = new StringWriter())
            {
                if (FormatForParentControl)
                {
                    if (!(CurrentAncestorList.Count >= 3 && CurrentAncestorList[CurrentAncestorList.Count - 1] == typeof(RuminantInitialCohorts).Name))
                    {
                        RuminantType rumtype = FindAncestor <RuminantType>();
                        if (rumtype != null)
                        {
                            var newInd = Ruminant.Create(Sex, rumtype, Age);

                            string normWtString = newInd.NormalisedAnimalWeight.ToString("#,##0");
                            if (this.Weight != 0 && Math.Abs(this.Weight - newInd.NormalisedAnimalWeight) / newInd.NormalisedAnimalWeight > 0.2)
                            {
                                normWtString = "<span class=\"errorlink\">" + normWtString + "</span>";
                                (this.Parent as RuminantInitialCohorts).WeightWarningOccurred = true;
                            }
                            string weightstring = "";
                            if (this.Weight > 0)
                            {
                                weightstring = $"<span class=\"setvalue\">{this.Weight.ToString() + ((this.WeightSD > 0) ? " (" + this.WeightSD.ToString() + ")" : "")}</span>";
                            }

                            htmlWriter.Write($"\r\n<tr{(this.Enabled ? "" : " class=\"disabled\"")}><td>{this.Name}</td><td><span class=\"setvalue\">{this.Sex}</span></td><td><span class=\"setvalue\">{this.Age.ToString()}</span></td><td>{weightstring}</td><td>{normWtString}</td><td><span class=\"setvalue\">{this.Number.ToString()}</span></td><td{((this.Suckling) ? " class=\"fill\"" : "")}></td><td{((this.Sire) ? " class=\"fill\"" : "")}></td>");

                            if ((Parent as RuminantInitialCohorts).ConceptionsFound)
                            {
                                var setConceptionFound = this.FindChild <SetPreviousConception>();
                                if (setConceptionFound != null)
                                {
                                    htmlWriter.Write($"<td class=\"fill\"><span class=\"setvalue\">{setConceptionFound.NumberMonthsPregnant}</span> mths</td>");
                                }
                                else
                                {
                                    htmlWriter.Write("<td></td>");
                                }
                            }

                            if ((Parent as RuminantInitialCohorts).AttributesFound)
                            {
                                var setAttributesFound = this.FindAllChildren <SetAttributeWithValue>();
                                if (setAttributesFound.Any())
                                {
                                    htmlWriter.Write($"<td class=\"fill\">");
                                    foreach (var attribute in setAttributesFound)
                                    {
                                        htmlWriter.Write($"<span class=\"setvalue\">{attribute.AttributeName}</span> ");
                                    }
                                    htmlWriter.Write($"</td>");
                                }
                                else
                                {
                                    htmlWriter.Write("<td></td>");
                                }
                            }

                            htmlWriter.Write("</tr>");
                        }
                    }
                }
                else
                {
                    htmlWriter.Write("\r\n</div>");
                }

                return(htmlWriter.ToString());
            }
        }
Beispiel #12
0
        /// <summary>
        /// Create the individual ruminant animals using the Cohort parameterisations.
        /// </summary>
        /// <param name="number">The number of individuals to create</param>
        /// <param name="initialAttributes">The initial attributes found from parent and this cohort</param>
        /// <param name="ruminantType">The breed parameters if overwritten</param>
        /// <returns>List of ruminants</returns>
        public List <Ruminant> CreateIndividuals(int number, List <ISetAttribute> initialAttributes, RuminantType ruminantType = null)
        {
            List <Ruminant> individuals = new List <Ruminant>();

            if (number > 0)
            {
                RuminantType parent = ruminantType;
                if (parent is null)
                {
                    parent = FindAncestor <RuminantType>();
                }

                // get Ruminant Herd resource for unique ids
                RuminantHerd ruminantHerd = parent.Parent as RuminantHerd; // Resources.FindResourceGroup<RuminantHerd>();

                for (int i = 1; i <= number; i++)
                {
                    double weight = 0;
                    if (Weight > 0)
                    {
                        // avoid accidental small weight if SD provided but weight is 0
                        // if weight is 0 then the normalised weight will be applied in Ruminant constructor.
                        double u1            = RandomNumberGenerator.Generator.NextDouble();
                        double u2            = RandomNumberGenerator.Generator.NextDouble();
                        double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) *
                                               Math.Sin(2.0 * Math.PI * u2);
                        weight = Weight + WeightSD * randStdNormal;
                    }

                    Ruminant ruminant = Ruminant.Create(Sex, parent, Age, weight);

                    ruminant.ID       = ruminantHerd.NextUniqueID;
                    ruminant.Breed    = parent.Breed;
                    ruminant.HerdName = parent.Name;
                    ruminant.SaleFlag = HerdChangeReason.None;

                    if (Suckling)
                    {
                        if (Age >= ((parent.NaturalWeaningAge == 0)?parent.GestationLength: parent.NaturalWeaningAge))
                        {
                            string limitstring = (parent.NaturalWeaningAge == 0) ? $"gestation length [{parent.GestationLength}]" : $"natural weaning age [{parent.NaturalWeaningAge}]";
                            string warn        = $"Individuals older than {limitstring} cannot be assigned as suckling [r={parent.Name}][r={this.Parent.Name}][r={this.Name}]{Environment.NewLine}These individuals have not been assigned suckling.";
                            Warnings.CheckAndWrite(warn, Summary, this, MessageType.Warning);
                        }
                        else
                        {
                            ruminant.SetUnweaned();
                        }
                    }

                    if (Sire)
                    {
                        if (this.Sex == Sex.Male)
                        {
                            RuminantMale ruminantMale = ruminant as RuminantMale;
                            ruminantMale.Attributes.Add("Sire");
                        }
                        else
                        {
                            string warn = $"Breeding sire switch is not valid for individual females [r={parent.Name}][r={this.Parent.Name}][r={this.Name}]{Environment.NewLine}These individuals have not been assigned sires. Change Sex to Male to create sires in initial herd.";
                            Warnings.CheckAndWrite(warn, Summary, this, MessageType.Warning);
                        }
                    }

                    // if weight not provided use normalised weight
                    ruminant.PreviousWeight = ruminant.Weight;

                    if (this.Sex == Sex.Female)
                    {
                        RuminantFemale ruminantFemale = ruminant as RuminantFemale;
                        ruminantFemale.WeightAtConception = ruminant.Weight;
                        ruminantFemale.NumberOfBirths     = 0;

                        if (setPreviousConception != null)
                        {
                            setPreviousConception.SetConceptionDetails(ruminantFemale);
                        }
                    }

                    // initialise attributes
                    foreach (ISetAttribute item in initialAttributes)
                    {
                        ruminant.Attributes.Add(item.AttributeName, item.GetAttribute(true));
                    }

                    individuals.Add(ruminant);
                }

                // add any mandatory attributes to the list on the ruminant type
                foreach (var mattrib in initialAttributes.Where(a => a.Mandatory))
                {
                    parent.AddMandatoryAttribute(mattrib.AttributeName);
                }
            }

            return(individuals);
        }
Beispiel #13
0
        /// <summary>
        /// Create the individual ruminant animals using the Cohort parameterisations.
        /// </summary>
        /// <param name="initialAttributes">The initial attributes found from parent</param>
        /// <param name="ruminantType">The breed parameters if overwritten</param>
        /// <returns>List of ruminants</returns>
        public List <Ruminant> CreateIndividuals(List <ISetAttribute> initialAttributes, RuminantType ruminantType = null)
        {
            List <ISetAttribute> localAttributes = new List <ISetAttribute>();

            // add any whole herd attributes
            if (initialAttributes != null)
            {
                localAttributes.AddRange(initialAttributes);
            }
            // Add any attributes defined at the cohort level
            localAttributes.AddRange(this.FindAllChildren <ISetAttribute>().ToList());

            return(CreateIndividuals(Convert.ToInt32(this.Number, CultureInfo.InvariantCulture), localAttributes, ruminantType));
        }
Beispiel #14
0
 /// <summary>
 /// Constructor
 /// </summary>
 public RuminantMale(RuminantType setParams, double setAge, double setWeight)
     : base(setParams, setAge, setWeight)
 {
 }
Beispiel #15
0
 /// <summary>
 /// Constructor
 /// </summary>
 public RuminantMale(double setAge, Sex setGender, double setWeight, RuminantType setParams) : base(setAge, setGender, setWeight, setParams)
 {
     BreedingSire = false;
     Draught      = false;
 }
Beispiel #16
0
        /// <summary>
        /// Create the individual ruminant animals using the Cohort parameterisations.
        /// </summary>
        /// <param name="number">The number of individuals to create</param>
        /// <returns>List of ruminants</returns>
        public List <Ruminant> CreateIndividuals(int number)
        {
            List <Ruminant> individuals = new List <Ruminant>();

            if (number > 0)
            {
                RuminantType parent = FindAncestor <RuminantType>();

                // get Ruminant Herd resource for unique ids
                RuminantHerd ruminantHerd = Resources.RuminantHerd();

                for (int i = 1; i <= number; i++)
                {
                    double weight = 0;
                    if (Weight > 0)
                    {
                        // avoid accidental small weight if SD provided but weight is 0
                        // if weight is 0 then the normalised weight will be applied in Ruminant constructor.
                        double u1            = RandomNumberGenerator.Generator.NextDouble();
                        double u2            = RandomNumberGenerator.Generator.NextDouble();
                        double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) *
                                               Math.Sin(2.0 * Math.PI * u2);
                        weight = Weight + WeightSD * randStdNormal;
                    }

                    object ruminantBase;
                    if (this.Gender == Sex.Male)
                    {
                        ruminantBase = new RuminantMale(Age, Gender, weight, parent);
                    }
                    else
                    {
                        ruminantBase = new RuminantFemale(Age, Gender, weight, parent);
                    }

                    Ruminant ruminant = ruminantBase as Ruminant;
                    ruminant.ID       = ruminantHerd.NextUniqueID;
                    ruminant.Breed    = parent.Breed;
                    ruminant.HerdName = parent.Name;
                    ruminant.SaleFlag = HerdChangeReason.None;
                    if (Suckling)
                    {
                        ruminant.SetUnweaned();
                    }

                    if (Sire)
                    {
                        if (this.Gender == Sex.Male)
                        {
                            RuminantMale ruminantMale = ruminantBase as RuminantMale;
                            ruminantMale.IsSire = true;
                        }
                        else
                        {
                            Summary.WriteWarning(this, "Breeding sire switch is not valid for individual females [r=" + parent.Name + "].[r=" + this.Parent.Name + "].[r=" + this.Name + "]");
                        }
                    }

                    // if weight not provided use normalised weight
                    ruminant.PreviousWeight = ruminant.Weight;

                    if (this.Gender == Sex.Female)
                    {
                        RuminantFemale ruminantFemale = ruminantBase as RuminantFemale;
                        ruminantFemale.DryBreeder         = true;
                        ruminantFemale.WeightAtConception = ruminant.Weight;
                        ruminantFemale.NumberOfBirths     = 0;
                    }

                    individuals.Add(ruminantBase as Ruminant);
                }
            }

            return(individuals);
        }
Beispiel #17
0
        /// <summary>
        /// Create the individual ruminant animals using the Cohort parameterisations.
        /// </summary>
        /// <param name="number">The number of individuals to create</param>
        /// <param name="initialAttributes">The initial attributes found from parent and this cohort</param>
        /// <param name="ruminantType">The breed parameters if overwritten</param>
        /// <returns>List of ruminants</returns>
        public List <Ruminant> CreateIndividuals(int number, List <ISetAttribute> initialAttributes, RuminantType ruminantType = null)
        {
            List <Ruminant> individuals = new List <Ruminant>();

            if (number > 0)
            {
                RuminantType parent = ruminantType;
                if (parent is null)
                {
                    parent = FindAncestor <RuminantType>();
                }

                // get Ruminant Herd resource for unique ids
                RuminantHerd ruminantHerd = parent.Parent as RuminantHerd; // Resources.FindResourceGroup<RuminantHerd>();

                for (int i = 1; i <= number; i++)
                {
                    double weight = 0;
                    if (Weight > 0)
                    {
                        // avoid accidental small weight if SD provided but weight is 0
                        // if weight is 0 then the normalised weight will be applied in Ruminant constructor.
                        double u1            = RandomNumberGenerator.Generator.NextDouble();
                        double u2            = RandomNumberGenerator.Generator.NextDouble();
                        double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) *
                                               Math.Sin(2.0 * Math.PI * u2);
                        weight = Weight + WeightSD * randStdNormal;
                    }

                    Ruminant ruminant = Ruminant.Create(Sex, parent, Age, weight);

                    ruminant.ID       = ruminantHerd.NextUniqueID;
                    ruminant.Breed    = parent.Breed;
                    ruminant.HerdName = parent.Name;
                    ruminant.SaleFlag = HerdChangeReason.None;

                    if (Suckling)
                    {
                        ruminant.SetUnweaned();
                    }

                    if (Sire)
                    {
                        if (this.Sex == Sex.Male)
                        {
                            RuminantMale ruminantMale = ruminant as RuminantMale;
                            ruminantMale.Attributes.Add("Sire");
                        }
                        else
                        {
                            Summary.WriteWarning(this, "Breeding sire switch is not valid for individual females [r=" + parent.Name + "].[r=" + this.Parent.Name + "].[r=" + this.Name + "]");
                        }
                    }

                    // if weight not provided use normalised weight
                    ruminant.PreviousWeight = ruminant.Weight;

                    if (this.Sex == Sex.Female)
                    {
                        RuminantFemale ruminantFemale = ruminant as RuminantFemale;
                        ruminantFemale.WeightAtConception = ruminant.Weight;
                        ruminantFemale.NumberOfBirths     = 0;

                        if (setPreviousConception != null)
                        {
                            setPreviousConception.SetConceptionDetails(ruminantFemale);
                        }
                    }

                    // initialise attributes
                    foreach (ISetAttribute item in initialAttributes)
                    {
                        ruminant.Attributes.Add(item.AttributeName, item.GetAttribute(true));
                    }

                    individuals.Add(ruminant);
                }

                // add any mandatory attributes to the list on the ruminant type
                foreach (var mattrib in initialAttributes.Where(a => a.Mandatory))
                {
                    parent.AddMandatoryAttribute(mattrib.AttributeName);
                }
            }

            return(individuals);
        }
Beispiel #18
0
 /// <summary>
 /// Constructor
 /// </summary>
 public RuminantFemale(RuminantType setParams, double setAge, double setWeight)
     : base(setParams, setAge, setWeight)
 {
     SucklingOffspringList = new List <Ruminant>();
 }
Beispiel #19
0
        /// <summary>
        /// Create the individual ruminant animals using the Cohort parameterisations.
        /// </summary>
        /// <returns></returns>
        public List <Ruminant> CreateIndividuals()
        {
            List <Ruminant> Individuals = new List <Ruminant>();

            RuminantType parent = this.Parent.Parent as RuminantType;

            // get Ruminant Herd resource for unique ids
            RuminantHerd ruminantHerd = Resources.RuminantHerd();

            if (Number > 0)
            {
                for (int i = 1; i <= Number; i++)
                {
                    object ruminantBase = null;
                    if (this.Gender == Sex.Male)
                    {
                        ruminantBase = new RuminantMale();
                    }
                    else
                    {
                        ruminantBase = new RuminantFemale();
                    }

                    Ruminant ruminant = ruminantBase as Ruminant;

                    ruminant.ID          = ruminantHerd.NextUniqueID;
                    ruminant.BreedParams = parent;
                    ruminant.Breed       = parent.Breed;
                    ruminant.HerdName    = parent.Name;
                    ruminant.Gender      = Gender;
                    ruminant.Age         = Age;
                    ruminant.SaleFlag    = HerdChangeReason.None;
                    if (Suckling)
                    {
                        ruminant.SetUnweaned();
                    }
                    if (Sire)
                    {
                        if (this.Gender == Sex.Male)
                        {
                            RuminantMale ruminantMale = ruminantBase as RuminantMale;
                            ruminantMale.BreedingSire = true;
                        }
                        else
                        {
                            Summary.WriteWarning(this, "Breeding sire switch is not valid for individual females");
                        }
                    }

                    double u1            = ZoneCLEM.RandomGenerator.NextDouble();
                    double u2            = ZoneCLEM.RandomGenerator.NextDouble();
                    double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) *
                                           Math.Sin(2.0 * Math.PI * u2);
                    ruminant.Weight         = Weight + WeightSD * randStdNormal;
                    ruminant.PreviousWeight = ruminant.Weight;

                    if (this.Gender == Sex.Female)
                    {
                        RuminantFemale ruminantFemale = ruminantBase as RuminantFemale;
                        ruminantFemale.DryBreeder         = true;
                        ruminantFemale.WeightAtConception = ruminant.Weight;
                        ruminantFemale.NumberOfBirths     = 0;
                    }

                    Individuals.Add(ruminantBase as Ruminant);
                }
            }

            return(Individuals);
        }
Beispiel #20
0
 private void OnCLEMInitialiseResources(object sender, EventArgs e)
 {
     Details      = this.FindAllChildren <RuminantTypeCohort>().FirstOrDefault();
     ruminantType = Resources.GetResourceItem(this.Parent as Model, RuminantTypeName, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop) as RuminantType;
 }