private void OnCLEMCollectManure(object sender, EventArgs e)
        {
            Status = ActivityStatus.Critical;
            // is manure in resources
            if (manureStore != null)
            {
                if (this.TimingOK)
                {
                    List <ResourceRequest> resourcesneeded = GetResourcesNeededForActivityLocal();
                    bool tookRequestedResources            = TakeResources(resourcesneeded, true);
                    // get all shortfalls
                    double labourNeeded = 0;
                    double labourLimit  = 1;
                    if (tookRequestedResources & (ResourceRequestList != null))
                    {
                        labourNeeded = ResourceRequestList.Where(a => a.ResourceType == typeof(Labour)).Sum(a => a.Required);
                        double labourProvided = ResourceRequestList.Where(a => a.ResourceType == typeof(Labour)).Sum(a => a.Provided);
                        labourLimit = labourProvided / labourNeeded;
                    }

                    if (labourLimit == 1 || this.OnPartialResourcesAvailableAction == OnPartialResourcesAvailableActionTypes.UseResourcesAvailable)
                    {
                        foreach (ManureStoreUncollected msu in manureStore.UncollectedStores)
                        {
                            manureStore.Collect(msu.Name, labourLimit, this.Name);
                            SetStatusSuccess();
                        }
                    }
                }
            }
        }
        private void OnCLEMAnimalManage(object sender, EventArgs e)
        {
            // if management month
            if (this.TimingOK)
            {
                double          labourlimit = this.LabourLimitProportion;
                int             weanedCount = 0;
                ResourceRequest labour      = ResourceRequestList.Where(a => a.ResourceType == typeof(LabourType)).FirstOrDefault <ResourceRequest>();
                // Perform weaning
                int count = this.CurrentHerd(true).Where(a => a.Weaned == false).Count();
                foreach (var ind in this.CurrentHerd(true).Where(a => a.Weaned == false))
                {
                    if (ind.Age >= WeaningAge || ind.Weight >= WeaningWeight)
                    {
                        string reason = (ind.Age >= WeaningAge)? "Age" : "Weight";
                        ind.Wean(true, reason);
                        ind.Location = grazeStore;
                        weanedCount++;
                        Status = ActivityStatus.Success;
                    }

                    // stop if labour limited individuals reached and LabourShortfallAffectsActivity
                    if (weanedCount > Convert.ToInt32(count * labourlimit))
                    {
                        break;
                    }
                }
            }
        }
Example #3
0
        private void OnCLEMInitialiseActivity(object sender, EventArgs e)
        {
            if (Area == 0 & AreaRequested > 0)
            {
                ResourceRequestList = new List <ResourceRequest>();
                ResourceRequestList.Add(new ResourceRequest()
                {
                    AllowTransmutation = false,
                    Required           = AreaRequested, // * (double)unitsOfArea,
                    ResourceType       = typeof(Land),
                    ResourceTypeName   = LandItemNameToUse,
                    ActivityModel      = this,
                    Reason             = "Assign",
                    FilterDetails      = null
                }
                                        );
            }

            gotLandRequested = TakeResources(ResourceRequestList, false);


            //Now the Land has been allocated we have an Area
            if (gotLandRequested)
            {
                //Assign the area actually got after taking it. It might be less than AreaRequested (if partial)
                Area = ResourceRequestList.FirstOrDefault().Provided;
            }
        }
Example #4
0
        /// <summary>
        /// Method to provide the proportional limit based on specified resource type
        /// A proportion less than 1 will only be returned if LabourShortfallAffectsActivity is true in the LabourRequirement
        /// </summary>
        /// <returns></returns>
        public double LimitProportion(Type resourceType)
        {
            double proportion = 1.0;

            if (ResourceRequestList == null)
            {
                return(proportion);
            }

            double totalNeeded = ResourceRequestList.Where(a => a.ResourceType == resourceType).Sum(a => a.Required);

            foreach (ResourceRequest item in ResourceRequestList.Where(a => a.ResourceType == resourceType).ToList())
            {
                if (resourceType == typeof(LabourType))
                {
                    if (item.FilterDetails != null && ((item.FilterDetails.First() as LabourFilterGroup).Parent as LabourRequirement).LabourShortfallAffectsActivity)
                    {
                        proportion *= item.Provided / item.Required;
                    }
                }
                else // all other types
                {
                    proportion *= item.Provided / item.Required;
                }
            }
            return(proportion);
        }
