Esempio n. 1
0
 public ExtendedPrescription(
     HarvestManagement.Prescription prescription, ManagementArea managementArea, Percentage harvestAreaPercent,
     Percentage harvestStandsAreaPercent, int startTime, int endTime
     )
 {
     Prescription             = prescription;
     ManagementArea           = managementArea;
     HarvestAreaPercent       = harvestAreaPercent;
     HarvestStandsAreaPercent = harvestStandsAreaPercent;
     StartTime = startTime;
     EndTime   = endTime;
 }
        //---------------------------------------------------------------------
        public AppliedPrescription(Prescription prescription,
            Percentage percentageToHarvest,
            Percentage percentStandsToHarvest,
            int          beginTime,
            int          endTime)
        {
            //set prescription
            this.prescription = prescription;

            //set stand ranking method
            this.standSpreadSiteSelector = prescription.SiteSelectionMethod as StandSpreading;

            //set harvest percentage
            this.percentageToHarvest = percentageToHarvest;

            //set harvest stands percentage
            this.percentStandsToHarvest = percentStandsToHarvest;

            //set begin time and end time
            this.beginTime = beginTime;
            this.endTime = endTime;
        }
        //---------------------------------------------------------------------

        /// <summary>
        /// Adds a prescription to be applied to the management area.
        /// </summary>
        public void ApplyPrescription(Prescription prescription,
                                      Percentage   percentageToHarvest,
                                      int          startTime,
                                      int          endTime)
        {

            // tjs - 2008.12.17 - reversing if and else if so that it checks for
            // SingleRepeatHarvest. This is done because SingleRepeatHarvest
            // is a descendent of RepeatHarvest, so the RepeatHarvest condition
            // is true if prescription is SingleRepeatHarvest

            if(prescription is SingleRepeatHarvest)
            {
                AppliedRepeatHarvest appy = new AppliedRepeatHarvest((SingleRepeatHarvest) prescription,
                    percentageToHarvest,
                    startTime,
                    endTime);
                prescriptions.Add(appy);
            }
            else if (prescription is RepeatHarvest)
            {
                AppliedRepeatHarvest appy = new AppliedRepeatHarvest((RepeatHarvest)prescription, percentageToHarvest, startTime, endTime);
                prescriptions.Add(appy);
            }
            else
                prescriptions.Add(new AppliedPrescription(prescription,
                                                      percentageToHarvest,
                                                      startTime,
                                                      endTime));
        }
Esempio n. 4
0
        //---------------------------------------------------------------------

        IEnumerator <ActiveSite> IEnumerable <ActiveSite> .GetEnumerator()
        {
            // harvestable sites are thos sites that will be harvested if
            // the minTargetSize is reached
            //
            // standsToHarvest are the stands from which harvesting will
            // be done if minTargetSize is reached.
            //
            // standsToHarvestRankings holds the rankings of the stands
            // we will be harvesting.
            //
            // standsToReject are those stands immediately that
            // are not harvestable and that will be marked
            // as rejected for the current prescription name

            harvestableSites        = new Queue <ActiveSite>();
            areaSelected            = 0;
            standsToHarvest         = new Queue <Stand>();
            standsToHarvestRankings = new Queue <double>();
            standsToReject          = new List <Stand>();
            string       prescriptionName = initialStand.PrescriptionName;
            Prescription lastPrescription = initialStand.LastPrescription;

            minTimeSinceDamage = initialStand.MinTimeSinceDamage;
            this.HarvestedNeighbors.Clear();

            // Attempt to do the harvest
            if (SpreadFromStand(initialStand))
            {
                int eventId = EventId.MakeNewId();

                // loop through all harvestable stands and update
                // appropriate items
                foreach (Stand standToHarvest in standsToHarvest)
                {
                    standToHarvest.MarkAsHarvested();
                    standToHarvest.EventId            = eventId;
                    standToHarvest.PrescriptionName   = prescriptionName;
                    standToHarvest.LastPrescription   = lastPrescription;
                    standToHarvest.MinTimeSinceDamage = minTimeSinceDamage;
                    standToHarvest.HarvestedRank      = standsToHarvestRankings.Dequeue();
                    if (!(standToHarvest == initialStand))
                    {
                        this.HarvestedNeighbors.Add(standToHarvest);
                    }
                } // foreach(Stand standToHarvest in standsToHarvest)
            }
            else
            {
                // if this set of stands is not harvestable by this prescription
                // mark them all as such using the prescriptionName.

                foreach (Stand standToReject in standsToHarvest)
                {
                    //Model.Core.UI.WriteLine("Rejecting stand {0} for prescription {1}",standToReject.MapCode, prescriptionName);
                    standToReject.RejectPrescriptionName(prescriptionName);
                    standToReject.HarvestedRank = standsToHarvestRankings.Dequeue();
                } // foreach(Stand standToReject in standsToHarvest)
            }     // if(SpreadFromStand(initialStand)) ... else

            // mark all rejected stands as rejected for this
            // prescription name

            foreach (Stand standToReject in standsToReject)
            {
                //Model.Core.UI.WriteLine("Rejecting stand {0} for prescription {1}",standToReject.MapCode, prescriptionName);
                standToReject.RejectPrescriptionName(prescriptionName);
            }

            // If what was found is enough to harvest, yield it
            if (harvestableSites.Count >= minTargetSize)
            {
                while (harvestableSites.Count > 0)
                {
                    yield return(harvestableSites.Dequeue());
                }
            }
        } // IEnumerator<ActiveSite> IEnumerable<ActiveSite>.GetEnumerator()
