コード例 #1
0
ファイル: stock_vars.cs プロジェクト: mcauliffer/ApsimX
        /// <summary>
        /// Populate metabolizable energy use array
        /// Note: these are an* ME* partition
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="aValue"></param>
        public static void MakeEnergyUse(TStockList Model, ref TEnergyUse[] aValue)
        {
            double dME_Metab;
            double dME_MoveGraze;
            int    Idx;

            for (Idx = 1; Idx <= Model.Count(); Idx++)
            {
                TAnimalGroup group = Model.At(Idx);
                dME_Metab     = group.AnimalState.EnergyUse.Metab / group.AnimalState.Efficiency.Maint;
                dME_MoveGraze = group.AnimalState.EnergyUse.Maint - dME_Metab - group.AnimalState.EnergyUse.Cold;

                aValue[Idx].maint_base       = dME_Metab;
                aValue[Idx].maint_move_graze = dME_MoveGraze;  // Separating E(graze) and E(move) requires work in AnimGRP.pas...
                aValue[Idx].maint_cold       = group.AnimalState.EnergyUse.Cold;
                aValue[Idx].conceptus        = group.AnimalState.EnergyUse.Preg;
                aValue[Idx].lactation        = group.AnimalState.EnergyUse.Lact;
                aValue[Idx].fleece           = group.AnimalState.EnergyUse.Wool / group.AnimalState.Efficiency.Gain;
                aValue[Idx].gain             = group.AnimalState.EnergyUse.Gain / group.AnimalState.Efficiency.Gain;
            }
        }
コード例 #2
0
        /// <summary>
        /// Populate metabolizable energy use array
        /// Note: these are an* ME* partition
        /// </summary>
        /// <param name="model">The animal model</param>
        /// <param name="energyValues">The energy use returned</param>
        public static void MakeEnergyUse(StockList model, ref EnergyUse[] energyValues)
        {
            double ME_Metab;
            double ME_MoveGraze;
            int    idx;

            for (idx = 1; idx <= model.Count(); idx++)
            {
                TAnimalGroup group = model.At(idx);
                ME_Metab     = group.AnimalState.EnergyUse.Metab / group.AnimalState.Efficiency.Maint;
                ME_MoveGraze = group.AnimalState.EnergyUse.Maint - ME_Metab - group.AnimalState.EnergyUse.Cold;

                energyValues[idx].MaintBase      = ME_Metab;
                energyValues[idx].MaintMoveGraze = ME_MoveGraze;  // Separating E(graze) and E(move) requires work in AnimGRP.pas...
                energyValues[idx].MaintCold      = group.AnimalState.EnergyUse.Cold;
                energyValues[idx].Conceptus      = group.AnimalState.EnergyUse.Preg;
                energyValues[idx].Lactation      = group.AnimalState.EnergyUse.Lact;
                energyValues[idx].Fleece         = group.AnimalState.EnergyUse.Wool / group.AnimalState.Efficiency.Gain;
                energyValues[idx].Gain           = group.AnimalState.EnergyUse.Gain / group.AnimalState.Efficiency.Gain;
            }
        }
