예제 #1
0
 /// <summary>
 ///		Initialize a cYearList by specifying the number of years.  Winter types
 ///		are generated randomly with a bias toward the type specified by the
 ///		'WinterBias' parameter.  If YearRnd is null, the winters are generated as
 ///		soon as the YearRnd property is set.
 /// </summary>
 /// <param name="NYears">
 ///		The number of years to place in the list.  An ArgumentException is raised
 ///		if NYears is less than or equal to zero.
 /// </param>
 /// <param name="WinterBias">
 ///		The bias of the randomly generated winter types.  Options include Very Severe,
 ///		Severe, Normal, Mild, and Very Mild.
 /// </param>
 public cYearList(int NYears, cUniformRandom YearRnd, enumWinterType WinterBias)
 {
     // make sure nYears > 0
     if (NYears <= 0)
     {
         ThrowNYearsException();
     }
     // store random number generator
     _yearRnd = YearRnd;
     // create the list
     Values = new List <cYear>();
     // create the object
     if (_yearRnd != null)
     {
         GenerateYearsRandom(WinterBias, NYears);
     }
     else
     {
         GenerateYearsOnRandomSet = true;
         GenerateYearsWinterType  = WinterBias;
         GenerateYearsNYears      = NYears;
     }
     // initialize to first year
     mvarCurrentYearNum = 0;
 }
예제 #2
0
        // Add years to the list with randomly generated winter types.
        private void GenerateYearsRandom(enumWinterType WinterBias, int NYears)
        {
            // make sure we can do this
            if (_yearRnd == null)
            {
                throw new InvalidOperationException("Error generating winter list. The random number generator is not set");
            }

            double RanValue;

            // array of probabilities for each winter bias
            int[,] Probabilities = new int[5, 5] {
                { 40, 30, 20, 10, 0 },
                { 22, 40, 22, 12, 4 },
                { 10, 20, 40, 20, 10 },
                { 4, 12, 22, 40, 22 },
                { 0, 10, 20, 30, 40 }
            };
            int            ProbSum, TempWType;
            enumWinterType WType;
            cYear          Year;

            // create an array of about 1000 random numbers.  This way, no matter how many years are run, the results
            // will be the same
            int[] RandomValues = new int[1000];
            for (int i = 0; i < 1000; i++)
            {
                RandomValues[i] = _yearRnd.IntValue(0, 100);
            }
            // create NYears cYear objects
            int randomCounter = 0;

            for (int i = 0; i < NYears; i++)
            {
                // set WType to lowest value
                TempWType = 0;
                // get a random number
                RanValue = RandomValues[randomCounter];
                randomCounter++;
                if (randomCounter == 1000)
                {
                    randomCounter = 0;
                }
                // loop, adding together appropriate probablities for selected winter bias
                // until the sum is greater than the random value.  As you do this, keep
                // incrementing the winter type (TempWType).
                ProbSum = 0;
                while (ProbSum < RanValue)
                {
                    ProbSum += Probabilities[(int)WinterBias - 1, TempWType];
                    TempWType++;
                }
                WType = (enumWinterType)TempWType;
                // create a year with this winter type
                Year = new cYear(Values.Count, WType);
                // add this year to the list
                Values.Add(Year);
            }
            GenerateYearsOnRandomSet = false;
        }
예제 #3
0
 // ************* constructor *******************************************
 /// <summary>
 ///		Initialize a cYear object.
 /// </summary>
 /// <param name="ID">The numeric ID of the year.</param>
 /// <param name="WinterType">
 ///		The type of winter for this year.  Options are Very Severe, Severe, Normal,
 ///		Mild, and Very Mild.
 ///	</param>
 public cYear(int ID, enumWinterType WinterType)
 {
     // year starts at week 1
     mvarCurrentWeek = 1;
     // set WinterType.  Note this is the only place this value can be set.
     mvarWinterType = WinterType;
     // set the ID
     mvarID = ID;
 }
