示例#1
0
        /// <summary>
        /// Manage the initialisation of the animal groups for the enterprise.
        /// Called at the end of evtINITSTEP
        /// </summary>
        /// <param name="currentDay"></param>
        /// <param name="curEnt"></param>
        /// <param name="latitude"></param>
        protected void manageInitialiseStock(int currentDay, TEnterpriseInfo curEnt, double latitude)
        {
            double area;
            int numToBuy;
            TCohortsInfo CohortsInfo = new TCohortsInfo();
            int birthDay;
            int replaceAge;
            int ageOffset;
            int yngYrs = 0, oldYrs = 0;
            int i;
            TAnimalParamSet genoprms;
            int iBuyYears;
            int dtBuy;
            List<int> newGroups;
            int groupIdx;
            TEnterpriseInfo.TStockEnterprise stockEnt;
            double survivalRate;

            area = calcStockArea(curEnt);
            if (area > 0)
            {
                newGroups = new List<int>();
                numToBuy = Convert.ToInt32(Math.Truncate(curEnt.StockRateFemale * area));
                stockEnt = curEnt.EntTypeFromName(curEnt.EntClass);

                //calc the birth date based on age at replacement
                replaceAge = Convert.ToInt32(Math.Truncate(MONTH2DAY * curEnt.ReplaceAge + 0.5));
                ageOffset = (replaceAge + DaysFromDOY(curEnt.ReplacementDay, currentDay)) % 366;

                //get age range - from calc'd birth to CFA age
                GetAgeRange(curEnt.ReplacementDay, replaceAge, curEnt.getFirstSaleYears(1), curEnt.getFirstSaleDay(1), currentDay, ref yngYrs, ref oldYrs);
                genoprms = getGenotype(curEnt.BaseGenoType);
                if (curEnt.getPurchase(1))
                {
                    iBuyYears = curEnt.ReplaceAge / 12;
                    dtBuy = StdDate.DateVal(StdDate.DayOf(curEnt.ReplacementDay), StdDate.MonthOf(curEnt.ReplacementDay), 1900 + (iBuyYears + 1));
                    birthDay = StdDate.DateShift(dtBuy, 0, -curEnt.ReplaceAge, 0) & 0xFFFF;
                }
                else
                    birthDay = 1 + (curEnt.MateDay + 12 + genoprms.Gestation) % 365;

                survivalRate = Math.Min(1.0 - genoprms.AnnualDeaths(false), 0.999999);

                CohortsInfo.sGenotype = curEnt.BaseGenoType;
                CohortsInfo.iNumber = Convert.ToInt32(Math.Truncate(numToBuy * Math.Pow(survivalRate, ((currentDay - curEnt.ReplacementDay + 365) % 365) / 365)));
                CohortsInfo.iMinYears = yngYrs;
                CohortsInfo.iMaxYears = oldYrs;
                CohortsInfo.iAgeOffsetDays = StdDate.Interval(birthDay, currentDay);
                CohortsInfo.fMeanLiveWt = curEnt.ReplaceWeight;
                CohortsInfo.fCondScore = curEnt.ReplaceCond;

                switch (stockEnt)
                {
                    case TEnterpriseInfo.TStockEnterprise.entEweWether:

                        //setup cohorts for the females
                        CohortsInfo.ReproClass = GrazType.ReproType.Empty;   // or preg
                        CohortsInfo.fMeanGFW = genoprms.PotentialGFW * DaysFromDOY(curEnt.ShearingDate, currentDay) / 365.0;
                        CohortsInfo.iFleeceDays = DaysFromDOY365(curEnt.ShearingDate, currentDay);
                        if (curEnt.ManageReproduction)
                            CohortsInfo.sMatedTo = curEnt.MateWith;
                        else
                            CohortsInfo.sMatedTo = curEnt.BaseGenoType;
                        //        CohortsInfo.iDaysPreg =
                        /*          CohortsInfo.fFoetuses = eventData.member("foetuses").asDouble();
                                  CohortsInfo.iDaysLact = eventData.member("lactating").asInteger();
                                  CohortsInfo.fOffspring = eventData.member("offspring").asDouble();
                                  CohortsInfo.fOffspringWt = eventData.member("young_wt").asDouble();
                                  CohortsInfo.fOffspringCS = eventData.member("young_cond_score").asDouble();
                                  CohortsInfo.fLambGFW = eventData.member("young_fleece_wt").asDouble();
                          */
                        if (CohortsInfo.iNumber > 0)
                            AddCohorts(CohortsInfo, 1 + DaysFromDOY365(1, currentDay), latitude, null);

                        //tag the groups
                        for (i = 0; i <= newGroups.Count - 1; i++)
                        {
                            groupIdx = newGroups[i];
                            TagGroup(curEnt, groupIdx, 1);          //tag the group
                        }
                        DraftToOpenPaddocks(curEnt, area);        //move the groups to paddocks

                        //setup wether cohorts
                        break;
                    case TEnterpriseInfo.TStockEnterprise.entLamb:
                    case TEnterpriseInfo.TStockEnterprise.entWether:
                    case TEnterpriseInfo.TStockEnterprise.entSteer:
                        CohortsInfo.ReproClass = GrazType.ReproType.Castrated;
                        //birthday offset from the current date
                        CohortsInfo.fMeanGFW = 0;
                        CohortsInfo.iFleeceDays = 0;
                        CohortsInfo.sMatedTo = "";
                        CohortsInfo.iDaysPreg = 0;
                        CohortsInfo.fFoetuses = 0;
                        CohortsInfo.iDaysLact = 0;
                        CohortsInfo.fOffspring = 0;
                        CohortsInfo.fOffspringWt = 0;
                        CohortsInfo.fOffspringCS = 0;
                        CohortsInfo.fLambGFW = 0;
                        if ((stockEnt == TEnterpriseInfo.TStockEnterprise.entWether) || (stockEnt == TEnterpriseInfo.TStockEnterprise.entLamb))
                        {
                            CohortsInfo.fMeanGFW = genoprms.PotentialGFW * DaysFromDOY(curEnt.ShearingDate, currentDay) / 365.0;
                        }
                        if (CohortsInfo.iNumber > 0)
                            AddCohorts(CohortsInfo, currentDay, latitude, newGroups);
                        //tag the groups
                        for (i = 0; i <= newGroups.Count - 1; i++)
                        {
                            groupIdx = newGroups[i];
                            TagGroup(curEnt, groupIdx, 1);          //tag the group
                        }
                        DraftToOpenPaddocks(curEnt, area);        //move the groups to paddocks
                        break;
                    case TEnterpriseInfo.TStockEnterprise.entBeefCow:
                        break;
                    default:
                        break;
                }
                newGroups = null;
            }
        }
示例#2
0
        /// <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++;
                }
            }
        }