コード例 #3
0
ファイル: stock_intf.cs プロジェクト: hol353/ApsimX
        /// <summary>
        /// Returns the group index of the group that was added. 0->n                    
        /// </summary>
        /// <param name="Inits"></param>
        /// <returns></returns>
        public int Add(TAnimalInits Inits)
        {
            TAnimalGroup NewGroup;
            TPaddockInfo Paddock;

            NewGroup = new TAnimalGroup(getGenotype(Inits.sGenotype),
                                             Inits.Sex,
                                             Inits.Number,
                                             Inits.AgeDays,
                                             Inits.Weight,
                                             Inits.Fleece_Wt,
                                             RandFactory);
            if (bIsGiven(Inits.MaxPrevWt))
                NewGroup.MaxPrevWeight = Inits.MaxPrevWt;
            if (bIsGiven(Inits.Fibre_Diam))
                NewGroup.FibreDiam = Inits.Fibre_Diam;

            if (Inits.sMatedTo != "")
                NewGroup.MatedTo = getGenotype(Inits.sMatedTo);
            if ((NewGroup.ReproState == GrazType.ReproType.Empty) && (Inits.Pregnant > 0))
            {
                NewGroup.Pregnancy = Inits.Pregnant;
                if (Inits.No_Foetuses > 0)
                    NewGroup.NoFoetuses = Inits.No_Foetuses;
            }
            if ((NewGroup.ReproState == GrazType.ReproType.Empty) || (NewGroup.ReproState == GrazType.ReproType.EarlyPreg) || (NewGroup.ReproState == GrazType.ReproType.LatePreg) && (Inits.Lactating > 0))
            {
                NewGroup.Lactation = Inits.Lactating;
                if (Inits.No_Suckling > 0)
                    NewGroup.NoOffspring = Inits.No_Suckling;
                else if ((NewGroup.Animal == GrazType.AnimalType.Cattle) && (Inits.No_Suckling == 0))
                {
                    NewGroup.Young = null;
                }
                if (bIsGiven(Inits.Birth_CS))
                    NewGroup.BirthCondition = TAnimalParamSet.CondScore2Condition(Inits.Birth_CS, TAnimalParamSet.TCond_System.csSYSTEM1_5);
            }

            if (NewGroup.Young != null)
            {
                if (bIsGiven(Inits.Young_Wt))
                    NewGroup.Young.LiveWeight = Inits.Young_Wt;
                if (bIsGiven(Inits.Young_GFW))
                    NewGroup.Young.FleeceCutWeight = Inits.Young_GFW;
            }

            Paddock = FPaddocks.byName(Inits.Paddock.ToLower());
            if (Paddock == null)
                Paddock = FPaddocks.byIndex(0);

            return Add(NewGroup, Paddock, Inits.Tag, Inits.Priority);
        }
コード例 #4
0
ファイル: stock_intf.cs プロジェクト: hol353/ApsimX
        /// <summary>
        /// Add a group of animals to the list                                           
        /// Returns the group index of the group that was added. 0->n                    
        /// </summary>
        /// <param name="aGroup"></param>
        /// <param name="PaddInfo"></param>
        /// <param name="iTagVal"></param>
        /// <param name="iPriority"></param>
        /// <returns></returns>
        public int Add(TAnimalGroup aGroup, TPaddockInfo PaddInfo, int iTagVal, int iPriority)
        {
            int Idx;

            aGroup.Calc_IntakeLimit();

            Idx = FStock.Length;
            Array.Resize(ref FStock, Idx + 1);
            FStock[Idx] = new TStockContainer();
            FStock[Idx].Animals = aGroup.Copy();
            FStock[Idx].PaddOccupied = PaddInfo;
            FStock[Idx].iTag = iTagVal;
            FStock[Idx].iPriority = iPriority;

            setInitialStockInputs(Idx);
            return Idx;
        }
コード例 #5
0
ファイル: stock_intf.cs プロジェクト: hol353/ApsimX
 private void setAt(int iPosn, TAnimalGroup AG)
 {
     if ((iPosn == Count() + 1) && (AG != null))
         Add(AG, Paddocks.byIndex(0), 0, 0);
     else
         FStock[iPosn].Animals = AG;
 }
コード例 #6
0
ファイル: stock_intf.cs プロジェクト: hol353/ApsimX
        private double getPaddockRank(TPaddockInfo aPaddock,
                                      TAnimalGroup aGroup)
        {
            double Result;
            GrazType.TGrazingInputs forageInputs;
            GrazType.TGrazingInputs paddockInputs;
            double[] fHerbageRI = new double[GrazType.DigClassNo + 1];
            double[,] fSeedRI = new double[GrazType.MaxPlantSpp + 1, GrazType.RIPE + 1];
            double fDummy = 0.0;
            int Jdx;
            int iClass;

            aGroup.PaddSteep = aPaddock.Steepness;
            aGroup.WaterLogging = aPaddock.fWaterlog;
            aGroup.RationFed.Assign(aPaddock.SuppInPadd);
            aGroup.RationFed.TotalAmount = 0.0;                                        // No supplementary feed here

            paddockInputs = new GrazType.TGrazingInputs();
            for (Jdx = 0; Jdx <= aPaddock.Forages.Count() - 1; Jdx++)
            {
                forageInputs = aPaddock.Forages.byIndex(Jdx).availForage(aGroup.Genotype.GrazeC[17],
                                                                           aGroup.Genotype.GrazeC[18],
                                                                           aGroup.Genotype.GrazeC[19]);
                GrazType.addGrazingInputs(Jdx + 1, forageInputs, ref paddockInputs);
            }
            aGroup.Herbage = paddockInputs;

            aGroup.CalculateRelIntake(aGroup, 1.0, false, 1.0, ref fHerbageRI, ref fSeedRI, ref fDummy);

            Result = 0.0;
            for (iClass = 1; iClass <= GrazType.DigClassNo; iClass++)                                             // Function result is DMDI/pot. intake
                Result = Result + fHerbageRI[iClass] * GrazType.ClassDig[iClass];
            return Result;
        }