예제 #4
0
        // *************************** internal members ********************************
        /// <summary>
        ///		Add a year to the year list, setting the current weeek of that year at the
        ///		same time.  This is an internal function that can only be called by objects
        ///		within the Rabies_Model_Core namespace.
        /// </summary>
        /// <param name="WinterType">The winter type of the new year.</param>
        /// <param name="CurrentWeek">
        ///		The current week of the new year.  An ArgumentOutOfRangeException exception is
        ///		raised if the value of CurrentWeek is not between 1 and 52.
        ///	</param>
        /// <returns>A reference to the new year.</returns>
        internal cYear Add(enumWinterType WinterType, int CurrentWeek)
        {
            // create the year
            cYear NewYear = new cYear(Values.Count, WinterType);

            NewYear.SetCurrentWeek(CurrentWeek);
            // add the year to the list
            Values.Add(NewYear);
            // return the newly create year
            return(NewYear);
        }
예제 #5
0
        /// <summary>
        ///		Add 'NYears' additional years to this list.  The winter types of the new
        ///		years will be randomly generated but biased towards the value of
        ///		'WinterBias'.
        /// </summary>
        /// <param name="NYears">
        ///		The number of years to add.  An ArgumentException exception is raised if NYears
        ///		is less than or equal to zero.</param>
        /// <param name="WinterBias">
        ///		The bias of the randomly generated winter types.  Options include Very Severe,
        ///		Severe, Normal, Mild, and Very Mild.
        ///	</param>
        public void AddYears(int NYears, enumWinterType WinterBias)
        {
            //System.Diagnostics.Debug.WriteLine("");
            //System.Diagnostics.Debug.WriteLine("cYearList.cs: AddYears() with WinterBias");

            // make sure nYears > 0
            if (NYears <= 0)
            {
                ThrowNYearsException();
            }
            GenerateYearsRandom(WinterBias, NYears);
        }
예제 #6
0
        /// <summary>
        ///		Add a year to the year list.
        /// </summary>
        /// <param name="WinterType">The winter type of the added year.</param>
        /// <returns>The newly created year.</returns>
        public cYear Add(enumWinterType WinterType)
        {
            //System.Diagnostics.Debug.WriteLine("");
            //System.Diagnostics.Debug.WriteLine("cYearList.cs: cYear: Add()");

            // create the year
            cYear NewYear = new cYear(Values.Count, WinterType);

            // add the year to the list
            Values.Add(NewYear);
            // return the value
            return(NewYear);
        }
 /// <summary>
 ///		Create a read-only rabies model datasource from a passed cells datasource with
 ///		NYears years with the passed winter bias.
 /// </summary>
 /// <param name="Rnd">The random number generator to be used by the generated background</param>
 /// <param name="Cells">
 ///		The cells datasource.  An ArgumentNullException exception is raised if Cells
 ///		is null.
 ///	</param>
 /// <param name="NYears">
 ///		The number of years to create.  An ArgumentOutOfRangeException exception is
 ///		raised if NYears is less than one.
 ///	</param>
 /// <param name="WinterBias">The winter type bias for those years.</param>
 ///	<param name="MaleMarkers">
 ///	    The markers for the seed male animal
 /// </param>
 /// <param name="FemaleMarkers">
 ///     The markers for the seed female animal
 /// </param>
 public cModelDataSource(cUniformRandom Rnd, cCellsDataSource Cells, int NYears, enumWinterType WinterBias,
                         string MaleMarkers, string FemaleMarkers)
 {
     // set the values
     mvarCells      = Cells;
     mvarYears      = NYears;
     mvarWinterBias = WinterBias;
     mvarRnd        = Rnd;
     // make sure that they are valid
     CheckCells();
     CheckNYears();
     CheckRandom();
     // get markers
     mvarMaleMarkers   = MaleMarkers;
     mvarFemaleMarkers = FemaleMarkers;
 }
        /// <summary>
        ///		Read year data from the datasource.  An InvalidOperationException exception is
        ///		raised if the datasource has not been connected.
        /// </summary>
        /// <param name="WinterType">The winter type for the year.</param>
        /// <param name="CurrentWeek">The current week value for the year.</param>
        /// <returns>True if a year was available from the datasource.</returns>
        protected override bool GetYearData(ref enumWinterType WinterType, ref int CurrentWeek)
        {
            if (mvarConnection == null)
            {
                ThrowConnectionException();
            }
            // return false if we have reached the end of the record set
            if (YearReadPosition == mvarDataSet.Tables["Years"].Rows.Count)
            {
                return(false);
            }
            // copy the data to the Attributes object
            DataTable dt = mvarDataSet.Tables["Years"];
            // get the datarow at the current read position
            DataRow dr = dt.Rows[YearReadPosition];

            // get the year data
            WinterType  = (enumWinterType)Convert.ToInt32(dr["WinterType"]);
            CurrentWeek = Convert.ToInt32(dr["CurrentWeek"]);
            // get next year
            YearReadPosition++;
            return(true);
        }
