Exemple #1
0
        private void CheckAssignLabourAvailability(LabourType labour)
        {
            List <LabourType> checkList = new List <LabourType>()
            {
                labour
            };

            if (labour.LabourAvailability != null)
            {
                // check labour availability still ok
                if (checkList.Filter(labour.LabourAvailability).Count == 0)
                {
                    labour.LabourAvailability = null;
                }
            }

            // if not assign new value
            if (labour.LabourAvailability == null)
            {
                foreach (Model availItem in availabilityList.Children.Where(a => typeof(LabourSpecificationItem).IsAssignableFrom(a.GetType())).ToList())
                {
                    if (checkList.Filter(availItem).Count > 0)
                    {
                        labour.LabourAvailability = availItem as LabourSpecificationItem;
                        break;
                    }
                }
                // if still null report error
                if (labour.LabourAvailability == null)
                {
                    throw new ApsimXException(this, string.Format("Unable to find labour availability suitable for labour type [f=Name:{0}] [f=Gender:{1}] [f=Age:{2}]\r\nAdd additional labour availability item to [r={3}] under [r={4}]", labour.Name, labour.Gender, labour.Age, availabilityList.Name, this.Name));
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Get value of a specific individual
        /// </summary>
        /// <returns>value</returns>
        public double PayRate(LabourType ind)
        {
            if (PricingAvailable)
            {
                List <LabourType> labourList = new List <LabourType>()
                {
                    ind
                };

                // search through RuminantPriceGroups for first match with desired purchase or sale flag
                foreach (LabourPriceGroup item in PayList.FindAllChildren <LabourPriceGroup>().Cast <LabourPriceGroup>())
                {
                    if (labourList.Filter(item).Count() == 1)
                    {
                        return(item.Value);
                    }
                }
                // no price match found.
                string warningString = $"No [Pay] price entry was found for individual [r={ind.Name}] with details [f=age: {ind.Age}] [f=gender: {ind.Gender.ToString()}]";
                if (!WarningsNotFound.Contains(warningString))
                {
                    WarningsNotFound.Add(warningString);
                    Summary.WriteWarning(this, warningString);
                }
            }
            return(0);
        }
Exemple #3
0
        private void OnSimulationCommencing(object sender, EventArgs e)
        {
            Items = new List <LabourType>();
            foreach (LabourType labourChildModel in Apsim.Children(this, typeof(LabourType)).Cast <LabourType>().ToList())
            {
                for (int i = 0; i < labourChildModel.Individuals; i++)
                {
                    // get the availability from provided list

                    LabourType labour = new LabourType()
                    {
                        Gender             = labourChildModel.Gender,
                        Individuals        = 1,
                        InitialAge         = labourChildModel.InitialAge,
                        AgeInMonths        = labourChildModel.InitialAge * 12,
                        LabourAvailability = labourChildModel.LabourAvailability,
                        Parent             = this,
                        Name  = labourChildModel.Name + ((labourChildModel.Individuals > 1)?"_" + (i + 1).ToString():""),
                        Hired = labourChildModel.Hired
                    };
                    labour.TransactionOccurred += Resource_TransactionOccurred;
                    Items.Add(labour);
                }
            }
            // clone pricelist so model can modify if needed and not affect initial parameterisation
            if (Apsim.Children(this, typeof(LabourPricing)).Count() > 0)
            {
                PayList = (Apsim.Children(this, typeof(LabourPricing)).FirstOrDefault() as LabourPricing).Clone();
            }
        }
Exemple #4
0
        private void OnSimulationCommencing(object sender, EventArgs e)
        {
            // locate AE relationship
            adultEquivalentRelationship = this.FindAllChildren <Relationship>().FirstOrDefault(a => a.Name.ToUpper().Contains("AE"));

            Items = new List <LabourType>();
            foreach (LabourType labourChildModel in this.FindAllChildren <LabourType>().Cast <LabourType>().ToList())
            {
                for (int i = 0; i < labourChildModel.Individuals; i++)
                {
                    // get the availability from provided list

                    LabourType labour = new LabourType()
                    {
                        Gender             = labourChildModel.Gender,
                        Individuals        = 1,
                        Parent             = this,
                        InitialAge         = labourChildModel.InitialAge,
                        AgeInMonths        = labourChildModel.InitialAge * 12,
                        LabourAvailability = labourChildModel.LabourAvailability,
                        Name  = labourChildModel.Name + ((labourChildModel.Individuals > 1) ? "_" + (i + 1).ToString() : ""),
                        Hired = labourChildModel.Hired
                    };
                    labour.TransactionOccurred += Resource_TransactionOccurred;
                    Items.Add(labour);
                }
            }
            // clone pricelist so model can modify if needed and not affect initial parameterisation
            if (this.FindAllChildren <LabourPricing>().Count() > 0)
            {
                PayList = Apsim.Clone(this.FindAllChildren <LabourPricing>().FirstOrDefault()) as LabourPricing;
            }
        }
Exemple #5
0
        private void CheckAssignLabourAvailability(LabourType labour)
        {
            List <LabourType> checkList = new List <LabourType>()
            {
                labour
            };

            if (labour.LabourAvailability != null)
            {
                // check labour availability still ok
                if (!(labour.LabourAvailability as IFilterGroup).Filter(checkList).Any())
                {
                    labour.LabourAvailability = null;
                }
            }

            // if not assign new value
            if (labour.LabourAvailability == null)
            {
                foreach (var availItem in availabilityList.FindAllChildren <ILabourSpecificationItem>())
                {
                    if (availItem is IFilterGroup group && group.Filter(checkList).Any())
                    {
                        labour.LabourAvailability = availItem;
                        break;
                    }
                }
                // if still null report error
                if (labour.LabourAvailability == null)
                {
                    string msg = $"Unable to find labour availability suitable for labour type" +
                                 $" [f=Name:{labour.Name}] [f=Gender:{labour.Sex}] [f=Age:{labour.Age}]" +
                                 $"\r\nAdd additional labour availability item to " +
                                 $"[r={availabilityList.Name}] under [r={Name}]";

                    throw new ApsimXException(this, msg);
                }
            }
        }
Exemple #6
0
        private void CheckAssignLabourAvailability(LabourType labour)
        {
            List <LabourType> checkList = new List <LabourType>()
            {
                labour
            };

            if (labour.LabourAvailability != null)
            {
                // check labour availability still ok
                if (checkList.Filter(labour.LabourAvailability).Count() == 0)
                {
                    labour.LabourAvailability = null;
                }
            }

            // if not assign new value
            if (labour.LabourAvailability == null)
            {
                foreach (Model availItem in availabilityList.Children.Where(a => typeof(LabourSpecificationItem).IsAssignableFrom(a.GetType())).ToList())
                {
                    if (checkList.Filter(availItem).Count() > 0)
                    {
                        labour.LabourAvailability = availItem as LabourSpecificationItem;
                        break;
                    }
                }
                // if still null report error
                if (labour.LabourAvailability == null)
                {
                    string msg = $"Unable to find labour availability suitable for labour type" +
                                 $" [f=Name:{labour.Name}] [f=Gender:{labour.Gender}] [f=Age:{labour.Age}]" +
                                 $"\r\nAdd additional labour availability item to " +
                                 $"[r={availabilityList.Name}] under [r={Name}]";

                    throw new ApsimXException(this, msg);
                }
            }
        }
Exemple #7
0
 private void OnSimulationCommencing(object sender, EventArgs e)
 {
     Items = new List <LabourType>();
     foreach (LabourType labourChildModel in Apsim.Children(this, typeof(IModel)).Cast <LabourType>().ToList())
     {
         for (int i = 0; i < Math.Max(labourChildModel.Individuals, 1); i++)
         {
             LabourType labour = new LabourType()
             {
                 Gender          = labourChildModel.Gender,
                 Individuals     = 1,
                 InitialAge      = labourChildModel.InitialAge,
                 AgeInMonths     = labourChildModel.InitialAge * 12,
                 MaxLabourSupply = labourChildModel.MaxLabourSupply,
                 Parent          = this,
                 Name            = labourChildModel.Name // + ((labourChildModel.Individuals>1)?i.ToString():"")
             };
             labour.TransactionOccurred += Resource_TransactionOccurred;
             Items.Add(labour);
         }
     }
 }
Exemple #8
0
        /// <summary>
        /// Get value of a specific individual
        /// </summary>
        /// <returns>value</returns>
        public double PayRate(LabourType ind)
        {
            if (PricingAvailable)
            {
                // search through RuminantPriceGroups for first match with desired purchase or sale flag
                foreach (LabourPriceGroup item in PayList.FindAllChildren <LabourPriceGroup>())
                {
                    if (item.Filter(ind))
                    {
                        return(item.Value);
                    }
                }

                // no price match found.
                string warningString = $"No [Pay] price entry was found for individual [r={ind.Name}] with details [f=age: {ind.Age}] [f=sex: {ind.Sex}]";
                if (!warningsNotFound.Contains(warningString))
                {
                    warningsNotFound.Add(warningString);
                    Summary.WriteMessage(this, warningString, MessageType.Warning);
                }
            }
            return(0);
        }
Exemple #9
0
        /// <summary>
        /// Get value of a specific individual with special requirements check (e.g. breeding sire or draught purchase)
        /// </summary>
        /// <returns>value</returns>
        public double PayRate(LabourType ind, LabourFilterParameters property, string value)
        {
            double price = 0;

            if (PricingAvailable)
            {
                string            criteria   = property.ToString().ToUpper() + ":" + value.ToUpper();
                List <LabourType> labourList = new List <LabourType>()
                {
                    ind
                };

                //find first pricing entry matching specific criteria
                LabourPriceGroup matchIndividual = null;
                LabourPriceGroup matchCriteria   = null;
                foreach (LabourPriceGroup item in PayList.FindAllChildren <LabourPriceGroup>().Cast <LabourPriceGroup>())
                {
                    if (labourList.Filter(item).Count() == 1 && matchIndividual == null)
                    {
                        matchIndividual = item;
                    }

                    // check that pricing item meets the specified criteria.
                    if (item.FindAllChildren <LabourFilter>().Cast <LabourFilter>().Where(a => (a.Parameter.ToString().ToUpper() == property.ToString().ToUpper() && a.Value.ToUpper() == value.ToUpper())).Count() > 0)
                    {
                        if (matchCriteria == null)
                        {
                            matchCriteria = item;
                        }
                        else
                        {
                            // multiple price entries were found. using first. value = xxx.
                            if (!WarningsMultipleEntry.Contains(criteria))
                            {
                                WarningsMultipleEntry.Add(criteria);
                                Summary.WriteWarning(this, "Multiple specific pay rate entries were found where [" + property + "]" + (value.ToUpper() != "TRUE" ? " = [" + value + "]." : ".") + "\r\nOnly the first entry will be used. Pay [" + matchCriteria.Value.ToString("#,##0.##") + "].");
                            }
                        }
                    }
                }

                if (matchCriteria == null)
                {
                    // report specific criteria not found in price list
                    string warningString = "No [Pay] rate entry was found meeting the required criteria [" + property + "]" + (value.ToUpper() != "TRUE" ? " = [" + value + "]." : ".");

                    if (matchIndividual != null)
                    {
                        // add using the best pricing available for [][] purchases of xx per head
                        warningString += "\r\nThe best available pay rate [" + matchIndividual.Value.ToString("#,##0.##") + "] will be used.";
                        price          = matchIndividual.Value;
                    }
                    else
                    {
                        Summary.WriteWarning(this, "\r\nNo alternate pay rate for individuals could be found for the individuals. Add a new [r=LabourPriceGroup] entry in the [r=LabourPricing]");
                    }
                    if (!WarningsNotFound.Contains(criteria))
                    {
                        WarningsNotFound.Add(criteria);
                        Summary.WriteWarning(this, warningString);
                    }
                }
                else
                {
                    price = matchCriteria.Value;
                }
            }
            return(price);
        }
Exemple #10
0
        /// <summary>
        /// Get value of a specific individual with special requirements check (e.g. breeding sire or draught purchase)
        /// </summary>
        /// <returns>value</returns>
        public double PayRate(LabourType ind, PropertyInfo property, string value)
        {
            double price = 0;

            if (PricingAvailable)
            {
                string criteria = property.Name.ToUpper() + ":" + value.ToUpper();

                //find first pricing entry matching specific criteria
                LabourPriceGroup matchIndividual = null;
                LabourPriceGroup matchCriteria   = null;
                foreach (LabourPriceGroup priceGroup in PayList.FindAllChildren <LabourPriceGroup>())
                {
                    if (priceGroup.Filter(ind) && matchIndividual == null)
                    {
                        matchIndividual = priceGroup;
                    }

                    // check that pricing item meets the specified criteria.
                    var items = priceGroup.FindAllChildren <FilterByProperty>()
                                .Where(f => priceGroup.GetProperty(f.PropertyOfIndividual) == property)
                                .Where(f => f.Value.ToString().ToUpper() == value.ToUpper());

                    var suitableFilters = priceGroup.FindAllChildren <FilterByProperty>()
                                          .Where(a => (priceGroup.GetProperty(a.PropertyOfIndividual) == property) &
                                                 (
                                                     (a.Operator == System.Linq.Expressions.ExpressionType.Equal && a.Value.ToString().ToUpper() == value.ToUpper()) |
                                                     (a.Operator == System.Linq.Expressions.ExpressionType.NotEqual && a.Value.ToString().ToUpper() != value.ToUpper()) |
                                                     (a.Operator == System.Linq.Expressions.ExpressionType.IsTrue && value.ToUpper() == "TRUE") |
                                                     (a.Operator == System.Linq.Expressions.ExpressionType.IsFalse && value.ToUpper() == "FALSE")
                                                 )
                                                 ).Any();

                    if (suitableFilters)
                    {
                        if (matchCriteria == null)
                        {
                            matchCriteria = priceGroup;
                        }
                        else
                        {
                            // multiple price entries were found. using first. value = xxx.
                            if (!warningsMultipleEntry.Contains(criteria))
                            {
                                warningsMultipleEntry.Add(criteria);
                                Summary.WriteWarning(this, $"Multiple specific pay rate entries were found where [{property}]{(value.ToUpper() != "TRUE" ? " = [" + value + "]." : ".")}\r\nOnly the first entry will be used. Pay [{matchCriteria.Value.ToString("#,##0.##")}].");
                            }
                        }
                    }
                }

                if (matchCriteria == null)
                {
                    // report specific criteria not found in price list
                    string warningString = $"No [Pay] rate entry was found meeting the required criteria [{property.Name}]{(value.ToUpper() != "TRUE" ? " = [" + value + "]." : ".")}";

                    if (matchIndividual != null)
                    {
                        // add using the best pricing available for [][] purchases of xx per head
                        warningString += $"\r\nThe best available pay rate [{matchIndividual.Value:#,##0.##}] will be used.";
                        price          = matchIndividual.Value;
                    }
                    else
                    {
                        Summary.WriteWarning(this, "\r\nNo alternate pay rate for individuals could be found for the individuals. Add a new [r=LabourPriceGroup] entry in the [r=LabourPricing]");
                    }

                    if (!warningsNotFound.Contains(criteria))
                    {
                        warningsNotFound.Add(criteria);
                        Summary.WriteWarning(this, warningString);
                    }
                }
                else
                {
                    price = matchCriteria.Value;
                }
            }
            return(price);
        }