/// <summary> /// Remove individual/cohort from the herd /// </summary> /// <param name="ind">Individual Ruminant to remove</param> public void RemoveRuminant(Ruminant ind) { // Remove mother ID from any suckling offspring if (ind.Gender == Sex.Female) { foreach (var offspring in (ind as RuminantFemale).SucklingOffspring) { offspring.Mother = null; } } Herd.Remove(ind); LastIndividualChanged = ind; ResourceTransaction details = new ResourceTransaction(); details.Debit = -1; details.Activity = "Unknown"; details.Reason = "Unknown"; details.ResourceType = this.Name; details.ExtraInformation = ind; LastTransaction = details; TransactionEventArgs te = new TransactionEventArgs() { Transaction = details }; OnTransactionOccurred(te); // HerdChanged(new EventArgs()); // remove change flag ind.SaleFlag = Common.HerdChangeReason.None; }
/// <summary> /// Add individual/cohort to the the herd /// </summary> /// <param name="ind">Individual Ruminant to add</param> public void AddRuminant(Ruminant ind) { if (ind.ID == 0) { ind.ID = this.NextUniqueID; } Herd.Add(ind); LastIndividualChanged = ind; ResourceTransaction details = new ResourceTransaction(); details.Credit = 1; details.Activity = "Unknown"; details.Reason = "Unknown"; details.ResourceType = this.Name; details.ExtraInformation = ind; LastTransaction = details; TransactionEventArgs te = new TransactionEventArgs() { Transaction = details }; OnTransactionOccurred(te); // HerdChanged(new EventArgs()); // remove change flag ind.SaleFlag = Common.HerdChangeReason.None; }
/// <summary> /// Create the individual ruminant animals using the Cohort parameterisations. /// </summary> /// <returns></returns> public List <Ruminant> CreateIndividuals() { List <Ruminant> Individuals = new List <Ruminant>(); IModel parentNode = Apsim.Parent(this, typeof(IModel)); RuminantType parent = parentNode as RuminantType; // get Ruminant Herd resource for unique ids RuminantHerd ruminantHerd = Resources.RuminantHerd(); parent = this.Parent as RuminantType; if (StartingNumber > 0) { //TODO: get random generator from global store with seed Random rand = new Random(); for (int i = 1; i <= StartingNumber; i++) { object ruminantBase = null; if (this.Gender == Sex.Male) { ruminantBase = new RuminantMale(); } else { ruminantBase = new RuminantFemale(); } Ruminant ruminant = ruminantBase as Ruminant; ruminant.ID = ruminantHerd.NextUniqueID; ruminant.BreedParams = parent; ruminant.Breed = parent.Breed; ruminant.HerdName = parent.Name; ruminant.Gender = Gender; ruminant.Age = StartingAge; ruminant.SaleFlag = Common.HerdChangeReason.None; if (Suckling) { ruminant.SetUnweaned(); } double u1 = rand.NextDouble(); double u2 = rand.NextDouble(); double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * Math.Sin(2.0 * Math.PI * u2); ruminant.Weight = StartingWeight + StartingWeightSD * randStdNormal; ruminant.PreviousWeight = ruminant.Weight; if (this.Gender == Sex.Female) { RuminantFemale ruminantFemale = ruminantBase as RuminantFemale; ruminantFemale.DryBreeder = true; ruminantFemale.WeightAtConception = this.StartingWeight; ruminantFemale.NumberOfBirths = 0; } Individuals.Add(ruminantBase as Ruminant); } } return(Individuals); }