/// <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> /// Read cell data from the data source and fill the passed cell list. This /// method will raise an exception if 1) a supercell ID in the database is not /// found in the Background assigned to this class (ArgumentException exception) or /// 2) a cell is assigned a reference to a neighbour that does not exist /// (ArgumentException exception). /// </summary> /// <param name="Cells"> /// The cell list to fill. The cells are added to any that are already in the /// list. An ArgumentNullException exception is raised if Cells is null. /// </param> /// <param name="SuperCells"> /// A list of Supercells that these cells will belong to. An ArgumentNullException /// is raised if SuperCells is null. An ArgumentException is raised if SuperCells /// is an empty list. /// </param> public void GetCellData(cCellList Cells, cSuperCellList Supercells) { // make sure Cells is not null if (Cells == null) { throw new ArgumentNullException("Cells", "Cells must not be null."); } // make sure Supercells is not null if (Supercells == null) { ThrowSupercellsException(); } // the supercell list must contain at least one super cell if (Supercells.Count == 0) { throw new ArgumentException("Supercell list must contain at least one supercell.", "Supercells"); } // retrieve the name of this list of cells Cells.Name = this.GetName(); // create a cell data object cCellData CellData = new cCellData(); // loop, loading cell data one at a time this.Reset(); while (this.GetNextCellRecord(CellData)) { // create the new cell cCell Cell = new cCell(CellData.ID, Supercells[CellData.SuperCellID], CellData.K, CellData.XLoc, CellData.YLoc); Cells.Add(Cell); } // loop again, this time assigning neighbours. If an invalid refence exception // is thrown, then the neighbour ID is invalid. this.Reset(); while (this.GetNextCellRecord(CellData)) { // loop through the six neighbour positions for (int i = 0; i < 6; i++) { // note: if the neighbour value in the datasource is "b", this indicates // that the neighbour is on the bouandary if (CellData.Neighbours[i] == "b") { Cells[CellData.ID].SetNeighbour((enumNeighbourPosition)i, null); } else { Cells[CellData.ID].SetNeighbour((enumNeighbourPosition)i, Cells[CellData.Neighbours[i]]); } } } }
/// <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> /// Read supercell data from the data source and fill the passed supercell /// list. /// </summary> /// <param name="Supercells"> /// The cell list to fill. The cells are added to any that are already in the /// list. An ArgumentNullException exception is raised if Supercells is null. /// </param> public void GetSuperCellData(cSuperCellList Supercells) { // make sure Supercells is not null if (Supercells == null) { ThrowSupercellsException(); } // reset the supercell recordset this.ResetSupercells(); string Name = ""; int InResistance = 0, OutResistance = 0; while (this.GetNextSupercellRecord(ref Name, ref InResistance, ref OutResistance)) { // create a new supercell cSuperCell SuperCell = new cSuperCell(Name, InResistance, OutResistance); // add the new supercell to the supercell list Supercells.Add(SuperCell); } }