/// <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); }
/// <summary> /// Updates an existing animal data source. Animals in the passed animal list but /// not in the datasource are added to the data source. Animal in the list and in /// the data source are updated. /// </summary> /// <param name="Animals"> /// The animal list containing the animals to be added and updated. /// </param> /// <param name="BG">The background that the animals occupy.</param> public void UpdateAnimalData(cAnimalList Animals, cBackground BG) { if (Animals == null) { ThrowAnimalsException(); } if (BG == null) { ThrowBGException(); } // throw an exception if data source is read only if (this.ReadOnly) { ThrowReadOnlyException(); } // create a cAnimalAttributes object cAnimalAttributes Attributes = new cAnimalAttributes(); // write the time stamp this.WriteTime(BG.Years.CurrentYearNum, BG.Years.CurrentYear.CurrentWeek, BG.HaveRunWeeklyEvents); // loop through all foxes, writing each one to the datasource for (int i = 0; i < Animals.Count; i++) { Animals[i].GetAttributes(Attributes); Attributes.ListIndex = i; this.WriteAnimalRecord(Attributes, true); // write markers if the version is correct if (GetVersion() > 1) { this.WriteMarkers(Attributes, true); } } }
/// <summary> /// Initialize a cCombinedStrategy. /// </summary> /// <param name="BG"> /// The background object against which this strategy shall be applied. An /// ArgumentNullException exception is raised if BG is null. /// </param> /// <param name="Cells"> /// The list of cells to which this strategy will apply. An ArgumentNullException /// exception is raised if Cells is null. An ArgumentException exception is raised /// if Cells is an empty list or if it contains cell IDs not found in the passed /// Background object (BG). /// </param> /// <param name="Level"> /// The level at with this strategy shall be applied. An ArgumentOutOfRangeException /// exception is raised if Level is not in the range of 0-100. /// </param> /// <param name="Year"> /// The year in which this strategy will be applied. An ArgumentOutOfRangeException /// exception is raised if Year is less then zero. /// </param> /// <param name="Week"> /// The week in which this strategy will be applied. An ArgumentOutOfRangeException /// exception is raised if Week is not in the range of 1-52. /// </param> /// <param name="DiseaseName"> /// The name of the disease to protect against. An ArgumentException exception is /// raised if DiseaseName is zero length. /// </param> /// <param name="VaccineEffectivePeriod"> /// The effective period (in weeks) of the vaccine being used. An /// ArgumentOutOfRangeException exception is raise if VaccineEffectivePeriod /// is less than zero. /// </param> /// <param name="FertilityEffectivePeriod"> /// The effective period(in weeks) of the fertility control. An ArgumentOutOfRangeException /// exception is raised if FertilityEffectivePeriod is less than zero. /// </param> public cCombinedStrategy(cBackground BG, cCellList Cells, double Level, int Year, int Week, string DiseaseName, int VaccineEffectivePeriod, int FertilityEffectivePeriod) : base(BG, Cells, Level, Year, Week) { // DiseaseName should not be zero length if (DiseaseName.Length == 0) { throw new ArgumentException("DiseaseName cannot be zero length.", "DiseaseName"); } // Effective Periods must be greater than zero if (VaccineEffectivePeriod < 1) { throw new ArgumentOutOfRangeException("VaccineEffectivePeriod", "VaccineEffectivePeriod must be greater than zero."); } if (FertilityEffectivePeriod < 1) { throw new ArgumentOutOfRangeException("FertilityEffectivePeriod", "FertilityEffectivePeriod must be greater than zero."); } // set values mvarDiseaseName = DiseaseName; mvarVaccineEffectivePeriod = VaccineEffectivePeriod; mvarFertilityEffectivePeriod = FertilityEffectivePeriod; }
/// <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 a cFertility strategy. /// </summary> /// <param name="BG"> /// The background object against which this strategy shall be applied. An /// ArgumentNullException exception is raised if BG is null. /// </param> /// <param name="Cells"> /// The list of cells to which this strategy will apply. An ArgumentNullException /// exception is raised if Cells is null. An ArgumentException exception is raised /// if Cells is an empty list or if it contains cell IDs not found in the passed /// Background object (BG). /// </param> /// <param name="Level"> /// The level at with this strategy shall be applied. An ArgumentOutOfRangeException /// exception is raised if Level is not in the range of 0-100. /// </param> /// <param name="Year"> /// The year in which this strategy will be applied. An ArgumentOutOfRangeException /// exception is raised if Year is less then zero. /// </param> /// <param name="Week"> /// The week in which this strategy will be applied. An ArgumentOutOfRangeException /// exception is raised if Week is not in the range of 1-52. /// </param> /// <param name="EffectivePeriod"> /// The length of time (in weeks) that the fertility control is effective. An ArgumentOutOfRangeException /// exception is raised if Effective Period is not greater than 0. /// </param> public cFertilityStrategy(cBackground BG, cCellList Cells, double Level, int Year, int Week, int EffectivePeriod) : base(BG, Cells, Level, Year, Week) { if (EffectivePeriod < 1) { throw new ArgumentOutOfRangeException("EffectivePeriod", "EffectivePeriod must be greater than zero."); } mvarEffectivePeriod = EffectivePeriod; }
// ************************** Constructors ************************************* /// <summary> /// Initialize the master cell list. /// </summary> /// <param name="Background"> /// The background object that owns this master cell list. An ArgumentNullEception /// exception is raised if Background is null. /// </param> /// <param name="ScrambleRandom">A random number generator to use if the list is to be scrambled</param> public cMasterCellList(cBackground Background, cUniformRandom ScrambleRandom) : base(ScrambleRandom) { // make sure background is valid if (Background == null) { throw new ArgumentNullException("Background", "Background must reference a valid background object."); } // set the background mvarBackground = Background; }
// ********************** Constructor ************************************** /// <summary> /// Initialize. /// </summary> /// <param name="Background"> /// The background against which this event is being raised. An ArgumentNullException /// exception is raised in Background is null. /// </param> public cWeeklyUpdateEventArgs(cBackground Background) { if (Background == null) { throw new ArgumentNullException("Background", "Background must not be null."); } // set the parameters mvarYear = Background.Years.CurrentYearNum; mvarWeek = Background.Years.CurrentYear.CurrentWeek; mvarBackground = Background; mvarAbort = false; }
// initialize the class private void InitClass(cBackground BG, cCellList Cells, double Level, int Year, int Week) { // make sure Background is not a null reference if (BG == null) { throw new ArgumentNullException("BG", "BG must not be null."); } // make sure Cells is not null if (Cells == null) { throw new ArgumentNullException("Cells", "Cells must not be null."); } // make sure Cells contains at least one cell if (Cells.Count == 0) { throw new ArgumentException("Cells must not be an empty list", "Cells"); } // make sure all passed cells are in the background foreach (cCell Cell in Cells) { if (!BG.Cells.ContainsKey(Cell.ID)) { throw new ArgumentException("All passed cells must be part of the passed background.", "Cells"); } } // make sure Level is correct if (Level < 0 || Level > 100) { ThrowLevelException(); } // check the year and the week if (Year < 0) { throw new ArgumentOutOfRangeException("Year", "Year must be greater than zero."); } if (Week < 1 || Week > 52) { throw new ArgumentOutOfRangeException("Week", "Week must be in the range of 1-52."); } // create the internal hashtable, applying the passed Value to each cell Values = new Dictionary <string, double>(Cells.Count); // loop through all passed cells, creating an entry for each foreach (cCell Cell in Cells) { Values.Add(Cell.ID, Level); } // store the reference to the background mvarBackground = BG; // set the year and week that the strategy is applied mvarYear = Year; mvarWeek = Week; }
/// <summary> /// Writes the animals in the passed animal list into the data source. This /// method overwrites any data that is already in the data source. /// </summary> /// <param name="Animals"> /// The list of animals to be written into the datasource. /// </param> /// <param name="BG">The background that the animals occupy.</param> public void WriteAnimalData(cAnimalList Animals, cBackground BG) { //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData()"); if (Animals == null) { ThrowAnimalsException(); } //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 01"); if (BG == null) { ThrowBGException(); } //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 02"); // throw an exception if data source is read only if (this.ReadOnly) { ThrowReadOnlyException(); } //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 03"); // erase the existing contents of this datasource this.Clear(); //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 04"); // write the time stamp this.WriteTime(BG.Years.CurrentYearNum, BG.Years.CurrentYear.CurrentWeek, BG.HaveRunWeeklyEvents); //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 05"); // create a cAnimalAttributes object cAnimalAttributes Attributes = new cAnimalAttributes(); //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 06"); // loop through all foxes, writing each one to the datasource for (int i = 0; i < Animals.Count; i++) { //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() i = " + i); //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 06 i = " + i); Animals[i].GetAttributes(Attributes); //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 06 b"); Attributes.ListIndex = i; //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 06 c"); this.WriteAnimalRecord(Attributes, false); //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 06 d"); // write markers if the version is correct if (GetVersion() > 1) { this.WriteMarkers(Attributes, false); } } //System.Diagnostics.Debug.WriteLine("cAnimalDataSource.cs: WriteAnimalData() HERE 07"); // lastly, reset the datasource so that subsequent reads are correct this.Reset(); }
// common initialization code private void InitClass(cBackground Background, string DiseaseName, int Year, int Week) { // check parameters // background cannot be null if (Background == null) { throw new ArgumentNullException("Background", "Background must reference a valid background object."); } // the disease must be found in the background if (!Background.Diseases.ContainsKey(DiseaseName)) { throw new ArgumentException("Disease name passed is not contained in the background object.", "DiseaseName"); } // year must not be < 0 and week must be 1-52. if (Year < 0) { ThrowYearException(); } if (Week < 1 || Week > 52) { ThrowWeekException(); } // set parameters mvarBackground = Background; mvarDisease = Background.Diseases[DiseaseName]; mvarYear = Year; mvarWeek = Week; mvarIsFatal = mvarDisease.GetAnimalDies(); // EER: set the infection history if (mvarIsFatal) { mvarNaturalImmunity = "Infected_died"; } else { mvarNaturalImmunity = "Infected_recovered"; } //System.Diagnostics.Debug.WriteLine("cInfection.cs: InitClass(): mvarIsFatal = " + mvarIsFatal + "; mvarNaturalImmunity = " + mvarNaturalImmunity); //System.Diagnostics.Debug.WriteLine("cInfection.cs: InitClass(): mvarNaturalImmunity = " + mvarNaturalImmunity); }
/// <summary> /// Read animal data from the data source and fill the passed animal list. /// </summary> /// <param name="Animals"> /// The animal list to fill. The animals are added to any that are already in /// the list. /// </param> /// <param name="BG">The background that these animals will occupy.</param> public void GetAnimalData(cAnimalList Animals, cBackground BG) { cAnimal AnimalObj; if (Animals == null) { ThrowAnimalsException(); } if (BG == null) { ThrowBackgroundException(); } // go to the beginning of the list this.Reset(); // get subtraction factor for year of birth // this.ReadTimeRecord(ref DataYear, ref DataWeek); cAnimalAttributes NewAnimal = new cAnimalAttributes(); // loop through all animals in the list while (this.GetNextAnimalRecord(NewAnimal, BG)) { // create the new animal AnimalObj = GetNewAnimal(NewAnimal, BG); AnimalObj.ListIndex = NewAnimal.ListIndex; // read markers for this animal if datasource is of appropriate version // number if (GetVersion() > 1) { ReadMarkers(NewAnimal); AnimalObj.AutoMarker = NewAnimal.AutoMarker; AnimalObj.Marker = NewAnimal.Marker; } // add the animal to the list Animals.Add(AnimalObj); // create a new animal attributes object so that we don't load the // same data into all animals NewAnimal = new cAnimalAttributes(); // advance to the next record in the dataset this.MoveToNextRecord(); } // now reorder the list based on current list index Animals.ReorderByListIndex(); }
// private constructor for cloning private cInfection(int IncubationPeriod, int InfectiousPeriod, int Year, int Week, cDisease Disease, cBackground Background, string InfectingAnimalID) { mvarIncubationPeriod = IncubationPeriod; mvarInfectiousPeriod = InfectiousPeriod; mvarYear = Year; mvarWeek = Week; mvarDisease = Disease; mvarBackground = Background; mvarInfectingAnimalID = InfectingAnimalID; mvarIsFatal = mvarDisease.GetAnimalDies(); // EER: set the infection history if (mvarIsFatal) { mvarNaturalImmunity = "Infected_died"; } else { mvarNaturalImmunity = "Infected_recovered"; } }
// *********************** Constructor ******************************************* /// <summary> /// Initialize an Infection. /// </summary> /// <param name="Background"> /// The background object of the animal being infected. An ArgumentNullException /// exception is raised if Background is null. /// </param> /// <param name="DiseaseName"> /// The disease causing this infection. An ArgumentException exception is raised /// if DiseaseName is not the name of a disease in the Background object. /// </param> /// <param name="Year"> /// The year the infection occured. An ArgumentOutOfRangeException exception is /// raised if Year is less than zero. /// </param> /// <param name="Week"> /// The week the infection occured. An ArgumentOutOfRangeException exception is /// raised if Week is not in the range of 1-52. /// </param> /// <param name="InfectingAnimalID"> /// The ID of the animal causing the infection /// </param> /// <param name="NoIncubation"> /// If set to true, the infection will have no incubation period. The infected animal will be /// immediately infectious /// </param> /// <param name="NaturalImmunity"> /// EER: The infection history of the animal: Never_infected, Infected_died, Infected_recovered /// </param> public cInfection(cBackground Background, string DiseaseName, int Year, int Week, string InfectingAnimalID, bool NoIncubation) { // common initialization InitClass(Background, DiseaseName, Year, Week); // calculate the incubation and infectious period for this instance of the // disease if (NoIncubation) { mvarIncubationPeriod = 1; } else { mvarIncubationPeriod = mvarDisease.GetIncubationPeriod(); } mvarInfectiousPeriod = mvarDisease.GetInfectiousPeriod(); // set the InfectingAnimal mvarInfectingAnimalID = InfectingAnimalID; //System.Diagnostics.Debug.WriteLine("cInfection.cs: cInfection() 1: NaturalImmunity = " + NaturalImmunity); }
/// <summary> /// Initialize an Infection directly passing an incubation and infection period. /// </summary> /// <param name="Background"> /// The background object of the animal being infected. An ArgumentNullException /// exception is raised if Background is null. /// </param> /// <param name="DiseaseName"> /// The disease causing this infection. An ArgumentException exception is raised /// if DiseaseName is not the name of a disease in the Background object. /// </param> /// <param name="Year"> /// The year the infection occured. An ArgumentOutOfRangeException exception is /// raised if Year is less than zero. /// </param> /// <param name="Week"> /// The week the infection occured. An ArgumentOutOfRangeException exception is /// raised if Week is not in the range of 1-52. /// </param> /// <param name="IncubationPeriod"> /// The incubation period of the infection in weeks. An ArgumantOutOfRangeException /// exception is raised if IncubationPeriod is less than zero. /// </param> /// <param name="InfectiousPeriod"> /// The infectious period of the infectiion in weeks. An ArgumantOutOfRangeException /// exception is raised if IncubationPeriod is less than one. /// </param> /// <param name="NaturalImmunity"> /// EER: The infection history of the animal: Never_infected, Infected_died, Infected_recovered /// </param> public cInfection(cBackground Background, string DiseaseName, int Year, int Week, int IncubationPeriod, int InfectiousPeriod, string InfectingAnimalID) { // common initialization InitClass(Background, DiseaseName, Year, Week); // make sure that the incubation and infectious period are in range if (IncubationPeriod < 0) { ThrowIncubationPeriodException(); } if (InfectiousPeriod < 1) { ThrowInfectiousPeriodException(); } // set the Incubation and Infectious period mvarIncubationPeriod = IncubationPeriod; mvarInfectiousPeriod = InfectiousPeriod; // set the InfectingAnimal mvarInfectingAnimalID = InfectingAnimalID; // EER: set the infection history //mvarNaturalImmunity = NaturalImmunity; //System.Diagnostics.Debug.WriteLine("cInfection.cs: cInfection() 2: NaturalImmunity = " + NaturalImmunity); }
/// <summary> /// Initialize a cCull strategy. /// </summary> /// <param name="BG"> /// The background object against which this strategy shall be applied. An /// ArgumentNullException exception is raised if BG is null. /// </param> /// <param name="Cells"> /// The list of cells to which this strategy will apply. An ArgumentNullException /// exception is raised if Cells is null. An ArgumentException exception is raised /// if Cells is an empty list or if it contains cell IDs not found in the passed /// Background object (BG). /// </param> /// <param name="Level"> /// The level at with this strategy shall be applied. An ArgumentOutOfRangeException /// exception is raised if Level is not in the range of 0-100. /// </param> /// <param name="Year"> /// The year in which this strategy will be applied. An ArgumentOutOfRangeException /// exception is raised if Year is less then zero. /// </param> /// <param name="Week"> /// The week in which this strategy will be applied. An ArgumentOutOfRangeException /// exception is raised if Week is not in the range of 1-52. /// </param> public cCullStrategy(cBackground BG, cCellList Cells, double Level, int Year, int Week) : base(BG, Cells, Level, Year, Week) { }
/// <summary> /// Retrieves a single Animal record from the data source and places it in the /// passed Animal data object. /// </summary> /// <param name="Data"> /// The Animal data object that will contain the Animal data. /// </param> /// <returns> /// True if the retrieval was successful, False if there are no more records to /// retrieve. /// </returns> protected abstract bool GetNextAnimalRecord(cAnimalAttributes Data, cBackground Background);
/// <summary> /// Create a new specific animal type /// </summary> /// <param name="Animal">The animal attributes used to define the animal.</param> /// <param name="BG">The background in which the animal will live.</param> /// <returns>The new animal as a cAnimal type.</returns> protected abstract cAnimal GetNewAnimal(cAnimalAttributes NewAnimal, cBackground BG);
// ************************ Protected Members *************************************** /// <summary> /// Create a new animal in the passed background. /// </summary> /// <param name="ID">The ID of the new animal.</param> /// <param name="CellID"> /// The ID of the cell containing the new animal. /// </param> /// <param name="Background"> /// The background object that the animal will live in. /// </param> /// <param name="Gender">The gender of the new animal.</param> /// <returns>A reference to the newly created animal.</returns> protected abstract cAnimal GetNewAnimal(string ID, string CellID, cBackground Background, enumGender Gender);
// ************************ Constructors **************************************** /// <summary> /// Construct a cStrategy object by applying a strategy at the same level /// across the entire set of cells. /// </summary> /// <param name="BG"> /// The background object against which this strategy shall be applied. An /// ArgumentNullException exception is raised if BG is null. /// </param> /// <param name="Cells"> /// The list of cells to which this strategy will apply. An ArgumentNullException /// exception is raised if Cells is null. An ArgumentException exception is raised /// if Cells is an empty list or if it contains cell IDs not found in the passed /// Background object (BG). /// </param> /// <param name="Level"> /// The level at with this strategy shall be applied. An ArgumentOutOfRangeException /// exception is raised if Level is not in the range of 0-100. /// </param> /// <param name="Year"> /// The year in which this strategy will be applied. An ArgumentOutOfRangeException /// exception is raised if Year is less then zero. /// </param> /// <param name="Week"> /// The week in which this strategy will be applied. An ArgumentOutOfRangeException /// exception is raised if Week is not in the range of 1-52. /// </param> public cStrategy(cBackground BG, cCellList Cells, double Level, int Year, int Week) { InitClass(BG, Cells, Level, Year, Week); }
/// <summary> /// Construct a cStrategy object. Each cell in the strategy is given a 0% /// level value by default. /// </summary> /// <param name="BG"> /// The background object against which this strategy shall be applied. An /// ArgumentNullException exception is raised if BG is null. /// </param> /// <param name="Cells"> /// The list of cells to which this strategy will apply. An ArgumentNullException /// exception is raised if Cells is null. An ArgumentException exception is raised /// if Cells is an empty list or if it contains cell IDs not found in the passed /// Background object (BG). /// </param> /// <param name="Year"> /// The year in which this strategy will be applied. An ArgumentOutOfRangeException /// exception is raised if Year is less then zero. /// </param> /// <param name="Week"> /// The week in which this strategy will be applied. An ArgumentOutOfRangeException /// exception is raised if Week is not in the range of 1-52. /// </param> public cStrategy(cBackground BG, cCellList Cells, int Year, int Week) { InitClass(BG, Cells, 0, Year, Week); }