示例#1
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");
            }
        }
示例#2
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
             double mortality = cohortItem.Count - cohortItem.Count * (1 - func.Value());
             cohortItem.Count     = cohortItem.Count * (1 - func.Value());
             cohortItem.Mortality = mortality;
         }
     }
 }
示例#3
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");
     }
 }
        /// <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
                }
            }
        }
示例#5
0
 /// <summary>
 /// Construct and store reference to owner.
 /// </summary>
 /// <param name="owner"></param>
 public Cohort(Lifestage owner)
 {
     OwningStage = owner;
 }
示例#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");
            }
        }
示例#7
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");
     }
 }
示例#8
0
文件: Cohort.cs 项目: hol353/ApsimX
 /// <summary>
 /// Construct and store reference to owner.
 /// </summary>
 /// <param name="owner"></param>
 public Cohort(Lifestage owner)
 {
     OwningStage = owner;
 }