コード例 #1
0
ファイル: GetStandFromPlot.cs プロジェクト: OSU-MARS/SEEM
        protected override void ProcessRecord()
        {
            PlotsWithHeight plot;

            if (this.ExpansionFactor.HasValue)
            {
                plot = new PlotsWithHeight(this.Plots !, this.ExpansionFactor.Value);
            }
            else
            {
                plot = new PlotsWithHeight(this.Plots !);
            }
            plot.Read(this.Xlsx !, this.XlsxSheet);

            OrganonConfiguration configuration = new OrganonConfiguration(OrganonVariant.Create(this.Model));
            OrganonStand         stand;

            if (this.Trees.HasValue)
            {
                stand = plot.ToOrganonStand(configuration, this.Age, this.SiteIndex, this.Trees.Value);
            }
            else
            {
                stand = plot.ToOrganonStand(configuration, this.Age, this.SiteIndex);
            }
            if (this.PlantingDensity.HasValue)
            {
                stand.PlantingDensityInTreesPerHectare = this.PlantingDensity.Value;
            }
            this.WriteObject(stand);
        }
コード例 #2
0
ファイル: GetStandTrajectory.cs プロジェクト: OSU-MARS/SEEM
        protected override void ProcessRecord()
        {
            if (this.ThinPeriod > this.HarvestPeriods)
            {
                throw new ArgumentOutOfRangeException(nameof(this.ThinPeriod));
            }

            OrganonConfiguration configuration = new OrganonConfiguration(new OrganonVariantNwo());

            if (this.ThinPeriod > 0)
            {
                configuration.Treatments.Harvests.Add(new ThinByPrescription(this.ThinPeriod)
                {
                    FromAbovePercentage    = this.ThinFromAbovePercentage,
                    ProportionalPercentage = this.ProportionalThinPercentage,
                    FromBelowPercentage    = this.ThinFromBelowPercentage
                });
            }

            OrganonStandTrajectory trajectory = new OrganonStandTrajectory(this.Stand !, configuration, this.TimberValue, this.PlanningPeriods, this.ScaledVolume);

            if (this.Name != null)
            {
                trajectory.Name = this.Name;
            }

            trajectory.Simulate();
            this.WriteObject(trajectory);
        }
コード例 #3
0
 public RandomGuessing(OrganonStand stand, OrganonConfiguration configuration, Objective objective, HeuristicParameters parameters)
     : base(stand, configuration, objective, parameters)
 {
     this.CentralSelectionPercentage = parameters.ProportionalPercentage;
     this.Iterations = 4 * stand.GetTreeRecordCount();
     this.SelectionPercentageWidth = 20.0F;
 }
コード例 #4
0
ファイル: OrganonVariantRap.cs プロジェクト: OSU-MARS/SEEM
        public override float GetGrowthEffectiveAge(OrganonConfiguration configuration, OrganonStand stand, Trees trees, int treeIndex, out float potentialHeightGrowth)
        {
            float growthEffectiveAge;

            if (trees.Species == FiaCode.AlnusRubra)
            {
                // GROWTH EFFECTIVE AGE AND POTENTIAL HEIGHT GROWTH FROM WEISKITTEL, HANN, HIBBS, LAM, AND BLUHM (2009) RED ALDER TOP HEIGHT GROWTH
                float siteIndexFromGround = stand.SiteIndex + 4.5F;
                RedAlder.WHHLB_HG(siteIndexFromGround, configuration.PDEN, trees.Height[treeIndex], 1.0F, out growthEffectiveAge, out potentialHeightGrowth);
            }
            else if (trees.Species == FiaCode.TsugaHeterophylla)
            {
                // POTENTIAL HEIGHT GROWTH FROM FLEWELLING'S WESTERN HEMLOCK DOMINANT HEIGHT GROWTH
                // BUGBUG: why isn't redcedar also on this code path?
                float siteIndexFromGround             = OrganonVariantNwo.ToHemlockSiteIndexStatic(stand.HemlockSiteIndex); // stand.HemlockSiteIndex is interpreted as PSME site index
                WesternHemlock.SiteConstants tsheSite = new WesternHemlock.SiteConstants(siteIndexFromGround);
                growthEffectiveAge = WesternHemlock.GetFlewellingGrowthEffectiveAge(tsheSite, this.TimeStepInYears, trees.Height[treeIndex], out potentialHeightGrowth);
            }
            else
            {
                // POTENTIAL HEIGHT GROWTH FROM BRUCE'S (1981) DOMINANT HEIGHT GROWTH FOR DOUGLAS-FIR AND GRAND FIR
                DouglasFir.SiteConstants psmeSite = new DouglasFir.SiteConstants(stand.HemlockSiteIndex); // stand.HemlockSiteIndex is interpreted as PSME site index
                growthEffectiveAge = DouglasFir.GetBrucePsmeAbgrGrowthEffectiveAge(psmeSite, this.TimeStepInYears, trees.Height[treeIndex], out potentialHeightGrowth);
            }
            return(growthEffectiveAge);
        }
コード例 #5
0
ファイル: OptimizePrescription.cs プロジェクト: OSU-MARS/SEEM
 protected override Heuristic CreateHeuristic(OrganonConfiguration organonConfiguration, Objective objective, PrescriptionParameters parameters)
 {
     if (this.BestOf != 1)
     {
         throw new NotSupportedException(nameof(this.BestOf)); // enumeration is deterministic, so no value in repeated runs
     }
     return(new PrescriptionEnumeration(this.Stand !, organonConfiguration, objective, parameters));
 }
コード例 #6
0
 public static void ReduceExpansionFactors(OrganonConfiguration configuration, int simulationStep, OrganonStand stand, OrganonStandDensity densityBeforeGrowth)
 {
     foreach (Trees treesOfSpecies in stand.TreesBySpecies.Values)
     {
         FiaCode species = treesOfSpecies.Species;
         float   fertilizationExponent = OrganonMortality.GetMortalityFertilizationAdjustment(species, configuration.Variant.TreeModel, simulationStep, configuration.Treatments);
         configuration.Variant.ReduceExpansionFactors(stand, densityBeforeGrowth, treesOfSpecies, fertilizationExponent);
     }
 }
