/// <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; }
/// <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; }
/// <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); }