/// <summary> /// YM : /// This function is used to determine the reproduction week. /// It is a probability function distribution value /// assuming a Gaussian distribuion, where the Mean and the Variance were given by the user. /// </summary> /// <returns> The value of the reproduction week.</returns> public override int ComputeReproductionWeekGaussian2() { Double FoxReproductionWeekMeanDouble = Convert.ToDouble((this.Background as cFoxBackground).FoxReproductionWeekMean2); Double FoxReproductionWeekVarianceDouble = Convert.ToDouble((this.Background as cFoxBackground).FoxReproductionWeekVariance2); int FoxReproductionWeekInt = (int)FoxReproductionWeekMeanDouble; if (FoxReproductionWeekMeanDouble > 0) { // if the variance > 0, calculate the reproduction week, otherwise, the reproduction week is fixed if (FoxReproductionWeekVarianceDouble > 0) { cRandomBase rnd = new cUniformRandom(); cGaussianRandom RandomGaussianValue = new cGaussianRandom(FoxReproductionWeekMeanDouble, FoxReproductionWeekVarianceDouble, rnd); do { FoxReproductionWeekInt = (int)RandomGaussianValue.Value; } while (FoxReproductionWeekInt < 0 || FoxReproductionWeekInt > 52); } } return(FoxReproductionWeekInt); //System.Diagnostics.Debug.WriteLine("cFox.cs: FoxReproductionWeekInt"); }
static void Main(string[] args) { // // TODO: Add code to start application here // cGaussianRandom R = new cGaussianRandom(0, -100, 20); for (int i = 1; i < 100; i++) { Console.Write(R.Value); Console.Write(" "); } Console.ReadLine(); }
{ /// <summary> /// Initialize a Disease. /// </summary> /// <param name="Name"> /// The name of the disease. An ArgumentException exception is raised if Name has /// zero length. /// </param> /// <param name="IncubationPeriod"> /// The average incubation period of the disease. An ArgumentOutOfRangeException /// exception is raised if IncubationPeriod is less than zero. /// </param> /// <param name="IncubationVariance"> /// The variance in the incubation period. An ArgumentOutOfRangeException /// exception is raised if IncubationVariance is less than zero. /// </param> /// <param name="InfectiousPeriod"> /// The average infectious period of the disease. An ArgumentOutOfRangeException /// exception is raised if InfectiousPeriod is less than one. /// </param> /// <param name="InfectiousVariance"> /// The variance in the infectious period. An ArgumentOutOfRangeException /// exception is raised if InfectiousVariance is less than zero. /// </param> /// <param name="ContactRate"> /// The contact rate for the infected animal. That is, the weekly chance of spreading /// the disease to each animal in the infected animals activity radius. The value is /// expressed as a percent. An ArgumentOutOfRangeException exception is raised if /// CellContaceRate is not in the range of 0 to 100. /// </param> /// <param name="ChanceOfDeath"> /// The probability that the animal will die once the disease has run its /// course. An ArgumentOutOfRangeException exception is raised if ChanceOfDeath /// is not in the range of 0 to 100. /// </param> /// <param name="BecomesImmune"> /// If set to true, any animal that recovers from this disease will become immune for /// life. /// </param> /// <param name="RecoveredNotInfectious"> /// If set to true, recovered animals will not become infectious /// </param> /// <param name="Rnd">The random number generator used by this disease /// </param> public cDisease(string Name, int IncubationPeriod, double IncubationVariance, int InfectiousPeriod, double InfectiousVariance, double ContactRate, double ChanceOfDeath, bool BecomesImmune, bool RecoveredNotInfectious, cUniformRandom Rnd) { // name must not be zero length if (Name.Length == 0) { throw new ArgumentException("Name must not be 0 length.", "Name"); } // Incubation period must not be negative if (IncubationPeriod < 0) { throw new ArgumentOutOfRangeException("IncubationPeriod", "Incubation period must be >= 0"); } if (InfectiousPeriod < 1) { throw new ArgumentOutOfRangeException("InfectiousPeriod", "The infectious period must have a value of at leat one"); } // contact rates must be between 0 and 1. if (ContactRate < 0 || ContactRate > 100) { throw new ArgumentOutOfRangeException("ContactRate", "The contact rate must be between 0 and 100."); } // chance of death must be between 0 and 100 if (ChanceOfDeath < 0 || ChanceOfDeath > 100) { throw new ArgumentOutOfRangeException("ChanceOfDeath", "Chance of death must be between 0 and 100."); } // set the values mvarName = Name; mvarIncubationPeriod = new cGaussianRandom((double)IncubationPeriod, IncubationVariance, Rnd); mvarInfectiousPeriod = new cGaussianRandom((double)InfectiousPeriod, InfectiousVariance, Rnd); mvarContactRate = ContactRate; mvarChanceOfDeath = ChanceOfDeath / 100; mvarRandom = Rnd; mvarBecomesImmune = BecomesImmune; mvarRecoveredNotInfectious = RecoveredNotInfectious; }