コード例 #7
0
ファイル: TabuSearch.cs プロジェクト: OSU-MARS/SEEM
 public TabuSearch(OrganonStand stand, OrganonConfiguration organonConfiguration, Objective objective, TabuParameters parameters)
     :  base(stand, organonConfiguration, objective, parameters)
 {
     this.EscapeAfter    = parameters.EscapeAfter;
     this.EscapeDistance = parameters.EscapeDistance;
     this.Iterations     = parameters.Iterations;
     //this.Jump = parameters.Jump;
     this.MaximumTenure = parameters.MaximumTenure;
     this.Tenure        = parameters.Tenure;
 }
コード例 #8
0
ファイル: OrganonTest.cs プロジェクト: OSU-MARS/SEEM
        protected static OrganonConfiguration CreateOrganonConfiguration(OrganonVariant variant)
        {
            OrganonConfiguration configuration = new OrganonConfiguration(variant)
            {
                DefaultMaximumSdi = TestConstant.Default.MaximumReinekeStandDensityIndex,
                TrueFirMaximumSdi = TestConstant.Default.MaximumReinekeStandDensityIndex,
                HemlockMaximumSdi = TestConstant.Default.MaximumReinekeStandDensityIndex,
            };

            return(configuration);
        }
コード例 #9
0
ファイル: OptimizeHero.cs プロジェクト: OSU-MARS/SEEM
        protected override Heuristic CreateHeuristic(OrganonConfiguration organonConfiguration, Objective objective, HeuristicParameters parameters)
        {
            Hero hero = new Hero(this.Stand !, organonConfiguration, objective, parameters)
            {
                IsStochastic = this.Stochastic
            };

            if (this.MaxIterations.HasValue)
            {
                hero.MaximumIterations = this.MaxIterations.Value;
            }
            return(hero);
        }
コード例 #10
0
ファイル: OptimizeRandom.cs プロジェクト: OSU-MARS/SEEM
        protected override Heuristic CreateHeuristic(OrganonConfiguration organonConfiguration, Objective objective, HeuristicParameters parameters)
        {
            RandomGuessing random = new RandomGuessing(this.Stand !, organonConfiguration, objective, parameters);

            if (this.Iterations.HasValue)
            {
                random.Iterations = this.Iterations.Value;
            }
            if (this.SelectionProbabilityWidth.HasValue)
            {
                random.SelectionPercentageWidth = this.SelectionProbabilityWidth.Value;
            }
            return(random);
        }
コード例 #11
0
ファイル: GreatDeluge.cs プロジェクト: OSU-MARS/SEEM
        public GreatDeluge(OrganonStand stand, OrganonConfiguration organonConfiguration, Objective objective, HeuristicParameters parameters)
            : base(stand, organonConfiguration, objective, parameters)
        {
            int treeRecords = stand.GetTreeRecordCount();

            this.ChangeToExchangeAfter = Int32.MaxValue;
            this.FinalMultiplier       = Constant.MonteCarloDefault.DelugeFinalMultiplier;
            this.IntitialMultiplier    = Constant.MonteCarloDefault.DelugeInitialMultiplier;
            this.Iterations            = Constant.MonteCarloDefault.IterationMultiplier * treeRecords;
            this.LowerWaterAfter       = (int)(Constant.MonteCarloDefault.ReheatAfter * treeRecords + 0.5F);
            this.LowerWaterBy          = Constant.MonteCarloDefault.DelugeLowerWaterBy;
            this.MoveType  = MoveType.OneOpt;
            this.RainRate  = null;
            this.StopAfter = Constant.MonteCarloDefault.StopAfter * treeRecords;
        }
コード例 #12
0
ファイル: RecordTravel.cs プロジェクト: OSU-MARS/SEEM
        public RecordTravel(OrganonStand stand, OrganonConfiguration organonConfiguration, Objective objective, HeuristicParameters parameters)
            : base(stand, organonConfiguration, objective, parameters)
        {
            int treeRecordCount = stand.GetTreeRecordCount();

            this.Alpha = Constant.MonteCarloDefault.RecordTravelAlpha;
            this.ChangeToExchangeAfter = Int32.MaxValue;
            this.FixedDeviation        = 0.0F;
            this.FixedIncrease         = 0.0F;
            this.IncreaseAfter         = (int)(Constant.MonteCarloDefault.ReheatAfter * treeRecordCount + 0.5F);
            this.Iterations            = Constant.MonteCarloDefault.IterationMultiplier * treeRecordCount;
            this.MoveType          = MoveType.OneOpt;
            this.RelativeDeviation = 0.0F;
            this.RelativeIncrease  = Constant.MonteCarloDefault.RecordTravelRelativeIncrease;
            this.StopAfter         = Constant.MonteCarloDefault.StopAfter * treeRecordCount;
        }
コード例 #13
0
        public void SubmaxApi()
        {
            this.TestContext !.WriteLine("version, A1, A2");
            foreach (OrganonVariant variant in TestConstant.Variants)
            {
                OrganonConfiguration configuration = OrganonTest.CreateOrganonConfiguration(variant);
                TestStand            stand         = OrganonTest.CreateDefaultStand(configuration);
                this.TestContext.WriteLine("{0},{1},{2}", variant, stand.A1, stand.A2);

                Assert.IsTrue(stand.A1 < 7.0F);
                Assert.IsTrue(stand.A1 > 5.0F);
                Assert.IsTrue(stand.A2 > 0.60F);
                Assert.IsTrue(stand.A2 < 0.65F);
                OrganonTest.Verify(ExpectedTreeChanges.NoDiameterOrHeightGrowth, stand, variant);
            }
        }
