예제 #1
0
파일: animprm.cs 프로젝트: hol353/ApsimX
        /// <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);
        }
예제 #2
0
파일: animprm.cs 프로젝트: hol353/ApsimX
        /// <summary>
        /// Called by CreateFactory() and creates a mixture of several genotypes                                       
        /// </summary>
        /// <param name="sBreedName"></param>
        /// <param name="Blend"></param>
        public virtual void InitParameterSet(string sBreedName, TAnimalParamBlend[] Blend)
        {
            TParameterDefinition prmDefn;
            TAnimalParamSet Breed0;
            TAnimalParamSet Breed1;
            double fPropn0;
            double fPropn1;
            double fParamSum;
            double fPropnSum;
            int iDecPlaces;
            int Idx, Jdx, Kdx;
            //TGrazType.ReproType Repro;

            if (Blend.Length == 2)                                             // Special case: optimized for speed
            {                                                                  //   (used in producing offspring)
                Breed0 = Blend[0].Breed;
                Breed1 = Blend[1].Breed;

                fPropn0 = Blend[0].fPropn;
                fPropn1 = Blend[1].fPropn;
                if (fPropn1 > 0.0)
                    fPropn0 = fPropn0 / (fPropn0 + fPropn1);
                else
                    fPropn0 = 1.0;
                fPropn1 = 1.0 - fPropn0;

                sEditor = Breed0.sEditor;                                       // String and integer parameters
                sEditDate = Breed0.sEditDate;                                     //   (consistent with the general case)
                Animal = Breed0.Animal;
                bDairyBreed = Breed0.bDairyBreed;
                MaxYoung = Breed0.MaxYoung;
                FUseDairyCurve = Breed0.FUseDairyCurve;
                OvulationPeriod = Breed0.OvulationPeriod;
                Puberty = Breed0.Puberty;

                FBreedSRW = fPropn0 * Breed0.FBreedSRW + fPropn1 * Breed1.FBreedSRW;
                FPotFleeceWt = fPropn0 * Breed0.FPotFleeceWt + fPropn1 * Breed1.FPotFleeceWt;
                FDairyIntakePeak = fPropn0 * Breed0.FDairyIntakePeak + fPropn1 * Breed1.FDairyIntakePeak;
                FDairyIntakeTime = fPropn0 * Breed0.FDairyIntakeTime + fPropn1 * Breed1.FDairyIntakeTime;
                FDairyIntakeShape = fPropn0 * Breed0.FDairyIntakeShape + fPropn1 * Breed1.FDairyIntakeShape;
                FleeceRatio = fPropn0 * Breed0.FleeceRatio + fPropn1 * Breed1.FleeceRatio;
                MaxFleeceDiam = fPropn0 * Breed0.MaxFleeceDiam + fPropn1 * Breed1.MaxFleeceDiam;
                PeakMilk = fPropn0 * Breed0.PeakMilk + fPropn1 * Breed1.PeakMilk;
                for (Idx = 1; Idx <= 2; Idx++)
                    MortRate[Idx] = fPropn0 * Breed0.MortRate[Idx] + fPropn1 * Breed1.MortRate[Idx];
                for (Idx = 1; Idx <= 2; Idx++)
                    MortAge[Idx] = fPropn0 * Breed0.MortAge[Idx] + fPropn1 * Breed1.MortAge[Idx];
                MortIntensity = fPropn0 * Breed0.MortIntensity + fPropn1 * Breed1.MortIntensity;
                MortCondConst = fPropn0 * Breed0.MortCondConst + fPropn1 * Breed1.MortCondConst;
                MortWtDiff = fPropn0 * Breed0.MortWtDiff + fPropn1 * Breed1.MortWtDiff;

                for (Idx = 0; Idx < SRWScalars.Length; Idx++) SRWScalars[Idx] = fPropn0 * Breed0.SRWScalars[Idx] + fPropn1 * Breed1.SRWScalars[Idx];
                for (Idx = 1; Idx < GrowthC.Length; Idx++) GrowthC[Idx] = fPropn0 * Breed0.GrowthC[Idx] + fPropn1 * Breed1.GrowthC[Idx];
                for (Idx = 1; Idx < IntakeC.Length; Idx++) IntakeC[Idx] = fPropn0 * Breed0.IntakeC[Idx] + fPropn1 * Breed1.IntakeC[Idx];
                for (Idx = 0; Idx < IntakeLactC.Length; Idx++) IntakeLactC[Idx] = fPropn0 * Breed0.IntakeLactC[Idx] + fPropn1 * Breed1.IntakeLactC[Idx];
                for (Idx = 1; Idx < GrazeC.Length; Idx++) GrazeC[Idx] = fPropn0 * Breed0.GrazeC[Idx] + fPropn1 * Breed1.GrazeC[Idx];
                for (Idx = 1; Idx < EfficC.Length; Idx++) EfficC[Idx] = fPropn0 * Breed0.EfficC[Idx] + fPropn1 * Breed1.EfficC[Idx];
                for (Idx = 1; Idx < MaintC.Length; Idx++) MaintC[Idx] = fPropn0 * Breed0.MaintC[Idx] + fPropn1 * Breed1.MaintC[Idx];
                for (Idx = 1; Idx < DgProtC.Length; Idx++) DgProtC[Idx] = fPropn0 * Breed0.DgProtC[Idx] + fPropn1 * Breed1.DgProtC[Idx];
                for (Idx = 1; Idx < ProtC.Length; Idx++) ProtC[Idx] = fPropn0 * Breed0.ProtC[Idx] + fPropn1 * Breed1.ProtC[Idx];
                for (Idx = 1; Idx < PregC.Length; Idx++) PregC[Idx] = fPropn0 * Breed0.PregC[Idx] + fPropn1 * Breed1.PregC[Idx];
                for (Idx = 1; Idx < PregScale.Length; Idx++) PregScale[Idx] = fPropn0 * Breed0.PregScale[Idx] + fPropn1 * Breed1.PregScale[Idx];
                for (Idx = 1; Idx < BirthWtScale.Length; Idx++) BirthWtScale[Idx] = fPropn0 * Breed0.BirthWtScale[Idx] + fPropn1 * Breed1.BirthWtScale[Idx];
                for (Idx = 1; Idx < PeakLactC.Length; Idx++) PeakLactC[Idx] = fPropn0 * Breed0.PeakLactC[Idx] + fPropn1 * Breed1.PeakLactC[Idx];
                for (Idx = 1; Idx < LactC.Length; Idx++) LactC[Idx] = fPropn0 * Breed0.LactC[Idx] + fPropn1 * Breed1.LactC[Idx];
                for (Idx = 1; Idx < WoolC.Length; Idx++) WoolC[Idx] = fPropn0 * Breed0.WoolC[Idx] + fPropn1 * Breed1.WoolC[Idx];
                for (Idx = 1; Idx < ChillC.Length; Idx++) ChillC[Idx] = fPropn0 * Breed0.ChillC[Idx] + fPropn1 * Breed1.ChillC[Idx];
                for (Idx = 1; Idx < GainC.Length; Idx++) GainC[Idx] = fPropn0 * Breed0.GainC[Idx] + fPropn1 * Breed1.GainC[Idx];
                for (Idx = 1; Idx < PhosC.Length; Idx++) PhosC[Idx] = fPropn0 * Breed0.PhosC[Idx] + fPropn1 * Breed1.PhosC[Idx];
                for (Idx = 1; Idx < SulfC.Length; Idx++) SulfC[Idx] = fPropn0 * Breed0.SulfC[Idx] + fPropn1 * Breed1.SulfC[Idx];
                for (Idx = 1; Idx < MethC.Length; Idx++) MethC[Idx] = fPropn0 * Breed0.MethC[Idx] + fPropn1 * Breed1.MethC[Idx];
                for (Idx = 1; Idx < AshAlkC.Length; Idx++) AshAlkC[Idx] = fPropn0 * Breed0.AshAlkC[Idx] + fPropn1 * Breed1.AshAlkC[Idx];
                for (Idx = 1; Idx < DayLengthConst.Length; Idx++) DayLengthConst[Idx] = fPropn0 * Breed0.DayLengthConst[Idx] + fPropn1 * Breed1.DayLengthConst[Idx];
                for (Idx = 0; Idx < ToxaemiaSigs.Length; Idx++) ToxaemiaSigs[Idx] = fPropn0 * Breed0.ToxaemiaSigs[Idx] + fPropn1 * Breed1.ToxaemiaSigs[Idx];
                for (Idx = 0; Idx < DystokiaSigs.Length; Idx++) DystokiaSigs[Idx] = fPropn0 * Breed0.DystokiaSigs[Idx] + fPropn1 * Breed1.DystokiaSigs[Idx];
                for (Idx = 0; Idx < ExposureConsts.Length; Idx++) ExposureConsts[Idx] = fPropn0 * Breed0.ExposureConsts[Idx] + fPropn1 * Breed1.ExposureConsts[Idx];

                FertWtDiff = fPropn0 * Breed0.FertWtDiff + fPropn1 * Breed1.FertWtDiff;
                SelfWeanPropn = fPropn0 * Breed0.SelfWeanPropn + fPropn1 * Breed1.SelfWeanPropn;
                for (Idx = 1; Idx < ConceiveSigs.Length; Idx++)
                    for (Jdx = 0; Jdx < ConceiveSigs[Idx].Length; Jdx++)
                        ConceiveSigs[Idx][Jdx] = fPropn0 * Breed0.ConceiveSigs[Idx][Jdx] + fPropn1 * Breed1.ConceiveSigs[Idx][Jdx];

                for (Idx = 0; Idx <= iDefinitionCount() - 1; Idx++)
                    getDefinition(Idx).setDefined(Blend[0].Breed.getDefinition(Idx));
            }
            else                                                                         // Mixture of breeds provided
            {
                if (Blend.Length > 1)                                                 // Blend the numeric parameter values
                {
                    for (Idx = 0; Idx <= iParamCount() - 1; Idx++)
                    {
                        prmDefn = getParam(Idx);
                        if (prmDefn.paramType == ptyReal)
                        {
                            fParamSum = 0.0;
                            fPropnSum = 0.0;
                            for (Jdx = 0; Jdx <= Blend.Length - 1; Jdx++)
                            {
                                if (Blend[Jdx].Breed.bIsDefined(prmDefn.sFullName))
                                {
                                    fParamSum = fParamSum + Blend[Jdx].fPropn * Blend[Jdx].Breed.fParam(prmDefn.sFullName);
                                    fPropnSum = fPropnSum + Blend[Jdx].fPropn;
                                }
                            }
                            if (fPropnSum > 0.0)
                                setParam(prmDefn.sFullName, fParamSum / fPropnSum);
                        }
                    }
                }
            }

            if (Blend.Length > 0)
            {
                fPropnSum = 0.0;
                for (Jdx = 0; Jdx <= Blend.Length - 1; Jdx++)
                    fPropnSum = fPropnSum + Blend[Jdx].fPropn;

                if (fPropnSum > 0.0)
                {
                    for (Idx = 0; Idx <= FParentage.Length - 1; Idx++)
                        FParentage[Idx].fPropn = 0.0;
                    for (Jdx = 0; Jdx <= Blend.Length - 1; Jdx++)
                    {
                        for (Kdx = 0; Kdx <= Blend[Jdx].Breed.FParentage.Length - 1; Kdx++)
                        {
                            Idx = 0;
                            while ((Idx < FParentage.Length) && (Blend[Jdx].Breed.FParentage[Kdx].sBaseBreed != FParentage[Idx].sBaseBreed))
                                Idx++;
                            if (Idx == FParentage.Length)
                            {
                                Array.Resize(ref FParentage, Idx + 1);
                                FParentage[Idx].sBaseBreed = Blend[Jdx].Breed.FParentage[Kdx].sBaseBreed;
                                FParentage[Idx].fPropn = 0.0;
                            }
                            FParentage[Idx].fPropn = FParentage[Idx].fPropn
                                                      + (Blend[Jdx].fPropn / fPropnSum) * Blend[Jdx].Breed.FParentage[Kdx].fPropn;
                        }
                    }
                }
            }

            if (sBreedName != "")                                                    // Construct a name for the new genotype
                sName = sBreedName;
            else if (FParentage.Length == 1)
                sName = FParentage[0].sBaseBreed;
            else if (FParentage.Length > 1)
            {
                iDecPlaces = 0;
                for (Idx = 0; Idx <= FParentage.Length - 1; Idx++)
                {
                    if ((FParentage[Idx].fPropn > 0.0005) && (FParentage[Idx].fPropn <= 0.05))
                        iDecPlaces = 1;
                }

                sName = "";
                for (Idx = 0; Idx <= FParentage.Length - 1; Idx++)
                {
                    if (FParentage[Idx].fPropn > 0.0005)
                    {
                        if (sName != "")
                            sName = sName + ", ";
                        sName = sName + FParentage[Idx].sBaseBreed + " "
                                         + String.Format("{0:0." + new String('0', iDecPlaces) + "}", 100.0 * FParentage[Idx].fPropn) + "%";
                    }
                }
            }
        }
예제 #3
0
파일: animprm.cs 프로젝트: hol353/ApsimX
        /// <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;
        }