// a private common initilization function
 private void InitClass(string ID, cSuperCell SuperCell, double K, double XLoc,
                        double YLoc)
 {
     // check the parameters to make sure that they are valid.  Throw exceptions if
     // they are not.
     // ID must not be 0 length.
     if (ID.Length == 0)
     {
         throw new ArgumentException("ID must not be an empty string.", "ID");
     }
     // SuperCell must be a valid reference
     if (SuperCell == null)
     {
         ThrowSuperCellException();
     }
     // K must be greater than or equal to 0
     if (K < 0)
     {
         ThrowKException();
     }
     // set the ID value and K
     mvarID = ID;
     mvarK  = K;
     // add this cell to the supercell
     SuperCell.Add(this);
     // set the x,y location
     mvarXLoc = XLoc;
     mvarYLoc = YLoc;
     // create the neighbours array
     mvarNeighbours = new cCell[6];
     // create the list of animals
     mvarAnimals = new cAnimalList(null);
 }
Esempio 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");
 }
Esempio n. 3
0
        /// <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);
                }
            }
        }
Esempio n. 4
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);
 }
        /// <summary>
        ///		Add the babies stored in the Babies list to the main list.  This is an
        ///		internal method that may only be called by classes in the Rabies_Model_Core
        ///		namespace.
        /// </summary>
        /// <param name="EHandler">An event handler for the AnimalInfected event.</param>
        internal void AddBabiesToList(AnimalInfectedEventHandler EHandler)
        {
            //System.Diagnostics.Debug.WriteLine("");
            //System.Diagnostics.Debug.WriteLine("cMasterAnimalList.cs: AddBabiesToList()");

            if (Babies.Count > 0)
            {
                // loop through all animals in the babies list
                foreach (cAnimal BabyAnimal in Babies)
                {
                    // set the event handler
                    if (EHandler != null)
                    {
                        BabyAnimal.AnimalInfected += EHandler;
                    }
                    // add to main list
                    this.Add(BabyAnimal);
                    // add to all animals list
                    if (mvarKeepAllAnimals)
                    {
                        AllAnimals.Add(BabyAnimal);
                    }
                }
                // destroy this version of the BabyAnimal list and create a new one
                Babies = new cAnimalList(null);
            }
        }
 /// <summary>
 ///		Constructor - set all values
 /// </summary>
 /// <param name="StartAt">The position in the list (EER: of animals) to start running</param>
 /// <param name="EndAt">The position in the list (EER: of animals) to stop running</param>
 /// <param name="Animals">A reference to the list of animals</param>
 /// <param name="CurrentWeek">The current week of the year</param>
 /// <param name="PreventIncest">A flag that prevents siblings from mating if set to true</param>
 public cWeeklyActivityThread(int StartAt, int EndAt, cAnimalList Animals, int CurrentWeek, bool PreventIncest)
 {
     mvarStartAt       = StartAt;
     mvarEndAt         = EndAt;
     mvarCurrentWeek   = CurrentWeek;
     mvarAnimals       = Animals;
     mvarPreventIncest = PreventIncest;
 }
 // ******************* Constructors *********************************************
 /// <summary>
 ///		Initialize a Master animal list.
 /// </summary>
 /// <param name="Background">
 ///		The background object that owns this master list.  An ArgumentNullEception
 ///		exception is raised if Background is null.
 ///	</param>
 /// <param name="StartingID">
 ///		The numeric value of the first animal ID generated when the model is run.
 ///	</param>
 ///	<param name="KeepAllAnimals">
 ///		A flag indicating whether animals should remain in the database after they
 ///		die.
 ///	</param>
 /// <param name="ScrambleRandom">A random number generator to use if the list is to be scrambled</param>
 public cMasterAnimalList(int StartingID, bool KeepAllAnimals, cUniformRandom ScrambleRandom)
     : base(ScrambleRandom)
 {
     mvarIDManager        = new cIDManager(StartingID);
     mvarIDManager.Prefix = "";
     mvarIDManager.Suffix = "";
     mvarKeepAllAnimals   = KeepAllAnimals;
     if (mvarKeepAllAnimals)
     {
         mvarAllAnimals = new cAnimalList(ScrambleRandom);
     }
     Babies = new cAnimalList(null);
 }
