Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SupplementModel"/> class.
 /// </summary>
 public SupplementModel()
     : base()
 {
     AddToStore(0.0, FODDER, ROUGHAGE);
     SuppArray[0].DMPropn = 0.85;
     this.currPaddSupp    = new FoodSupplement();
 }
Beispiel #2
0
        /// <summary>
        /// Feed the supplement
        /// </summary>
        /// <param name="newAmount">The amount to feed in kg</param>
        /// <param name="newSupp">The supplement to feed</param>
        /// <param name="feedSuppFirst">True if bail feeding</param>
        public void FeedSupplement(double newAmount, FoodSupplement newSupp, bool feedSuppFirst)
        {
            bool found;
            int  idx;

            this.FeedSuppFirst = false;
            if (newAmount > 0.0)
            {
                this.FeedSuppFirst = feedSuppFirst;
                idx   = 0;
                found = false;
                while (!found && (idx < this.SuppInPadd.Count))
                {
                    found = newSupp.IsSameAs(this.SuppInPadd[idx]);
                    if (!found)
                    {
                        idx++;
                    }
                }
                if (found)
                {
                    this.SuppInPadd[idx].Amount = this.SuppInPadd[idx].Amount + newAmount;
                }
                else
                {
                    FoodSupplement oneSupp = new FoodSupplement();
                    oneSupp.Assign(newSupp);
                    this.SuppInPadd.Add(oneSupp, newAmount);
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// Transfers the specified source.
 /// </summary>
 /// <param name="src">The source.</param>
 /// <param name="srcIdx">Index of the source.</param>
 /// <param name="dest">The dest.</param>
 /// <param name="destIdx">Index of the dest.</param>
 /// <param name="amount">The amount.</param>
 /// <exception cref="System.Exception">Invalid transfer of feed</exception>
 private void Transfer(SupplementRation src, int srcIdx, SupplementRation dest, int destIdx, double amount)
 {
     if (srcIdx < 0 || srcIdx >= src.Count || destIdx < 0 || destIdx > dest.Count)
     {
         throw new Exception("Invalid transfer of feed");
     }
     if (src[srcIdx].Amount > 0)
     {
         if (amount > 0.0)
         {
             if (destIdx < dest.Count)
             {
                 SuppIntoRation(dest, destIdx, src[srcIdx], amount);
             }
             else
             {
                 FoodSupplement copy = new FoodSupplement();
                 copy.Assign(src[srcIdx]);
                 dest.Add(copy, amount);
             }
             src[srcIdx].Amount -= amount;
         }
     }
     else
     {
         dest[destIdx].Amount = 0;
     }
 }
Beispiel #4
0
 /// <summary>
 /// Mixes the supplement into the ration.
 /// </summary>
 /// <param name="ration">The ration.</param>
 /// <param name="idx">The index.</param>
 /// <param name="supp">The supp.</param>
 /// <param name="amount">The amount.</param>
 private void SuppIntoRation(SupplementRation ration, int idx, FoodSupplement supp, double amount)
 {
     if (amount > 0.0)
     {
         double propn = amount / (amount + ration[idx].Amount);
         ration[idx].Mix(supp, ration[idx], propn);
         ration[idx].Amount += amount;
     }
 }
Beispiel #5
0
        /// <summary>
        /// Adds the fodder.
        /// </summary>
        /// <param name="destStore">The dest store.</param>
        /// <param name="fodderFW">The fodder fw.</param>
        /// <param name="DMP">The DMP.</param>
        /// <param name="DMD">The DMD.</param>
        /// <param name="NConc">The n conc.</param>
        /// <param name="PConc">The p conc.</param>
        /// <param name="SConc">The s conc.</param>
        /// <param name="ashAlk">The ash alk.</param>
        public void AddFodder(string destStore, double fodderFW, double DMP, double DMD, double NConc, double PConc, double SConc, double ashAlk)
        {
            if (string.IsNullOrWhiteSpace(destStore))
            {
                destStore = FODDER;
            }

            double protDg  = System.Math.Min(0.9, DMD + 0.1);
            double ADIP2CP = 0.19 * (1.0 - protDg);
            double EE      = 0.02;
            double MEDM    = FoodSupplement.ConvertDMDToME2DM(DMD, true, EE);

            AddToStore(fodderFW, destStore, ROUGHAGE, DMP, DMD, MEDM, FoodSupplement.N2PROTEIN * NConc, protDg, EE, ADIP2CP, PConc, SConc, ashAlk, 0.0);
        }
Beispiel #6
0
        /// <summary>
        /// Adds the supplement to the store.
        /// </summary>
        /// <param name="suppKg">The supp kg.</param>
        /// <param name="suppComp">The supp comp.</param>
        /// <returns>The supplement index</returns>
        /// <exception cref="System.Exception">Supplement submodel: cannot combine roughage and concentrate, both named  + suppComp.sName</exception>
        public int AddToStore(double suppKg, FoodSupplement suppComp)
        {
            int suppIdx = IndexOf(suppComp.Name);

            if (suppIdx < 0)
            {
                suppIdx = Add(suppComp, suppKg);
            }
            else if (suppKg > 0.0)
            {
                if (suppComp.IsRoughage != SuppArray[suppIdx].IsRoughage)
                {
                    throw new Exception("Supplement submodel: cannot combine roughage and concentrate, both named " + suppComp.Name);
                }
                SuppIntoRation(this, suppIdx, suppComp, suppKg);
            }
            return(suppIdx);
        }
Beispiel #7
0
        /// <summary>
        /// Blends the specified source store.
        /// </summary>
        /// <param name="srcStore">The source store.</param>
        /// <param name="transferKg">The transfer kg.</param>
        /// <param name="destStore">The dest store.</param>
        /// <exception cref="System.Exception">Supplement \ + srcStore + \ not recognised</exception>
        public void Blend(string srcStore, double transferKg, string destStore)
        {
            int srcIdx = IndexOf(srcStore);

            if (srcIdx < 0)
            {
                throw new Exception("Supplement \"" + srcStore + "\" not recognised");
            }

            transferKg = System.Math.Min(transferKg, this[srcIdx].Amount);
            if (transferKg > 0.0)
            {
                int dstIdx = IndexOf(destStore);
                if (dstIdx < 0)
                {
                    FoodSupplement newSupp = new FoodSupplement();
                    newSupp.Assign(this[srcIdx]);
                    newSupp.Name = destStore;
                    dstIdx       = AddToStore(0.0, newSupp);
                }
                Transfer(this, srcIdx, this, dstIdx, transferKg);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Adds an amount of a supplement to a store.
        /// * If the store name already exists in the FStores array, the method adds
        /// the supplement to that store.  Otherwise a new store is created.
        /// * The DMP, DMD, MEDM, CP, DG, EE and ADIP2CP parameters may be set to zero,
        /// in which case the default values for the supplement name are used.
        /// Defaults are taken from the current store if the name is already defined,
        /// and from grazSUPP.PAS otherwise.  If defaults cannot be found for a name,
        /// wheat is used as the default composition.
        /// </summary>
        /// <param name="suppKg">Amount (kg fresh weight) of the supplement to be included in the store.</param>
        /// <param name="suppName">Name of the supplement.</param>
        /// <param name="roughage">The roughage.</param>
        /// <param name="dmp">Proportion of the fresh weight which is dry matter   kg/kg FW</param>
        /// <param name="dmd">Dry matter digestibility of the supplement           kg/kg DM</param>
        /// <param name="medm">Metabolisable energy content of dry matter          MJ/kg DM</param>
        /// <param name="cp">Crude protein content                                 kg/kg DM</param>
        /// <param name="dg">Degradability of the crude protein                    kg/kg CP</param>
        /// <param name="ee">Ether-extractable content                             kg/kg DM</param>
        /// <param name="adip2cp">Ratio of acid detergent insoluble protein to CP  kg/kg CP</param>
        /// <param name="phos">Phosphorus content                                  kg/kg DM</param>
        /// <param name="sulf">Sulphur content                                     kg/kg DM</param>
        /// <param name="ashAlk">Ash alkalinity                                    mol/kg DM</param>
        /// <param name="maxPass">Maximum passage rate                             0-1</param>
        /// <returns>
        /// Index of the supplement in the store
        /// </returns>
        public int AddToStore(double suppKg, string suppName, int roughage = DEFAULT, double dmp = 0.0, double dmd = 0.0,
                              double medm = 0.0, double cp   = 0.0, double dg     = 0.0, double ee      = 0.0, double adip2cp = 0.0,
                              double phos = 0.0, double sulf = 0.0, double ashAlk = 0.0, double maxPass = 0.0)
        {
            int idx = IndexOf(suppName);

            FoodSupplement addSupp = new FoodSupplement(suppName);

            if (idx >= 0)                             // Work out the composition of the supplement being added
            {
                addSupp.Assign(this[idx]);
            }
            else
            {
                addSupp.DefaultFromName();
            }
            addSupp.Name = suppName.ToLower();

            if (roughage == ROUGHAGE)                 // Override the default composition as required
            {
                addSupp.IsRoughage = true;
            }
            else if (roughage != DEFAULT)
            {
                addSupp.IsRoughage = false;
            }

            if (dmp > 0.0)
            {
                addSupp.DMPropn = dmp;
            }
            if (dmd > 0.0)
            {
                addSupp.DMDigestibility = dmd;
            }
            if (medm > 0.0)
            {
                addSupp.ME2DM = medm;
            }
            if (cp > 0.0)
            {
                addSupp.CrudeProt = cp;
            }
            if (dg > 0.0)
            {
                addSupp.DegProt = dg;
            }
            if (ee > 0.0)
            {
                addSupp.EtherExtract = ee;
            }
            if (adip2cp > 0.0)
            {
                addSupp.ADIP2CP = adip2cp;
            }
            if (phos > 0.0)
            {
                addSupp.Phosphorus = phos;
            }
            if (sulf > 0.0)
            {
                addSupp.Sulphur = sulf;
            }
            if (ashAlk > 0.0)
            {
                addSupp.AshAlkalinity = ashAlk;
            }
            if (maxPass > 0.0)
            {
                addSupp.MaxPassage = maxPass;
            }

            if (dmd > 0.0 && medm == 0.0)
            {
                addSupp.ME2DM = addSupp.DefaultME2DM();
            }
            else if (dmd == 0.0 && medm > 0.0)
            {
                addSupp.DMDigestibility = addSupp.DefaultDMD();
            }

            return(AddToStore(suppKg, addSupp));
        }
Beispiel #9
0
 /// <summary>
 /// Adds the specified FoodSupplement.
 /// </summary>
 /// <param name="supplement">Supplement to be added</param>
 /// <returns>Index of the added supplement</returns>
 public int Add(FoodSupplement supplement)
 {
     return(theModel.AddToStore(0.0, supplement));
 }