Example #5
0
        /// <summary>
        /// The method allows the activity to adjust resources requested based on shortfalls (e.g. labour) before they are taken from the pools
        /// </summary>
        public override void AdjustResourcesNeededForActivity()
        {
            // adjust amount needed by labour shortfall.
            double labprop = this.LabourLimitProportion;

            // get additional reduction based on labour cost shortfall as cost has already been accounted for
            double priceprop = 1;

            if (labprop < 1)
            {
                if (unitsCanAfford < units)
                {
                    priceprop = unitsCanAfford / units;
                }
                if (labprop < priceprop)
                {
                    unitsCanAfford = units * labprop;
                    if (price.UseWholePackets)
                    {
                        unitsCanAfford = Math.Truncate(unitsCanAfford);
                    }
                }
            }

            if (unitsCanAfford > 0 & (resourceToBuy as CLEMResourceTypeBase).MarketStoreExists)
            {
                // find resource entry in market if present and reduce
                ResourceRequest rr = ResourceRequestList.Where(a => a.Resource == (resourceToBuy as CLEMResourceTypeBase).EquivalentMarketStore).FirstOrDefault();
                if (rr.Required != unitsCanAfford * price.PacketSize * this.FarmMultiplier)
                {
                    rr.Required = unitsCanAfford * price.PacketSize * this.FarmMultiplier;
                }
            }
            return;
        }
Example #6
0
        private void OnCLEMAnimalMilking(object sender, EventArgs e)
        {
            if (this.TimingOK & this.Status != ActivityStatus.Ignored)
            {
                if (ProportionToRemove > 0)
                {
                    // get labour shortfall
                    double labourLimiter = 1.0;
                    if (this.Status == ActivityStatus.Partial & this.OnPartialResourcesAvailableAction == OnPartialResourcesAvailableActionTypes.UseResourcesAvailable)
                    {
                        double labourLimit    = 1;
                        double labourNeeded   = ResourceRequestList.Where(a => a.ResourceType == typeof(Labour)).Sum(a => a.Required);
                        double labourProvided = ResourceRequestList.Where(a => a.ResourceType == typeof(Labour)).Sum(a => a.Provided);
                        if (labourNeeded > 0)
                        {
                            labourLimit = labourProvided / labourNeeded;
                        }
                    }

                    // get dry breeders
                    RuminantHerd          ruminantHerd = Resources.RuminantHerd();
                    List <RuminantFemale> herd         = this.CurrentHerd(true).Where(a => a.Gender == Sex.Female).Cast <RuminantFemale>().ToList();

                    // get dry breeders from females
                    foreach (RuminantFemale female in herd.Where(a => a.Age - a.AgeAtLastBirth >= MonthsSinceBirth & a.PreviousConceptionRate >= MinimumConceptionBeforeSell & a.AgeAtLastBirth > 0))
                    {
                        if (ZoneCLEM.RandomGenerator.NextDouble() <= ProportionToRemove * labourLimiter)
                        {
                            // flag female ready to transport.
                            female.SaleFlag = HerdChangeReason.DryBreederSale;
                        }
                    }
                }
            }
        }
Example #7
0
        /// <summary>
        /// Method to determine resources required for this activity in the current month
        /// </summary>
        /// <returns>List of required resource requests</returns>
        public override List <ResourceRequest> GetResourcesNeededForActivity()
        {
            ResourceRequestList = null;
            if (this.TimingOK)
            {
                // get all potential dry breeders
                List <RuminantFemale> herd = this.CurrentHerd(false).Where(a => a.Gender == Sex.Female).Cast <RuminantFemale>().Where(a => a.Age - a.AgeAtLastBirth >= MonthsSinceBirth & a.PreviousConceptionRate >= MinimumConceptionBeforeSell & a.AgeAtLastBirth > 0).ToList();
                int    head = herd.Count();
                double AE   = herd.Sum(a => a.AdultEquivalent);

                if (head == 0)
                {
                    return(null);
                }

                // for each labour item specified
                foreach (var item in labour)
                {
                    double daysNeeded = 0;
                    switch (item.UnitType)
                    {
                    case LabourUnitType.Fixed:
                        daysNeeded = item.LabourPerUnit;
                        break;

                    case LabourUnitType.perHead:
                        daysNeeded = Math.Ceiling(head / item.UnitSize) * item.LabourPerUnit;
                        break;

                    case LabourUnitType.perAE:
                        daysNeeded = Math.Ceiling(AE / item.UnitSize) * item.LabourPerUnit;
                        break;

                    default:
                        throw new Exception(String.Format("LabourUnitType {0} is not supported for {1} in {2}", item.UnitType, item.Name, this.Name));
                    }
                    if (daysNeeded > 0)
                    {
                        if (ResourceRequestList == null)
                        {
                            ResourceRequestList = new List <ResourceRequest>();
                        }
                        ResourceRequestList.Add(new ResourceRequest()
                        {
                            AllowTransmutation = false,
                            Required           = daysNeeded,
                            ResourceType       = typeof(Labour),
                            ResourceTypeName   = "",
                            ActivityModel      = this,
                            FilterDetails      = new List <object>()
                            {
                                item
                            }
                        }
                                                );
                    }
                }
            }
            return(ResourceRequestList);
        }
        /// <summary>
        /// Method to determine resources required for this activity in the current month
        /// </summary>
        /// <returns></returns>
        public override List <ResourceRequest> GetResourcesNeededForActivity()
        {
            // zero based month index for array
            int month = Clock.Today.Month - 1;

            if (DaysWorkAvailableEachMonth[month] > 0)
            {
                foreach (LabourFilterGroup filter in Apsim.Children(this, typeof(LabourFilterGroup)))
                {
                    if (ResourceRequestList == null)
                    {
                        ResourceRequestList = new List <ResourceRequest>();
                    }
                    ResourceRequestList.Add(new ResourceRequest()
                    {
                        AllowTransmutation = false,
                        Required           = DaysWorkAvailableEachMonth[month],
                        ResourceType       = typeof(Labour),
                        ResourceTypeName   = "",
                        ActivityModel      = this,
                        Reason             = this.Name,
                        FilterDetails      = new List <object>()
                        {
                            filter
                        }                                            // filter.ToList<object>() // this.Children.Where(a => a.GetType() == typeof(LabourFilterGroup)).ToList<object>()
                    }
                                            );
                }
            }
            else
            {
                return(null);
            }
            return(ResourceRequestList);
        }
