Exemple #1
0
        private static ISiteSelector CopySiteSelector(ISiteSelector siteSelector)
        {
            ISiteSelector siteSelectorCopy;

            if (siteSelector is CompleteStand)
            {
                siteSelectorCopy = new CompleteStand();
            }
            else if (siteSelector is PartialStandSpreading partialStandSpreading)
            {
                var minTargetSize = GetTypePrivateField <double>(partialStandSpreading, "minTargetSize");
                var maxTargetSize = GetTypePrivateField <double>(partialStandSpreading, "maxTargetSize");
                siteSelectorCopy = new PartialStandSpreading(minTargetSize, maxTargetSize);
            }
            else if (siteSelector is CompleteStandSpreading completeStandSpreading)
            {
                var minTargetSize = GetTypePrivateField <double>(completeStandSpreading, "minTargetSize");
                var maxTargetSize = GetTypePrivateField <double>(completeStandSpreading, "maxTargetSize");
                siteSelectorCopy = new CompleteStandSpreading(minTargetSize, maxTargetSize);
            }
            else if (siteSelector is PatchCutting patchCutting)
            {
                var percent      = GetTypePrivateField <double>(patchCutting, "percent");
                var patchSize    = GetTypePrivateField <double>(patchCutting, "patch_size");
                var allowOverlap = GetTypePrivateField <bool>(patchCutting, "allowOverlap");
                siteSelectorCopy = new PatchCutting(new Percentage(percent), patchSize,
                                                    allowOverlap ? "AllowOverlap" : string.Empty);
            }
            else
            {
                throw new Exception();
            }

            return(siteSelectorCopy);
        }
        //---------------------------------------------------------------------

        public Prescription(string              name,
                            IStandRankingMethod rankingMethod,
                            ISiteSelector       siteSelector,
                            ICohortSelector     cohortSelector)
        {
            this.name = name;
            this.rankingMethod = rankingMethod;
            this.siteSelector = siteSelector;
            this.cohortSelector = cohortSelector;
        }
        //---------------------------------------------------------------------

        public RepeatHarvest(string               name,
                             IStandRankingMethod  rankingMethod,
                             ISiteSelector        siteSelector,
                             ICohortSelector      cohortSelector,
                             Planting.SpeciesList speciesToPlant,
                             int                  interval)
            : base(name, rankingMethod, siteSelector, cohortSelector, speciesToPlant)
        {
            this.interval = interval;
            this.spreadingSiteSelector = siteSelector as StandSpreading;
            this.harvestedStands = new List<Stand>();
        }
        //---------------------------------------------------------------------

        public SingleRepeatHarvest(string               name,
                                   IStandRankingMethod  rankingMethod,
                                   ISiteSelector        siteSelector,
                                   ICohortSelector      cohortSelector,
                                   Planting.SpeciesList speciesToPlant,
                                   ICohortSelector      additionalCohortSelector,
                                   Planting.SpeciesList additionalSpeciesToPlant,
                                   int                  interval)
            : base(name, rankingMethod, siteSelector, cohortSelector, speciesToPlant, interval)
        {
            this.initialCohortSelector = cohortSelector;
            this.initialSpeciesToPlant = speciesToPlant;

            this.additionalCohortSelector = additionalCohortSelector;
            this.additionalSpeciesToPlant = additionalSpeciesToPlant;
        }
