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


C# ActiveSite.GetNeighbor方法代码示例

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


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

示例1: DefoliateCohort

        //---------------------------------------------------------------------
        // This method replaces the delegate method.  It is called every year when
        // ACT_ANPP is calculated, for each cohort.  Therefore, this method is operating at
        // an ANNUAL time step and separate from the normal extension time step.

        // The method calculates a fraction of leaf biomass lost to defoliation.

        public static double DefoliateCohort(ICohort cohort, ActiveSite site, int siteBiomass)
        {

            //PlugIn.ModelCore.Log.WriteLine("   Calculating insect defoliation...");

            int sppIndex = cohort.Species.Index;
            double totalDefoliation = 0.0;

            foreach(IInsect insect in manyInsect)
            {
                if (!insect.ActiveOutbreak)
                {
                    //if (PlugIn.ModelCore.CurrentTime >= 8)
                    //    PlugIn.ModelCore.Log.WriteLine("   {0} is NOT active.  ", insect.Name);
                    continue;
                }

                //if (PlugIn.ModelCore.CurrentTime >= 8)
                //    PlugIn.ModelCore.Log.WriteLine("   Begin defoliation within Succession... ");


                double defoliation = 0.0;
                double weightedDefoliation = 0.0;
                int suscIndex = insect.SppTable[sppIndex].Susceptibility - 1;


                // Get the Neighborhood GrowthReduction Density
                double meanNeighborhoodDefoliation = 0.0;
                int neighborCnt = 0;

                // If it is the first year, the neighborhood growth reduction
                // will have been initialized in Outbreak.InitializeDefoliationPatches

                if(insect.NeighborhoodDefoliation[site] > 0)
                {
                    //PlugIn.ModelCore.Log.WriteLine("   First Year of Defoliation:  Using initial patch defo={0:0.00}.", SiteVars.NeighborhoodDefoliation[site]);
                    meanNeighborhoodDefoliation = insect.NeighborhoodDefoliation[site];
                }

                // If not the first year, calculate mean neighborhood defoliation based on the
                // previous year.
                else
                {
                    double sumNeighborhoodDefoliation = 0.0;

                    //PlugIn.ModelCore.Log.WriteLine("Look at the Neighbors... ");
                    foreach (RelativeLocation relativeLoc in insect.Neighbors)
                    {
                        Site neighbor = site.GetNeighbor(relativeLoc);
                        if (neighbor != null && neighbor.IsActive)
                        {
                            neighborCnt++;
                            sumNeighborhoodDefoliation += insect.LastYearDefoliation[neighbor];
                        }
                    }

                    if(neighborCnt > 0.0)
                        meanNeighborhoodDefoliation = sumNeighborhoodDefoliation / (double) neighborCnt;

                }  //endif

                if(meanNeighborhoodDefoliation > 1.0 || meanNeighborhoodDefoliation < 0)
                {
                    PlugIn.ModelCore.UI.WriteLine("MeanNeighborhoodDefoliation={0}; NeighborCnt={1}.", meanNeighborhoodDefoliation, neighborCnt);
                    throw new ApplicationException("Error: Mean Neighborhood GrowthReduction is not between 1.0 and 0.0");
                }

                // First assume that there are no neighbors whatsoever:
                DistributionType dist = insect.SusceptibleTable[suscIndex].Distribution_0.Name;
                double value1 = insect.SusceptibleTable[suscIndex].Distribution_0.Value1;
                double value2 = insect.SusceptibleTable[suscIndex].Distribution_0.Value2;

                if(meanNeighborhoodDefoliation <= 1.0 && meanNeighborhoodDefoliation >= 0.8)
                {
                    dist = insect.SusceptibleTable[suscIndex].Distribution_80.Name;
                    value1 = insect.SusceptibleTable[suscIndex].Distribution_80.Value1;
                    value2 = insect.SusceptibleTable[suscIndex].Distribution_80.Value2;
                }
                else if(meanNeighborhoodDefoliation < 0.8 && meanNeighborhoodDefoliation >= 0.6)
                {
                    dist = insect.SusceptibleTable[suscIndex].Distribution_60.Name;
                    value1 = insect.SusceptibleTable[suscIndex].Distribution_60.Value1;
                    value2 = insect.SusceptibleTable[suscIndex].Distribution_60.Value2;
                }
                else if(meanNeighborhoodDefoliation < 0.6 && meanNeighborhoodDefoliation >= 0.4)
                {
                    dist = insect.SusceptibleTable[suscIndex].Distribution_40.Name;
                    value1 = insect.SusceptibleTable[suscIndex].Distribution_40.Value1;
                    value2 = insect.SusceptibleTable[suscIndex].Distribution_40.Value2;
                }
                else if(meanNeighborhoodDefoliation < 0.4 && meanNeighborhoodDefoliation >= 0.2)
                {
                    dist = insect.SusceptibleTable[suscIndex].Distribution_20.Name;
//.........这里部分代码省略.........
开发者ID:pjbitterman,项目名称:Extensions-Disturbance,代码行数:101,代码来源:Defoliate.cs

示例2: DefoliateCohort

        //---------------------------------------------------------------------
        // This method replaces the delegate method.  It is called every year when
        // ACT_ANPP is calculated, for each cohort.  Therefore, this method is operating at
        // an ANNUAL time step and separate from the normal extension time step.
        //static int LastYearDefoliationCohortWasCalled = int.MinValue; // Add this for error capture. Ensure timestep for succession is annual. Previous method doesn't work with new biomass library.
        //static bool TimeStepChecked = false;

        public static double DefoliateCohort(ActiveSite site,
                                         ISpecies species,
                                         int cohortBiomass,
                                         int siteBiomass)
        {
        //    if (TimeStepChecked == false)
        //    {
        //       if (LastYearDefoliationCohortWasCalled > 0 && PlugIn.ModelCore.CurrentTime - LastYearDefoliationCohortWasCalled > 1)
	    //            {
        //                throw new System.Exception("  CAUTION! If using Biomass Insects, Succession Extension should be operating at an ANNUAL time step.");
	    //            }
	    //        LastYearDefoliationCohortWasCalled = PlugIn.ModelCore.CurrentTime;
	   //         TimeStepChecked = true;
       //    }
            // PlugIn.ModelCore.UI.WriteLine("   Calculating insect defoliation...");

            int sppIndex = species.Index;
            double totalDefoliation = 0.0;

            foreach (IInsect insect in manyInsect)
            {
                if (!insect.ActiveOutbreak)
                    continue;

                double defoliation = 0.0;
                double weightedDefoliation = 0.0;
                int suscIndex = insect.SppTable[sppIndex].Susceptibility - 1;

                if (suscIndex < 0) suscIndex = 0;

                // Get the Neighborhood GrowthReduction Density
                double meanNeighborhoodDefoliation = 0.0;
                int neighborCnt = 0;

                // If it is the first year, the neighborhood growth reduction
                // will have been initialized in Outbreak.InitializeDefoliationPatches

                if (insect.NeighborhoodDefoliation[site] > 0)
                {
                    // PlugIn.ModelCore.UI.WriteLine("   First Year of Defoliation:  Using initial patch defo={0:0.00}.", SiteVars.NeighborhoodDefoliation[site]);
                    meanNeighborhoodDefoliation = insect.NeighborhoodDefoliation[site];
                }

                // If not the first year, calculate mean neighborhood defoliation based on the
                // previous year.
                else
                {
                    double sumNeighborhoodDefoliation = 0.0;

                    // PlugIn.ModelCore.UI.WriteLine("Look at the Neighbors... ");
                    foreach (RelativeLocation relativeLoc in insect.Neighbors)
                    {
                        Site neighbor = site.GetNeighbor(relativeLoc);
                        if (neighbor != null && neighbor.IsActive)
                        {
                            neighborCnt++;
                            sumNeighborhoodDefoliation += insect.LastYearDefoliation[neighbor];
                        }
                    }

                    if (neighborCnt > 0.0)
                        meanNeighborhoodDefoliation = sumNeighborhoodDefoliation / (double)neighborCnt;

                }  //endif

                if (meanNeighborhoodDefoliation > 1.0 || meanNeighborhoodDefoliation < 0)
                {
                    PlugIn.ModelCore.UI.WriteLine("MeanNeighborhoodDefoliation={0}; NeighborCnt={1}.", meanNeighborhoodDefoliation, neighborCnt);
                    throw new ApplicationException("Error: Mean Neighborhood GrowthReduction is not between 1.0 and 0.0");
                }

                // First assume that there are no neighbors whatsoever:
                DistributionType dist = insect.SusceptibleTable[suscIndex].Distribution_0.Name;
                double value1 = insect.SusceptibleTable[suscIndex].Distribution_0.Value1;
                double value2 = insect.SusceptibleTable[suscIndex].Distribution_0.Value2;

                if (meanNeighborhoodDefoliation <= 1.0 && meanNeighborhoodDefoliation >= 0.8)
                {
                    dist = insect.SusceptibleTable[suscIndex].Distribution_80.Name;
                    value1 = insect.SusceptibleTable[suscIndex].Distribution_80.Value1;
                    value2 = insect.SusceptibleTable[suscIndex].Distribution_80.Value2;
                }
                else if (meanNeighborhoodDefoliation < 0.8 && meanNeighborhoodDefoliation >= 0.6)
                {
                    dist = insect.SusceptibleTable[suscIndex].Distribution_60.Name;
                    value1 = insect.SusceptibleTable[suscIndex].Distribution_60.Value1;
                    value2 = insect.SusceptibleTable[suscIndex].Distribution_60.Value2;
                }
                else if (meanNeighborhoodDefoliation < 0.6 && meanNeighborhoodDefoliation >= 0.4)
                {
                    dist = insect.SusceptibleTable[suscIndex].Distribution_40.Name;
                    value1 = insect.SusceptibleTable[suscIndex].Distribution_40.Value1;
                    value2 = insect.SusceptibleTable[suscIndex].Distribution_40.Value2;
//.........这里部分代码省略.........
开发者ID:pjbitterman,项目名称:Extensions-Disturbance,代码行数:101,代码来源:Defoliate.cs

示例3: DefoliateCohort

        //---------------------------------------------------------------------
        // This method replaces the delegate method.  It is called every year when
        // ACT_ANPP is calculated, for each cohort.  Therefore, this method is operating at
        // an ANNUAL time step and separate from the normal extension time step.

        public static double DefoliateCohort(ActiveSite site, ISpecies species, int cohortBiomass, int siteBiomass)
        {
            //PlugIn.ModelCore.UI.WriteLine("   Calculating insect defoliation...");

            double totalDefoliation = 0.0;  // Cohort total defoliation

            foreach (IInsect insect in manyInsect)
            {
                if (!insect.ActiveOutbreak)
                    continue;
                double defoliation = 0.0;

                // Calculate biomass proportion of "protective" species
                double protectBiomass = 0;
                foreach (Landis.Library.BiomassCohorts.ISpeciesCohorts spp in SiteVars.Cohorts[site])
                {
                    foreach (Landis.Library.BiomassCohorts.ICohort spp_cohort in spp)
                    {
                        if (insect.Susceptibility[spp_cohort.Species] == 4)
                            protectBiomass += spp_cohort.Biomass;
                    }
                }
                double protectProp = protectBiomass / (double)siteBiomass;

                int suscIndex = insect.Susceptibility[species] - 1;


                if (suscIndex < 0) suscIndex = 0;
                if (suscIndex > 2) suscIndex = 2;

                // Get the Neighborhood GrowthReduction Density
                double meanNeighborhoodDefoliation = 0.0;
                int neighborCnt = 0;

                // If it is the first year, the neighborhood growth reduction
                // will have been initialized in Outbreak.InitializeDefoliationPatches

                if (insect.NeighborhoodDefoliation[site] > 0)
                {
                    //PlugIn.ModelCore.UI.WriteLine("   First Year of Defoliation:  Using initial patch defo={0:0.00}.", SiteVars.NeighborhoodDefoliation[site]);
                    meanNeighborhoodDefoliation = insect.NeighborhoodDefoliation[site];
                }

                // If not the first year, calculate mean neighborhood defoliation based on the
                // previous year.
                else
                {
                    double sumNeighborhoodDefoliation = 0.0;

                    //PlugIn.ModelCore.UI.WriteLine("Look at the Neighbors... ");
                    foreach (RelativeLocation relativeLoc in insect.Neighbors)
                    {
                        Site neighbor = site.GetNeighbor(relativeLoc);
                        if (neighbor != null && neighbor.IsActive)
                        {
                            neighborCnt++;

                            // The previous year...
                            //if(SiteVars.DefoliationByYear[neighbor].ContainsKey(PlugIn.ModelCore.CurrentTime - 1))
                            //    sumNeighborhoodDefoliation += SiteVars.DefoliationByYear[neighbor][PlugIn.ModelCore.CurrentTime - 1];

                            // BUG - This does not sum values in the nbrhd, just uses the last nbr value
                            //sumNeighborhoodDefoliation = Math.Min(1.0, insect.LastYearDefoliation[neighbor]);
                            // BUG FIX - BRM
                            sumNeighborhoodDefoliation += Math.Min(1.0, insect.LastYearDefoliation[neighbor]);
                        }
                    }

                    if (neighborCnt > 0.0)
                        meanNeighborhoodDefoliation = sumNeighborhoodDefoliation / (double)neighborCnt;

                }  //endif

                if (meanNeighborhoodDefoliation > 1.0 || meanNeighborhoodDefoliation < 0)
                {
                    PlugIn.ModelCore.UI.WriteLine("MeanNeighborhoodDefoliation={0}; NeighborCnt={1}.", meanNeighborhoodDefoliation, neighborCnt);
                    throw new ApplicationException("Error: Mean Neighborhood GrowthReduction is not between 1.0 and 0.0");
                }

                // First assume that there are no neighbors whatsoever:
                DistributionType dist = insect.SusceptibleTable[suscIndex].Distribution_0.Name;
                double value1 = insect.SusceptibleTable[suscIndex].Distribution_0.Value1;
                double value2 = insect.SusceptibleTable[suscIndex].Distribution_0.Value2;

                if (meanNeighborhoodDefoliation <= 1.0 && meanNeighborhoodDefoliation >= 0.8)
                {
                    dist = insect.SusceptibleTable[suscIndex].Distribution_80.Name;
                    value1 = insect.SusceptibleTable[suscIndex].Distribution_80.Value1;
                    value2 = insect.SusceptibleTable[suscIndex].Distribution_80.Value2;
                }
                else if (meanNeighborhoodDefoliation < 0.8 && meanNeighborhoodDefoliation >= 0.6)
                {
                    dist = insect.SusceptibleTable[suscIndex].Distribution_60.Name;
                    value1 = insect.SusceptibleTable[suscIndex].Distribution_60.Value1;
                    value2 = insect.SusceptibleTable[suscIndex].Distribution_60.Value2;
//.........这里部分代码省略.........
开发者ID:pjbitterman,项目名称:Extensions-Disturbance,代码行数:101,代码来源:Defoliate.cs

示例4: Algorithm

        //---------------------------------------------------------------------
        public static bool Algorithm(ISpecies   species,
            ActiveSite site)
        {
            if (species.EffectiveSeedDist == Universal)
                return UniversalDispersal.Algorithm(species, site);

            if (! Reproduction.SufficientResources(species, site)) {
                if (isDebugEnabled)
                    log.DebugFormat("site {0}: {1} not seeded: insufficient light",
                                    site.Location, species.Name);
                return false;
            }

            if (! Reproduction.Establish(species, site)) {
                if (isDebugEnabled)
                    log.DebugFormat("site {0}: {1} not seeded: cannot establish",
                                    site.Location, species.Name);
                return false;
            }

            if (Reproduction.MaturePresent(species, site)) {
                if (isDebugEnabled)
                    log.DebugFormat("site {0}: {1} seeded on site",
                                    site.Location, species.Name);
                return true;
            }

            if (isDebugEnabled)
                log.DebugFormat("site {0}: search neighbors for {1}",
                                site.Location, species.Name);

            foreach (RelativeLocationWeighted reloc in Seeding.MaxSeedQuarterNeighborhood)
            {
                double distance = reloc.Weight;
                int rRow = (int) reloc.Location.Row;
                int rCol = (int) reloc.Location.Column;

                double EffD = (double) species.EffectiveSeedDist;
                double MaxD = (double) species.MaxSeedDist;

                if(distance > MaxD + ((double) Model.Core.CellLength / 2.0 * 1.414))
                    return false;  //Check no further

                double dispersalProb = GetDispersalProbability(EffD, MaxD, distance);

                //First check the Southeast quadrant:
                if (dispersalProb > Model.Core.GenerateUniform())
                {
                    Site neighbor = site.GetNeighbor(reloc.Location);
                    if (neighbor != null && neighbor.IsActive)
                        if (Reproduction.MaturePresent(species, (ActiveSite) neighbor))
                            return true;
                }

                //Next, check all other quadrants:
                if (dispersalProb > Model.Core.GenerateUniform())
                {
                    Site neighbor = site.GetNeighbor(new RelativeLocation(rRow * -1, rCol));
                    if(rCol == 0)
                        neighbor = site.GetNeighbor(new RelativeLocation(0, rRow));
                    if (neighbor != null && neighbor.IsActive)
                        if (Reproduction.MaturePresent(species, (ActiveSite) neighbor))
                            return true;
                }

                if (dispersalProb > Model.Core.GenerateUniform())
                {
                    Site neighbor = site.GetNeighbor(new RelativeLocation(rRow * -1, rCol * -1));
                    if (neighbor != null && neighbor.IsActive)
                        if (Reproduction.MaturePresent(species, (ActiveSite) neighbor))
                            return true;
                 }

                if (dispersalProb > Model.Core.GenerateUniform())
                {
                    Site neighbor = site.GetNeighbor(new RelativeLocation(rRow, rCol * -1));
                    if(rCol == 0)
                        neighbor = site.GetNeighbor(new RelativeLocation(0, rRow * -1));
                    if (neighbor != null && neighbor.IsActive)
                        if (Reproduction.MaturePresent(species, (ActiveSite) neighbor))
                            return true;
                }

            }  // end foreach relativelocation

            return false;
        }
开发者ID:LANDIS-II-Foundation,项目名称:Library-Succession,代码行数:88,代码来源:WardSeedDispersal.cs


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