コード例 #7
0
ファイル: stock_intf.cs プロジェクト: hol353/ApsimX
        /// <summary>
        /// Executes a "buy" event
        /// </summary>
        /// <param name="AnimalInfo"></param>
        /// <returns></returns>
        protected int Buy(TPurchaseInfo AnimalInfo)
        {
            TAnimalParamSet aGenotype;
            TAnimalGroup NewGroup;
            double fBodyCondition;
            double fLiveWeight;
            double fLowBaseWeight = 0.0;
            double fHighBaseWeight = 0.0;
            TAnimalList WeanList;
            int PaddNo;

            int result = 0;

            if (AnimalInfo.Number > 0)
            {
                aGenotype = getGenotype(AnimalInfo.sGenotype);

                if (AnimalInfo.LiveWt > 0.0)
                    fLiveWeight = AnimalInfo.LiveWt;
                else
                {
                    fLiveWeight = GrowthCurve(AnimalInfo.AgeDays, AnimalInfo.Repro, aGenotype);
                    if (AnimalInfo.fCondScore > 0.0)
                        fLiveWeight = fLiveWeight * TAnimalParamSet.CondScore2Condition(AnimalInfo.fCondScore);
                    if (aGenotype.Animal == GrazType.AnimalType.Sheep)
                        fLiveWeight = fLiveWeight + AnimalInfo.GFW;
                }

                // Construct a new group of animals.
                NewGroup = new TAnimalGroup(aGenotype,
                                                 AnimalInfo.Repro,                         //   Repro should be Empty, Castrated or
                                                 AnimalInfo.Number,                        //   Male; pregnancy is handled with the
                                                 AnimalInfo.AgeDays,                       //   Preg  field.
                                                 fLiveWeight,
                                                 AnimalInfo.GFW,
                                                 RandFactory);

                if ((AnimalInfo.fCondScore > 0.0) && (AnimalInfo.LiveWt > 0.0))        // Adjust the condition score if it has
                {                                                                      //   been given
                    fBodyCondition = TAnimalParamSet.CondScore2Condition(AnimalInfo.fCondScore);
                    NewGroup.WeightRangeForCond(AnimalInfo.Repro, AnimalInfo.AgeDays,
                                                fBodyCondition, NewGroup.Genotype,
                                                ref fLowBaseWeight, ref fHighBaseWeight);

                    if ((NewGroup.BaseWeight >= fLowBaseWeight) && (NewGroup.BaseWeight <= fHighBaseWeight))
                        NewGroup.setConditionAtWeight(fBodyCondition);
                    else
                    {
                        NewGroup = null;
                        throw new Exception("Purchased animals with condition score "
                                                + AnimalInfo.fCondScore.ToString() + "\n"
                                                + " must have a base weight in the range "
                                                + fLowBaseWeight.ToString()
                                                + "-" + fHighBaseWeight.ToString() + " kg");
                    }
                }

                if (NewGroup.ReproState == GrazType.ReproType.Empty)
                {
                    if (AnimalInfo.sMatedTo != "")                                      // Use TAnimalGroup's property interface
                        NewGroup.MatedTo = getGenotype(AnimalInfo.sMatedTo);            //   to set up pregnancy and lactation.
                    NewGroup.Pregnancy = AnimalInfo.Preg;
                    NewGroup.Lactation = AnimalInfo.Lact;
                    if ((NewGroup.Animal == GrazType.AnimalType.Cattle)
                       && (AnimalInfo.Lact > 0) && (AnimalInfo.NYoung == 0))            // NYoung denotes the number of
                    {                                                                   //   *suckling* young in lactating cows,
                        WeanList = null;                                                //   which isn't quite the same as the
                        NewGroup.Wean(true, true, ref WeanList, ref WeanList);          //   YoungNo property
                        WeanList = null; ;
                    }
                    else if (AnimalInfo.NYoung > 0)
                    {
                        // if the animals are pregnant then they need feotuses
                        if (NewGroup.Pregnancy > 0)
                        {
                            if ((AnimalInfo.Lact > 0) && (NewGroup.Animal == GrazType.AnimalType.Cattle))
                            {
                                NewGroup.NoOffspring = 1;
                                NewGroup.NoFoetuses = Math.Min(2, Math.Max(0, AnimalInfo.NYoung - 1));
                            }
                            else
                            {
                                NewGroup.NoFoetuses = Math.Min(3, AnimalInfo.NYoung);                 // recalculates livewt
                            }
                        }
                        else
                            NewGroup.NoOffspring = AnimalInfo.NYoung;
                    }

                    if (NewGroup.Young != null)                                         // Lamb/calf weights and lamb fleece
                    {                                                                   //   weights are optional.
                        if (bIsGiven(AnimalInfo.YoungWt))
                            NewGroup.Young.LiveWeight = AnimalInfo.YoungWt;
                        if (bIsGiven(AnimalInfo.YoungGFW))
                            NewGroup.Young.FleeceCutWeight = AnimalInfo.YoungGFW;
                    }
                } //if (ReproState = Empty)

                PaddNo = 0;                                                             // Newly bought animals have tag # zero
                while ((PaddNo < Paddocks.Count()) && (Paddocks.byIndex(PaddNo).sName == ""))  // and go in the first named paddock.
                    PaddNo++;
                if (PaddNo >= Paddocks.Count())
                    PaddNo = 0;
                result = Add(NewGroup, Paddocks.byIndex(PaddNo), 0, 0);
            } // if AnimalInfo.Number > 0
            return result;
        }
