当前位置: 首页>>代码示例>>C#>>正文


C# ICore.GenerateUniform方法代码示例

本文整理汇总了C#中ICore.GenerateUniform方法的典型用法代码示例。如果您正苦于以下问题:C# ICore.GenerateUniform方法的具体用法?C# ICore.GenerateUniform怎么用?C# ICore.GenerateUniform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICore的用法示例。


在下文中一共展示了ICore.GenerateUniform方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Grow

        //---------------------------------------------------------------------

        /// <summary>
        /// Grows all the cohorts by advancing their ages.
        /// </summary>
        /// <param name="years">
        /// The number of years to advance each cohort's age.
        /// </param>
        /// <param name="successionTimestep">
        /// Indicates whether the current timestep is a succession timestep.
        /// If so, then all young cohorts (i.e., those whose ages are less than
        /// or equal to the succession timestep are combined into a single
        /// cohort whose age is the succession timestep.
        /// </param>
        /// <param name="site">
        /// The site where the cohorts are located.
        /// </param>
        public void Grow(ushort     years,
                         ActiveSite site,
                         int?       successionTimestep,
                         ICore      mCore)
        {
            //  Update ages
            for (int i = 0; i < ages.Count; i++) {
                if (successionTimestep.HasValue && (ages[i] < successionTimestep.Value))
                    // Young cohort
                    ages[i] = (ushort) successionTimestep.Value;
                else
                    ages[i] += years;
            }

            //  Combine young cohorts if succession timestep
            if (successionTimestep.HasValue) {
                //  Go backwards through list of ages, so the removal of an age
                //  doesn't mess up the loop.
                bool left1YoungCohort = false;
                for (int i = ages.Count - 1; i >= 0; i--) {
                    if (ages[i] == successionTimestep.Value) {
                        // Young cohort
                        if (left1YoungCohort)
                            ages.RemoveAt(i);
                        else
                            left1YoungCohort = true;
                    }
                }
            }

            //  Now go through ages and check for age-related mortality and
            //  senescence.  Again go backwards through the list, so the
            //  removal of an age doesn't mess up the loop.
            isMaturePresent = false;
            for (int i = ages.Count - 1; i >= 0; i--) {
                bool cohortDies = false;
                ushort age = ages[i];
                if (age > species.Longevity)
                    cohortDies = true;
                else if (age >= 0.8 * species.Longevity) {
                    //  Below is the annual age-related mortality probability,
                    //  so we need to check it for each year of growth.
                    double ageRelatedMortalityProb = (4 * ((double) age / species.Longevity) - 3) / 10;
                    for (int j = years; j > 0; j--) {
                        if (mCore.GenerateUniform() < ageRelatedMortalityProb)
                        {
                            cohortDies = true;
                            break;
                        }
                    }
                }
                if (cohortDies) {
                    ages.RemoveAt(i);
                    Cohort.Died(this, new Cohort(species, age), site, null);
                }
                else if (age >= species.Maturity)
                    isMaturePresent = true;
            }
        }
开发者ID:LANDIS-II-Foundation,项目名称:Libraries,代码行数:76,代码来源:SpeciesCohorts.cs


注:本文中的ICore.GenerateUniform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。