예제 #9
0
        /// <summary>
        ///		Load a list of years from the data source.
        /// </summary>
        /// <param name="Years">
        ///		The list of years to fill.  An ArgumentNullException exception is raised if
        ///		Years is null.
        /// </param>
        public void GetYears(cYearList Years)
        {
            // make sure Years is not null
            if (Years == null)
            {
                ThrowYearsException();
            }
            // get data
            enumWinterType WinterType  = enumWinterType.Normal;
            int            CurrentWeek = 0;
            int            CurrentYear = 0;

            // clear the current years from the list.
            Years.Clear();
            // add years from the datasource, one-by-one
            while (GetYearData(ref WinterType, ref CurrentWeek))
            {
                Years.Add(WinterType, CurrentWeek);
            }
            // get the current time stamp
            this.ReadTimeRecord(ref CurrentYear, ref CurrentWeek);
            // set the current year and week for the year list.
            Years.SetYearAndWeek(CurrentYear, CurrentWeek);
        }
 /// <summary>
 ///		Initialize the background specifying the initial number of years and their
 ///		winter bias.
 /// </summary>
 /// <param name="Rnd">The random number generator to be used by the background</param>
 /// <param name="Name">
 ///		The name to assign to this background.  An ArgumentException is raised if
 ///		Name is zero length.
 ///	</param>
 /// <param name="KeepAllAnimals">
 ///		A flag indicating whether a record of all animals should be kept during
 ///		a run.
 ///	</param>
 /// <param name="NYears">
 ///		The initial number of years. An ArgumentException is raised in NYears is
 ///		less than or equal to zero.
 ///	</param>
 /// <param name="WinterBias">The winter bias of the initial years.</param>
 public cFoxBackground(cUniformRandom Rnd, string Name, bool KeepAllAnimals, int NYears, enumWinterType WinterBias)
     : base(Rnd, Name, KeepAllAnimals, NYears, WinterBias)
 {
     InitValues();
 }
 /// <summary>
 ///		Create a read-only rabies model datasource from a passed cells datasource with
 ///		NYears years with the passed winter bias.
 /// </summary>
 /// <param name="Rnd">The random number generator used by the generated background</param>
 /// <param name="TheCells">The cells datasource.</param>
 /// <param name="NYears">The number of years to create.</param>
 /// <param name="WinterBias">The winter type bias for those years.</param>
 ///	<param name="MaleMarkers">
 ///	    The markers for the seed male animal
 /// </param>
 /// <param name="FemaleMarkers">
 ///     The markers for the seed female animal
 /// </param>
 public cFoxModelDataSource(cUniformRandom Rnd, cCellsDataSource TheCells, int NYears, enumWinterType WinterBias,
                            string MaleMarkers, string FemaleMarkers)
     : base(Rnd, TheCells, NYears, WinterBias, MaleMarkers, FemaleMarkers)
 {
 }
 /// <summary>
 ///     Construct a new background object of the approriate type
 /// </summary>
 /// <param name="Rnd">The random number generator for the background</param>
 /// <param name="BackgroundName">The name of the background</param>
 /// <param name="KeepAllAnimals">A boolean value that indicates whether or not the background should retain a list of all animals</param>
 /// <param name="NYears">The number of years</param>
 /// <param name="WinterBias">The winter type bias for the years</param>
 /// <returns>A new background object ofthe approriate type</returns>
 protected abstract cBackground GetNewBackground(cUniformRandom Rnd, string BackgroundName, bool KeepAllAnimals,
                                                 int NYears, enumWinterType WinterBias);