コード例 #8
0
ファイル: stock_intf.cs プロジェクト: hol353/ApsimX
        // Paddock rank order ......................................................
        /// <summary>
        /// Rank the paddocks
        /// </summary>
        /// <param name="sList"></param>
        public void rankPaddocks(List<string> sList)
        {
            double[] fPaddockRank = new double[Paddocks.Count()];
            TAnimalGroup tempAnimals;
            int iBestPadd;
            double fBestRank;
            int iPadd, Idx;

            if (Count() > 0)
                tempAnimals = At(1).Copy();
            else
                tempAnimals = new TAnimalGroup(getGenotype("Medium Merino"), GrazType.ReproType.Empty, 1, 365 * 4, 50.0, 0.0, RandFactory);
            for (iPadd = 0; iPadd <= Paddocks.Count() - 1; iPadd++)
                fPaddockRank[iPadd] = getPaddockRank(Paddocks.byIndex(iPadd), tempAnimals);

            sList.Clear();
            for (Idx = 0; Idx <= Paddocks.Count() - 1; Idx++)
            {
                fBestRank = -1.0;
                iBestPadd = -1;
                for (iPadd = 0; iPadd <= Paddocks.Count() - 1; iPadd++)
                {
                    if (fPaddockRank[iPadd] > fBestRank)
                    {
                        iBestPadd = iPadd;
                        fBestRank = fPaddockRank[iPadd];
                    }
                }
                sList.Add(Paddocks.byIndex(iBestPadd).sName);
                fPaddockRank[iBestPadd] = -999.9;
            }
        }
コード例 #9
0
ファイル: stock_intf.cs プロジェクト: hol353/ApsimX
 /// <summary>
 /// Calculate the intake limit
 /// </summary>
 /// <param name="aGroup"></param>
 public void computeIntakeLimit(TAnimalGroup aGroup)
 {
     aGroup.Calc_IntakeLimit();
     if (aGroup.Young != null)
         aGroup.Young.Calc_IntakeLimit();
 }