Ejemplo n.º 1
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;
     }
 }
Ejemplo n.º 2
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;
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Completes the time step.
        /// </summary>
        public void CompleteTimeStep()
        {
            int lastDay = (int)(SpoilageTime - 1.0e-6);

            for (int paddIdx = 0; paddIdx < Paddocks.Length; paddIdx++)
            {
                SupplementRation ration = Paddocks[paddIdx].SupptFed;
                if (ration.Count > 0)
                {
                    for (int dayNum = System.Math.Min(lastDay, ration.Count); dayNum > 0; dayNum--)
                    {
                        ration[dayNum]        = ration[dayNum - 1];
                        ration[dayNum].Amount = ration[dayNum - 1].Amount * (SpoilageTime - dayNum) / (SpoilageTime - (dayNum - 1));
                    }
                    ration[0].Amount = 0.0;
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Removes the supplement
        /// </summary>
        /// <param name="paddIdx">Index of the padd.</param>
        /// <param name="suppKg">The supp kg.</param>
        /// <exception cref="System.Exception">Paddock not recognised</exception>
        private void RemoveSuppt(int paddIdx, double suppKg)
        {
            if (paddIdx < 0)
            {
                throw new Exception("Paddock not recognised");
            }

            SupplementRation ration = Paddocks[paddIdx].SupptFed;

            if (suppKg > 0.0 && ration.TotalAmount > 0.0)
            {
                double removePropn = suppKg / ration.TotalAmount;
                if (removePropn < 1.0 - 1.0e-6)
                {
                    ration.TotalAmount -= suppKg;
                }
                else
                {
                    ration.TotalAmount = 0.0;
                }
            }
        }