/// <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> /// 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; }
/// <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]]); } } } }
// 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 name of the cells data source that these animals are associated /// with. /// </summary> /// <param name="Cells">The list of cells with the name to be written.</param> protected abstract void WriteCellsName(cCellList Cells);
// ***************************** Protected Methods ********************************* /// <summary> /// Checks to see if the name of the cell data source matches the cell data /// source name stored in the animals data source. /// </summary> /// <param name="Cells">The list of cells containing the name to be checked.</param> /// <returns>True if the name match.</returns> protected abstract bool CheckCellsName(cCellList Cells);
/// <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); }
// ************************ 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); }
// ************************** Methods ******************************************* /// <summary> /// Calculate a path through a series of cells with a bias in the specified /// direction. Note, the returned path may not be as long as expected for two /// possible reasons; 1) The path encounters the boundary of the region under /// study or 2) The path attempts to cross a supercell boundary and cannot /// overcome the resistances involved to do so. /// </summary> /// <param name="StartCellID"> /// The ID of the cell at the start of the path. If if a cell with the passed ID /// is not in the list, an ArgumentException exception is raised. /// </param> /// <param name="PathLength"> /// The number of cells the path should pass through. /// </param> /// <param name="DirectionBias">The directional bias of the path.</param> /// <returns> /// A cCellList containing the cells within the path in order to the end of /// the path. The starting cell IS NOT included in this list. /// </returns> public cCellList CalculatePath(string StartCellID, int PathLength, enumNeighbourPosition DirectionBias) { cCellList Path = new cCellList(null); cCell CurrentCell = this[StartCellID]; cCell NextCell; int RanNum; enumNeighbourPosition Direction; // if requested path is zero length or less, then do nothing if (PathLength > 0) { // loop for desired path length for (int i = 0; i < PathLength; i++) { // get a Random number from the random number generator //mvarBackground.RandomNum.MinValue = 0; //mvarBackground.RandomNum.MaxValue = 100; RanNum = mvarBackground.RandomNum.IntValue(1, 100); // get a direction for the next cell based on the value of the // random number if (RanNum <= 20) { Direction = DirectionBias - 1; if (Direction < 0) { Direction += 6; } } else if (RanNum <= 80) { Direction = DirectionBias; } else { Direction = DirectionBias + 1; if ((int)Direction > 5) { Direction -= 6; } } // now try to get the neighbour. If this is a boundary cell, we can go // no further and will stop calculating the path. // is this neighbour on the boundary. If it is, break out of the loop // immediately. if (CurrentCell.IsBoundary(Direction)) { break; } // get the neighbouring cell NextCell = CurrentCell.GetNeighbour(Direction); // is the next cell in the same super group as the current cell. // If not see if we can overcome both the exiting and entering // resistances. if (NextCell.SuperCell != CurrentCell.SuperCell) { // the two cells do not share the same supercell. We must check // resistances // check out resistance of current cell. If we do not overcome it, // stop here. if (CurrentCell.SuperCell.OutResistance > 0) { //mvarBackground.RandomNum.MinValue = 0; //mvarBackground.RandomNum.MaxValue = 100; if (Background.RandomNum.IntValue(1, 100) <= CurrentCell.SuperCell.OutResistance) { break; } } // check in resistance of next cell. If we do not overcome it, // stop here if (NextCell.SuperCell.InResistance > 0) { //mvarBackground.RandomNum.MinValue = 0; //mvarBackground.RandomNum.MaxValue = 100; if (Background.RandomNum.IntValue(1, 100) <= NextCell.SuperCell.InResistance) { break; } } } // add the neigbour to our list try { Path.Add(NextCell); } catch { return(Path); } // now make next cell the current cell CurrentCell = NextCell; } } // return the calculted path return(Path); }
/// <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) { }