コード例 #14
0
        protected override Heuristic CreateHeuristic(OrganonConfiguration organonConfiguration, Objective objective, HeuristicParameters parameters)
        {
            ThresholdAccepting acceptor = new ThresholdAccepting(this.Stand !, organonConfiguration, objective, parameters);

            if (this.IterationsPerThreshold != null)
            {
                acceptor.IterationsPerThreshold.Clear();
                acceptor.IterationsPerThreshold.AddRange(this.IterationsPerThreshold);
            }
            if (this.Thresholds != null)
            {
                acceptor.Thresholds.Clear();
                acceptor.Thresholds.AddRange(this.Thresholds);
            }
            return(acceptor);
        }
コード例 #15
0
        public void OrganonStandGrowthApi()
        {
            TestStand.WriteTreeHeader(this.TestContext !);
            foreach (OrganonVariant variant in TestConstant.Variants)
            {
                OrganonConfiguration configuration = OrganonTest.CreateOrganonConfiguration(variant);

                // check crown competition API
                TestStand stand = OrganonTest.CreateDefaultStand(configuration);
                float     crownCompetitionFactor = OrganonStandDensity.GetCrownCompetitionByHeight(variant, stand)[0];
                Assert.IsTrue(crownCompetitionFactor >= 0.0F);
                Assert.IsTrue(crownCompetitionFactor <= TestConstant.Maximum.CrownCompetitionFactor);
                OrganonTest.Verify(ExpectedTreeChanges.NoDiameterOrHeightGrowth | ExpectedTreeChanges.NoDiameterOrHeightGrowth, stand, variant);

                // recalculate heights and crown ratios for all trees
                Dictionary <FiaCode, SpeciesCalibration> calibrationBySpecies = configuration.CreateSpeciesCalibration();
                foreach (Trees treesOfSpecies in stand.TreesBySpecies.Values)
                {
                    OrganonGrowth.SetIngrowthHeightAndCrownRatio(variant, stand, treesOfSpecies, treesOfSpecies.Count, calibrationBySpecies);
                }
                OrganonTest.Verify(ExpectedTreeChanges.NoDiameterOrHeightGrowth | ExpectedTreeChanges.NoDiameterOrHeightGrowth, stand, variant);

                // run Organon growth simulation
                stand = OrganonTest.CreateDefaultStand(configuration);
                if (configuration.IsEvenAge)
                {
                    // stand error if less than one year to grow to breast height
                    stand.AgeInYears = stand.BreastHeightAgeInYears + 2;
                }
                stand.SetQuantiles();
                stand.WriteTreesAsCsv(this.TestContext !, variant, 0, false);

                TestStand        initialStand = new TestStand(stand);
                TreeLifeAndDeath treeGrowth   = new TreeLifeAndDeath();
                for (int simulationStep = 0; simulationStep < TestConstant.Default.SimulationCyclesToRun; ++simulationStep)
                {
                    OrganonGrowth.Grow(simulationStep, configuration, stand, calibrationBySpecies);
                    treeGrowth.AccumulateGrowthAndMortality(stand);
                    OrganonTest.Verify(ExpectedTreeChanges.DiameterGrowth | ExpectedTreeChanges.HeightGrowth, OrganonWarnings.LessThan50TreeRecords, stand, variant);

                    stand.WriteTreesAsCsv(this.TestContext !, variant, variant.GetEndYear(simulationStep), false);
                }

                OrganonTest.Verify(ExpectedTreeChanges.DiameterGrowth | ExpectedTreeChanges.HeightGrowth, treeGrowth, initialStand, stand);
                OrganonTest.Verify(calibrationBySpecies);
            }
        }
コード例 #16
0
        public void DiameterGrowthApi()
        {
            foreach (OrganonVariant variant in TestConstant.Variants)
            {
                OrganonConfiguration configuration = OrganonTest.CreateOrganonConfiguration(variant);
                TestStand            stand         = OrganonTest.CreateDefaultStand(configuration);
                Dictionary <FiaCode, SpeciesCalibration> calibrationBySpecies = configuration.CreateSpeciesCalibration();

                Dictionary <FiaCode, float[]> previousTreeDiametersBySpecies = new Dictionary <FiaCode, float[]>();
                foreach (Trees treesOfSpecies in stand.TreesBySpecies.Values)
                {
                    previousTreeDiametersBySpecies.Add(treesOfSpecies.Species, new float[treesOfSpecies.Capacity]);
                }

                for (int simulationStep = 0; simulationStep < TestConstant.Default.SimulationCyclesToRun; ++simulationStep)
                {
                    OrganonStandDensity treeCompetition = new OrganonStandDensity(stand, variant);
                    foreach (Trees treesOfSpecies in stand.TreesBySpecies.Values)
                    {
                        float[] previousTreeDiameters = previousTreeDiametersBySpecies[treesOfSpecies.Species];
                        OrganonGrowth.GrowDiameter(configuration, simulationStep, stand, treesOfSpecies, treeCompetition, calibrationBySpecies[treesOfSpecies.Species].Diameter);
                        stand.SetSdiMax(configuration);
                        for (int treeIndex = 0; treeIndex < treesOfSpecies.Count; ++treeIndex)
                        {
                            float dbhInInches         = treesOfSpecies.Dbh[treeIndex];
                            float previousDbhInInches = previousTreeDiameters[treeIndex];
                            Assert.IsTrue(dbhInInches >= previousDbhInInches);
                            Assert.IsTrue(dbhInInches <= TestConstant.Maximum.DiameterInInches);
                        }
                    }

                    OrganonTest.Verify(ExpectedTreeChanges.DiameterGrowth, stand, variant);
                    OrganonTest.Verify(calibrationBySpecies);
                }

                OrganonStandDensity densityForLookup = new OrganonStandDensity(stand, variant);
                for (float dbhInInches = 0.5F; dbhInInches <= 101.0F; ++dbhInInches)
                {
                    float basalAreaLarger = densityForLookup.GetBasalAreaLarger(dbhInInches);
                    Assert.IsTrue(basalAreaLarger >= 0.0F);
                    Assert.IsTrue(basalAreaLarger <= densityForLookup.BasalAreaPerAcre);
                    float crownCompetitionLarger = densityForLookup.GetCrownCompetitionFactorLarger(dbhInInches);
                    Assert.IsTrue(crownCompetitionLarger >= 0.0F);
                    Assert.IsTrue(crownCompetitionLarger <= densityForLookup.CrownCompetitionFactor);
                }
            }
        }