Example #9
0
 /// <summary>
 /// Method to determine resources required for this activity in the current month
 /// </summary>
 /// <returns>List of required resource requests</returns>
 public override List <ResourceRequest> DetermineResourcesNeeded()
 {
     ResourceRequestList = null;
     if (Clock.Today.Month == Month)
     {
         // if labour item(s) found labour will be requested for this activity.
         if (LabourRequired > 0)
         {
             if (ResourceRequestList == null)
             {
                 ResourceRequestList = new List <ResourceRequest>();
             }
             // determine head to be mustered
             RuminantHerd    ruminantHerd = Resources.RuminantHerd();
             List <Ruminant> herd         = ruminantHerd.Herd;
             int             head         = herd.Filter(this).Count();
             ResourceRequestList.Add(new ResourceRequest()
             {
                 AllowTransmutation = true,
                 Required           = Math.Ceiling(head / this.LabourHeadUnit) * this.LabourRequired,
                 ResourceName       = "Labour",
                 ResourceTypeName   = "",
                 Requestor          = this.Name,
                 FilterSortDetails  = LabourFilterList
             }
                                     );
         }
     }
     return(ResourceRequestList);
 }
Example #10
0
        /// <inheritdoc/>
        public override void DoActivity()
        {
            if (PaymentCalculationStyle == PayHiredLabourCalculationStyle.ByAvailableLabour)
            {
                Status = ActivityStatus.Warning;

                // get amount of finance needed and provided
                double financeRequired = 0;
                double financeProvided = 0;
                foreach (ResourceRequest item in ResourceRequestList.Where(a => a.ResourceType == typeof(Finance)))
                {
                    financeRequired += item.Required;
                    financeProvided += item.Provided;
                    Status           = ActivityStatus.NotNeeded;
                }

                if (financeRequired > 0)
                {
                    Status = ActivityStatus.Success;
                }

                // reduce limiters based on financial shortfall
                if (financeProvided < financeRequired)
                {
                    if (this.OnPartialResourcesAvailableAction == OnPartialResourcesAvailableActionTypes.UseResourcesAvailable)
                    {
                        Status = ActivityStatus.Partial;
                        int    currentmonth = clock.Today.Month;
                        double currentCost  = 0;

                        // step through all hired labour in order and set limiter where needed
                        foreach (LabourType item in labour.Items.Where(a => a.Hired))
                        {
                            // get days needed
                            double daysNeeded = item.LabourAvailability.GetAvailability(currentmonth - 1);
                            // calculate rate and amount needed
                            double rate = item.PayRate();

                            double cost = daysNeeded * rate;

                            if (currentCost == financeProvided)
                            {
                                item.AvailabilityLimiter = 0;
                                cost = 0;
                            }
                            else if (currentCost + cost > financeProvided)
                            {
                                //  reduce limit
                                double excess = currentCost + cost - financeProvided;
                                item.AvailabilityLimiter = (cost - excess) / cost;
                                cost = financeProvided - currentCost;
                            }
                            currentCost += cost;
                        }
                    }
                }
            }
            return;
        }
        /// <summary>
        /// Method to determine resources required for this activity in the current month
        /// </summary>
        /// <returns>List of required resource requests</returns>
        public override List <ResourceRequest> GetResourcesNeededForActivity()
        {
            ResourceRequestList = null;
            if (this.TimingOK)
            {
                List <Ruminant> herd = this.CurrentHerd(false);
                int             head = herd.Count();
                double          AE   = herd.Sum(a => a.AdultEquivalent);

                if (head == 0)
                {
                    return(null);
                }

                // for each labour item specified
                foreach (var item in labour)
                {
                    double daysNeeded = 0;
                    switch (item.UnitType)
                    {
                    case LabourUnitType.Fixed:
                        daysNeeded = item.LabourPerUnit;
                        break;

                    case LabourUnitType.perHead:
                        daysNeeded = Math.Ceiling(head / item.UnitSize) * item.LabourPerUnit;
                        break;

                    case LabourUnitType.perAE:
                        daysNeeded = Math.Ceiling(AE / item.UnitSize) * item.LabourPerUnit;
                        break;

                    default:
                        throw new Exception(String.Format("LabourUnitType {0} is not supported for {1} in {2}", item.UnitType, item.Name, this.Name));
                    }
                    if (daysNeeded > 0)
                    {
                        if (ResourceRequestList == null)
                        {
                            ResourceRequestList = new List <ResourceRequest>();
                        }
                        ResourceRequestList.Add(new ResourceRequest()
                        {
                            AllowTransmutation = false,
                            Required           = daysNeeded,
                            ResourceType       = typeof(Labour),
                            ResourceTypeName   = "",
                            ActivityModel      = this,
                            FilterDetails      = new List <object>()
                            {
                                item
                            }
                        }
                                                );
                    }
                }
            }
            return(ResourceRequestList);
        }
