Exemplo n.º 1
0
 /// <summary>
 ///		Write year and animal data to the data source.  All existing data in the
 ///		data source is overwritten.
 /// </summary>
 /// <param name="Years">
 ///		The list of years to write.  An ArgumentNullException exception is raised
 ///		if Years is null.
 /// </param>
 /// <param name="Animals">
 ///		The list of animals to write.  An ArgumentNullException exception is raised
 ///		if Animals is null.
 ///	</param>
 /// <param name="BG">
 ///		The background that these animals occupy.  An ArgumentNullException
 ///		exception is raised if BG is null.
 ///	</param>
 public void WriteYearAndAnimalData(cYearList Years, cAnimalList Animals,
                                    cBackground BG)
 {
     // make sure Years is not null
     if (Years == null)
     {
         ThrowYearsException();
     }
     // make sure Animals is not null
     if (Animals == null)
     {
         ThrowAnimalsException();
     }
     // make sure BG is not null
     if (BG == null)
     {
         ThrowBGException();
     }
     // write the animal data
     this.WriteAnimalData(Animals, BG);
     // write the name of the cell list
     this.WriteCellsName(BG.Cells);
     // write the years
     this.WriteYears(Years);
 }
Exemplo n.º 2
0
 /// <summary>
 ///		Loads the animal and year data.
 /// </summary>
 /// <param name="Years">
 ///		The list of years to be filled.  An ArgumentNullException exception is raised
 ///		if Years is null.
 /// </param>
 /// <param name="Animals">
 ///		The list of animals to be filled.  An ArgumentNullException exception is raised
 ///		if Animals is null.
 ///	</param>
 /// <param name="BG">
 ///		The background that these animals will occupy.  An ArgumentNullException
 ///		exception is raised if BG is null.  An InvalidOperationException exception is
 ///		raised if name of the cell list in the datasource does not match the name of
 ///		the cell list in the passed background.
 ///	</param>
 public void LoadYearAndAnimalData(cYearList Years, cAnimalList Animals,
                                   cBackground BG)
 {
     //System.Diagnostics.Debug.WriteLine("cAnimalsDataSource.cs: LoadYearAndAnimalData");
     // make sure Years is not null
     if (Years == null)
     {
         ThrowYearsException();
     }
     // make sure Animals is not null
     if (Animals == null)
     {
         ThrowAnimalsException();
     }
     // make sure BG is not null
     if (BG == null)
     {
         ThrowBGException();
     }
     // make sure the cell list name of the data source matches the cell list
     // name of the cells belonging to the background.
     if (!this.CheckCellsName(BG.Cells))
     {
         throw new InvalidOperationException("The cell list name associated with this animal data source does not match the cell list name associated with the background.");
     }
     // load the years
     this.GetYears(Years);
     // load the animals
     this.GetAnimalData(Animals, BG);
     //System.Diagnostics.Debug.WriteLine("cAnimalsDataSource.cs: LoadYearAndAnimalData END");
 }
        /// <summary>
        ///		Initialize the background, passing a list of years and a seed for all
        ///		random number generators in the model.  This is an internal constructor
        ///		and may only be used by classes within the Rabies_Model_Core namespace.
        /// </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="YList">
        ///		The list of years.  An ArgumentException exception is raised if YList is empty.
        ///	</param>
        ///	<param name="DList">
        ///		A list of diseases that will affect the animals in this background.
        ///	</param>
        public cBackground(cUniformRandom Rnd, string Name, bool KeepAllAnimals, cYearList YList, cDiseaseList DList)
        {
            if (Rnd == null)
            {
                throw new ArgumentNullException("Rnd");
            }
            if (YList == null)
            {
                throw new ArgumentNullException("YList");
            }
            if (DList == null)
            {
                throw new ArgumentNullException("DList");
            }

            // make sure that Name is not zero length
            if (string.IsNullOrEmpty(Name))
            {
                throw new ArgumentException("Name must not be zero length.", "Name");
            }
            // make sure the Years list contains at least one year
            if (YList.Count == 0)
            {
                throw new ArgumentException("Year list must contain at least one year.",
                                            "Years");
            }
            // create the random number generator
            RandomNum          = Rnd;
            RandomNum.MinValue = 0;
            RandomNum.MaxValue = 100;
            // copy the name
            this.Name = Name;
            // create a super cell list
            SuperCells = new cSuperCellList();
            // create a master cell list
            Cells = new cMasterCellList(this, RandomNum);
            // generate winter and animal lists
            Years         = YList;
            Years.YearRnd = RandomNum;
            // create the master list of animals
            Animals = new cMasterAnimalList(1, KeepAllAnimals, RandomNum);
            // create the list of diseases
            Diseases = DList;
            // 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;
        }
Exemplo n.º 4
0
 /// <summary>
 ///		Write a list of years into the datasource.  Any years already in the data
 ///		source are overwritten.
 /// </summary>
 /// <param name="Years">
 ///		The list of years to write into the datasource.  An ArgumentNullException
 ///		exception is raised if Years is null.
 ///	</param>
 public void WriteYears(cYearList Years)
 {
     // make sure Years is not null
     if (Years == null)
     {
         ThrowYearsException();
     }
     // remove the current years from the datasource
     this.ClearYears();
     // add the years to the list, one-by-one
     foreach (cYear Year in Years)
     {
         WriteYearData(Year);
     }
 }
 /// <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;
 }