コード例 #17
0
 public void MortalityApi()
 {
     foreach (OrganonVariant variant in TestConstant.Variants)
     {
         OrganonConfiguration configuration = OrganonTest.CreateOrganonConfiguration(variant);
         TestStand            stand         = OrganonTest.CreateDefaultStand(configuration);
         OrganonStandDensity  density       = new OrganonStandDensity(stand, variant);
         for (int simulationStep = 0; simulationStep < TestConstant.Default.SimulationCyclesToRun; ++simulationStep)
         {
             OrganonMortality.ReduceExpansionFactors(configuration, simulationStep, stand, density);
             stand.SetSdiMax(configuration);
             OrganonTest.Verify(ExpectedTreeChanges.NoDiameterOrHeightGrowth, stand, variant);
             float oldGrowthIndicator = OrganonMortality.GetOldGrowthIndicator(variant, stand);
             Assert.IsTrue(oldGrowthIndicator >= 0.0F);
             Assert.IsTrue(oldGrowthIndicator <= 2.0F);
         }
     }
 }
コード例 #18
0
        public void Plot14ImmediateThin()
        {
            int  thinPeriod      = 1;
            int  lastPeriod      = 4;
            bool useScaledVolume = false;

            PlotsWithHeight      plot14        = PublicApi.GetPlot14();
            OrganonConfiguration configuration = OrganonTest.CreateOrganonConfiguration(new OrganonVariantNwo());
            OrganonStand         stand         = plot14.ToOrganonStand(configuration, 30, 130.0F);

            stand.PlantingDensityInTreesPerHectare = TestConstant.Plot14ReplantingDensityInTreesPerHectare;

            configuration.Treatments.Harvests.Add(new ThinByPrescription(thinPeriod)
            {
                FromAbovePercentage    = 0.0F,
                ProportionalPercentage = 30.0F,
                FromBelowPercentage    = 0.0F
            });
            OrganonStandTrajectory thinnedTrajectory = new OrganonStandTrajectory(stand, configuration, TimberValue.Default, lastPeriod, useScaledVolume);

            AssertNullable.IsNotNull(thinnedTrajectory.StandByPeriod[0]);
            Assert.IsTrue(thinnedTrajectory.StandByPeriod[0] !.GetTreeRecordCount() == 222);
            thinnedTrajectory.Simulate();

            // verify thinned trajectory
            //                                        0      1       2       3       4
            float[] minimumThinnedQmd = new float[] { 9.16F, 10.47F, 11.64F, 12.64F, 13.52F };       // in
            //                                              0      1       2       3       4
            float[] minimumThinnedTopHeight = new float[] { 92.9F, 101.4F, 110.4F, 118.9F, 126.7F }; // ft
            float[] minimumThinnedVolume;
            if (thinnedTrajectory.UseScaledVolume)
            {
                minimumThinnedVolume = new float[] { 51.59F, 51.75F, 66.71F, 81.88F, 97.72F }; // Poudel 2018 + Scribner long log net MBF/ha
            }
            else
            {
                //                                   0       1       2       3       4
                minimumThinnedVolume = new float[] { 43.74F, 49.00F, 68.86F, 87.95F, 105.8F }; // Browning 1977 (FIA) MBF/ha
            }

            PublicApi.Verify(thinnedTrajectory, minimumThinnedQmd, minimumThinnedTopHeight, minimumThinnedVolume, thinPeriod, lastPeriod, 65, 70, configuration.Variant.TimeStepInYears);
            PublicApi.Verify(thinnedTrajectory, minimumThinnedVolume, thinPeriod);
            Assert.IsTrue(thinnedTrajectory.GetFirstHarvestAge() == 30);
        }
コード例 #19
0
        public void StandGrowthPerformance()
        {
            int thinningPeriod = 4;
            int runs           = 4; // 1 warmup run + measured runs
            int trees          = 300;

            #if DEBUG
            runs  = 1; // do only functional validation of test on DEBUG builds to reduce test execution time
            trees = 10;
            #endif

            PlotsWithHeight      nelder        = PublicApi.GetNelder();
            OrganonConfiguration configuration = PublicApi.CreateOrganonConfiguration(new OrganonVariantNwo());
            configuration.Treatments.Harvests.Add(new ThinByIndividualTreeSelection(thinningPeriod));
            OrganonStand stand = nelder.ToOrganonStand(configuration, 20, 130.0F, trees);
            stand.PlantingDensityInTreesPerHectare = TestConstant.NelderReplantingDensityInTreesPerHectare;

            Objective landExpectationValue = new Objective()
            {
                IsLandExpectationValue = true,
                PlanningPeriods        = 9
            };
            HeuristicParameters defaultParameters = new HeuristicParameters();

            TimeSpan runtime = TimeSpan.Zero;
            for (int run = 0; run < runs; ++run)
            {
                // after warmup: 3 runs * 300 trees = 900 measured growth simulations on i7-3770 (4th gen, Sandy Bridge)
                // dispersion of 5 runs                   min   mean  median  max
                // .NET 5.0 with removed tree compaction  1.67  1.72  1.72    1.82
                Hero hero = new Hero(stand, configuration, landExpectationValue, defaultParameters)
                {
                    IsStochastic      = false,
                    MaximumIterations = 2
                };
                hero.RandomizeTreeSelection(TestConstant.Default.SelectionPercentage);
                if (run > 0)
                {
                    // skip first run as a warmup run
                    runtime += hero.Run();
                }
            }
            this.TestContext !.WriteLine(runtime.TotalSeconds.ToString());
        }