예제 #13
0
 /// <summary>
 ///		Read year data from the datasource.
 /// </summary>
 /// <param name="WinterType">The winter type for the year.</param>
 /// <param name="CurrentWeek">The current week value for the year.</param>
 /// <returns>True if a year was available from the datasource.</returns>
 protected abstract bool GetYearData(ref enumWinterType WinterType, ref int CurrentWeek);
 // ********************* methods ******************************************
 /// <summary>
 ///     Add a new winter type to the list.  The new value is put at the end
 ///     of the list.
 /// </summary>
 /// <param name="eWinterType">
 ///		The winter type: Very Severe, Severe, Normal, Mild, or Very Mild.
 /// </param>
 public void Add(enumWinterType eWinterType)
 {
     Values.Add(eWinterType);
 }
예제 #15
0
 /// <summary>
 ///		Create a read-only rabies model datasource from a passed cells datasource with
 ///		NYears years with the passed winter bias.
 /// </summary>
 /// <param name="Rnd">The random number generator used by the generated background</param>
 /// <param name="TheCells">The cells datasource.</param>
 /// <param name="NYears">The number of years to create.</param>
 /// <param name="WinterBias">The winter type bias for those years.</param>
 public cRaccoonModelDataSource(cUniformRandom Rnd, cCellsDataSource TheCells, int NYears, enumWinterType WinterBias)
     : base(Rnd, TheCells, NYears, WinterBias)
 {
 }
예제 #16
0
 /// <summary>
 ///     Construct a new background object of the approriate type
 /// </summary>
 /// <param name="Rnd">The random number generator for the background</param>
 /// <param name="BackgroundName">The name of the background</param>
 /// <param name="KeepAllAnimals">A boolean value that indicates whether or not the background should retain a list of all animals</param>
 /// <param name="NYears">The number of years</param>
 /// <param name="WinterBias">The winter type bias for the years</param>
 /// <returns>A new background object ofthe approriate type</returns>
 protected override cBackground GetNewBackground(cUniformRandom Rnd, string BackgroundName, bool KeepAllAnimals,
                                                 int NYears, enumWinterType WinterBias)
 {
     return(new cRaccoonBackground(Rnd, BackgroundName, KeepAllAnimals, NYears, WinterBias));
 }
 /// <summary>
 ///		Initialize the background specifying the initial number of years and their
 ///		winter bias.
 /// </summary>
 /// <param name="Rnd">The random number generator to be used by the background</param>
 /// <param name="Name">
 ///		The name to assign to this background.  An ArgumentException is raised if
 ///		Name is zero length.
 ///	</param>
 /// <param name="KeepAllAnimals">
 ///		A flag indicating whether a record of all animals should be kept during
 ///		a run.
 ///	</param>
 /// <param name="NYears">
 ///		The initial number of years. An ArgumentException is raised in NYears is
 ///		less than or equal to zero.
 ///	</param>
 /// <param name="WinterBias">The winter bias of the initial years.</param>
 public cBackground(cUniformRandom Rnd, string Name, bool KeepAllAnimals, int NYears, enumWinterType WinterBias)
 {
     if (Rnd == null)
     {
         throw new ArgumentNullException("Rnd");
     }
     // reference the random number generator
     RandomNum          = Rnd;
     RandomNum.MinValue = 0;
     RandomNum.MaxValue = 100;
     // make sure that Name is not zero length
     if (string.IsNullOrEmpty(Name))
     {
         throw new ArgumentException("Name must not be zero length.", "Name");
     }
     // make sure NYears > 0
     if (NYears <= 0)
     {
         throw new ArgumentException("NYears must be greater than 0.", "NYears");
     }
     // copy the name
     this.Name = Name;
     // create a super cell list
     SuperCells = new cSuperCellList();
     // create a master cell list
     Cells = new cMasterCellList(this, RandomNum);
     // create list of years
     Years = new cYearList(NYears, RandomNum, WinterBias);
     // create the master list of animals
     Animals = new cMasterAnimalList(1, KeepAllAnimals, RandomNum);
     // create the list of diseases
     Diseases = new cDiseaseList(RandomNum);
     // create the strategy list
     Strategies      = new cStrategyList();
     StrategyCounter = 0;
     // set have run weekly events to false
     mvarHaveRunWeeklyEvents = false;
     // scramble list is false by default
     ScrambleList = false;
     // abort on disease disappearance is true by default
     AbortOnDiseaseDisappearance = true;
     // prevent incest flag - set to false by default
     PreventIncest = false;
 }