//--------------------------------------------------------------------- void IStandRankingMethod.RankStands(List<Stand> stands, StandRanking[] rankings) { InitializeForRanking(stands, stands.Count); for (int i = 0; i < stands.Count; i++) { Stand stand = stands[i]; double rank = 0; if (! stand.IsSetAside) { //check if stand meets all the ranking requirements bool meetsAllRequirements = true; foreach (IRequirement requirement in requirements) { if (! requirement.MetBy(stand)) { meetsAllRequirements = false; //set stand rank to 0 rankings[i].Rank = 0; break; } } //if the stand meets all the requirements and is not set-aside,, get its rank if (meetsAllRequirements) { rank = ComputeRank(stand, i); } //otherwise, rank it 0 (so it will not be harvested.) else { rank = 0; //PlugIn.ModelCore.UI.WriteLine(" Stand {0} did not meet its requirements.", stand.MapCode); } } else { rankings[i].Rank = 0; } // Hack for land-use: set a stand's rank to 0 if it has at least one site whose land use doesn't allow harvesting // Really intended for case where each stand has one site. foreach (ActiveSite site in stand) { // TO DO: Land-use library should initialize the site variable to have a default land-use // that allows harvesting (e.g., "forest"). bool siteAllowsHarvest = (LandUse.SiteVar == null) || LandUse.SiteVar[site].AllowsHarvest; if (!siteAllowsHarvest) { rank = 0; break; } } rankings[i].Stand = stand; rankings[i].Rank = rank; //assign rank to stand //PlugIn.ModelCore.UI.WriteLine(" Stand {0} rank = {1}.", rankings[i].Stand.MapCode, rankings[i].Rank); } }
//--------------------------------------------------------------------- void IStandRankingMethod.RankStands(List<Stand> stands, StandRanking[] rankings) { InitializeForRanking(stands, stands.Count); for (int i = 0; i < stands.Count; i++) { Stand stand = stands[i]; double rank = 0; if (! stand.IsSetAside) { //check if stand meets all the ranking requirements bool meetsAllRequirements = true; foreach (IRequirement requirement in requirements) { if (! requirement.MetBy(stand)) { meetsAllRequirements = false; //set stand rank to 0 rankings[i].Rank = 0; break; } } //if the stand meets all the requirements and is not set-aside,, get its rank if (meetsAllRequirements) { rank = ComputeRank(stand, i); } //otherwise, rank it 0 (so it will not be harvested.) else { rank = 0; //PlugIn.ModelCore.UI.WriteLine(" Stand {0} did not meet its requirements.", stand.MapCode); } } else { rankings[i].Rank = 0; } rankings[i].Stand = stand; rankings[i].Rank = rank; //assign rank to stand //PlugIn.ModelCore.UI.WriteLine(" Stand {0} rank = {1}.", rankings[i].Stand.MapCode, rankings[i].Rank); } }
//--------------------------------------------------------------------- /// <summary> /// Compares two stand rankings such that the higher ranking comes /// before the lower ranking. /// </summary> public static int CompareRankings(StandRanking x, StandRanking y) { if (x.Rank > y.Rank) return -1; else if (x.Rank < y.Rank) return 1; else return 0; }
//--------------------------------------------------------------------- private static bool RankOfZero(StandRanking rank) { if (rank.Rank == 0) return false; else return true; }