Exemple #5
0
        //---------------------------------------------------------------------

        public RepeatHarvest(string name,
                             IStandRankingMethod rankingMethod,
                             ISiteSelector siteSelector,
                             ICohortCutter cohortCutter,
                             Planting.SpeciesList speciesToPlant,
                             ISiteSelector additionalSiteSelector,
                             int minTimeSinceDamage,
                             bool preventEstablishment,
                             int interval)
            : base(name, rankingMethod, siteSelector, cohortCutter, speciesToPlant, minTimeSinceDamage, preventEstablishment)
        {
            this.interval = interval;
            this.spreadingSiteSelector  = siteSelector as StandSpreading;
            this.additionalSiteSelector = additionalSiteSelector;
            this.harvestedStands        = new List <Stand>();
        }
        //---------------------------------------------------------------------

        public RepeatHarvest(string               name,
                             IStandRankingMethod  rankingMethod,
                             ISiteSelector        siteSelector,
                             ICohortCutter        cohortCutter,
                             Planting.SpeciesList speciesToPlant,
                             ISiteSelector        additionalSiteSelector,
                             int                  minTimeSinceDamage,
                             bool                 preventEstablishment,
                             int                  interval)
            : base(name, rankingMethod, siteSelector, cohortCutter, speciesToPlant, minTimeSinceDamage, preventEstablishment)
        {
            this.interval = interval;
            this.spreadingSiteSelector = siteSelector as StandSpreading;
            this.additionalSiteSelector = additionalSiteSelector;
            this.harvestedStands = new List<Stand>();
        }
        //---------------------------------------------------------------------

        public Prescription(string name,
                            IStandRankingMethod rankingMethod,
                            ISiteSelector siteSelector,
                            ICohortSelector cohortSelector,
                            Planting.SpeciesList speciesToPlant,
                            int minTimeSinceDamage,
                            bool preventEstablishment)
        {
            this.number = nextNumber;
            nextNumber++;

            this.name                 = name;
            this.rankingMethod        = rankingMethod;
            this.siteSelector         = siteSelector;
            this.cohortSelector       = cohortSelector;
            this.speciesToPlant       = speciesToPlant;
            this.minTimeSinceDamage   = minTimeSinceDamage;
            this.preventEstablishment = preventEstablishment;
        }
        //---------------------------------------------------------------------
        public Prescription(string               name,
            IStandRankingMethod  rankingMethod,
            ISiteSelector        siteSelector,
            ICohortSelector      cohortSelector,
            Planting.SpeciesList speciesToPlant,
            int                  minTimeSinceDamage,
            bool                 preventEstablishment)
        {
            this.number = nextNumber;
            nextNumber++;

            this.name = name;
            this.rankingMethod = rankingMethod;
            this.siteSelector = siteSelector;
            this.cohortSelector = cohortSelector;
            this.speciesToPlant = speciesToPlant;
            this.minTimeSinceDamage = minTimeSinceDamage;
            this.preventEstablishment = preventEstablishment;
        }
        //---------------------------------------------------------------------

        public SingleRepeatHarvest(string name,
                                   IStandRankingMethod rankingMethod,
                                   ISiteSelector siteSelector,
                                   ICohortSelector cohortSelector,
                                   Planting.SpeciesList speciesToPlant,
                                   ICohortSelector additionalCohortSelector,
                                   Planting.SpeciesList additionalSpeciesToPlant,
                                   ISiteSelector additionalSiteSelector,
                                   int minTimeSinceDamage,
                                   bool preventEstablishment,
                                   int interval)
            : base(name, rankingMethod, siteSelector, cohortSelector, speciesToPlant, additionalSiteSelector, minTimeSinceDamage, preventEstablishment, interval)
        {
            this.initialCohortSelector = cohortSelector;
            this.initialSpeciesToPlant = speciesToPlant;

            this.additionalCohortSelector = additionalCohortSelector;
            this.additionalSpeciesToPlant = additionalSpeciesToPlant;
            this.additionalSiteSelector   = additionalSiteSelector;
        }
        //---------------------------------------------------------------------

        public SingleRepeatHarvest(string               name,
                                   IStandRankingMethod  rankingMethod,
                                   ISiteSelector        siteSelector,
                                   ICohortSelector      cohortSelector,
                                   Planting.SpeciesList speciesToPlant,
                                   ICohortSelector      additionalCohortSelector,
                                   Planting.SpeciesList additionalSpeciesToPlant,
                                   ISiteSelector        additionalSiteSelector,
                                   int                  minTimeSinceDamage,
                                   bool                 preventEstablishment,
                                   int                  interval)
            : base(name, rankingMethod, siteSelector, cohortSelector, speciesToPlant,additionalSiteSelector, minTimeSinceDamage, preventEstablishment, interval)
        {
            this.initialCohortSelector = cohortSelector;
            this.initialSpeciesToPlant = speciesToPlant;

            this.additionalCohortSelector = additionalCohortSelector;
            this.additionalSpeciesToPlant = additionalSpeciesToPlant;
            this.additionalSiteSelector = additionalSiteSelector;
        }