Esempio n. 5
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Reads harvest implementations: which prescriptions are applied to
        /// which management areas.
        /// </summary>
        protected void ReadHarvestImplementations(ManagementAreaDataset mgmtAreas,
                                                  List <Prescription> prescriptions)
        {
            ReadName(Names.HarvestImplementations);

            InputVar <ushort>     mgmtAreaMapCode  = new InputVar <ushort>("Mgmt Area");
            InputVar <string>     prescriptionName = new InputVar <string>("Prescription");
            InputVar <int>        beginTimeVar     = new InputVar <int>("Begin Time");
            InputVar <int>        endTimeVar       = new InputVar <int>("End Time");
            InputVar <Percentage> areaToHarvest    = new InputVar <Percentage>("Area To Harvest");

            while (!AtEndOfInput && CurrentName != Names.PrescriptionMaps)
            {
                StringReader currentLine = new StringReader(CurrentLine);

                //  Mgmt Area column
                ReadValue(mgmtAreaMapCode, currentLine);
                ushort         mapCode  = mgmtAreaMapCode.Value.Actual;
                ManagementArea mgmtArea = mgmtAreas.Find(mapCode);
                if (mgmtArea == null)
                {
                    //add the management area, and add it to the collection of management areas
                    mgmtArea = new ManagementArea(mapCode);
                    mgmtAreas.Add(mgmtArea);
                }

                //  Prescription column
                ReadValue(prescriptionName, currentLine);
                string       name         = prescriptionName.Value.Actual;
                Prescription prescription = prescriptions.Find(new MatchName(name).Predicate);
                if (prescription == null)
                {
                    throw new InputValueException(prescriptionName.Value.String,
                                                  prescriptionName.Value.String + " is an unknown prescription name");
                }



                //  Area to Harvest column
                ReadValue(areaToHarvest, currentLine);
                //get percentage to harvest (type Percentage ensures that it is in percent format)
                Percentage percentageToHarvest = areaToHarvest.Value.Actual;
                //check for valid percentage
                if (percentageToHarvest <= 0.0 || percentageToHarvest > 1.0)
                {
                    throw new InputValueException(areaToHarvest.Value.String,
                                                  "Percentage must be between 0% and 100%");
                }

                //  Begin Time and End Time columns
                //  They are optional, so the possibilities are:
                //
                //          Begin Time   End Time
                //          ----------   --------
                //      1)   present     present
                //      2)   present     missing
                //      3)   missing     missing

                //  The default values for the starting and ending times for
                //  an applied prescription.
                int beginTime = scenarioStart;
                int endTime   = scenarioEnd;

                TextReader.SkipWhitespace(currentLine);
                if (currentLine.Peek() != -1)
                {
                    ReadValue(beginTimeVar, currentLine);
                    beginTime = beginTimeVar.Value.Actual;
                    if (beginTime < scenarioStart)
                    {
                        throw new InputValueException(beginTimeVar.Value.String,
                                                      string.Format("Year {0} is before the scenario start year ({1})",
                                                                    beginTimeVar.Value.String,
                                                                    scenarioStart));
                    }
                    if (beginTime > scenarioEnd)
                    {
                        //throw new InputValueException(beginTimeVar.Value.String,
                        //                              string.Format("Year {0} is after the scenario' end year ({1})",
                        //                                            beginTimeVar.Value.String,
                        //                                            scenarioEnd));
                        string        line1    = string.Format("   NOTE: Begin year {0} is after the scenario' end year {1}", beginTimeVar.Value.String, scenarioEnd);
                        string        line2    = string.Format("         on line {0} of the harvest input file...", LineNumber);
                        List <string> noteList = new List <string>();
                        noteList.Add(line1);
                        noteList.Add(line2);
                        parserNotes.Add(noteList);
                    }

                    TextReader.SkipWhitespace(currentLine);
                    if (currentLine.Peek() != -1)
                    {
                        ReadValue(endTimeVar, currentLine);
                        endTime = endTimeVar.Value.Actual;
                        if (endTime < beginTime)
                        {
                            throw new InputValueException(endTimeVar.Value.String,
                                                          string.Format("Year {0} is before the Begin Time ({1})",
                                                                        endTimeVar.Value.String,
                                                                        beginTimeVar.Value.String));
                        }
                        if (endTime > scenarioEnd)
                        {
                            //    throw new InputValueException(endTimeVar.Value.String,
                            //                                  string.Format("Year {0} is after the scenario' end year ({1})",
                            //                                                endTimeVar.Value.String,
                            //                                                scenarioEnd));

                            string        line1    = string.Format("   NOTE: End Year {0} is after the scenario' end year {1}", endTimeVar.Value.String, scenarioEnd);
                            string        line2    = string.Format("         on line {0} of the harvest input file...", LineNumber);
                            List <string> noteList = new List <string>();
                            noteList.Add(line1);
                            noteList.Add(line2);
                            parserNotes.Add(noteList);
                        }

                        CheckNoDataAfter("the " + endTimeVar.Name + " column",
                                         currentLine);
                    }
                }


                //if the perscription has already been applied to this management area
                //NOTE: .IsApplied has been modified, and this has been moved to AFTER the
                //begin and end times are founded.
                if (mgmtArea.IsApplied(prescriptionName.Value.String, beginTime, endTime))
                {
                    throw new InputValueException(prescriptionName.Value.String,
                                                  "Prescription {0} has already been applied to management area {1} with begin time = {2} and end time = {3}",
                                                  prescriptionName.Value.String, mgmtArea.MapCode, beginTime, endTime);
                }

                //begin applying prescription to this management area
                mgmtArea.ApplyPrescription(prescription,
                                           percentageToHarvest,
                                           beginTime,
                                           endTime);



                CheckNoDataAfter("the " + prescriptionName.Name + " column",
                                 currentLine);
                GetNextLine();
            }
        }
