Exemplo n.º 1
0
        /// <summary>
        /// Mix of two genotypes (as at mating)
        /// </summary>
        /// <param name="sBreedName"></param>
        /// <param name="damBreed"></param>
        /// <param name="sireBreed"></param>
        /// <param name="iGeneration"></param>
        /// <returns>The new object</returns>
        public static TAnimalParamSet CreateFactory(string sBreedName, TAnimalParamSet damBreed, TAnimalParamSet sireBreed, int iGeneration = 1)
        {
            TAnimalParamBlend[] aBlend = new TAnimalParamBlend[2];

            aBlend[0].Breed = damBreed;
            aBlend[0].fPropn = Math.Pow(0.5, iGeneration);
            aBlend[1].Breed = sireBreed;
            aBlend[1].fPropn = 1.0 - aBlend[0].fPropn;
            return CreateFactory(sBreedName, aBlend);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Default fleece weight as a function of age, sex and time since shearing     
        /// </summary>
        /// <param name="Params"></param>
        /// <param name="iAgeDays"></param>
        /// <param name="Repr"></param>
        /// <param name="iFleeceDays"></param>
        /// <returns></returns>
        public static double fDefaultFleece(TAnimalParamSet Params,
                                     int iAgeDays,
                                     GrazType.ReproType Repr,
                                     int iFleeceDays)
        {
            double Result;
            double fMeanAgeFactor;

            iFleeceDays = Math.Min(iFleeceDays, iAgeDays);

            if ((Params.Animal == GrazType.AnimalType.Sheep) && (iFleeceDays > 0))
            {
                fMeanAgeFactor = 1.0 - (1.0 - Params.WoolC[5])
                                        * (Math.Exp(-Params.WoolC[12] * (iAgeDays - iFleeceDays)) - Math.Exp(-Params.WoolC[12] * iAgeDays))
                                        / (Params.WoolC[12] * iFleeceDays);
                Result = Params.FleeceRatio * Params.fSexStdRefWt(Repr) * fMeanAgeFactor * iFleeceDays / 365.0;
            }
            else
                Result = 0.0;
            return Result;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Copies a parameter set from AnimalParamsGlb
        /// </summary>
        /// <param name="sBreedName"></param>
        public static TAnimalParamSet CreateFactory(string sBreedName)
        {
            TAnimalParamSet newObj = null;

            TAnimalParamSet baseParams;

            baseParams = (TAnimalParamSet)TGAnimalParams.AnimalParamsGlb().getNode(sBreedName);
            if (baseParams != null)
                newObj = new TAnimalParamSet(null, baseParams);
            else
            {
                newObj = new TAnimalParamSet();
                throw new Exception("Breed name \"" + sBreedName + "\" not recognised");
            }

            return newObj;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates an object based on the parameters passed
        /// </summary>
        /// <param name="sBreedName"></param>
        /// <param name="Blend"></param>
        /// <returns></returns>
        public static TAnimalParamSet CreateFactory(string sBreedName, TAnimalParamBlend[] Blend)
        {
            TAnimalParamSet newObj = null;
            if (Blend.Length == 0)                                                   // No mixture of breeds provided, so
                newObj = CreateFactory(sBreedName);                                     //   copy a breed from AnimalParamsGlb
            else if (Blend.Length == 2)                                             // Special case: optimized for speed
            {
                newObj = new TAnimalParamSet((TParameterSet)null, (TAnimalParamSet)null);
            }
            else
            {
                newObj = new TAnimalParamSet(null, Blend[0].Breed);                            // Sets the integer, string and Boolean
            }
            newObj.InitParameterSet(sBreedName, Blend);

            return newObj;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Construct an animal parameter set from a source one
 /// </summary>
 public TAnimalParamSet(TAnimalParamSet src)
     : base(src)
 {
     for (int i = 0; i < ConceiveSigs.Length; i++)
         ConceiveSigs[i] = new double[2];
     ConstructCopy(src);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Alternative copy constructor
        /// </summary>
        /// <param name="aParent"></param>
        /// <param name="srcSet"></param>
        public TAnimalParamSet(TParameterSet aParent, TAnimalParamSet srcSet)
            : base(aParent/*, srcSet*/)
        {
            //create a new array
            for (int i = 0; i < ConceiveSigs.Length; i++)
                ConceiveSigs[i] = new double[2];
            ConstructCopy(srcSet);

            int Jdx;

            if (srcSet != null)
            {
                if (srcSet.Animal == GrazType.AnimalType.Sheep)
                    setPotGFW(srcSet.PotentialGFW);

                if (srcSet.bUseDairyCurve)
                    setPeakMilk(srcSet.PotMilkYield);

                if (srcSet.FParentage.Length == 0)
                {
                    Array.Resize(ref FParentage, 1);
                    FParentage[0].sBaseBreed = srcSet.sName;
                    FParentage[0].fPropn = 1.0;
                }
                else
                {
                    Array.Resize(ref FParentage, srcSet.FParentage.Length);
                    for (Jdx = 0; Jdx <= FParentage.Length - 1; Jdx++)
                    {
                        FParentage[Jdx].sBaseBreed = srcSet.FParentage[Jdx].sBaseBreed;
                        FParentage[Jdx].fPropn = srcSet.FParentage[Jdx].fPropn;
                    }
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// GrowthCurve calculates MaxNormalWt (see below) for an animal with the   
        /// default birth weight.                                                   
        /// </summary>
        /// <param name="SRW"></param>
        /// <param name="BW"></param>
        /// <param name="AgeDays"></param>
        /// <param name="Params"></param>
        /// <returns></returns>
        private double MaxNormWtFunc(double SRW, double BW, int AgeDays, TAnimalParamSet Params)
        {
            double GrowthRate;

            GrowthRate = Params.GrowthC[1] / Math.Pow(SRW, Params.GrowthC[2]);
            return SRW - (SRW - BW) * Math.Exp(-GrowthRate * AgeDays);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Calculate the growth from the standard growth curve
        /// </summary>
        /// <param name="iAgeDays"></param>
        /// <param name="Repr"></param>
        /// <param name="Params"></param>
        /// <returns></returns>
        public double GrowthCurve(int iAgeDays, GrazType.ReproType Repr, TAnimalParamSet Params)
        {
            double SRW;

            SRW = Params.BreedSRW;
            if ((Repr == GrazType.ReproType.Male) || (Repr == GrazType.ReproType.Castrated))
                SRW = SRW * Params.SRWScalars[(int)Repr];
            return MaxNormWtFunc(SRW, Params.StdBirthWt(1), iAgeDays, Params);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="CohortsInfo"></param>
        /// <param name="mainGenotype"></param>
        /// <param name="AgeInfo"></param>
        /// <param name="fLatitude"></param>
        /// <param name="iMateDOY"></param>
        /// <param name="fCondition"></param>
        /// <param name="fChill"></param>
        /// <returns></returns>
        private double getReproRate(TCohortsInfo CohortsInfo, TAnimalParamSet mainGenotype, TAgeInfo[] AgeInfo, double fLatitude, int iMateDOY, double fCondition, double fChill)
        {
            double Result = 0.0;
            double[] fPregRate = new double[4];
            int iCohort;
            int N;

            for (iCohort = CohortsInfo.iMinYears; iCohort <= CohortsInfo.iMaxYears; iCohort++)
            {
                fPregRate = getOffspringRates(mainGenotype, fLatitude, iMateDOY,
                                                AgeInfo[iCohort].iAgeAtMating,
                                                AgeInfo[iCohort].fSizeAtMating,
                                                fCondition, fChill);
                for (N = 1; N <= 3; N++)
                    Result = Result + AgeInfo[iCohort].fPropn * fPregRate[N];
            }

            return Result;
        }
Exemplo n.º 10
0
 /// <summary>
 /// Makes a copy of TAnimalParamsGlb and modifies it according to sConstFile     
 /// </summary>
 /// <param name="sConstFile"></param>
 /// <returns></returns>
 private TAnimalParamSet MakeParamSet(string sConstFile)
 {
     TAnimalParamSet Result = new TAnimalParamSet((TAnimalParamSet)null);
     Result.CopyAll(TGAnimalParams.AnimalParamsGlb());
     if (sConstFile != "")
         TGParamFactory.ParamXMLFactory().readFromFile(sConstFile, Result, true);
     Result.sCurrLocale = GrazLocale.sDefaultLocale();
     return Result;
 }
Exemplo n.º 11
0
        private double[] getOffspringRates(TAnimalParamSet Params,
                                    double fLatitude,
                                    int iMateDOY,
                                    int iAgeDays,
                                    double fMatingSize,
                                    double fCondition,
                                    double fChillIndex = 0.0)
        {
            const double NO_CYCLES = 2.5;
            const double STD_LATITUDE = -35.0;                                                      // Latitude (in degrees) for which the
            //   DayLengthConst[] parameters are set
            double[] Result;
            double[] Conceptions = new double[4];
            double fEmptyPropn;
            double fDLFactor;
            double fPropn;
            double fExposureOdds;
            double fDeathRate;
            int N;

            fDLFactor = (1.0 - Math.Sin(GrazEnv.DAY2RAD * (iMateDOY + 10)))
                         * Math.Sin(GrazEnv.DEG2RAD * fLatitude) / Math.Sin(GrazEnv.DEG2RAD * STD_LATITUDE);
            for (N = 1; N <= Params.MaxYoung; N++)
            {
                if ((iAgeDays > Params.Puberty[0]) && (Params.ConceiveSigs[N][0] < 5.0))     //Puberty[false]
                    fPropn = StdMath.DIM(1.0, Params.DayLengthConst[N] * fDLFactor)
                              * StdMath.SIG(fMatingSize * fCondition, Params.ConceiveSigs[N]);
                else
                    fPropn = 0.0;

                if (N == 1)
                    Conceptions[N] = fPropn;
                else
                {
                    Conceptions[N] = fPropn * Conceptions[N - 1];
                    Conceptions[N - 1] = Conceptions[N - 1] - Conceptions[N];
                }
            }

            fEmptyPropn = 1.0;
            for (N = 1; N <= Params.MaxYoung; N++)
                fEmptyPropn = fEmptyPropn - Conceptions[N];

            Result = new double[4];
            if (fEmptyPropn < 1.0)
                for (N = 1; N <= Params.MaxYoung; N++)
                    Result[N] = Conceptions[N] * (1.0 - Math.Pow(fEmptyPropn, NO_CYCLES)) / (1.0 - fEmptyPropn);

            if ((fChillIndex > 0) && (Params.Animal == GrazType.AnimalType.Sheep))
            {
                for (N = 1; N <= Params.MaxYoung; N++)
                {
                    fExposureOdds = Params.ExposureConsts[0] - Params.ExposureConsts[1] * fCondition + Params.ExposureConsts[2] * fChillIndex;
                    if (N > 1)
                        fExposureOdds = fExposureOdds + Params.ExposureConsts[3];
                    fDeathRate = Math.Exp(fExposureOdds) / (1.0 + Math.Exp(fExposureOdds));

                    Result[N] = (1.0 - fDeathRate) * Result[N];
                }
            }
            return Result;
        }
Exemplo n.º 12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="mainParams"></param>
        /// <param name="Inits"></param>
        /// <param name="sName"></param>
        /// <param name="iSearchBefore"></param>
        /// <returns></returns>
        private TAnimalParamSet findGenotype(TAnimalParamSet mainParams, TSingleGenotypeInits[] Inits, string sName, int iSearchBefore)
        {
            TAnimalParamSet Result;
            TAnimalParamSet foundParams;
            int Idx;

            Idx = 0;
            while ((Idx < iSearchBefore) && (sName.ToLower() != Inits[Idx].sGenotypeName.ToLower()))
                Idx++;
            if (Idx < iSearchBefore)
                Result = ParamsFromGenotypeInits(mainParams, Inits, Idx);
            else
            {
                foundParams = mainParams.Match(sName);
                if (foundParams != null)
                    Result = new TAnimalParamSet(null, foundParams);
                else
                    throw new Exception("Breed name \"" + sName + "\" not recognised");
            }
            return Result;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Always makes a copy
        /// </summary>
        /// <param name="mainParams"></param>
        /// <param name="Inits"></param>
        /// <param name="iGenotype"></param>
        /// <returns></returns>
        public TAnimalParamSet ParamsFromGenotypeInits(TAnimalParamSet mainParams,
                                          TSingleGenotypeInits[] Inits,
                                          int iGenotype)
        {
            TAnimalParamSet Result;
            //bool bWeaner;

            if (Inits[iGenotype].sDamBreed == String.Empty)
                Result = findGenotype(mainParams, Inits, Inits[iGenotype].sGenotypeName, 0);
            else if (Inits[iGenotype].iGeneration == 0)
                Result = findGenotype(mainParams, Inits, Inits[iGenotype].sDamBreed, 0);
            else
                Result = TAnimalParamSet.CreateFactory(Inits[iGenotype].sGenotypeName,
                                                  findGenotype(mainParams, Inits, Inits[iGenotype].sDamBreed, iGenotype),
                                                  findGenotype(mainParams, Inits, Inits[iGenotype].sSireBreed, iGenotype));

            Result.sName = Inits[iGenotype].sGenotypeName;

            if (bIsGiven(Inits[iGenotype].SRW))
                Result.BreedSRW = Inits[iGenotype].SRW;
            if (bIsGiven(Inits[iGenotype].PotFleeceWt))
                Result.PotentialGFW = Inits[iGenotype].PotFleeceWt;
            if (bIsGiven(Inits[iGenotype].MaxFibreDiam))
                Result.MaxMicrons = Inits[iGenotype].MaxFibreDiam;
            if (bIsGiven(Inits[iGenotype].FleeceYield))
                Result.FleeceYield = Inits[iGenotype].FleeceYield;
            if (bIsGiven(Inits[iGenotype].PeakMilk))
                Result.PotMilkYield = Inits[iGenotype].PeakMilk;
            for (int iWeaner = 0; iWeaner <= 1; iWeaner++)
            {
                if (Inits[iGenotype].DeathRate[iWeaner] != StdMath.DMISSING)                    // A zero death rate is permissible
                    Result.SetAnnualDeaths(iWeaner == 1, Inits[iGenotype].DeathRate[iWeaner]);
            }
            if (bIsGiven(Inits[iGenotype].Conceptions[1]))
                Result.Conceptions = Inits[iGenotype].Conceptions;

            return Result;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Default fibre diameter as a function of age, sex, time since shearing and fleece weight                                                             
        /// </summary>
        /// <param name="Params"></param>
        /// <param name="iAgeDays"></param>
        /// <param name="Repr"></param>
        /// <param name="iFleeceDays"></param>
        /// <param name="fGFW"></param>
        /// <returns></returns>
        public static double fDefaultMicron(TAnimalParamSet Params, int iAgeDays, GrazType.ReproType Repr, int iFleeceDays, double fGFW)
        {
            double fPotFleece;

            if ((iFleeceDays > 0) && (fGFW > 0.0))
            {
                fPotFleece = fDefaultFleece(Params, iAgeDays, Repr, iFleeceDays);
                return Params.MaxMicrons * Math.Pow(fGFW / fPotFleece, Params.WoolC[13]);
            }
            else
                return Params.MaxMicrons;
        }
Exemplo n.º 15
0
 private void setParamFile(string sFileName)
 {
     FBaseParams = null;
     FBaseParams = MakeParamSet(sFileName);
     FParamFile = sFileName;
 }
Exemplo n.º 16
0
        /// <summary>
        /// Returns TRUE i.f.f. all parameters other than the breed name are identical
        /// </summary>
        /// <param name="otherSet"></param>
        /// <returns></returns>
        public bool bFunctionallySame(TAnimalParamSet otherSet)
        {
            int iCount;
            TParameterDefinition Defn;
            string sTag;
            int iPrm;

            bool result = true;
            iCount = this.iParamCount();

            iPrm = 0;
            while ((iPrm < iCount) && result)
            {
                Defn = this.getParam(iPrm);
                if (Defn != null)
                {
                    sTag = Defn.sFullName;
                    if (this.bIsDefined(sTag))
                    {
                        switch (Defn.paramType)
                        {
                            case ptyText: result = (result && (this.sParam(sTag) == otherSet.sParam(sTag)));
                                break;
                            case ptyReal: result = (result && (this.fParam(sTag) == otherSet.fParam(sTag)));
                                break;
                            case ptyInt: result = (result && (this.iParam(sTag) == otherSet.iParam(sTag)));
                                break;
                            case ptyBool: result = (result && (this.bParam(sTag) == otherSet.bParam(sTag)));
                                break;
                        }
                    }
                    else
                        result = (result && !otherSet.bIsDefined(Defn.sFullName));
                }
                else
                    result = false;

                iPrm++;
            }
            return result;
        }
Exemplo n.º 17
0
        /// <summary>
        /// Locate a genotype in FGenotypes. If this fails, try searching for it in the  
        /// main parameter set and adding it to FGenotypes.                            
        /// </summary>
        /// <param name="sName"></param>
        /// <returns></returns>
        public TAnimalParamSet getGenotype(string sName)
        {
            int Idx;
            TAnimalParamSet srcParamSet;

            TAnimalParamSet Result = null;
            if ((sName == "") && (FGenotypes.Length >= 1))                           // Null string is a special case
                Result = FGenotypes[0];
            else
            {
                Idx = 0;
                while ((Idx < FGenotypes.Length) && (sName.ToLower() != FGenotypes[Idx].sName.ToLower()))
                    Idx++;

                if (Idx < FGenotypes.Length)
                    Result = FGenotypes[Idx];
                else
                {
                    srcParamSet = FBaseParams.Match(sName);
                    if (srcParamSet != null)
                    {
                        Result = new TAnimalParamSet(null, srcParamSet);
                        Idx = FGenotypes.Length;
                        Array.Resize(ref FGenotypes, Idx + 1);
                        FGenotypes[Idx] = Result;
                    }
                }
            }

            if (Result == null)
                throw new Exception("Genotype name \"" + sName + "\" not recognised");

            return Result;
        }