Exemple #11
0
        //---------------------------------------------------------------------

        public Prescription(string name,
                            IStandRankingMethod rankingMethod,
                            ISiteSelector siteSelector,
                            ICohortCutter cohortCutter,
                            Planting.SpeciesList speciesToPlant,
                            int minTimeSinceDamage,
                            bool preventEstablishment)
        {
            this.number = nextNumber;
            nextNumber++;

            this.name                       = name;
            this.rankingMethod              = rankingMethod;
            this.siteSelector               = siteSelector;
            this.cohortCutter               = cohortCutter;
            this.speciesToPlant             = speciesToPlant;
            this.minTimeSinceDamage         = minTimeSinceDamage;
            this.preventEstablishment       = preventEstablishment;
            this.isSingleRepeatStep         = false;
            this.isSingleRepeatPrescription = false;

            cohortCounts = new CohortCounts();
        }
Exemple #12
0
        //---------------------------------------------------------------------

        public RepeatHarvest(string name,
                             IStandRankingMethod rankingMethod,
                             ISiteSelector siteSelector,
                             ICohortCutter cohortCutter,
                             Planting.SpeciesList speciesToPlant,
                             int minTimeSinceDamage,
                             bool preventEstablishment,
                             int interval,
                             int timesToRepeat = 0)
            : base(name, rankingMethod, siteSelector, cohortCutter, speciesToPlant, minTimeSinceDamage, preventEstablishment)
        {
            this.interval = interval;
            this.spreadingSiteSelector = siteSelector as StandSpreading;
            this.harvestedStands       = new List <Stand>();

            if (timesToRepeat > 1)
            {
                this.timesToRepeat = timesToRepeat;
            }
            else
            {
                this.timesToRepeat = int.MaxValue;
            }
        }
        //---------------------------------------------------------------------

        public SiteSelectorWrapper(ISiteSelector siteSelector)
        {
            Require.ArgumentNotNull(siteSelector);
            this.originalSelector = siteSelector;
        }
        //---------------------------------------------------------------------

        public Prescription(string               name,
                            IStandRankingMethod  rankingMethod,
                            ISiteSelector        siteSelector,
                            ICohortSelector      cohortSelector,
                            Planting.SpeciesList speciesToPlant)
        {
            this.number = nextNumber;
            nextNumber++;

            this.name = name;
            this.rankingMethod = rankingMethod;
            this.siteSelector = siteSelector;
            this.cohortSelector = cohortSelector;
            this.speciesToPlant = speciesToPlant;
        }
        //---------------------------------------------------------------------

        // Wraps a site selector with a class that handles partial cohort
        // thinning.
        protected ISiteSelector WrapSiteSelector(ISiteSelector siteSelector)
        {
            if (siteSelector is BaseHarvest.CompleteStandSpreading)
                return new CompleteStandSpreading(standSpreadMinTargetSize, standSpreadMaxTargetSize);
            else if (siteSelector is BaseHarvest.PartialStandSpreading)
                return new PartialStandSpreading(standSpreadMinTargetSize, standSpreadMaxTargetSize);
            else
                return new SiteSelectorWrapper(siteSelector);
        }
