private void OnCLEMDoCutAndCarry(object sender, EventArgs e)
        {
            AmountHarvested           = 0;
            AmountAvailableForHarvest = 0;

            if (this.TimingOK)
            {
                int             year  = Clock.Today.Year;
                int             month = Clock.Today.Month - 1;
                List <Ruminant> herd  = new List <Ruminant>();

                // determine amount to be cut and carried
                if (CutStyle != RuminantFeedActivityTypes.SpecifiedDailyAmount)
                {
                    herd = CurrentHerd(false);
                }
                switch (CutStyle)
                {
                case RuminantFeedActivityTypes.SpecifiedDailyAmount:
                    AmountHarvested += Supply * 30.4;
                    break;

                case RuminantFeedActivityTypes.ProportionOfWeight:
                    foreach (Ruminant ind in herd)
                    {
                        AmountHarvested += Supply * ind.Weight * 30.4;
                    }
                    break;

                case RuminantFeedActivityTypes.ProportionOfPotentialIntake:
                    foreach (Ruminant ind in herd)
                    {
                        AmountHarvested += Supply * ind.PotentialIntake;
                    }
                    break;

                case RuminantFeedActivityTypes.ProportionOfRemainingIntakeRequired:
                    foreach (Ruminant ind in herd)
                    {
                        AmountHarvested += Supply * (ind.PotentialIntake - ind.Intake);
                    }
                    break;

                default:
                    throw new Exception(String.Format("FeedActivityType {0} is not supported in {1}", CutStyle, this.Name));
                }

                AmountAvailableForHarvest = AmountHarvested;
                // reduce amount by limiter if present.
                if (limiter != null)
                {
                    double canBeCarried = limiter.GetAmountAvailable(Clock.Today.Month);
                    AmountHarvested = Math.Max(AmountHarvested, canBeCarried);
                    limiter.AddWeightCarried(AmountHarvested);
                }
            }

            // get resources
            GetResourcesRequiredForActivity();
        }
예제 #2
0
        /// <summary>
        /// Determines how much labour is required from this activity based on the requirement provided
        /// </summary>
        /// <param name="requirement">The details of how labour are to be provided</param>
        /// <returns></returns>
        public override double GetDaysLabourRequired(LabourRequirement requirement)
        {
            int    year   = Clock.Today.Year;
            int    month  = Clock.Today.Month;
            double amount = 0;

            if (NextHarvest != null)
            {
                //if this month is a harvest month for this crop
                if ((year == NextHarvest.HarvestDate.Year) && (month == NextHarvest.HarvestDate.Month))
                {
                    if (this.TimingOK)
                    {
                        if (IsTreeCrop)
                        {
                            amount = NextHarvest.AmtKg * TreesPerHa * parentManagementActivity.Area * UnitsToHaConverter * ProportionKept;
                        }
                        else
                        {
                            amount = NextHarvest.AmtKg * parentManagementActivity.Area * UnitsToHaConverter * ProportionKept;
                        }

                        if (limiter != null)
                        {
                            double canBeCarried = limiter.GetAmountAvailable(Clock.Today.Month);
                            amount = Math.Max(amount, canBeCarried);
                        }
                    }
                }
            }

            double daysNeeded;
            double numberUnits;

            switch (requirement.UnitType)
            {
            case LabourUnitType.Fixed:
                daysNeeded = requirement.LabourPerUnit;
                break;

            case LabourUnitType.perKg:
                daysNeeded = amount * requirement.LabourPerUnit;
                break;

            case LabourUnitType.perUnit:
                numberUnits = amount / requirement.UnitSize;
                if (requirement.WholeUnitBlocks)
                {
                    numberUnits = Math.Ceiling(numberUnits);
                }

                daysNeeded = numberUnits * requirement.LabourPerUnit;
                break;

            case LabourUnitType.perHa:
                numberUnits = parentManagementActivity.Area / requirement.UnitSize;
                if (requirement.WholeUnitBlocks)
                {
                    numberUnits = Math.Ceiling(numberUnits);
                }

                daysNeeded = numberUnits * requirement.LabourPerUnit;
                break;

            default:
                throw new Exception(String.Format("LabourUnitType {0} is not supported for {1} in {2}", requirement.UnitType, requirement.Name, this.Name));
            }
            return(daysNeeded);
        }