コード例 #20
0
ファイル: SimulatedAnnealing.cs プロジェクト: OSU-MARS/SEEM
        public SimulatedAnnealing(OrganonStand stand, OrganonConfiguration organonConfiguration, Objective objective, HeuristicParameters parameters)
            :  base(stand, organonConfiguration, objective, parameters)
        {
            int treeRecords = stand.GetTreeRecordCount();

            this.Alpha = Constant.MonteCarloDefault.AnnealingAlpha;
            this.ChangeToExchangeAfter    = Int32.MaxValue;
            this.FinalProbability         = 0.0F;
            this.InitialProbability       = 0.0F;
            this.Iterations               = Constant.MonteCarloDefault.IterationMultiplier * treeRecords;
            this.IterationsPerTemperature = Constant.MonteCarloDefault.AnnealingIterationsPerTemperature;
            this.MoveType = MoveType.OneOpt;
            this.ProbabilityWindowLength = Constant.MonteCarloDefault.AnnealingAveragingWindowLength;
            this.ReheatAfter             = (int)(Constant.MonteCarloDefault.ReheatAfter * treeRecords + 0.5F);
            this.ReheatBy = Constant.MonteCarloDefault.AnnealingReheadBy;

            // float temperatureSteps = (float)(defaultIterations / this.IterationsPerTemperature);
            // this.Alpha = 1.0F / MathF.Pow(this.InitialAcceptProbability / this.FinalAcceptProbability, 1.0F / temperatureSteps);
        }
コード例 #21
0
        protected override Heuristic CreateHeuristic(OrganonConfiguration organonConfiguration, Objective objective, HeuristicParameters parameters)
        {
            SimulatedAnnealing annealer = new SimulatedAnnealing(this.Stand !, organonConfiguration, objective, parameters);

            if (this.Alpha.HasValue)
            {
                annealer.Alpha = this.Alpha.Value;
            }
            if (this.ChangeToExchangeAfter.HasValue)
            {
                annealer.ChangeToExchangeAfter = this.ChangeToExchangeAfter.Value;
            }
            if (this.FinalProbability.HasValue)
            {
                annealer.FinalProbability = this.FinalProbability.Value;
            }
            if (this.InitialProbability.HasValue)
            {
                annealer.InitialProbability = this.InitialProbability.Value;
            }
            if (this.Iterations.HasValue)
            {
                annealer.Iterations = this.Iterations.Value;
            }
            if (this.IterationsPerTemperature.HasValue)
            {
                annealer.IterationsPerTemperature = this.IterationsPerTemperature.Value;
            }
            if (this.ProbabilityWindowLength.HasValue)
            {
                annealer.ProbabilityWindowLength = this.ProbabilityWindowLength.Value;
            }
            if (this.ReheatAfter.HasValue)
            {
                annealer.ReheatAfter = this.ReheatAfter.Value;
            }
            if (this.ReheatBy.HasValue)
            {
                annealer.ReheatBy = this.ReheatBy.Value;
            }
            return(annealer);
        }
コード例 #22
0
        public void StatsApi()
        {
            // no test coverage: one line function
            // Stats.CON_RASI();

            // no test coverage: one line function
            // Stats.RASITE();

            foreach (OrganonVariant variant in TestConstant.Variants)
            {
                OrganonConfiguration configuration = OrganonTest.CreateOrganonConfiguration(variant);
                TestStand            stand         = OrganonTest.CreateDefaultStand(configuration);
                OrganonStandDensity  standDensity  = new OrganonStandDensity(stand, variant);

                this.TestContext !.WriteLine("{0},{1} ft²/ac,{2} trees per acre,{3} crown competition factor", variant, standDensity.BasalAreaPerAcre, standDensity.TreesPerAcre, standDensity.CrownCompetitionFactor);
                this.TestContext.WriteLine("index,large tree BA larger,large tree CCF larger");
                for (int largeTreeCompetitionIndex = 0; largeTreeCompetitionIndex < standDensity.LargeTreeBasalAreaLarger.Length; ++largeTreeCompetitionIndex)
                {
                    float largeTreeBasalAreaLarger        = standDensity.LargeTreeBasalAreaLarger[largeTreeCompetitionIndex];
                    float largeTreeCrownCompetitionFactor = standDensity.LargeTreeCrownCompetition[largeTreeCompetitionIndex];
                    Assert.IsTrue(largeTreeBasalAreaLarger >= 0.0F);
                    Assert.IsTrue(largeTreeBasalAreaLarger < TestConstant.Maximum.TreeBasalAreaLarger);
                    Assert.IsTrue(largeTreeCrownCompetitionFactor >= 0.0F);
                    Assert.IsTrue(largeTreeCrownCompetitionFactor < TestConstant.Maximum.StandCrownCompetitionFactor);
                    this.TestContext.WriteLine("{0},{1}", largeTreeBasalAreaLarger, largeTreeCrownCompetitionFactor);
                }
                this.TestContext.WriteLine("index,small tree BA larger,large tree CCF larger");
                for (int smallTreeCompetitionIndex = 0; smallTreeCompetitionIndex < standDensity.SmallTreeBasalAreaLarger.Length; ++smallTreeCompetitionIndex)
                {
                    float smallTreeBasalAreaLarger        = standDensity.SmallTreeBasalAreaLarger[smallTreeCompetitionIndex];
                    float smallTreeCrownCompetitionFactor = standDensity.SmallTreeCrownCompetition[smallTreeCompetitionIndex];
                    Assert.IsTrue(smallTreeBasalAreaLarger >= 0.0F);
                    Assert.IsTrue(smallTreeBasalAreaLarger < TestConstant.Maximum.TreeBasalAreaLarger);
                    Assert.IsTrue(smallTreeCrownCompetitionFactor >= 0.0F);
                    Assert.IsTrue(smallTreeCrownCompetitionFactor < TestConstant.Maximum.StandCrownCompetitionFactor);
                    this.TestContext.WriteLine("{0},{1}", smallTreeBasalAreaLarger, smallTreeCrownCompetitionFactor);
                }
                this.TestContext.WriteLine(String.Empty);

                OrganonTest.Verify(ExpectedTreeChanges.NoDiameterOrHeightGrowth, stand, variant);
            }
        }
