Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="request"></param>
        public new void Remove(ResourceRequest request)
        {
            // grazing or feeding from store treated the same way
            // grazing does not access pools by breed by gets all it needs of this quality common pasture
            // common pasture quality can be linked to a real pasture or foodstore and this has already been done.

            FoodResourcePacket additionalDetails = new FoodResourcePacket();

            additionalDetails.PercentN = this.Nitrogen;
            additionalDetails.DMD      = this.dryMatterDigestibility;
            additionalDetails.Amount   = request.Required;
            request.AdditionalDetails  = additionalDetails;

            // other non grazing activities requesting common land pasture
            request.Provided = request.Required;

            // report
            ResourceTransaction details = new ResourceTransaction();

            details.ResourceType = this.Name;
            details.Loss         = request.Provided;
            details.Activity     = request.ActivityModel.Name;
            details.ActivityType = request.ActivityModel.GetType().Name;
            details.Reason       = request.Reason;
            LastTransaction      = details;
            TransactionEventArgs te = new TransactionEventArgs()
            {
                Transaction = details
            };

            OnTransactionOccurred(te);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Remove from animal food store
        /// </summary>
        /// <param name="Request">Resource request class with details.</param>
        public void Remove(ResourceRequest Request)
        {
            if (Request.Required == 0)
            {
                return;
            }
            double amountRemoved = Request.Required;

            // avoid taking too much
            amountRemoved = Math.Min(this.amount, amountRemoved);
            this.amount  -= amountRemoved;

            FoodResourcePacket additionalDetails = new FoodResourcePacket();

            additionalDetails.DMD      = this.DMD;
            additionalDetails.PercentN = this.Nitrogen;
            Request.AdditionalDetails  = additionalDetails;

            Request.Provided = amountRemoved;
            ResourceTransaction details = new ResourceTransaction();

            details.ResourceType = this.Name;
            details.Debit        = amountRemoved * -1;
            details.Activity     = Request.ActivityModel.Name;
            details.Reason       = Request.Reason;
            LastTransaction      = details;
            TransactionEventArgs te = new TransactionEventArgs()
            {
                Transaction = details
            };

            OnTransactionOccurred(te);
            return;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Graze food add method.
        /// This style is not supported in GrazeFoodStoreType
        /// </summary>
        /// <param name="resourceAmount">Object to add. This object can be double or contain additional information (e.g. Nitrogen) of food being added</param>
        /// <param name="activity">Name of activity adding resource</param>
        /// <param name="reason">Name of individual adding resource</param>
        public new void Add(object resourceAmount, CLEMModel activity, string reason)
        {
            GrazeFoodStorePool pool;

            switch (resourceAmount.GetType().Name)
            {
            case "GrazeFoodStorePool":
                pool = resourceAmount as GrazeFoodStorePool;
                break;

            case "FoodResourcePacket":
                pool = new GrazeFoodStorePool();
                FoodResourcePacket packet = resourceAmount as FoodResourcePacket;
                pool.Set(packet.Amount);
                pool.Nitrogen = packet.PercentN;
                pool.DMD      = packet.DMD;
                break;

            case "Double":
                pool = new GrazeFoodStorePool();
                pool.Set((double)resourceAmount);
                pool.Nitrogen = this.Nitrogen;
                pool.DMD      = this.EstimateDMD(this.Nitrogen);
                break;

            default:
                // expecting a GrazeFoodStoreResource (PastureManage) or FoodResourcePacket (CropManage) or Double from G-Range
                throw new Exception(String.Format("ResourceAmount object of type {0} is not supported in Add method in {1}", resourceAmount.GetType().ToString(), this.Name));
            }

            if (pool.Amount > 0)
            {
                // allow decaying or no pools currently available
                if (PastureDecays || Pools.Count() == 0)
                {
                    Pools.Insert(0, pool);
                }
                else
                {
                    Pools[0].Add(pool);
                }
                // update biomass available
                biomassAddedThisYear += pool.Amount;

                ResourceTransaction details = new ResourceTransaction
                {
                    Gain         = pool.Amount,
                    Activity     = activity,
                    Reason       = reason,
                    ResourceType = this
                };
                LastTransaction = details;
                TransactionEventArgs te = new TransactionEventArgs()
                {
                    Transaction = details
                };
                OnTransactionOccurred(te);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Graze food add method.
        /// This style is not supported in GrazeFoodStoreType
        /// </summary>
        /// <param name="resourceAmount">Object to add. This object can be double or contain additional information (e.g. Nitrogen) of food being added</param>
        /// <param name="activity">Name of activity adding resource</param>
        /// <param name="relatesToResource"></param>
        /// <param name="category"></param>
        public new void Add(object resourceAmount, CLEMModel activity, string relatesToResource, string category)
        {
            // expecting a GrazeFoodStoreResource (PastureManage) or FoodResourcePacket (CropManage)
            if (!(resourceAmount.GetType() == typeof(GrazeFoodStorePool) || resourceAmount.GetType() != typeof(FoodResourcePacket)))
            {
                throw new Exception(String.Format("ResourceAmount object of type {0} is not supported in Add method in {1}", resourceAmount.GetType().ToString(), this.Name));
            }

            GrazeFoodStorePool pool;

            if (resourceAmount.GetType() == typeof(GrazeFoodStorePool))
            {
                pool = resourceAmount as GrazeFoodStorePool;
            }
            else
            {
                pool = new GrazeFoodStorePool();
                FoodResourcePacket packet = resourceAmount as FoodResourcePacket;
                pool.Set(packet.Amount);
                pool.Nitrogen = packet.PercentN;
                pool.DMD      = packet.DMD;
            }

            if (pool.Amount > 0)
            {
                // need to check the follwoing code is no longer needed.

                // allow decaying or no pools currently available
                //if (PastureDecays || Pools.Count() == 0)
                //{
                //    Pools.Insert(0, pool);
                //}
                //else
                //{
                //    Pools[0].Add(pool);
                //}
                //// update biomass available
                //biomassAddedThisYear += pool.Amount;

                ResourceTransaction details = new ResourceTransaction
                {
                    TransactionType   = TransactionType.Gain,
                    Amount            = pool.Amount,
                    Activity          = activity,
                    Category          = category,
                    RelatesToResource = relatesToResource,
                    ResourceType      = this
                };
                LastGain        = pool.Amount;
                LastTransaction = details;
                TransactionEventArgs te = new TransactionEventArgs()
                {
                    Transaction = details
                };
                OnTransactionOccurred(te);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Remove from animal food store
        /// </summary>
        /// <param name="request">Resource request class with details.</param>
        public new void Remove(ResourceRequest request)
        {
            if (request.Required == 0)
            {
                return;
            }

            // if this request aims to trade with a market see if we need to set up details for the first time
            if (request.MarketTransactionMultiplier > 0)
            {
                FindEquivalentMarketStore();
            }

            double amountRemoved = request.Required;

            // avoid taking too much
            amountRemoved = Math.Min(this.amount, amountRemoved);

            if (amountRemoved > 0)
            {
                this.amount -= amountRemoved;

                FoodResourcePacket additionalDetails = new FoodResourcePacket
                {
                    DMD      = this.DMD,
                    PercentN = this.CurrentStoreNitrogen
                };
                request.AdditionalDetails = additionalDetails;

                request.Provided = amountRemoved;

                // send to market if needed
                if (request.MarketTransactionMultiplier > 0 && EquivalentMarketStore != null)
                {
                    additionalDetails.Amount = amountRemoved * request.MarketTransactionMultiplier;
                    (EquivalentMarketStore as AnimalFoodStoreType).Add(additionalDetails, request.ActivityModel, request.ResourceTypeName, "Farm sales");
                }

                ResourceTransaction details = new ResourceTransaction
                {
                    ResourceType      = this,
                    Style             = TransactionStyle.Loss,
                    Amount            = amountRemoved,
                    Activity          = request.ActivityModel,
                    RelatesToResource = request.RelatesToResource,
                    Category          = request.Category
                };
                LastTransaction = details;
                TransactionEventArgs te = new TransactionEventArgs()
                {
                    Transaction = details
                };
                OnTransactionOccurred(te);
            }
            return;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// A funtion to add intake and track changes in %N and DietDryMatterDigestibility
 /// </summary>
 /// <param name="intake">Feed request containing intake information kg, %N, DMD</param>
 public void AddIntake(FoodResourcePacket intake)
 {
     if (intake.Amount > 0)
     {
         // determine the adjusted DMD of all intake
         this.DietDryMatterDigestibility = ((this.Intake * this.DietDryMatterDigestibility) + (intake.DMD * intake.Amount)) / (this.Intake + intake.Amount);
         // determine the adjusted percentage N of all intake
         this.PercentNOfIntake = ((this.Intake * this.PercentNOfIntake) + (intake.PercentN * intake.Amount)) / (this.Intake + intake.Amount);;
         this.Intake          += intake.Amount;
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Graze food add method.
        /// This style is not supported in GrazeFoodStoreType
        /// </summary>
        /// <param name="resourceAmount">Object to add. This object can be double or contain additional information (e.g. Nitrogen) of food being added</param>
        /// <param name="activity">Name of activity adding resource</param>
        /// <param name="reason">Name of individual adding resource</param>
        public new void Add(object resourceAmount, CLEMModel activity, string reason)
        {
            // expecting a GrazeFoodStoreResource (PastureManage) or FoodResourcePacket (CropManage)
            if (!(resourceAmount.GetType() == typeof(GrazeFoodStorePool) || resourceAmount.GetType() == typeof(FoodResourcePacket)))
            {
                throw new Exception(String.Format("ResourceAmount object of type {0} is not supported in Add method in {1}", resourceAmount.GetType().ToString(), this.Name));
            }

            GrazeFoodStorePool pool;

            if (resourceAmount.GetType() == typeof(GrazeFoodStorePool))
            {
                pool = resourceAmount as GrazeFoodStorePool;
            }
            else
            {
                pool = new GrazeFoodStorePool();
                FoodResourcePacket packet = resourceAmount as FoodResourcePacket;
                pool.Set(packet.Amount);
                pool.Nitrogen = packet.PercentN;
                pool.DMD      = packet.DMD;
            }

            if (pool.Amount > 0)
            {
                // allow decaying or no pools currently available
                if (PastureDecays || Pools.Count() == 0)
                {
                    Pools.Insert(0, pool);
                }
                else
                {
                    Pools[0].Add(pool);
                }
                // update biomass available
                biomassAddedThisYear += pool.Amount;

                ResourceTransaction details = new ResourceTransaction();
                details.Gain         = pool.Amount;
                details.Activity     = activity.Name;
                details.ActivityType = activity.GetType().Name;
                details.Reason       = reason;
                details.ResourceType = this.Name;
                LastTransaction      = details;
                TransactionEventArgs te = new TransactionEventArgs()
                {
                    Transaction = details
                };
                OnTransactionOccurred(te);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Graze food add method.
        /// This style is not supported in GrazeFoodStoreType
        /// </summary>
        /// <param name="resourceAmount">Object to add. This object can be double or contain additional information (e.g. Nitrogen) of food being added</param>
        /// <param name="activity">Name of activity adding resource</param>
        /// <param name="relatesToResource"></param>
        /// <param name="category"></param>
        public new void Add(object resourceAmount, CLEMModel activity, string relatesToResource, string category)
        {
            // expecting a GrazeFoodStoreResource (PastureManage) or FoodResourcePacket (CropManage)
            if (!(resourceAmount.GetType() == typeof(GrazeFoodStorePool) || resourceAmount.GetType() != typeof(FoodResourcePacket)))
            {
                throw new Exception(String.Format("ResourceAmount object of type {0} is not supported in Add method in {1}", resourceAmount.GetType().ToString(), this.Name));
            }

            GrazeFoodStorePool pool;

            if (resourceAmount.GetType() == typeof(GrazeFoodStorePool))
            {
                pool = resourceAmount as GrazeFoodStorePool;
            }
            else
            {
                pool = new GrazeFoodStorePool();
                FoodResourcePacket packet = resourceAmount as FoodResourcePacket;
                pool.Set(packet.Amount);
                pool.Nitrogen = packet.PercentN;
                pool.DMD      = packet.DMD;
            }

            if (pool.Amount > 0)
            {
                ResourceTransaction details = new ResourceTransaction
                {
                    TransactionType   = TransactionType.Gain,
                    Amount            = pool.Amount,
                    Activity          = activity,
                    Category          = category,
                    RelatesToResource = relatesToResource,
                    ResourceType      = this
                };
                LastGain        = pool.Amount;
                LastTransaction = details;
                TransactionEventArgs te = new TransactionEventArgs()
                {
                    Transaction = details
                };
                OnTransactionOccurred(te);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Remove from animal food store
        /// </summary>
        /// <param name="request">Resource request class with details.</param>
        public new void Remove(ResourceRequest request)
        {
            if (request.Required == 0)
            {
                return;
            }

            double amountRemoved = request.Required;

            // avoid taking too much
            amountRemoved = Math.Min(this.amount, amountRemoved);
            this.amount  -= amountRemoved;

            FoodResourcePacket additionalDetails = new FoodResourcePacket
            {
                DMD      = this.DMD,
                PercentN = this.CurrentStoreNitrogen
            };

            request.AdditionalDetails = additionalDetails;

            request.Provided = amountRemoved;
            ResourceTransaction details = new ResourceTransaction
            {
                ResourceType = this,
                Loss         = amountRemoved,
                Activity     = request.ActivityModel,
                Reason       = request.Reason
            };

            LastTransaction = details;
            TransactionEventArgs te = new TransactionEventArgs()
            {
                Transaction = details
            };

            OnTransactionOccurred(te);
            return;
        }
Ejemplo n.º 10
0
        /// <inheritdoc/>
        public new void Remove(ResourceRequest request)
        {
            // grazing or feeding from store treated the same way
            // grazing does not access pools by breed by gets all it needs of this quality common pasture
            // common pasture quality can be linked to a real pasture or foodstore and this has already been done.

            FoodResourcePacket additionalDetails = new FoodResourcePacket
            {
                PercentN = this.Nitrogen,
                DMD      = this.dryMatterDigestibility,
                Amount   = request.Required
            };

            request.AdditionalDetails = additionalDetails;

            // other non grazing activities requesting common land pasture
            request.Provided = request.Required;

            // report
            ResourceTransaction details = new ResourceTransaction
            {
                ResourceType      = this,
                TransactionType   = TransactionType.Loss,
                Amount            = request.Provided,
                Activity          = request.ActivityModel,
                Category          = request.Category,
                RelatesToResource = request.RelatesToResource
            };

            LastTransaction = details;
            TransactionEventArgs te = new TransactionEventArgs()
            {
                Transaction = details
            };

            OnTransactionOccurred(te);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Graze food add method.
        /// This style is not supported in GrazeFoodStoreType
        /// </summary>
        /// <param name="resourceAmount">Object to add. This object can be double or contain additional information (e.g. Nitrogen) of food being added</param>
        /// <param name="activity">Name of activity adding resource</param>
        /// <param name="relatesToResource"></param>
        /// <param name="category"></param>
        public new void Add(object resourceAmount, CLEMModel activity, string relatesToResource, string category)
        {
            GrazeFoodStorePool pool;

            switch (resourceAmount.GetType().Name)
            {
            case "GrazeFoodStorePool":
                pool = resourceAmount as GrazeFoodStorePool;
                // adjust N content only if new growth (age = 0) based on yield limits and month range defined in GrazeFoodStoreFertilityLimiter if present
                if (pool.Age == 0 && !(grazeFoodStoreFertilityLimiter is null))
                {
                    double reduction = grazeFoodStoreFertilityLimiter.GetProportionNitrogenLimited(pool.Amount / Manager.Area);
                    pool.Nitrogen = Math.Max(MinimumNitrogen, pool.Nitrogen * reduction);
                }
                break;

            case "FoodResourcePacket":
                pool = new GrazeFoodStorePool();
                FoodResourcePacket packet = resourceAmount as FoodResourcePacket;
                pool.Set(packet.Amount);
                pool.Nitrogen = packet.PercentN;
                pool.DMD      = packet.DMD;
                break;

            case "Double":
                pool = new GrazeFoodStorePool();
                pool.Set((double)resourceAmount);
                pool.Nitrogen = this.Nitrogen;
                pool.DMD      = this.EstimateDMD(this.Nitrogen);
                break;

            default:
                // expecting a GrazeFoodStoreResource (PastureManage) or FoodResourcePacket (CropManage) or Double from G-Range
                throw new Exception(String.Format("ResourceAmount object of type {0} is not supported in Add method in {1}", resourceAmount.GetType().ToString(), this.Name));
            }
            if (pool.Amount > 0)
            {
                // allow decaying or no pools currently available
                if (PastureDecays || Pools.Count() == 0)
                {
                    Pools.Insert(0, pool);
                }
                else
                {
                    Pools[0].Add(pool);
                }
                // update biomass available
                if (!category.StartsWith("Initialise"))
                {
                    // do not update if this is ian initialisation pool
                    biomassAddedThisYear += pool.Amount;
                }

                ResourceTransaction details = new ResourceTransaction
                {
                    Style             = TransactionStyle.Gain,
                    Amount            = pool.Amount,
                    Activity          = activity,
                    RelatesToResource = relatesToResource,
                    Category          = category,
                    ResourceType      = this
                };
                LastTransaction = details;
                LastGain        = pool.Amount;
                TransactionEventArgs te = new TransactionEventArgs()
                {
                    Transaction = details
                };
                OnTransactionOccurred(te);
            }
        }