Example #12
0
 /// <summary>
 /// Method used to perform activity if it can occur as soon as resources are available.
 /// </summary>
 public override void PerformActivity()
 {
     if (ResourceRequestList.Count() > 0)
     {
         Area = ResourceRequestList.FirstOrDefault().Available;
     }
     return;
 }
Example #13
0
 /// <inheritdoc/>
 public override void DoActivity()
 {
     // days provided from labour set in the requests in the resourceResquestList
     // receive payment for labour if bank type exists
     if (bankType != null)
     {
         bankType.Add(ResourceRequestList.Sum(a => a.Value), this, "", TransactionCategory);
     }
 }
 /// <summary>
 /// Method used to perform activity if it can occur as soon as resources are available.
 /// </summary>
 public override void DoActivity()
 {
     // days provided from labour set in the only request in the resourceResquestList
     // receive payment for labour if bank type exists
     if (bankType != null)
     {
         bankType.Add(ResourceRequestList.FirstOrDefault().Available *DailyRate, "Off farm labour", this.Name);
     }
 }
        /// <summary>
        /// Method to determine resources required for this activity in the current month
        /// </summary>
        /// <returns>List of required resource requests</returns>
        private List <ResourceRequest> GetResourcesNeededForActivityLocal()
        {
            ResourceRequestList = null;
            double amountAvailable = 0;

            // determine wet weight to move
            if (manureStore != null)
            {
                ManureStoreUncollected msu = manureStore.UncollectedStores.Where(a => a.Name.ToLower() == GrazeFoodStoreTypeName.ToLower()).FirstOrDefault();
                if (msu != null)
                {
                    amountAvailable = msu.Pools.Sum(a => a.WetWeight(manureStore.MoistureDecayRate, manureStore.ProportionMoistureFresh));
                }
            }
            // determine labour required
            if (amountAvailable > 0)
            {
                // for each labour item specified
                foreach (var item in labour)
                {
                    double daysNeeded = 0;
                    switch (item.UnitType)
                    {
                    case LabourUnitType.perKg:
                        daysNeeded = item.LabourPerUnit * amountAvailable;
                        break;

                    default:
                        throw new Exception(String.Format("LabourUnitType {0} is not supported for {1} in {2}", item.UnitType, item.Name, this.Name));
                    }
                    if (daysNeeded > 0)
                    {
                        if (ResourceRequestList == null)
                        {
                            ResourceRequestList = new List <ResourceRequest>();
                        }
                        ResourceRequestList.Add(new ResourceRequest()
                        {
                            AllowTransmutation = false,
                            Required           = daysNeeded,
                            ResourceType       = typeof(Labour),
                            ResourceTypeName   = "",
                            ActivityModel      = this,
                            Reason             = "Manure collection",
                            FilterDetails      = new List <object>()
                            {
                                item
                            }
                        }
                                                );
                    }
                }
            }
            return(ResourceRequestList);
        }
        /// <summary>
        /// Method to determine resources required for this activity in the current month
        /// </summary>
        /// <returns></returns>
        public override List <ResourceRequest> GetResourcesNeededForActivity()
        {
            ResourceRequestList = null;
            if (this.TimingOK)
            {
                double breeders = SelectedOtherAnimalsType.Cohorts.Where(a => a.Age >= this.BreedingAge).Sum(b => b.Number);
                if (breeders == 0)
                {
                    return(null);
                }

                // for each labour item specified
                foreach (var item in labour)
                {
                    double daysNeeded = 0;
                    switch (item.UnitType)
                    {
                    case LabourUnitType.Fixed:
                        daysNeeded = item.LabourPerUnit;
                        break;

                    case LabourUnitType.perHead:
                        daysNeeded = Math.Ceiling(breeders / item.UnitSize) * item.LabourPerUnit;
                        break;

                    default:
                        throw new Exception(String.Format("LabourUnitType {0} is not supported for {1} in {2}", item.UnitType, item.Name, this.Name));
                    }
                    if (daysNeeded > 0)
                    {
                        if (ResourceRequestList == null)
                        {
                            ResourceRequestList = new List <ResourceRequest>();
                        }
                        ResourceRequestList.Add(new ResourceRequest()
                        {
                            AllowTransmutation = false,
                            Required           = daysNeeded,
                            ResourceType       = typeof(Labour),
                            ResourceTypeName   = "",
                            ActivityModel      = this,
                            FilterDetails      = new List <object>()
                            {
                                item
                            }
                        }
                                                );
                    }
                }
            }
            return(ResourceRequestList);
        }
 /// <summary>
 /// Method used to perform activity if it can occur as soon as resources are available.
 /// </summary>
 public override void PerformActivity()
 {
     // if occurred
     if (this.NextDueDate.Year == Clock.Today.Year & this.NextDueDate.Month == Clock.Today.Month)
     {
         ResourceRequest thisRequest = ResourceRequestList.FirstOrDefault();
         if (thisRequest != null)
         {
             // update next due date
             this.NextDueDate = this.NextDueDate.AddMonths(this.PaymentInterval);
         }
     }
 }