コード例 #23
0
        protected override Heuristic CreateHeuristic(OrganonConfiguration organonConfiguration, Objective objective, HeuristicParameters parameters)
        {
            RecordTravel recordTravel = new RecordTravel(this.Stand !, organonConfiguration, objective, parameters);

            if (this.Alpha.HasValue)
            {
                recordTravel.Alpha = this.Alpha.Value;
            }
            if (this.ChangeToExchangeAfter.HasValue)
            {
                recordTravel.ChangeToExchangeAfter = this.ChangeToExchangeAfter.Value;
            }
            if (this.FixedDeviation.HasValue)
            {
                recordTravel.FixedDeviation = this.FixedDeviation.Value;
            }
            if (this.FixedIncrease.HasValue)
            {
                recordTravel.FixedIncrease = this.FixedIncrease.Value;
            }
            if (this.IncreaseAfter.HasValue)
            {
                recordTravel.IncreaseAfter = this.IncreaseAfter.Value;
            }
            if (this.Iterations.HasValue)
            {
                recordTravel.Iterations = this.Iterations.Value;
            }
            if (this.RelativeDeviation.HasValue)
            {
                recordTravel.RelativeDeviation = this.RelativeDeviation.Value;
            }
            if (this.RelativeIncrease.HasValue)
            {
                recordTravel.RelativeIncrease = this.RelativeIncrease.Value;
            }
            if (this.StopAfter.HasValue)
            {
                recordTravel.StopAfter = this.StopAfter.Value;
            }
            return(recordTravel);
        }
コード例 #24
0
        protected override Heuristic CreateHeuristic(OrganonConfiguration organonConfiguration, Objective objective, HeuristicParameters parameters)
        {
            GreatDeluge deluge = new GreatDeluge(this.Stand !, organonConfiguration, objective, parameters);

            if (this.ChangeToExchangeAfter.HasValue)
            {
                deluge.ChangeToExchangeAfter = this.ChangeToExchangeAfter.Value;
            }
            if (this.FinalMultiplier.HasValue)
            {
                deluge.FinalMultiplier = this.FinalMultiplier.Value * MathF.Abs(deluge.IntitialMultiplier);
            }
            if (this.InitialMultiplier.HasValue)
            {
                deluge.IntitialMultiplier = this.InitialMultiplier.Value;
            }

            if (this.Iterations.HasValue)
            {
                deluge.Iterations = this.Iterations.Value;
            }
            if (this.LowerAfter.HasValue)
            {
                deluge.LowerWaterAfter = this.LowerAfter.Value;
            }
            if (this.LowerBy.HasValue)
            {
                deluge.LowerWaterBy = this.LowerBy.Value;
            }

            if (this.RainRate.HasValue)
            {
                deluge.RainRate = this.RainRate.Value;
            }
            if (this.StopAfter.HasValue)
            {
                deluge.StopAfter = this.StopAfter.Value;
            }
            return(deluge);
        }
コード例 #25
0
ファイル: OrganonTest.cs プロジェクト: OSU-MARS/SEEM
        protected static void GrowPspStand(PspStand huffmanPeak, TestStand stand, OrganonVariant variant, int startYear, int endYear, string baseFileName)
        {
            OrganonConfiguration configuration   = OrganonTest.CreateOrganonConfiguration(variant);
            TestStand            initialTreeData = new TestStand(stand);
            TreeLifeAndDeath     treeGrowth      = new TreeLifeAndDeath();

            Dictionary <FiaCode, SpeciesCalibration> calibrationBySpecies = configuration.CreateSpeciesCalibration();

            if (configuration.IsEvenAge)
            {
                // stand error if less than one year to grow to breast height
                stand.AgeInYears = stand.BreastHeightAgeInYears + 2;
            }

            TestStandDensity density = new TestStandDensity(stand, variant);

            using StreamWriter densityWriter = density.WriteToCsv(baseFileName + " density.csv", variant, startYear);
            TreeQuantiles quantiles = new TreeQuantiles(stand);

            using StreamWriter quantileWriter   = quantiles.WriteToCsv(baseFileName + " quantiles.csv", variant, startYear);
            using StreamWriter treeGrowthWriter = stand.WriteTreesToCsv(baseFileName + " tree growth.csv", variant, startYear);
            for (int simulationStep = 0, year = startYear + variant.TimeStepInYears; year <= endYear; year += variant.TimeStepInYears, ++simulationStep)
            {
                OrganonGrowth.Grow(simulationStep, configuration, stand, calibrationBySpecies);
                treeGrowth.AccumulateGrowthAndMortality(stand);
                huffmanPeak.AddIngrowth(year, stand, density);
                OrganonTest.Verify(ExpectedTreeChanges.DiameterGrowthOrNoChange | ExpectedTreeChanges.HeightGrowthOrNoChange, stand, variant);

                density = new TestStandDensity(stand, variant);
                density.WriteToCsv(densityWriter, variant, year);
                quantiles = new TreeQuantiles(stand);
                quantiles.WriteToCsv(quantileWriter, variant, year);
                stand.WriteTreesToCsv(treeGrowthWriter, variant, year);
            }

            OrganonTest.Verify(ExpectedTreeChanges.ExpansionFactorConservedOrIncreased | ExpectedTreeChanges.DiameterGrowthOrNoChange | ExpectedTreeChanges.HeightGrowthOrNoChange, treeGrowth, initialTreeData, stand);
            OrganonTest.Verify(calibrationBySpecies);
        }
