Esempio n. 1
0
        /// <summary>
        /// The source cohort reproduces and sends count creatures to the destination stage.
        /// </summary>
        /// <param name="srcCohort">The source cohort</param>
        /// <param name="destStage">The destination LifeStage</param>
        /// <param name="count">The population for the migrated cohort</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");
            }
        }
Esempio n. 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;      // can be multiple mortality events in a lifestage step
         }
     }
 }
        /// <summary>
        /// Process this lifestage before cohorts are processed.
        /// This process is immigration.
        /// </summary>
        /// <param name="host">The host LifeStage</param>
        public void Process(LifeStage host)
        {
            double number = 0;

            // apply the functions from the function list to calculate the total number of immigrants
            foreach (IFunction func in FunctionList)
            {
                number += func.Value();
            }
            immigrantNumbers = number;
            host.AddImmigrants(number);
        }
Esempio n. 4
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)
     {
         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);
         }
     }
 }
Esempio n. 5
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
                }
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Construct and store reference to owner.
 /// </summary>
 /// <param name="owner"></param>
 public Cohort(LifeStage owner)
 {
     OwningStage = owner;
 }
Esempio n. 8
0
 /// <summary>
 /// Process this lifestage before cohorts are processed
 /// </summary>
 public void Process(LifeStage host)
 {
 }