Exemple #16
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Reads 0 or more prescriptions from text input.
        /// </summary>
        protected void ReadPrescriptions(List <Prescription> prescriptions,
                                         int harvestTimestep)
        {
            Dictionary <string, int> lineNumbers = new Dictionary <string, int>();

            InputVar <int> singleRepeat   = new InputVar <int>(Names.SingleRepeat);
            InputVar <int> multipleRepeat = new InputVar <int>(Names.MultipleRepeat);

            int nameLineNumber = LineNumber;
            InputVar <string> prescriptionName = new InputVar <string>(Names.Prescription);

            while (ReadOptionalVar(prescriptionName))
            {
                string name = prescriptionName.Value.Actual;
                int    lineNumber;
                if (lineNumbers.TryGetValue(name, out lineNumber))
                {
                    throw new InputValueException(prescriptionName.Value.String,
                                                  "The name {0} was previously used on line {1}",
                                                  prescriptionName.Value.String, lineNumber);
                }
                else
                {
                    lineNumbers[name] = nameLineNumber;
                }

                //get ranking method
                rankingMethod = ReadRankingMethod();

                //get stand-harvesting requirements, will modify rankingMethod variable
                ReadForestTypeTable();

                //get site selection method
                ISiteSelector siteSelector = ReadSiteSelector();

                //get the minTimeSinceDamage
                int            minTimeSinceDamage    = 0;
                InputVar <int> minTimeSinceDamageVar = new InputVar <int>("MinTimeSinceDamage");
                if (ReadOptionalVar(minTimeSinceDamageVar))
                {
                    minTimeSinceDamage = minTimeSinceDamageVar.Value;
                }

                bool preventEstablishment = ReadPreventEstablishment();

                ICohortSelector cohortSelector = ReadCohortSelector(false);
                ICohortCutter   cohortCutter   = CreateCohortCutter(cohortSelector);

                Planting.SpeciesList speciesToPlant = ReadSpeciesToPlant();

                //  Repeat harvest?
                int repeatParamLineNumber = LineNumber;
                if (ReadOptionalVar(singleRepeat))
                {
                    int interval = ValidateRepeatInterval(singleRepeat.Value,
                                                          repeatParamLineNumber,
                                                          harvestTimestep);
                    ICohortSelector      additionalCohortSelector = ReadCohortSelector(true);
                    ICohortCutter        additionalCohortCutter   = CreateCohortCutter(additionalCohortSelector);
                    Planting.SpeciesList additionalSpeciesToPlant = ReadSpeciesToPlant();
                    ISiteSelector        additionalSiteSelector   = new CompleteStand();
                    prescriptions.Add(new SingleRepeatHarvest(name,
                                                              rankingMethod,
                                                              siteSelector,
                                                              cohortCutter,
                                                              speciesToPlant,
                                                              additionalCohortCutter,
                                                              additionalSpeciesToPlant,
                                                              additionalSiteSelector,
                                                              minTimeSinceDamage,
                                                              preventEstablishment,
                                                              interval));
                }
                else if (ReadOptionalVar(multipleRepeat))
                {
                    int interval = ValidateRepeatInterval(multipleRepeat.Value,
                                                          repeatParamLineNumber,
                                                          harvestTimestep);
                    ISiteSelector additionalSiteSelector = new CompleteStand();
                    prescriptions.Add(new RepeatHarvest(name,
                                                        rankingMethod,
                                                        siteSelector,
                                                        cohortCutter,
                                                        speciesToPlant,
                                                        additionalSiteSelector,
                                                        minTimeSinceDamage,
                                                        preventEstablishment,
                                                        interval));
                }
                else
                {
                    prescriptions.Add(new Prescription(name,
                                                       rankingMethod,
                                                       siteSelector,
                                                       cohortCutter,
                                                       speciesToPlant,
                                                       minTimeSinceDamage,
                                                       preventEstablishment));
                }
            }
        }
        //---------------------------------------------------------------------

        public Prescription(string               name,
                            IStandRankingMethod  rankingMethod,
                            ISiteSelector        siteSelector,
                            ICohortSelector      cohortSelector,
                            Planting.SpeciesList speciesToPlant,
                            int                  minTimeSinceDamage,
                            bool                 preventEstablishment)
        {
            this.number = nextNumber;
            nextNumber++;

            this.name = name;
            this.rankingMethod = rankingMethod;
            this.siteSelector = siteSelector;
            this.cohortSelector = cohortSelector;
            this.speciesToPlant = speciesToPlant;
            this.minTimeSinceDamage = minTimeSinceDamage;
            this.preventEstablishment = preventEstablishment;

            // scan the name for LU-->{LU-name}
            const string LUmarker = "LU-->";
            int positionOfLUmarker = name.IndexOf(LUmarker);
            int positionOfLUname = positionOfLUmarker + LUmarker.Length;
            string LUname = name.Substring(positionOfLUname);
            this.landUseAfterHarvest = LandUse.LookupName(LUname);
        }