コード例 #26
0
        public void GrowApi()
        {
            foreach (OrganonVariant variant in TestConstant.Variants)
            {
                OrganonConfiguration configuration = OrganonTest.CreateOrganonConfiguration(variant);
                TestStand            stand         = OrganonTest.CreateDefaultStand(configuration);

                Dictionary <FiaCode, SpeciesCalibration> calibrationBySpecies = configuration.CreateSpeciesCalibration();
                OrganonStandDensity densityStartOfStep = new OrganonStandDensity(stand, variant);
                for (int simulationStep = 0; simulationStep < TestConstant.Default.SimulationCyclesToRun; ++simulationStep)
                {
                    float[] crownCompetitionByHeight = OrganonStandDensity.GetCrownCompetitionByHeight(variant, stand);
                    OrganonGrowth.Grow(simulationStep, configuration, stand, densityStartOfStep, calibrationBySpecies, ref crownCompetitionByHeight,
                                       out OrganonStandDensity densityEndOfStep, out int _);
                    stand.SetSdiMax(configuration);

                    OrganonTest.Verify(ExpectedTreeChanges.DiameterGrowth | ExpectedTreeChanges.HeightGrowth, stand, variant);
                    OrganonTest.Verify(calibrationBySpecies);

                    densityStartOfStep = densityEndOfStep;
                }
            }
        }
コード例 #27
0
        public void CrownGrowthApi()
        {
            foreach (OrganonVariant variant in TestConstant.Variants)
            {
                OrganonConfiguration configuration = OrganonTest.CreateOrganonConfiguration(variant);
                TestStand            stand         = OrganonTest.CreateDefaultStand(configuration);

                Dictionary <FiaCode, SpeciesCalibration> calibrationBySpecies = configuration.CreateSpeciesCalibration();
                for (int simulationStep = 0; simulationStep < TestConstant.Default.SimulationCyclesToRun; ++simulationStep)
                {
                    OrganonStandDensity densityStartOfStep = new OrganonStandDensity(stand, variant);
                    Assert.IsTrue(densityStartOfStep.BasalAreaPerAcre > 0.0F);
                    Assert.IsTrue(densityStartOfStep.CrownCompetitionFactor > 0.0F);
                    Assert.IsTrue(densityStartOfStep.TreesPerAcre > 0.0F);

                    float[] crownCompetitionByHeight = OrganonStandDensity.GetCrownCompetitionByHeight(variant, stand);
                    OrganonTest.Verify(crownCompetitionByHeight, variant);

                    foreach (Trees treesOfSpecies in stand.TreesBySpecies.Values)
                    {
                        variant.AddCrownCompetitionByHeight(treesOfSpecies, crownCompetitionByHeight);
                        OrganonTest.Verify(crownCompetitionByHeight, variant);
                    }

                    OrganonStandDensity densityEndOfStep = new OrganonStandDensity(stand, variant);
                    Assert.IsTrue(densityEndOfStep.BasalAreaPerAcre > 0.0F);
                    Assert.IsTrue(densityEndOfStep.CrownCompetitionFactor > 0.0F);
                    Assert.IsTrue(densityEndOfStep.TreesPerAcre > 0.0F);

                    #pragma warning disable IDE0059 // Unnecessary assignment of a value
                    crownCompetitionByHeight = OrganonGrowth.GrowCrown(variant, stand, densityEndOfStep, calibrationBySpecies);
                    #pragma warning restore IDE0059 // Unnecessary assignment of a value
                    OrganonTest.Verify(ExpectedTreeChanges.NoDiameterOrHeightGrowth, stand, variant);
                    OrganonTest.Verify(calibrationBySpecies);
                }
            }
        }
コード例 #28
0
        public void HuffmanPeakNobleFir()
        {
            string               plotFilePath  = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "OSU", "Organon", "HPNF.xlsx");
            PspStand             huffmanPeak   = new PspStand(plotFilePath, "HPNF", 0.2F);
            OrganonVariant       variant       = new OrganonVariantSwo(); // SWO allows mapping ABAM -> ABGR and ABPR -> ABCO
            OrganonConfiguration configuration = OrganonTest.CreateOrganonConfiguration(variant);
            TestStand            stand         = huffmanPeak.ToStand(configuration, 80.0F);
            int startYear = 1980;

            stand.WriteCompetitionAsCsv("HPNF initial competition.csv", variant, startYear);
            OrganonTest.GrowPspStand(huffmanPeak, stand, variant, startYear, 2015, Path.GetFileNameWithoutExtension(plotFilePath));

            TreeQuantiles measuredQuantiles = new TreeQuantiles(stand, huffmanPeak, startYear);

            using StreamWriter quantileWriter = measuredQuantiles.WriteToCsv("HPNF measured quantiles.csv", variant, startYear);
            foreach (int measurementYear in huffmanPeak.MeasurementYears)
            {
                if (measurementYear != startYear)
                {
                    measuredQuantiles = new TreeQuantiles(stand, huffmanPeak, measurementYear);
                    measuredQuantiles.WriteToCsv(quantileWriter, variant, measurementYear);
                }
            }
        }
