Beispiel #1
0
        private void OnWFAnimalMilking(object sender, EventArgs e)
        {
            if (ProportionToRemove > 0)
            {
                // get dry breeders
                RuminantHerd          ruminantHerd = Resources.RuminantHerd();
                List <RuminantFemale> herd         = ruminantHerd.Herd.Where(a => a.BreedParams.Name == HerdName & a.Gender == Sex.Female).Cast <RuminantFemale>().ToList();
                if (SellFromManagedPaddock)
                {
                    // in sepecified paddock
                    herd = herd.Where(a => a.Location == PaddockName).ToList();
                }

                TMyRandom randomGenerator = new TMyRandom(10);

                // get dry breeders from females
                foreach (RuminantFemale female in herd.Where(a => a.Age - a.AgeAtLastBirth >= MonthsSinceBirth & a.PreviousConceptionRate >= MinimumConceptionBeforeSell & a.AgeAtLastBirth > 0))
                {
                    if (randomGenerator.RandNo <= ProportionToRemove)
                    {
                        // flag female ready to transport.
                        female.SaleFlag = Common.HerdChangeReason.DryBreederSale;
                    }
                }
            }
        }
Beispiel #2
0
        private void OnWFAnimalDeath(object sender, EventArgs e)
        {
            // remove individuals that died
            // currently performed in the month after weight has been adjusted
            // and before breeding, trading, culling etc (See Clock event order)

            // Calculated by
            // critical weight &
            // juvenile (unweaned) death based on mothers weight &
            // adult weight adjusted base mortality.

            RuminantHerd    ruminantHerd = Resources.RuminantHerd();
            List <Ruminant> herd         = ruminantHerd.Herd;

            // weight based mortality
            List <Ruminant> died = herd.Where(a => a.Weight < (a.HighWeight * (1.0 - a.BreedParams.ProportionOfMaxWeightToSurvive))).ToList();

            // set died flag
            died.Select(a => { a.SaleFlag = Common.HerdChangeReason.Died; return(a); }).ToList();
            ruminantHerd.RemoveRuminant(died);

            TMyRandom randomGenerator = new TMyRandom(10);

            foreach (var ind in ruminantHerd.Herd)
            {
                double mortalityRate = 0;
                if (!ind.Weaned)
                {
                    mortalityRate = 0;
                    if (ind.Mother.Weight < ind.BreedParams.CriticalCowWeight * ind.StandardReferenceWeight)
                    {
                        mortalityRate = ind.BreedParams.JuvenileMortalityMaximum;
                    }
                    else
                    {
                        mortalityRate = Math.Exp(-Math.Pow(ind.BreedParams.JuvenileMortalityCoefficient * (ind.Weight / ind.NormalisedAnimalWeight), ind.BreedParams.JuvenileMortalityExponent)) / 100;
                    }
                    mortalityRate += mortalityRate + ind.BreedParams.MortalityBase;
                    mortalityRate  = Math.Max(mortalityRate, ind.BreedParams.JuvenileMortalityMaximum);
                }
                else
                {
                    mortalityRate = 1 - (1 - ind.BreedParams.MortalityBase) * (1 - Math.Exp(Math.Pow(-(ind.BreedParams.MortalityCoefficient * (ind.Weight / ind.NormalisedAnimalWeight - ind.BreedParams.MortalityIntercept)), ind.BreedParams.MortalityExponent)));
                }
                if (randomGenerator.RandNo <= mortalityRate)
                {
                    ind.Died = true;
                }
            }

            died = herd.Where(a => a.Died).ToList();
            died.Select(a => { a.SaleFlag = Common.HerdChangeReason.Died; return(a); }).ToList();
            ruminantHerd.RemoveRuminant(died);

            //// mortality calculation (calculation actually calculates the survival probability)
            //for (int i = herd.Count; i >= 0; i--)
            //{
            //	double mortalityRate = 0;
            //	if (!herd[i].Weaned)
            //	{
            //		mortalityRate = 0;
            //		if (herd[i].Mother.Weight < herd[i].BreedParams.CriticalCowWeight * herd[i].StandardReferenceWeight)
            //		{
            //			mortalityRate = herd[i].BreedParams.JuvenileMortalityMaximum;
            //		}
            //		else
            //		{
            //			mortalityRate = Math.Exp(-Math.Pow(herd[i].BreedParams.JuvenileMortalityCoefficient * (herd[i].Weight / herd[i].NormalisedAnimalWeight), herd[i].BreedParams.JuvenileMortalityExponent)) / 100;
            //		}
            //		mortalityRate += mortalityRate + herd[i].BreedParams.MortalityBase;
            //		mortalityRate = Math.Max(mortalityRate, herd[i].BreedParams.JuvenileMortalityMaximum);
            //	}
            //	else
            //	{
            //		mortalityRate = 1 - (1 - herd[i].BreedParams.MortalityBase) * (1 - Math.Exp(Math.Pow(-(herd[i].BreedParams.MortalityCoefficient * (herd[i].Weight / herd[i].NormalisedAnimalWeight - herd[i].BreedParams.MortalityIntercept)), herd[i].BreedParams.MortalityExponent)));
            //	}
            //	if (randomGenerator.RandNo <= mortalityRate)
            //	{
            //		herd[i].Died = true;
            //	}
            //}
        }