Example #18
0
        /// <summary>
        /// Method to determine resources required for this activity in the current month
        /// </summary>
        /// <returns>List of required resource requests</returns>
        public override List <ResourceRequest> GetResourcesNeededForActivity()
        {
            ResourceRequestList = null;

            List <RuminantFemale> herd = this.CurrentHerd(true).Where(a => a.Gender == Sex.Female).Cast <RuminantFemale>().Where(a => a.IsLactating == true & a.SucklingOffspring.Count() == 0).ToList();
            int head = herd.Count();

            if (head > 0)
            {
                // for each labour item specified
                foreach (var item in labour)
                {
                    double daysNeeded = 0;
                    switch (item.UnitType)
                    {
                    case LabourUnitType.Fixed:
                        daysNeeded = item.LabourPerUnit;
                        break;

                    case LabourUnitType.perHead:
                        daysNeeded = Math.Ceiling(head / item.UnitSize) * item.LabourPerUnit;
                        break;

                    default:
                        throw new Exception(String.Format("LabourUnitType {0} is not supported for {1} in {2}", item.UnitType, item.Name, this.Name));
                    }
                    if (daysNeeded > 0)
                    {
                        if (ResourceRequestList == null)
                        {
                            ResourceRequestList = new List <ResourceRequest>();
                        }
                        ResourceRequestList.Add(new ResourceRequest()
                        {
                            AllowTransmutation = false,
                            Required           = daysNeeded,
                            ResourceType       = typeof(Labour),
                            ResourceTypeName   = "",
                            ActivityModel      = this,
                            Reason             = "Milking",
                            FilterDetails      = new List <object>()
                            {
                                item
                            }
                        }
                                                );
                    }
                }
            }
            return(ResourceRequestList);
        }
Example #19
0
        /// <summary>
        /// Method to determine resources required for this activity in the current month
        /// </summary>
        /// <returns>List of required resource requests</returns>
        public override List <ResourceRequest> GetResourcesNeededForActivity()
        {
            ResourceRequestList = null;
            if (this.TimingOK)
            {
                double units = UnitsAvailableForSale;
                if (units > 0)
                {
                    // for each labour item specified
                    foreach (var item in Labour)
                    {
                        double daysNeeded = 0;
                        switch (item.UnitType)
                        {
                        case LabourUnitType.Fixed:
                            daysNeeded = item.LabourPerUnit;
                            break;

                        case LabourUnitType.perUnit:
                            daysNeeded = units * item.LabourPerUnit;
                            break;

                        default:
                            break;
                        }
                        if (daysNeeded > 0)
                        {
                            if (ResourceRequestList == null)
                            {
                                ResourceRequestList = new List <ResourceRequest>();
                            }
                            ResourceRequestList.Add(new ResourceRequest()
                            {
                                AllowTransmutation = false,
                                Required           = daysNeeded,
                                ResourceType       = typeof(Labour),
                                ResourceTypeName   = "",
                                ActivityModel      = this,
                                Reason             = "Sales",
                                FilterDetails      = new List <object>()
                                {
                                    item
                                }
                            }
                                                    );
                        }
                    }
                }
            }
            return(ResourceRequestList);
        }
        private void OnCLEMInitialiseResource(object sender, EventArgs e)
        {
            if (Area == 0 & AreaRequested > 0)
            {
                ResourceRequestList = new List <ResourceRequest>();
                ResourceRequestList.Add(new ResourceRequest()
                {
                    AllowTransmutation = false,
                    Required           = AreaRequested,
                    ResourceType       = typeof(Land),
                    ResourceTypeName   = LandTypeNameToUse,
                    ActivityModel      = this,
                    Reason             = "Assign",
                    FilterDetails      = null
                }
                                        );
            }
            // if we get here we assume some land has been supplied
            if (ResourceRequestList != null || ResourceRequestList.Count() > 0)
            {
                gotLandRequested = TakeResources(ResourceRequestList, false);
            }

            //Now the Land has been allocated we have an Area
            if (gotLandRequested)
            {
                //get the units of area for this run from the Land resource parent.
                unitsOfArea2Ha = Resources.Land().UnitsOfAreaToHaConversion;

                // locate Pasture Type resource
                LinkedNativeFoodType = Resources.GetResourceItem(this, typeof(GrazeFoodStore), FeedTypeName, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop) as GrazeFoodStoreType;

                //Assign the area actually got after taking it. It might be less than AreaRequested (if partial)
                Area = ResourceRequestList.FirstOrDefault().Provided;

                LinkedNativeFoodType.Area = Area;

                soilIndex = ((LandType)ResourceRequestList.FirstOrDefault().Resource).SoilType;

                LinkedNativeFoodType.CurrentEcologicalIndicators.LandConditionIndex = LandConditionIndex.StartingValue;
                LinkedNativeFoodType.CurrentEcologicalIndicators.GrassBasalArea     = GrassBasalArea.StartingValue;
                LinkedNativeFoodType.CurrentEcologicalIndicators.StockingRate       = StartingStockingRate;
                StockingRateSummed = StartingStockingRate;

                //Now we have a stocking rate and we have starting values for Land Condition and Grass Basal Area
                //get the starting pasture data list from GRASP
                GetPastureDataList_TodayToNextEcolCalculation();

                SetupStartingPasturePools(StartingAmount);
            }
        }