Esempio n. 6
0
            //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

            public bool Predicate(Prescription prescription)
            {
                return(prescription.Name == name);
            }
        //---------------------------------------------------------------------

        /// <summary>
        /// Reads harvest implementations: which prescriptions are applied to
        /// which management areas.
        /// </summary>
        protected void ReadHarvestImplementations(ManagementAreaDataset mgmtAreas,
                                                  List <Prescription> prescriptions)
        {
            ReadName(Names.HarvestImplementations);

            InputVar <ushort>     mgmtAreaMapCode  = new InputVar <ushort>("Mgmt Area");
            InputVar <string>     prescriptionName = new InputVar <string>("Prescription");
            InputVar <int>        beginTimeVar     = new InputVar <int>("Begin Time");
            InputVar <int>        endTimeVar       = new InputVar <int>("End Time");
            InputVar <Percentage> areaToHarvest    = new InputVar <Percentage>("Area To Harvest");
            InputVar <Percentage> standsToHarvest  = new InputVar <Percentage>("Stands To Harvest");
            StringReader          sr100            = new StringReader("100%");

            while (!AtEndOfInput && CurrentName != Names.PrescriptionMaps)
            {
                StringReader currentLine = new StringReader(CurrentLine);

                //  Mgmt Area column
                ReadValue(mgmtAreaMapCode, currentLine);
                ushort         mapCode  = mgmtAreaMapCode.Value.Actual;
                ManagementArea mgmtArea = mgmtAreas.Find(mapCode);
                if (mgmtArea == null)
                {
                    //add the management area, and add it to the collection of management areas
                    mgmtArea = new ManagementArea(mapCode);
                    mgmtAreas.Add(mgmtArea);
                }

                //  Prescription column
                ReadValue(prescriptionName, currentLine);
                string       name         = prescriptionName.Value.Actual;
                Prescription prescription = prescriptions.Find(new MatchName(name).Predicate);
                if (prescription == null)
                {
                    throw new InputValueException(prescriptionName.Value.String,
                                                  prescriptionName.Value.String + " is an unknown prescription name");
                }


                TextReader.SkipWhitespace(currentLine);
                //  Area to Harvest column
                string strVal = TextReader.ReadWord(currentLine);
                sr100 = new StringReader("100%");
                //If the keyword 'Stands' is attached to the area %, then applies to % of stands to harvest instead of area
                if (strVal.Contains("Stands"))
                {
                    char[]       trimChar = { 'S', 't', 'a', 'n', 'd', 's' };
                    string       clipText = strVal.TrimEnd(trimChar);
                    StringReader testRead = new StringReader(clipText);
                    ReadValue(standsToHarvest, testRead);
                    ReadValue(areaToHarvest, sr100);
                }
                else
                {
                    StringReader testRead = new StringReader(strVal);
                    //  Area to Harvest column
                    ReadValue(areaToHarvest, testRead);
                    ReadValue(standsToHarvest, sr100);
                }
                //get percentage to harvest (type Percentage ensures that it is in percent format)
                Percentage percentageToHarvest = areaToHarvest.Value.Actual;
                //check for valid percentage
                if (percentageToHarvest <= 0.0 || percentageToHarvest > 1.0)
                {
                    throw new InputValueException(areaToHarvest.Value.String,
                                                  "Percentage must be between 0% and 100%");
                }
                //get percentage of stands to harvest (type Percentage ensures that it is in percent format)
                Percentage percentStandsToHarvest = standsToHarvest.Value.Actual;
                //check for valid percentage
                if (percentStandsToHarvest <= 0.0 || percentStandsToHarvest > 1.0)
                {
                    throw new InputValueException(standsToHarvest.Value.String,
                                                  "Percentage must be between 0% and 100%");
                }

                //  Begin Time and End Time columns
                //  They are optional, so the possibilities are:
                //
                //          Begin Time   End Time
                //          ----------   --------
                //      1)   present     present
                //      2)   present     missing
                //      3)   missing     missing

                //  The default values for the starting and ending times for
                //  an applied prescription.
                int beginTime = scenarioStart;
                int endTime   = scenarioEnd;

                TextReader.SkipWhitespace(currentLine);
                if (currentLine.Peek() != -1)
                {
                    ReadValue(beginTimeVar, currentLine);
                    beginTime = beginTimeVar.Value.Actual;
                    if (beginTime < scenarioStart)
                    {
                        throw new InputValueException(beginTimeVar.Value.String,
                                                      string.Format("Year {0} is before the scenario start year ({1})",
                                                                    beginTimeVar.Value.String,
                                                                    scenarioStart));
                    }
                    if (beginTime > scenarioEnd)
                    {
                        throw new InputValueException(beginTimeVar.Value.String,
                                                      string.Format("Year {0} is after the scenario' end year ({1})",
                                                                    beginTimeVar.Value.String,
                                                                    scenarioEnd));
                    }

                    TextReader.SkipWhitespace(currentLine);
                    if (currentLine.Peek() != -1)
                    {
                        ReadValue(endTimeVar, currentLine);
                        endTime = endTimeVar.Value.Actual;
                        if (endTime < beginTime)
                        {
                            throw new InputValueException(endTimeVar.Value.String,
                                                          string.Format("Year {0} is before the Begin Time ({1})",
                                                                        endTimeVar.Value.String,
                                                                        beginTimeVar.Value.String));
                        }
                        if (endTime > scenarioEnd)
                        {
                            throw new InputValueException(endTimeVar.Value.String,
                                                          string.Format("Year {0} is after the scenario' end year ({1})",
                                                                        endTimeVar.Value.String,
                                                                        scenarioEnd));
                        }

                        CheckNoDataAfter("the " + endTimeVar.Name + " column",
                                         currentLine);
                    }
                }


                //if the perscription has already been applied to this management area
                //NOTE: .IsApplied has been modified, and this has been moved to AFTER the
                //begin and end times are founded.
                if (mgmtArea.IsApplied(prescriptionName.Value.String, beginTime, endTime))
                {
                    throw new InputValueException(prescriptionName.Value.String,
                                                  "Prescription {0} has already been applied to management area {1} with begin time = {2} and end time = {3}",
                                                  prescriptionName.Value.String, mgmtArea.MapCode, beginTime, endTime);
                }

                //begin applying prescription to this management area
                mgmtArea.ApplyPrescription(prescription,
                                           percentageToHarvest,
                                           percentStandsToHarvest,
                                           beginTime,
                                           endTime);



                CheckNoDataAfter("the " + prescriptionName.Name + " column",
                                 currentLine);
                GetNextLine();
            }
        }