コード例 #29
0
        public void RS39()
        {
            string               plotFilePath  = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "OSU", "Organon", "RS39 lower half.xlsx");
            PspStand             rs39          = new PspStand(plotFilePath, "RS39 lower half", 0.154441F);
            OrganonVariant       variant       = new OrganonVariantNwo();
            OrganonConfiguration configuration = new OrganonConfiguration(variant);
            TestStand            stand         = rs39.ToStand(configuration, 105.0F);
            int startYear = 1992;

            stand.WriteCompetitionAsCsv("RS39 lower half initial competition.csv", variant, startYear);
            OrganonTest.GrowPspStand(rs39, stand, variant, startYear, 2019, Path.GetFileNameWithoutExtension(plotFilePath));

            TreeQuantiles measuredQuantiles = new TreeQuantiles(stand, rs39, startYear);

            using StreamWriter quantileWriter = measuredQuantiles.WriteToCsv("RS39 lower half measured quantiles.csv", variant, startYear);
            foreach (int measurementYear in rs39.MeasurementYears)
            {
                if (measurementYear != startYear)
                {
                    measuredQuantiles = new TreeQuantiles(stand, rs39, measurementYear);
                    measuredQuantiles.WriteToCsv(quantileWriter, variant, measurementYear);
                }
            }
        }
コード例 #30
0
        public void HeightGrowthApi()
        {
            foreach (OrganonVariant variant in TestConstant.Variants)
            {
                OrganonConfiguration configuration = OrganonTest.CreateOrganonConfiguration(variant);
                Dictionary <FiaCode, SpeciesCalibration> calibrationBySpecies = configuration.CreateSpeciesCalibration();
                TestStand stand = OrganonTest.CreateDefaultStand(configuration);

                float[] crownCompetitionByHeight      = OrganonStandDensity.GetCrownCompetitionByHeight(variant, stand);
                DouglasFir.SiteConstants     psmeSite = new DouglasFir.SiteConstants(stand.SiteIndex);
                WesternHemlock.SiteConstants tsheSite = new WesternHemlock.SiteConstants(stand.HemlockSiteIndex);

                foreach (Trees treesOfSpecies in stand.TreesBySpecies.Values)
                {
                    variant.GetHeightPredictionCoefficients(treesOfSpecies.Species, out float B0, out float B1, out float B2);
                    for (int treeIndex = 0; treeIndex < treesOfSpecies.Count; ++treeIndex)
                    {
                        // predicted heights
                        float dbhInInches           = treesOfSpecies.Dbh[treeIndex];
                        float heightInFeet          = treesOfSpecies.Height[treeIndex];
                        float predictedHeightInFeet = 4.5F + MathV.Exp(B0 + B1 * MathV.Pow(dbhInInches, B2));
                        Assert.IsTrue(predictedHeightInFeet >= 0.0F);
                        // TODO: make upper limit of height species specific
                        Assert.IsTrue(predictedHeightInFeet < TestConstant.Maximum.HeightInFeet);

                        // growth effective age and potential height growth
                        bool  verifyAgeAndHeight        = false;
                        float growthEffectiveAgeInYears = -1.0F;
                        float potentialHeightGrowth     = -1.0F;
                        if ((variant.TreeModel == TreeModel.OrganonNwo) || (variant.TreeModel == TreeModel.OrganonSmc))
                        {
                            if (treesOfSpecies.Species == FiaCode.TsugaHeterophylla)
                            {
                                growthEffectiveAgeInYears = WesternHemlock.GetFlewellingGrowthEffectiveAge(tsheSite, variant.TimeStepInYears, heightInFeet, out potentialHeightGrowth);
                            }
                            else
                            {
                                growthEffectiveAgeInYears = DouglasFir.GetBrucePsmeAbgrGrowthEffectiveAge(psmeSite, variant.TimeStepInYears, heightInFeet, out potentialHeightGrowth);
                            }
                            verifyAgeAndHeight = true;
                        }
                        else if (variant.TreeModel == TreeModel.OrganonSwo)
                        {
                            if ((treesOfSpecies.Species == FiaCode.PinusPonderosa) || (treesOfSpecies.Species == FiaCode.PseudotsugaMenziesii))
                            {
                                DouglasFir.GetDouglasFirPonderosaHeightGrowth(treesOfSpecies.Species == FiaCode.PseudotsugaMenziesii, stand.SiteIndex, heightInFeet, out growthEffectiveAgeInYears, out potentialHeightGrowth);
                                verifyAgeAndHeight = true;
                            }
                        }
                        if (verifyAgeAndHeight)
                        {
                            Assert.IsTrue(growthEffectiveAgeInYears >= -2.0F);
                            Assert.IsTrue(growthEffectiveAgeInYears <= 500.0F);
                            Assert.IsTrue(potentialHeightGrowth >= 0.0F);
                            Assert.IsTrue(potentialHeightGrowth < 20.0F);
                        }
                    }
                }

                for (int simulationStep = 0; simulationStep < TestConstant.Default.SimulationCyclesToRun; ++simulationStep)
                {
                    foreach (Trees treesOfSpecies in stand.TreesBySpecies.Values)
                    {
                        if (variant.IsBigSixSpecies(treesOfSpecies.Species))
                        {
                            // TODO: why no height calibration in Organon API?
                            OrganonGrowth.GrowHeightBigSixSpecies(configuration, simulationStep, stand, treesOfSpecies, 1.0F, crownCompetitionByHeight, out _);
                        }
                        else
                        {
                            OrganonGrowth.GrowHeightMinorSpecies(configuration, stand, treesOfSpecies, calibrationBySpecies[treesOfSpecies.Species].Height);
                        }
                        stand.SetSdiMax(configuration);

                        for (int treeIndex = 0; treeIndex < treesOfSpecies.Count; ++treeIndex)
                        {
                            float heightInFeet = treesOfSpecies.Height[treeIndex];
                            // TODO: make upper limit of height species specific
                            Assert.IsTrue(heightInFeet < TestConstant.Maximum.HeightInFeet);
                        }
                    }

                    // since diameter growth is zero in this test any tree which is above its anticipated height for its current diameter
                    // should have zero growth
                    // This is expected behavior the height growth functions and, potentially, height growth limiting.
                    OrganonTest.Verify(ExpectedTreeChanges.HeightGrowthOrNoChange, stand, variant);
                    OrganonTest.Verify(calibrationBySpecies);
                }
            }
        }