Esempio n. 8
0
        /// <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();
        }
Esempio n. 9
0
        public int GetCountbyAgeGender(int AgeinYear, enumGender Gender)
        {
            cAnimalList Animals = this.GetByGender(Gender);
            int         count   = 0;

            foreach (cAnimal anim in Animals)
            {
                int AgeInYears = Convert.ToInt32(Math.Floor((double)anim.Age / 52));
                //Console.WriteLine("AgeInYears {0} et i {1}", AgeInYears, i);
                if (AgeInYears == AgeinYear)
                {
                    count++;
                }
            }
            return(count);
        }
Esempio n. 10
0
        /// <summary>
        ///		Get a sub-list of all animals of a particular age class.
        /// </summary>
        /// <param name="AgeClass">The age class of interest.</param>
        /// <returns>A cAnimalList containing the sub-list.</returns>
        public cAnimalList GetByAgeClass(enumAgeClass AgeClass)
        {
            // create a new cAnimalList
            cAnimalList NewList = new cAnimalList(null);

            // loop through the entire list adding those animals of the selected age class
            // to the new list.
            foreach (cAnimal Animal in Values)
            {
                if (Animal.AgeClass == AgeClass)
                {
                    NewList.Add(Animal);
                }
            }
            // return the newly created list
            return(NewList);
        }
Esempio n. 11
0
        /// <summary>
        ///		Get a sub-list of all animals of a particular gender.
        /// </summary>
        /// <param name="Gender">The gender of interest.</param>
        /// <returns>A cAnimalList containing the sub-list.</returns>
        public cAnimalList GetByGender(enumGender Gender)
        {
            // create a new cAnimalList
            cAnimalList NewList = new cAnimalList(null);

            // loop through the entire list adding those animals of the selected gender
            // to the new list.
            foreach (cAnimal Animal in this)
            {
                if (Animal.Gender == Gender)
                {
                    NewList.Add(Animal);
                }
            }
            // return the newly created list
            return(NewList);
        }