Example #21
0
        /// <summary>
        /// Method used to perform activity if it can occur as soon as resources are available.
        /// </summary>
        public override void DoActivity()
        {
            List <LabourType> group = Resources.Labour().Items.Where(a => a.Hired != true).ToList();

            if (group != null && group.Count > 0)
            {
                // calculate feed limit
                double feedLimit = 0.0;

                ResourceRequest feedRequest = ResourceRequestList.Where(a => a.ResourceType == typeof(HumanFoodStore)).FirstOrDefault();
                if (feedRequest != null)
                {
                    feedLimit = Math.Min(1.0, feedRequest.Provided / feedRequest.Required);
                }

                if (feedRequest == null || (feedRequest.Required == 0 | feedRequest.Available == 0))
                {
                    Status = ActivityStatus.NotNeeded;
                    return;
                }

                foreach (Model child in Apsim.Children(this, typeof(LabourFeedGroup)))
                {
                    double value = (child as LabourFeedGroup).Value;

                    foreach (LabourType ind in Resources.Labour().Items.Filter(child))
                    {
                        switch (FeedStyle)
                        {
                        case LabourFeedActivityTypes.SpecifiedDailyAmountPerIndividual:
                            feedRequest.Provided  = Math.Min(value * 30.4, FeedType.MaximumDailyIntakePerAE * ind.AdultEquivalent * 30.4);
                            feedRequest.Provided *= feedLimit;
                            ind.AddIntake(feedRequest);
                            break;

                        case LabourFeedActivityTypes.SpecifiedDailyAmountPerAE:
                            feedRequest.Provided  = Math.Min(value, FeedType.MaximumDailyIntakePerAE) * ind.AdultEquivalent * 30.4;
                            feedRequest.Provided *= feedLimit;
                            ind.AddIntake(feedRequest);
                            break;

                        default:
                            throw new Exception(String.Format("FeedStyle {0} is not supported in {1}", FeedStyle, this.Name));
                        }
                    }
                }
                SetStatusSuccess();
            }
        }
Example #22
0
        /// <summary>
        /// Method used to perform activity if it can occur as soon as resources are available.
        /// </summary>
        public override void DoActivity()
        {
            if (this.TimingOK)
            {
                // reduce if labour limiting
                double labourlimit = 1;
                if (ResourceRequestList != null && ResourceRequestList.Where(a => a.ResourceType == typeof(Labour)).Count() > 0)
                {
                    double amountLabourNeeded   = ResourceRequestList.Where(a => a.ResourceType == typeof(Labour)).Sum(a => a.Required);
                    double amountLabourProvided = ResourceRequestList.Where(a => a.ResourceType == typeof(Labour)).Sum(a => a.Provided);
                    if (amountLabourNeeded > 0)
                    {
                        if (amountLabourProvided == 0)
                        {
                            labourlimit = 0;
                        }
                        else
                        {
                            labourlimit = amountLabourNeeded / amountLabourProvided;
                        }
                    }
                }
                double units = 0;
                if (labourlimit == 1 || this.OnPartialResourcesAvailableAction == OnPartialResourcesAvailableActionTypes.UseResourcesAvailable)
                {
                    units = UnitsAvailableForSale * labourlimit;
                    if (SellWholeUnitsOnly)
                    {
                        units = Math.Truncate(units);
                    }
                }

                if (units > 0)
                {
                    // remove resource
                    ResourceRequest purchaseRequest = new ResourceRequest();
                    purchaseRequest.ActivityModel      = this;
                    purchaseRequest.Required           = units * UnitSize;
                    purchaseRequest.AllowTransmutation = false;
                    purchaseRequest.Reason             = "Sales";
                    resourceToSell.Remove(purchaseRequest);

                    // transfer money earned
                    bankAccount.Add(units * UnitPrice, this.Name, "Sales");
                    SetStatusSuccess();
                }
            }
        }
Example #23
0
        /// <inheritdoc/>
        public override void DoActivity()
        {
            // processed resource should already be taken
            Status = ActivityStatus.NotNeeded;
            // add created resources
            ResourceRequest rr = ResourceRequestList.Where(a => (a.Resource != null && a.Resource.GetType() == resourceTypeProcessModel.GetType())).FirstOrDefault();

            if (rr != null)
            {
                resourceTypeCreatedModel.Add(rr.Provided * ConversionRate, this, (resourceTypeCreatedModel as CLEMModel).NameWithParent, "Created");
                if (rr.Provided > 0)
                {
                    Status = ActivityStatus.Success;
                }
            }
        }