Exemplo n.º 6
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>
 ///     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="AnimalYears">A list of years</param>
 /// <param name="Diseases">A list of diseases in the background</param>
 /// <returns>A new background object ofthe approriate type</returns>
 protected abstract cBackground GetNewBackground(cUniformRandom Rnd, string BackgroundName, bool KeepAllAnimals,
                                                 cYearList AnimalYears, cDiseaseList Diseases);
        /// <summary>
        ///		Read the data from the datasource.
        /// </summary>
        /// <param name="BackgroundName">
        ///		The name to assign to the returned background object.  If BackgroundName has
        ///		zero length, an ArgumentException is raised.
        /// </param>
        /// <param name="KeepAllAnimals">
        ///		A boolean value indicating whether or not the created background should keep
        ///		a reference to animals that die.
        /// </param>
        /// <param name="Diseases">
        ///		The list of Diseases that can occur in this background.  If diseases is null, a
        ///		new empty disease list is created.
        /// </param>
        /// <returns>
        ///		A cBackground object containing the settings from this datasource.
        /// </returns>
        public cBackground ReadDatasource(string BackgroundName, bool KeepAllAnimals, cDiseaseList Diseases)
        {
            //System.Diagnostics.Debug.WriteLine("cModelDataSource.cs: cBackground: ReadDataSource: with disease arguments");

            cBackground NewBackground;

            // make sure BackgroundName is not zero length
            if (BackgroundName.Length == 0)
            {
                throw new ArgumentException("BackgroundName must not be zero length.", "BackgroundName");
            }
            // if the diseases list is null, create an empty list instead
            if (Diseases == null)
            {
                Diseases = new cDiseaseList(mvarRnd);
            }
            // we start by assigning years.  How we do this will depend on how this object
            // was originally created
            if (mvarAnimals != null)
            {
                // read the years from the animals datasource
                cYearList AnimalYears = new cYearList(1, mvarRnd);
                //mvarAnimals.GetYears(AnimalYears);
                // using these years, create a winter type list
                // create a background with this list of years
                //System.Diagnostics.Debug.WriteLine("cModelDataSource.cs: cBackground: mvarAnimals NULL = " + mvarYears);
                NewBackground = GetNewBackground(mvarRnd, BackgroundName, KeepAllAnimals, AnimalYears, Diseases);
            }
            else if (mvarYears > 0)
            {
                // create mvarYears years with a given winter bias
                //System.Diagnostics.Debug.WriteLine("cModelDataSource.cs: cBackground: mvarYears > 0 = " + mvarYears);
                NewBackground          = GetNewBackground(mvarRnd, BackgroundName, KeepAllAnimals, mvarYears, mvarWinterBias);
                NewBackground.Diseases = Diseases;
            }
            else
            {
                // create years from a given winter type list
                //System.Diagnostics.Debug.WriteLine("cModelDataSource.cs: cBackground: mvarAnimals ? " + mvarYears);
                NewBackground          = GetNewBackground(mvarRnd, BackgroundName, KeepAllAnimals, mvarWinters);
                NewBackground.Diseases = Diseases;
            }
            // now get the cell data.  This is the same no matter how the datasource
            // was created
            // get the supercells first
            mvarCells.GetSuperCellData(NewBackground.SuperCells);
            // now get the cell data
            //System.Diagnostics.Debug.WriteLine("cModelDataSource.cs: cBackground: GetCellData");
            mvarCells.GetCellData(NewBackground.Cells, NewBackground.SuperCells);

            // now either read the animals data from the animals datasource OR create a single
            // new animal
            if (mvarAnimals != null)
            {
                // read the animals
                // mvarAnimals.GetAnimalData(NewBackground.Animals, NewBackground);
                mvarAnimals.LoadYearAndAnimalData(NewBackground.Years, NewBackground.Animals, NewBackground);
                // now read the time stamp and set the current year and week
            }
            else
            {
                // seed a single male and female animal somewhere in the background
                int SeedCell = NewBackground.RandomNum.IntValue(0, NewBackground.Cells.Count - 1);
                // add the new female and male animals
                cAnimal NewFemale = GetNewAnimal("0", NewBackground.Cells[SeedCell].ID, NewBackground, enumGender.female);
                NewFemale.Marker = (string.IsNullOrEmpty(mvarFemaleMarkers) ? "M" : mvarFemaleMarkers);
                NewBackground.Animals.Add(NewFemale);

                cAnimal NewMale = GetNewAnimal("1", NewBackground.Cells[SeedCell].ID, NewBackground, enumGender.male);
                NewMale.Marker = (string.IsNullOrEmpty(mvarMaleMarkers) ? "M" : mvarMaleMarkers);
                NewBackground.Animals.Add(NewMale);
            }
            // return the newly create Background object
            //System.Diagnostics.Debug.WriteLine("cModelDataSource.cs: cBackground: ReadDatasource END");
            return(NewBackground);
        }