//---------------------------------------------------------------------
        // Re-written by R. Scheller to simplify and speed the stand processing.
        private bool CheckRule(Stand stand, InclusionRule rule)
        {
            //bool meets = false;
            int numCellsValid = 0;
            int numActiveCells = 0;
            
            int[] numCellsOtherSpecies = new int[Model.Core.Species.Count];
            
            foreach(ActiveSite site in stand.GetActiveSites())
            {
                //if(!site.IsActive)
                //    continue;

                numActiveCells++;
                    
                bool goodSite = false;
                //bool otherSpecies = false;
                    
                //Landis.Library.BaseCohorts.ISiteCohorts siteCohorts = (Landis.Library.BaseCohorts.ISiteCohorts) Model.Core.SuccessionCohorts[site];
                
                foreach(ISpecies species in Model.Core.Species)
                {
                    if(SiteVars.Cohorts[site][species] != null)
                    {
                        foreach (ICohort cohort in SiteVars.Cohorts[site][species])
                        {
                            if (rule.SpeciesList.Contains(species.Name) && rule.RuleAgeRange.Contains(cohort.Age)) 
                            {
                                goodSite = true;
                            }
                        
                            // Some other species, NOT in the list
                            if (!rule.SpeciesList.Contains(species.Name) && rule.RuleAgeRange.Contains(cohort.Age))   
                            {
                                //otherSpecies = true;
                                numCellsOtherSpecies[species.Index]++;
                            }
                        }
                    
                    }
                }
                
                if(goodSite) 
                    numCellsValid++;

                //if(otherSpecies)
                //numCellsOtherSpecies[species.Index]++;

                
            }  // done looping through sites
            
           if(numCellsValid == 0)  // There are no good cells whatsoever.
               return false;

            bool highest = true;

            //If percent != -1, compare to the Percent of Cells
            if (rule.PercentOfCells != -1) 
            {
                double targetNumCells = (double) numActiveCells * rule.PercentOfCells;
                
                if(targetNumCells > numActiveCells)
                {
                    string message = string.Format("  Harvest Inclusion Rule Error:  target number of cells {0} exceeds number in stand {1}", targetNumCells, numActiveCells);
                    throw new ApplicationException(message);
                }
                if(numCellsValid >= targetNumCells)
                {
                    //Model.Core.UI.WriteLine("       numGoodSites={0}, targetNumCells={1}", numCellsValid, targetNumCells);
                    return true;
                }
            }
            
            //If percent == -1, use 'highest' evaluation algorithm
            else 
            {
                    
                for(int i = 0; i < Model.Core.Species.Count; i++)
                {
                    if(numCellsValid < numCellsOtherSpecies[i])
                        highest = false;
                    //Model.Core.UI.WriteLine("       numGoodSites={0}, otherSppCnt={1}, true? {2}", numCellsValid, otherSpeciesCount[i], highest);
                }
            }
            
            return highest;
            
        }
Пример #2
0
        //---------------------------------------------------------------------
        // Re-written by R. Scheller to simplify and speed the stand processing.
        private bool CheckRule(Stand stand, InclusionRule rule)
        {
            //bool meets = false;
            int  numCellsValid  = 0;
            int  numActiveCells = 0;
            bool goodSite       = false;
            bool otherSpecies   = false;

            int[] numCellsOtherSpecies = new int[Model.Core.Species.Count];

            foreach (ActiveSite site in stand.GetActiveSites())
            {
                //if(!site.IsActive)
                //    continue;

                numActiveCells++;
                //bool otherSpecies = false;

                //Landis.Library.BaseCohorts.ISiteCohorts siteCohorts = (Landis.Library.BaseCohorts.ISiteCohorts) Model.Core.SuccessionCohorts[site];

                foreach (ISpecies species in Model.Core.Species)
                {
                    if (SiteVars.Cohorts[site][species] != null)
                    {
                        foreach (ICohort cohort in SiteVars.Cohorts[site][species])
                        {
                            if (rule.SpeciesList.Contains(species.Name) && rule.RuleAgeRange.Contains(cohort.Age))
                            {
                                goodSite = true;
                            }

                            // Some other species, NOT in the list
                            if (!rule.SpeciesList.Contains(species.Name) && rule.RuleAgeRange.Contains(cohort.Age))
                            {
                                otherSpecies = true;
                            }
                        }
                    }
                    if (otherSpecies)
                    {
                        numCellsOtherSpecies[species.Index]++;
                        otherSpecies = false;
                    }
                }
                if (goodSite)
                {
                    numCellsValid++;
                    goodSite = false;
                }
                //if(otherSpecies)
                //numCellsOtherSpecies[species.Index]++;
            }  // done looping through sites

            if (numCellsValid == 0) // There are no good cells whatsoever.
            {
                return(false);
            }

            bool highest = true;

            //If percent != -1, compare to the Percent of Cells
            if (rule.PercentOfCells != -1)
            {
                double targetNumCells = (double)numActiveCells * rule.PercentOfCells;

                if (targetNumCells > numActiveCells)
                {
                    string message = string.Format("  Harvest Inclusion Rule Error:  target number of cells {0} exceeds number in stand {1}", targetNumCells, numActiveCells);
                    throw new ApplicationException(message);
                }
                if (numCellsValid >= targetNumCells)
                {
                    //Model.Core.UI.WriteLine("       numGoodSites={0}, targetNumCells={1}", numCellsValid, targetNumCells);
                    return(true);
                }
            }

            //If percent == -1, use 'highest' evaluation algorithm
            else
            {
                for (int i = 0; i < Model.Core.Species.Count; i++)
                {
                    if (numCellsValid < numCellsOtherSpecies[i])
                    {
                        return(false);
                    }
                    //Model.Core.UI.WriteLine("       numGoodSites={0}, otherSppCnt={1}, true? {2}", numCellsValid, otherSpeciesCount[i], highest);
                }
            }

            return(highest);
        }