Example #24
0
        private void OnCLEMAnimalManage(object sender, EventArgs e)
        {
            // Weaning is performed in the Management event to ensure weaned individuals are treated as unweaned for their intake calculations
            // and the mother is considered lactating for lactation energy demands otherwise IsLactating stops as soon as ind.wean() is performed.

            // if wean month
            if (this.TimingOK)
            {
                double          labourlimit = this.LabourLimitProportion;
                int             weanedCount = 0;
                ResourceRequest labour      = ResourceRequestList.Where(a => a.ResourceType == typeof(LabourType)).FirstOrDefault <ResourceRequest>();
                // Perform weaning
                int count = this.CurrentHerd(false).Where(a => a.Weaned == false).Count();
                foreach (var ind in this.CurrentHerd(false).Where(a => a.Weaned == false))
                {
                    if (ind.Age >= WeaningAge || ind.Weight >= WeaningWeight)
                    {
                        string reason = (ind.Age >= WeaningAge)? "Age" : "Weight";
                        ind.Wean(true, reason);
                        ind.Location = grazeStore;
                        weanedCount++;
                        if (ind.Mother != null)
                        {
                            // report conception status changed when offspring weaned.
                            ind.Mother.BreedParams.OnConceptionStatusChanged(new Reporting.ConceptionStatusChangedEventArgs(Reporting.ConceptionStatus.Weaned, ind.Mother, Clock.Today));
                        }
                    }

                    // stop if labour limited individuals reached and LabourShortfallAffectsActivity
                    if (weanedCount > Convert.ToInt32(count * labourlimit, CultureInfo.InvariantCulture))
                    {
                        this.Status = ActivityStatus.Partial;
                        break;
                    }
                }

                if (weanedCount > 0)
                {
                    SetStatusSuccess();
                }
                else
                {
                    this.Status = ActivityStatus.NotNeeded;
                }
            }
        }
Example #25
0
        /// <inheritdoc/>
        public override void DoActivity()
        {
            // add all provided requests to the individuals intake pools.

            List <LabourType> group = people?.Items.Where(a => IncludeHiredLabour | a.Hired != true).ToList();

            Status = ActivityStatus.NotNeeded;
            if (group != null && group.Count > 0)
            {
                var requests = ResourceRequestList.Where(a => a.ResourceType == typeof(HumanFoodStore));
                if (requests.Any())
                {
                    double aE = group.Sum(a => a.TotalAdultEquivalents);
                    foreach (ResourceRequest request in requests.Where(a => a.Provided > 0))
                    {
                        // add to individual intake
                        foreach (LabourType labour in group)
                        {
                            double amount = request.Provided * (labour.TotalAdultEquivalents / aE);
                            labour.AddIntake(new LabourDietComponent()
                            {
                                AmountConsumed = amount,
                                FoodStore      = request.Resource as HumanFoodStoreType
                            });
                            labour.FeedToTargetIntake += amount;
                        }
                    }
                }
                if (this.FindAllChildren <LabourActivityFeedTarget>().Where(a => !a.TargetAchieved).Any())
                {
                    this.Status = ActivityStatus.Partial;
                }
                else
                {
                    this.Status = ActivityStatus.Success;
                }
            }
            // finished eating, so this household is now free to sell the resources
            // assumes all households above in the tree supply this level.
            // if sibling above relies on food from this household it own't work
            // selling is perfomed in the next method called in this same event
        }
Example #26
0
        /// <summary>
        /// Method used to perform activity if it can occur as soon as resources are available.
        /// </summary>
        public override void DoActivity()
        {
            Status = ActivityStatus.NotNeeded;
            // take local equivalent of market from resource

            double provided = 0;

            if ((resourceToBuy as CLEMResourceTypeBase).MarketStoreExists)
            {
                // find resource entry in market if present and reduce
                ResourceRequest rr = ResourceRequestList.Where(a => a.Resource == (resourceToBuy as CLEMResourceTypeBase).EquivalentMarketStore).FirstOrDefault();
                provided = rr.Provided / this.FarmMultiplier;
            }
            else
            {
                provided = unitsCanAfford * price.PacketSize;
            }

            if (provided > 0)
            {
                resourceToBuy.Add(provided, this, "", "Purchase");
                Status = ActivityStatus.Success;
            }

            // make financial transactions
            if (bankAccount != null)
            {
                ResourceRequest payment = new ResourceRequest()
                {
                    AllowTransmutation          = false,
                    MarketTransactionMultiplier = this.FarmMultiplier,
                    Required          = provided / price.PacketSize * price.PricePerPacket,
                    ResourceType      = typeof(Finance),
                    ResourceTypeName  = bankAccount.Name,
                    Category          = "Purchase",
                    RelatesToResource = (resourceToBuy as CLEMModel).NameWithParent,
                    ActivityModel     = this
                };
                bankAccount.Remove(payment);
            }
        }
