Example #1
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;
        }
Example #2
0
        // ******************* methods **************************************************
        /// <summary>
        ///		Increments time one week at a time.  If the week value of the current year
        ///		is 52, this method will switch to the next year in the year list.  Calling
        ///		this method after the week value of the last year in the list has reached
        ///		52 results in an ex_cYearList_TimeIncrementException exception being raised.
        /// </summary>
        public void IncrementTime()
        {
            //System.Diagnostics.Debug.WriteLine("");
            //System.Diagnostics.Debug.WriteLine("cYearList.cs: IncrementTime()");

            // has the current year reached week 52
            cYear TheYear = Values[mvarCurrentYearNum];

            //System.Diagnostics.Debug.WriteLine("cYearList.cs: IncrementTime(): TheYear = " + TheYear);

            if (TheYear.CurrentWeek == 52)
            {
                // YES it is 52
                // is the current year the last year
                if (mvarCurrentYearNum == Values.Count)
                {
                    // YES it is the last year
                    // throw an exception, we cannot count further
                    throw new InvalidOperationException(
                              "Cannot increment another week.  You are at the last week of the last year.");
                }
                else
                {
                    // NO it is not the last year
                    // move to the next year in the list
                    mvarCurrentYearNum++;
                }
            }
            else
            {
                // NO it is not 52
                // increment the week
                TheYear.IncrementWeek();
            }
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
0
        /// <summary>
        ///		Set the current year and week.  This is an internal function that can only be
        ///		called by objects within the Rabies_Model_Core namespace.
        /// </summary>
        /// <param name="CurrentYear">
        ///		The new current year.  An ArgumentOutOfRange Exception is raised if this value
        ///		is less than 0 or greater than the number of years minus one.
        /// </param>
        /// <param name="CurrentWeek">
        ///		The current week for the new current year.  An ArgumentOutOfRangeException
        ///		exception is raised if the value of CurrentWeek is not between 1 and 52.
        /// </param>
        internal void SetYearAndWeek(int CurrentYear, int CurrentWeek)
        {
            // make sure the current year exists in the list
            if (CurrentYear > Values.Count - 1)
            {
                throw new ArgumentOutOfRangeException("CurrentYear",
                                                      "The value of CurrentYear cannot exceed the number of years in the list");
            }
            // set the current year
            mvarCurrentYearNum = CurrentYear;
            // set the current week
            cYear TheYear = Values[mvarCurrentYearNum];

            TheYear.SetCurrentWeek(CurrentWeek);
        }
Example #6
0
        //	Add years to the list.  An ArgumentException exception is raised if the passed list
        //	of winter types is empty.
        private void AddYearsFromList(cWinterTypeList WTList)
        {
            cYear Year;

            // raise an exception if WTList is empty
            if (WTList.Count == 0)
            {
                throw new ArgumentException("The list of winter types cannot be empty.",
                                            "WTList");
            }
            // create the Years
            for (int i = 0; i < WTList.Count; i++)
            {
                // create year based on winter type in the list
                Year = new cYear(Values.Count, WTList[i]);
                // add this year to the list
                Values.Add(Year);
            }
            GenerateYearsOnRandomSet = false;
        }
Example #7
0
 /// <summary>
 ///		Write year data into the datasource.
 /// </summary>
 /// <param name="Years">The year to write into the datasource.</param>
 protected abstract void WriteYearData(cYear Year);