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