Example #27
0
        /// <inheritdoc/>
        public override void AdjustResourcesNeededForActivity()
        {
            // get labour shortfall
            double labprop = this.LimitProportion(typeof(LabourType));
            // get finance shortfall
            double finprop = this.LimitProportion(typeof(FinanceType));

            // reduce amount used
            double limit = Math.Min(labprop, finprop);

            if (limit < 1)
            {
                // find process resource entry in resource list
                ResourceRequest rr = ResourceRequestList.Where(a => a.ResourceType == resourceTypeProcessModel.GetType()).FirstOrDefault();
                if (rr != null)
                {
                    // reduce amount required
                    rr.Required *= limit;
                }
            }
        }
Example #28
0
        /// <summary>
        /// Method used to perform activity if it can occur as soon as resources are available.
        /// </summary>
        public override void DoActivity()
        {
            // add all provided requests to the individuals intake pools.

            List <LabourType> group = Resources.Labour().Items.Where(a => IncludeHiredLabour | a.Hired != true).ToList();
            double            aE    = group.Sum(a => a.AdultEquivalent);

            Status = ActivityStatus.NotNeeded;
            if (group != null && group.Count > 0)
            {
                var requests = ResourceRequestList.Where(a => a.ResourceType == typeof(HumanFoodStore));
                if (requests.Count() > 0)
                {
                    foreach (ResourceRequest request in requests)
                    {
                        if (request.Provided > 0)
                        {
                            // add to individual intake
                            foreach (LabourType labour in group)
                            {
                                labour.AddIntake(new LabourDietComponent()
                                {
                                    AmountConsumed = request.Provided * (labour.AdultEquivalent / aE),
                                    FoodStore      = request.Resource as HumanFoodStoreType
                                });
                            }
                        }
                    }
                }
                List <LabourActivityFeedTarget> labourActivityFeedTargets = this.FindAllChildren <LabourActivityFeedTarget>().Cast <LabourActivityFeedTarget>().ToList();
                if (labourActivityFeedTargets.Where(a => !a.TargetMet).Count() > 0)
                {
                    this.Status = ActivityStatus.Partial;
                }
                else
                {
                    this.Status = ActivityStatus.Success;
                }
            }
        }
Example #29
0
        /// <summary>
        /// Method to determine resources required for this activity in the current month
        /// </summary>
        /// <returns>List of required resource requests</returns>
        public override List <ResourceRequest> GetResourcesNeededForActivity()
        {
            ResourceRequestList = null;
            // for each labour item specified
            foreach (var item in labour)
            {
                double daysNeeded = 0;
                switch (item.UnitType)
                {
                case LabourUnitType.Fixed:
                    daysNeeded = item.LabourPerUnit;
                    break;

                default:
                    throw new Exception(String.Format("LabourUnitType {0} is not supported for {1} in {2}", item.UnitType, item.Name, this.Name));
                }
                if (daysNeeded > 0)
                {
                    if (ResourceRequestList == null)
                    {
                        ResourceRequestList = new List <ResourceRequest>();
                    }
                    ResourceRequestList.Add(new ResourceRequest()
                    {
                        AllowTransmutation = false,
                        Required           = daysNeeded,
                        ResourceType       = typeof(Labour),
                        ResourceTypeName   = "",
                        ActivityModel      = this,
                        FilterDetails      = new List <object>()
                        {
                            item
                        }
                    }
                                            );
                }
            }
            return(ResourceRequestList);
        }
        /// <summary>
        /// Method to determine resources required for this activity in the current month
        /// </summary>
        /// <returns>List of required resource requests</returns>
        public override List <ResourceRequest> GetResourcesNeededForActivity()
        {
            ResourceRequestList = null;
            double kgPerHa = grazeType.Amount / paddockActivity.Area;

            RuminantHerd    ruminantHerd = Resources.RuminantHerd();
            List <Ruminant> herd         = ruminantHerd.Herd.Where(a => a.Location == PaddockName).ToList();

            if (herd.Count() > 0)
            {
                double amount = 0;
                // get list of all Ruminants in this paddock
                foreach (Ruminant ind in herd)
                {
                    // Reduce potential intake based on pasture quality for the proportion consumed.

                    // TODO: build in pasture quality intake correction

                    // calculate intake from potential modified by pasture availability and hours grazed
                    amount += ind.PotentialIntake * (1 - Math.Exp(-ind.BreedParams.IntakeCoefficientBiomass * kgPerHa)) * (HoursGrazed / 8);
                }
                if (ResourceRequestList == null)
                {
                    ResourceRequestList = new List <ResourceRequest>();
                }
                ResourceRequestList.Add(new ResourceRequest()
                {
                    AllowTransmutation = true,
                    Required           = amount,
                    ResourceType       = typeof(GrazeFoodStore),
                    ResourceTypeName   = this.grazeType.Name,
                    ActivityModel      = this
                }
                                        );
            }
            return(ResourceRequestList);
        }