/// <summary>
        /// Applies each function in this Lifestage process to a cohort item that is owned by a Lifestage
        /// </summary>
        /// <param name="cohortItem"></param>
        public void ProcessCohort(Cohort cohortItem)
        {
            //apply the functions from the function list to this cohort
            foreach (IFunction func in FunctionList)
            {

                if (FecundityFunc != null && ProgenyFunc != null)
                {
                    if (cohortItem.Fecundity < 0)
                        cohortItem.Fecundity = FecundityFunc.Value;
                    double progenyrate = ProgenyFunc.Value;

                    if (cohortItem.Fecundity > 0)
                    {
                        //number of Progeny produced per individual per timestep
                        double progenyRate = Math.Max(0.0, Math.Min(cohortItem.Fecundity, progenyrate));
                        if (progenyRate > 0)
                        {
                            double numberToCreate = cohortItem.Count * progenyRate;
                            if (numberToCreate > 0)
                            {
                                //transfer magic here
                                Lifestage destStage = cohortItem.OwningStage.OwningCycle.ChildStages.Find(s => s.Name == TransferTo);
                                cohortItem.OwningStage.Reproduce(cohortItem, destStage, numberToCreate);
                            }
                            cohortItem.Fecundity -= progenyRate;
                        }
                    }
                }
                else
                {
                    throw new Exception("Fecundity and Progeny functions must be configured for " + this.Name + " lifestage");
                }
            }
        }
        /// <summary>
        /// Applies each function in this Lifestage process to a cohort item that is owned by a Lifestage
        /// </summary>
        /// <param name="cohortItem"></param>
        public void ProcessCohort(Cohort cohortItem)
        {
            //apply the functions from the function list to this cohort
            foreach (IFunction func in FunctionList)
            {
                if (func == ProgenyFunc)    // assume there is only one of these for the process
                {
                    if (FecundityFunc != null && ProgenyFunc != null)
                    {
                        if (cohortItem.Fecundity < 0)
                        {
                            cohortItem.Fecundity = FecundityFunc.Value();
                        }
                        double progenyrate = ProgenyFunc.Value();

                        if (cohortItem.Fecundity > 0)
                        {
                            //number of Progeny produced per individual per timestep
                            double progenyRate = Math.Max(0.0, Math.Min(cohortItem.Fecundity, progenyrate));
                            if (progenyRate > 0)
                            {
                                double numberToCreate = cohortItem.Count * progenyRate;
                                if (numberToCreate > 0)
                                {
                                    //transfer magic here
                                    Lifestage destStage = cohortItem.OwningStage.OwningCycle.ChildStages.Find(s => s.Name == TransferTo);
                                    cohortItem.OwningStage.Reproduce(cohortItem, destStage, numberToCreate);
                                }
                                cohortItem.Fecundity -= progenyRate;
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Fecundity and Progeny functions must be configured for " + this.Name + " lifestage");
                    }
                }
                else
                {
                    //execute another function
                }
            }
        }
Exemple #3
0
        private void OnStartOfSimulation(object sender, EventArgs e)
        {
            ChildStages = new List <Lifestage>();
            foreach (Lifestage stage in Apsim.Children(this, typeof(Lifestage)))
            {
                stage.OwningCycle = this;
                ChildStages.Add(stage);
            }

            int i = 0;

            //create new cohorts from the InitialPopulation[]
            foreach (Lifestage stage in ChildStages)
            {
                if (InitialPopulation.Length > i)
                {
                    Cohort newCohort = stage.NewCohort();
                    newCohort.Count = InitialPopulation[i];
                }
                i++;
            }
        }
Exemple #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="aCohort"></param>
 public void Remove(Cohort aCohort)
 {
     CohortList.Remove(aCohort);
 }
Exemple #5
0
 /// <summary>
 /// Applies each function in this Lifestage process to a cohort item that is owned by a Lifestage
 /// </summary>
 /// <param name="cohortItem"></param>
 public void ProcessCohort(Cohort cohortItem)
 {
     //apply the functions from the function list to this cohort
     foreach (IFunction func in FunctionList)
     {
         if (ProcessAction == ProcessType.PhysiologicalGrowth)
         {
             cohortItem.PhysiologicalAge += func.Value;
         }
         else if (ProcessAction == ProcessType.Transfer)
         {
             double numberToMove = cohortItem.Count * func.Value;
             if (numberToMove > 0)
             {
                 //transfer magic here
                 Lifestage destStage = cohortItem.OwningStage.OwningCycle.ChildStages.Find(s => s.Name == TransferTo);
                 cohortItem.OwningStage.PromoteGraduates(cohortItem, destStage, numberToMove);
             }
         }
         else if (ProcessAction == ProcessType.Mortality)
         {
             //kill some creatures
             cohortItem.Count = cohortItem.Count * (1 - func.Value);
         }
     }
 }
Exemple #6
0
        /// <summary>
        /// The source cohort reproduces and sends count creatures to the destination stage.
        /// </summary>
        /// <param name="srcCohort"></param>
        /// <param name="destStage"></param>
        /// <param name="count"></param>
        public void Reproduce(Cohort srcCohort, Lifestage destStage, double count)
        {
            if (destStage != null)
            {
                // move the count creatures into a new cohort
                Cohort newCohort = null;
                // find a cohort in the destStage that has PhenoAge = 0
                int i = 0;
                while (i < destStage.CohortList.Count)
                {
                    if (destStage.CohortList[i].PhenoAge == 0)
                    {
                        newCohort = destStage.CohortList[i];
                        i = destStage.CohortList.Count; // terminate loop
                    }
                    i++;
                }

                if (newCohort == null)
                    newCohort = destStage.NewCohort();
                newCohort.ChronoAge = 0;
                newCohort.PhenoAge = 0;
                newCohort.PhysiologicalAge = 0;
                newCohort.Count += count;
            }
            else
            {
                throw new Exception("Destination stage is incorrectly specified");
            }
        }
Exemple #7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="aCohort"></param>
 public void Remove(Cohort aCohort)
 {
     CohortList.Remove(aCohort);
 }
Exemple #8
0
 /// <summary>
 /// Move cohort on to the next stage
 /// </summary>
 public void PromoteGraduates(Cohort srcCohort, Lifestage destStage, double count)
 {
     if (destStage != null)
     {
         //move the count creatures into a new cohort
         Cohort newCohort = destStage.NewCohort();
         newCohort.ChronoAge = srcCohort.ChronoAge;
         newCohort.PhenoAge = 0;
         newCohort.PhysiologicalAge = 0;
         newCohort.Count = count;
         srcCohort.Count = srcCohort.Count - count;
     }
     else
     {
         throw new Exception("Destination stage is incorrectly specified");
     }
 }
Exemple #9
0
        /// <summary>
        /// Construct a new cohort, add it to the list and return a reference to it.
        /// </summary>
        /// <returns></returns>
        public Cohort NewCohort()
        {
            if (CohortList == null)
                CohortList = new List<Cohort>();

            Cohort a = new Cohort(this);
            CohortList.Add(a);
            return a;
        }