Esempio n. 12
0
        /// <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();
        }
 /// <summary>
 ///		Add the babies stored in the Babies list to the main list.  This is an
 ///		internal method that may only be called by classes in the Rabies_Model_Core
 ///		namespace.
 /// </summary>
 internal void AddBabiesToList()
 {
     if (Babies.Count > 0)
     {
         // loop through all animals in the babies list
         foreach (cAnimal BabyAnimal in Babies)
         {
             // add to main list
             this.Add(BabyAnimal);
             // add to all animals list
             if (mvarKeepAllAnimals)
             {
                 AllAnimals.Add(BabyAnimal);
             }
         }
         // destroy this version of the BabyAnimal list and create a new one
         Babies = new cAnimalList(null);
     }
 }
        /// <summary>
        /// //YM:
        /// Select the animal that will die in the current week according their age and the annual mortality rate
        /// </summary>
        public void SelectWillDieAnimal()
        {
            // Female
            cAnimalList FemaleAnimal = new cAnimalList(null);

            FemaleAnimal = this.Animals.GetByGender(enumGender.female);
            //Console.WriteLine("nb female :" + FemaleAnimal.Count);
            // create the list of animals with the same age
            for (int i = 0; i <= 7; i++)
            {
                //int count = 0;
                cAnimalList ListAnimalAge = new cAnimalList(null);
                foreach (cAnimal anim in FemaleAnimal)
                {
                    int AgeInYears = Convert.ToInt32(Math.Floor((double)anim.Age / 52));
                    //Console.WriteLine("AgeInYears {0} et i {1}", AgeInYears, i);
                    if (AgeInYears == i)
                    {
                        ListAnimalAge.Add(anim);
                        //FemaleAnimal.Remove(anim.ID);
                        //count++;
                    }
                }
                //Console.WriteLine("nb female {0} ans : {1}, count {2}", i, ListAnimalAge.Count, count);
                //Select randomly the will-die-animal in the ListAnimalAge
                int CountAnimalWillDiePrecise = Convert.ToInt32(Math.Floor(ListAnimalAge.Count * FemaleMortality[i] / 52));
                int MaxValue = Convert.ToInt32(Math.Floor(CountAnimalWillDiePrecise + CountAnimalWillDiePrecise * 0.05));
                int MinValue = Convert.ToInt32(Math.Floor(CountAnimalWillDiePrecise - CountAnimalWillDiePrecise * 0.05));
                // Select a number close to the count of will-die animals
                int CountAnimalWillDie = this.RandomNum.IntValue(MaxValue, MinValue);
                // For each age, select randomly the list of will-die animal
                for (int j = 0; j < CountAnimalWillDie; j++)
                {
                    int RanNum = this.RandomNum.IntValue(0, CountAnimalWillDie - 1);
                    if (ListAnimalAge[RanNum].WillDie)
                    {
                        if (ListAnimalAge[RanNum].WillDie)
                        {
                            do
                            {
                                RanNum = this.RandomNum.IntValue(0, CountAnimalWillDie - 1);
                            } while (!ListAnimalAge[RanNum].WillDie);
                            ListAnimalAge[RanNum].WillDie = true;
                        }
                        else
                        {
                            ListAnimalAge[RanNum].WillDie = true;
                        }
                    }
                    //ListAnimalAge[j].WillDie = true;
                }
                //Console.WriteLine("{0};{1};{2};{3};{4};{5};{6};{7}", Years.CurrentYearNum, Years.CurrentYear.CurrentWeek, enumGender.female, i, ListAnimalAge.Count, FemaleMortality[i], FemaleMortality[i]/52, CountAnimalWillDie);
            }



            // Male
            cAnimalList MaleAnimal = new cAnimalList(null);

            MaleAnimal = this.Animals.GetByGender(enumGender.male);
            // create the list of animals with the same age
            //Console.WriteLine("nb male :" + MaleAnimal.Count);
            for (int i = 0; i <= 7; i++)
            {
                cAnimalList ListAnimalAge = new cAnimalList(null);
                foreach (cAnimal anim in MaleAnimal)
                {
                    int AgeInYears = Convert.ToInt32(Math.Floor((double)anim.Age / 52));
                    if (AgeInYears == i)
                    {
                        ListAnimalAge.Add(anim);
                        //MaleAnimal.Remove(anim.ID);
                    }
                }
                //Console.WriteLine("nb male {0} ans : {1}", i, ListAnimalAge.Count);
                //Select randomly the will-die-animal in the ListAnimalAge
                int CountAnimalWillDiePrecise = Convert.ToInt32(Math.Floor(ListAnimalAge.Count * MaleMortality[i] / 52));
                int MaxValue = Convert.ToInt32(Math.Floor(CountAnimalWillDiePrecise + CountAnimalWillDiePrecise * 0.1));
                int MinValue = Convert.ToInt32(Math.Floor(CountAnimalWillDiePrecise - CountAnimalWillDiePrecise * 0.1));
                // Select a number close to the count of will-die animals
                int CountAnimalWillDie = this.RandomNum.IntValue(MaxValue, MinValue);
                // For each age, select randomly the list of will-die animal
                for (int j = 0; j < CountAnimalWillDie; j++)
                {
                    int RanNum = this.RandomNum.IntValue(0, CountAnimalWillDie - 1);
                    if (ListAnimalAge[RanNum].WillDie)
                    {
                        do
                        {
                            RanNum = this.RandomNum.IntValue(0, CountAnimalWillDie - 1);
                        } while (!ListAnimalAge[RanNum].WillDie);
                        ListAnimalAge[RanNum].WillDie = true;
                    }
                    else
                    {
                        ListAnimalAge[RanNum].WillDie = true;
                    }
                    //ListAnimalAge[j].WillDie = true;
                }
                //Console.WriteLine("{0};{1};{2};{3};{4};{5};{6};{7}", Years.CurrentYearNum, Years.CurrentYear.CurrentWeek, enumGender.male, i, ListAnimalAge.Count, MaleMortality[i], MaleMortality[i] / 52, CountAnimalWillDie);
            }
        }