/// <summary> /// Selling of young stock /// </summary> /// <param name="currentDay"></param> /// <param name="curEnt"></param> protected void manageSelling(int currentDay, TEnterpriseInfo curEnt) { int g; int groups; int number; bool saleDatesInRange; if (curEnt.getYoungSaleWeight(1) <= 0.0) //if sell on a fixed date { if (curEnt.getYoungSaleFirstDay(1) == currentDay) { switch (curEnt.EntTypeFromName(curEnt.EntClass)) { case TEnterpriseInfo.TStockEnterprise.entEweWether: //self replacing //not self replacing break; case TEnterpriseInfo.TStockEnterprise.entWether: case TEnterpriseInfo.TStockEnterprise.entSteer: g = 1; groups = Count(); //store this count while (g <= groups) //for each group { if (curEnt.ContainsTag(getTag(g))) //if this group belongs to this ent { //if this group is old enough if (At(g).AgeDays >= (365.25 * curEnt.getYoungSaleFirstYears(1))) { //SplitAge(g, 365 * curEnt.YoungSaleFirstYears[1]); //split this group based on age number = At(g).NoAnimals; Sell(g, number); //sell the animals } } g++; } //next group break; } } } else { if (curEnt.getYoungSaleWtGain(1) > TEnterpriseInfo.INVALID_WTGAIN) { //sell by weight gain //for each young animal (?) //calc d_wt // //calc ave weight change //At[g].WeightChange //for each animal group //if animal group is young //sell group //endif //next animal group } else { //sell by weight within a period switch (curEnt.EntTypeFromName(curEnt.EntClass)) { case TEnterpriseInfo.TStockEnterprise.entEweWether: //self replacing //not self replacing break; case TEnterpriseInfo.TStockEnterprise.entWether: case TEnterpriseInfo.TStockEnterprise.entSteer: //check if today is in the selling date range if ((curEnt.getYoungSaleFirstDay(1) <= curEnt.getYoungSaleLastDay(1))) saleDatesInRange = ((curEnt.getYoungSaleFirstDay(1) <= currentDay) && (currentDay <= curEnt.getYoungSaleLastDay(1))); else saleDatesInRange = ((curEnt.getYoungSaleFirstDay(1) <= currentDay) || (currentDay <= curEnt.getYoungSaleLastDay(1))); if (saleDatesInRange) { g = 1; groups = Count(); while (g <= groups) //for each group { if (curEnt.ContainsTag(getTag(g))) //if this group belongs to this ent { //if this group is old enough if (At(g).AgeDays >= (365.25 * curEnt.getYoungSaleFirstYears(1))) { //check for sale condition if ((At(g).LiveWeight >= curEnt.getYoungSaleWeight(1)) || (currentDay == curEnt.getYoungSaleLastDay(1))) { number = At(g).NoAnimals; Sell(g, number); //sell the animals } } } g++; } } //in date range break; } } } }
/// <summary> /// Execute on any of the shearing dates /// Shears all on a single date OR each specified tagged group on it's day of year. /// </summary> /// <param name="currentDay"></param> /// <param name="curEnt"></param> protected void manageShearing(int currentDay, TEnterpriseInfo curEnt) { int idx, g; TShearByTag shearInfo = new TShearByTag(); if (curEnt.ShearingTagCount == 0) { if (curEnt.ShearingDate == currentDay) //if shear all { //only shear the groups in this enterprise g = 1; while (g <= Count()) //for each group { if (curEnt.ContainsTag(getTag(g))) //if this group belongs to this ent { Shear(g, true, true); //shear this group } g++; } } } else //shear each group on it's specified day { for (idx = 1; idx <= curEnt.ShearingTagCount; idx++) { curEnt.getShearingTag(idx, ref shearInfo); if (shearInfo.doy == currentDay) { if (curEnt.ContainsTag(shearInfo.tagNo)) //if this tag belongs to this ent { g = 1; while (g <= Count()) //for each group { if (getTag(g) == shearInfo.tagNo) //if this group matches the tag { Shear(g, true, true); //shear this group } g++; } } } } } }
/// <summary> /// Process the reproduction logic specified by the dialog. /// Mating, Castrating, Weaning. /// </summary> /// <param name="currentDay"></param> /// <param name="curEnt"></param> protected void manageReproduction(int currentDay, TEnterpriseInfo curEnt) { int g; int t; int tagNo; int groups; int BirthDOY; int gestation; bool found; //Mating day if (curEnt.MateDay == currentDay) { //only mate the groups in this enterprise g = 1; groups = Count(); while (g <= groups) //for each group { for (t = 1; t <= curEnt.MateTagCount; t++) //for each tag that needs to be mated { tagNo = curEnt.getMateTag(t); if ((tagNo == getTag(g)) && (curEnt.ContainsTag(getTag(g)))) //if mate this group and this group belongs to this ent { if (At(g).AgeDays >= (365 * curEnt.MateYears)) { Join(g, curEnt.MateWith, 42); setTag(g, curEnt.JoinedTag); //retag the ewes that are mated into a ewe tag group } } } g++; } } //Castrate day if (curEnt.Castrate) { if (curEnt.IsCattle) gestation = TEnterpriseInfo.COWGESTATION; else gestation = TEnterpriseInfo.EWEGESTATION; BirthDOY = StdDate.DateShift(curEnt.MateDay, gestation, 0, 0); if (StdDate.DateShift(BirthDOY, 30, 0, 0) == currentDay) //if 30 days after birth (??) { g = 1; groups = Count(); while (g <= groups) //for each group { if (curEnt.ContainsTag(getTag(g))) //if this group belongs to this ent { Castrate(g, At(g).NoAnimals); //castrate all male young in the group } g++; } } } //Weaning day if (curEnt.WeanDay == currentDay) { g = 1; groups = Count(); //store the group count because it changes while (g <= groups) //for each group { if (curEnt.ContainsTag(getTag(g))) //if this group belongs to this ent { Wean(g, At(g).NoAnimals, true, true); //wean all young in the group if (curEnt.IsCattle) DryOff(g, At(g).NoAnimals); //## may be possible to include option in user interface //retag the mothers into dry ewes tag group setTag(g, curEnt.DryTag); } g++; } //go through all the new groups and determine the new weaner tag for them for (g = groups + 1; g <= Count(); g++) { found = false; t = 1; while (!found && (t <= curEnt.MateTagCount)) { if (getTag(g) == curEnt.getMateTag(t)) found = true; //this tag belongs to a mated group t++; } if (found) { //retag the weaners if (At(g).MaleNo > 0) { setTag(g, curEnt.WeanerMTag); } //the new group will be retagged M/F if (At(g).FemaleNo > 0) { setTag(g, curEnt.WeanerFTag); } } } } }
/// <summary> /// Manage the replacement of adults by purchasing or ageing the existing stock. /// </summary> /// <param name="currentDay"></param> /// <param name="curEnt"></param> protected void manageReplacement(int currentDay, TEnterpriseInfo curEnt) { double area; int numToBuy; int totalStock; int g, groups; int groupIdx; TPurchaseInfo AnimalInfo = new TPurchaseInfo(); int yrs; TAnimalParamSet genoprms; TEnterpriseInfo.TStockEnterprise stockEnt; if (curEnt.ReplacementDay == currentDay) { area = calcStockArea(curEnt); if (area > 0) { totalStock = 0; g = 1; groups = Count(); while (g <= groups) //for each group { if (curEnt.ContainsTag(getTag(g))) //if this group belongs to this ent totalStock = totalStock + At(g).NoAnimals; g++; } numToBuy = Convert.ToInt32(Math.Truncate(curEnt.StockRateFemale * area) - totalStock); //calc how many to purchase to maintain stocking rate if (!curEnt.getPurchase(1)) //if self replacing { // tag enough young ewes as replacements // sell excess young ewes } else { stockEnt = curEnt.EntTypeFromName(curEnt.EntClass); genoprms = getGenotype(curEnt.BaseGenoType); switch (stockEnt) { case TEnterpriseInfo.TStockEnterprise.entLamb: case TEnterpriseInfo.TStockEnterprise.entWether: case TEnterpriseInfo.TStockEnterprise.entSteer: AnimalInfo.sGenotype = curEnt.BaseGenoType; AnimalInfo.Number = numToBuy; AnimalInfo.Repro = GrazType.ReproType.Castrated; AnimalInfo.AgeDays = Convert.ToInt32(Math.Truncate(MONTH2DAY * curEnt.ReplaceAge + 0.5)); AnimalInfo.LiveWt = curEnt.ReplaceWeight; AnimalInfo.GFW = 0; AnimalInfo.fCondScore = TAnimalParamSet.Condition2CondScore(curEnt.ReplaceCond); AnimalInfo.sMatedTo = ""; AnimalInfo.Preg = 0; AnimalInfo.Lact = 0; AnimalInfo.NYoung = 0; AnimalInfo.NYoung = 0; AnimalInfo.YoungWt = 0; AnimalInfo.YoungGFW = 0; if ((stockEnt == TEnterpriseInfo.TStockEnterprise.entWether) || (stockEnt == TEnterpriseInfo.TStockEnterprise.entLamb)) { AnimalInfo.GFW = genoprms.PotentialGFW * DaysFromDOY(curEnt.ShearingDate, currentDay) / 365.0; } if (AnimalInfo.Number > 0) { groupIdx = Buy(AnimalInfo); yrs = AnimalInfo.AgeDays / 365; TagGroup(curEnt, groupIdx, 1); //tag the group // {TODO: before drafting, a request of forages should be done} DraftToOpenPaddocks(curEnt, area); /* //find the first paddock to be stocked for this enterprise p = 0; while (p <= paddocks.Count - 1) do begin if curEnt.StockedPaddock[p+1] //if paddock to be stocked begin InPadd[groupIdx] = paddocks.byIndex(p).sName; //move into correct paddock p = paddocks.Count; //terminate loop end; inc(p); end; //if none found default to the first paddock if p = paddocks.Count InPadd[groupIdx] = paddocks.byIndex(0).sName; */ } break; } } } } }
/// <summary> /// There can be a number of grazing periods. Each of these can include the /// movement of any number of tag groups to any paddocks. There are two types /// of grazing period, Fixed and Flexible. /// </summary> /// <param name="currentDate"></param> /// <param name="currentDay"></param> /// <param name="curEnt"></param> protected void manageGrazing(int currentDate, int currentDay, TEnterpriseInfo curEnt) { int p; int iPaddock, iTag; int tagno; int paddockIter, tagIter; int stockedIdx; List<string> exclPaddocks; bool found; int index; //int paddchosen; //TPaddockInfo ThePadd; for (p = 1; p <= GrazingPeriods.Count(); p++) //for each grazing period { //if this period applies - within dates or within wrapped dates if (TodayIsInPeriod(currentDay, GrazingPeriods.getStartDay(p), GrazingPeriods.getFinishDay(p))) { if ((GrazingPeriods.getPeriodType(p).ToLower()) == TEnterpriseInfo.PERIOD_TEXT[TEnterpriseInfo.FIXEDPERIOD].ToLower()) //if fixed period { //move the tag groups to their paddocks //(they may already be there, although it is possible they may not be due to starting part way through the period) for (paddockIter = 1; paddockIter <= GrazingPeriods.getFixedPaddCount(p); paddockIter++) //for each paddock in this grazing period { iPaddock = GrazingPeriods.getFixedPadd(p, paddockIter); //test this paddock index for (tagIter = 1; tagIter <= GrazingPeriods.getFixedPaddTagCount(p, paddockIter); tagIter++) //for each tag group that is planned for this paddock { iTag = GrazingPeriods.getFixedPaddTag(p, paddockIter, tagIter); if (curEnt.ContainsTag(iTag)) { stockedIdx = PaddockIndexStockedByTagNo(iTag); if (iPaddock != stockedIdx) MoveTagToPaddock(iTag, iPaddock); } } } } else if (GrazingPeriods.getPeriodType(p).ToLower() == TEnterpriseInfo.PERIOD_TEXT[TEnterpriseInfo.FLEXIBLEPERIOD].ToLower()) //else if flexible { // X day intervals from the start of the period if ((GrazingPeriods.getMoveCheck(p) > 0) && (StdDate.Interval(GrazingPeriods.getStartDay(p), currentDay) % GrazingPeriods.getMoveCheck(p) == 0)) //is this the check day or day one? { if (GrazingPeriods.getCriteria(p) == CRITERIA[DRAFT_MOVE]) //else if drafting for this period then { //get the list of excluded paddocks exclPaddocks = new List<string>(); //for each tag in the GrazingPeriod for (tagIter = 1; tagIter <= GrazingPeriods.getTagCount(p); tagIter++) //for each tag { for (index = 1; index <= Paddocks.Count() - 1; index++) { found = false; paddockIter = 1; while (paddockIter <= GrazingPeriods.getTagPaddocks(p, tagIter)) //for each paddock in the GrazingPeriod { iPaddock = GrazingPeriods.getPaddock(p, tagIter, paddockIter); if (iPaddock == index) found = true; paddockIter++; } if (!found) exclPaddocks.Add(Paddocks.byIndex(index).sName); //add to the exclude list } tagno = GrazingPeriods.getTag(p, tagIter); Draft(tagno, exclPaddocks); //now do the draft only for this tagno } //next tag } } } } } //next period }
//management events described by the livestock dialog /// <summary> /// If the stock are to be managed by this component then there are tasks to /// do such as ageing animals and re-tagging them if required. /// </summary> /// <param name="currentDay"></param> /// <param name="curEnt"></param> protected void manageDailyTasks(int currentDay, TEnterpriseInfo curEnt) { int g; int mob; if (curEnt.TagUpdateDay == currentDay) //if this is a re-tagging day { //only work on the groups in this enterprise g = 1; while (g <= Count()) //for each group { if (curEnt.ContainsTag(getTag(g))) //if this group belongs to this ent { //modify the tag value for this age group for (mob = 0; mob <= MOBS - 1; mob++) { if (ENTMOBS[(int)curEnt.EntTypeFromName(curEnt.EntClass), mob].MobName != "") //for each mob in this enterprise type TagGroup(curEnt, g, mob); //tag the group } } g++; } } }
/// <summary> /// Execute for CFA selling dates /// </summary> /// <param name="currentDay"></param> /// <param name="curEnt"></param> protected void manageCFA(int currentDay, TEnterpriseInfo curEnt) { int g; int number; int groups; if (curEnt.getFirstSaleDay(1) == currentDay) { //only sell from the groups in this enterprise g = 1; groups = Count(); //store this count because it changes while (g <= groups) //for each group { if (curEnt.ContainsTag(getTag(g))) //if this group belongs to this ent { SplitAge(g, 365 * curEnt.getFirstSaleYears(1)); //split this group based on age } g++; } //loop through the groups again to pick up the new groups of aged animals g = 1; while (g <= Count()) //for each group { if (curEnt.ContainsTag(getTag(g))) //if this group belongs to this ent { //remove animals that match the age criteria if (At(g).AgeDays >= 365 * curEnt.getFirstSaleYears(1)) { number = At(g).NoAnimals; Sell(g, number); //sell the aged animals } } g++; } } }