Beispiel #1
0
 //---------------------------------------------------------------------
 /// <summary>
 /// Determines if the stand has a rank not equal to 0
 /// Returns false if rank is 0, else returns true
 /// </summary>
 private static bool RankOfZero(StandRanking rank)
 {
     if (rank.Rank == 0)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Beispiel #2
0
        //---------------------------------------------------------------------

        /// <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);
            }
        }
Beispiel #3
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Adds a stand's unharvested neighbors and their rankings to a
        /// sorted list of stand rankings.
        /// </summary>
        /// <remarks>
        /// The stand rankings are in highest to lowest order.  A neighbor is
        /// only added to the list if its rank is > 0 and it isn't already in
        /// the list.
        /// </remarks>
        public void AddUnharvestedNeighbors(Stand stand,
                                            List <StandRanking> neighborRankings)
        {
            foreach (Stand neighbor in stand.Neighbors)
            {
                if (!neighbor.Harvested)
                {
                    bool inList = false;
                    foreach (StandRanking ranking in neighborRankings)
                    {
                        if (ranking.Stand == neighbor)
                        {
                            inList = true;
                            break;
                        }
                    }
                    if (inList)
                    {
                        continue;
                    }

                    StandRanking neighborRanking = GetRanking(neighbor);
                    if (neighborRanking.Rank <= 0)
                    {
                        continue;
                    }

                    int i;
                    for (i = 0; i < neighborRankings.Count; i++)
                    {
                        if (neighborRankings[i].Rank < neighborRanking.Rank)
                        {
                            break;
                        }
                    }

                    //Model.Core.UI.WriteLine("   place={0}, rank={1}.", i, neighborRanking.Rank);
                    neighborRankings.Insert(i, neighborRanking);
                }
            }
        }
        //---------------------------------------------------------------------
        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;
                        //Model.Core.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
                //Model.Core.UI.WriteLine("   Stand {0} rank = {1}.", rankings[i].Stand.MapCode, rankings[i].Rank);
            }
        }
Beispiel #5
0
        //--------------------------------------------------------------

        // For the starting stand do partial stand spreading until either
        // we run out of stands or we have our target area
        private bool SpreadFromStand(Stand startingStand)
        {
            List <Stand> standsConsidered = new List <Stand>();
            // a list of every stand we have thought about considering
            // used to prevent considering a stand more than once
            List <Stand>        standsToConsiderAll      = new List <Stand>();
            List <StandRanking> standsToConsiderRankings = new List <StandRanking>();
            bool       rtrnVal = false;
            Stand      crntStand;
            double     crntRank;
            ActiveSite startingSite;// = null;

            // If we have a valid starting stand, put it on the list to
            // consider
            if (startingStand != null && !startingStand.IsSetAside)
            {
                standsToConsiderRankings.Insert(0, GetRanking(startingStand));
                standsToConsiderAll.Add(startingStand);
            }

            while (standsToConsiderRankings.Count > 0 &&
                   standsToConsiderRankings[0].Rank > 0 &&
                   areaSelected < maxTargetSize)
            {
                // Get the stand to work with for this loop iteration
                crntStand = standsToConsiderRankings[0].Stand;
                crntRank  = standsToConsiderRankings[0].Rank;
                standsToConsiderRankings.RemoveAt(0);

                // If the stand is not set aside, Get the starting site
                if (!crntStand.IsSetAside)
                {
                    // first stand starts at a random site, subsequent
                    // stands start at an adjoining site
                    if (standsConsidered.Count == 0)
                    {
                        startingSite = crntStand.GetRandomActiveSite;
                    }
                    else
                    {
                        startingSite = GetNeighboringSite(standsConsidered, crntStand);
                        if (startingSite == false)
                        {
                            standsToReject.Add(crntStand);
                            continue;
                        }
                    }
                }
                else
                {
                    // if the stand is set aside, it doesn't get processed
                    // and its neighbors don't go on the stand list
                    standsToReject.Add(crntStand);
                    continue;
                }

                // Enqueue the eligible sites and put the stand
                // on the appropriate queue(s)
                if (EnqueueEligibleSites(startingSite, crntStand))
                {
                    standsToHarvest.Enqueue(crntStand);
                    standsToHarvestRankings.Enqueue(crntRank);
                }
                else
                {
                    standsToReject.Add(crntStand);
                }

                standsConsidered.Add(crntStand);

                if (areaSelected < maxTargetSize)
                {
                    // Get the neighbors and put them on the
                    // standsToConsider queue

                    foreach (Stand neighbor in crntStand.Neighbors)
                    {
                        if (!standsConsidered.Contains(neighbor) &&
                            !standsToConsiderAll.Contains(neighbor) &&
                            !neighbor.Harvested)
                        {
                            StandRanking neighborRanking = GetRanking(neighbor);
                            standsToConsiderAll.Add(neighbor);
                            if (neighborRanking.Rank <= 0)
                            {
                                continue;
                            }

                            int i;
                            for (i = 0; i < standsToConsiderRankings.Count; i++)
                            {
                                if (standsToConsiderRankings[i].Rank < neighborRanking.Rank)
                                {
                                    break;
                                }
                            }

                            standsToConsiderRankings.Insert(i, neighborRanking);
                        }
                    }
                }
            }

            // If we found enough to meet our goal, return true,
            // otherwise return the default of false.
            if (areaSelected >= minTargetSize)
            {
                rtrnVal = true;
            }

            return(rtrnVal);
        }
        //---------------------------------------------------------------------
        /// <summary>
        /// Determines if the stand has a rank not equal to 0
        /// Returns false if rank is 0, else returns true
        /// </summary>
        private static bool RankOfZero(StandRanking rank)
        {
            if (rank.Rank == 0)
                return false;
            else
                return true;

        }
        //---------------------------------------------------------------------

        /// <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;
        }
Beispiel #8
0
        } // IEnumerator<ActiveSite> IEnumerable<ActiveSite>.GetEnumerator()

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

        // For the starting stand do partial stand spreading until either
        // we run out of stands or we have our target area
        private bool SpreadFromStand(Stand startingStand)
        {
            List <Stand> standsConsidered = new List <Stand>();
            // a list of every stand we have thought about considering
            // used to prevent considering a stand more than once
            List <Stand>        standsToConsiderAll      = new List <Stand>();
            List <StandRanking> standsToConsiderRankings = new List <StandRanking>();
            bool   rtrnVal = false;
            Stand  crntStand;
            double crntRank;

            // If we have a valid starting stand, put it on the list to
            // consider
            if (startingStand != null && !startingStand.IsSetAside)
            {
                standsToConsiderRankings.Insert(0, GetRanking(startingStand));
                standsToConsiderAll.Add(startingStand);
            }

            // Miranda and Scheller testing methods to make repeat harvest work with stand spreading.
            //if (startingStand != null && startingStand.IsSetAside)
            //    if( startingStand.LastPrescription.
            //    //if (startingStand.LastPrescription.SiteSelectionMethod.ToString() == "Landis.Harvest.CompleteStandSpreading")
            //    {
            //        standsToConsiderRankings.Insert(0, GetRanking(startingStand));
            //        standsToConsiderAll.Add(startingStand);
            //        return true;
            //    }


            while (standsToConsiderRankings.Count > 0 &&
                   standsToConsiderRankings[0].Rank > 0 &&
                   areaSelected < maxTargetSize)
            {
                // Get the stand to work with for this loop iteration
                crntStand = standsToConsiderRankings[0].Stand;
                crntRank  = standsToConsiderRankings[0].Rank;
                standsToConsiderRankings.RemoveAt(0);

                // If the stand is set aside, it doesn't get processed
                if (crntStand.IsSetAside)
                {
                    continue;
                }

                // Enqueue the eligible sites and put the stand
                // on the appropriate queue(s)
                if (EnqueueEligibleSites(crntStand))
                {
                    standsToHarvest.Enqueue(crntStand);
                    standsToHarvestRankings.Enqueue(crntRank);
                }
                else
                {
                    standsToReject.Add(crntStand);
                }

                standsConsidered.Add(crntStand);

                if (areaSelected < maxTargetSize)
                {
                    // Get the neighbors and put them on the
                    // standsToConsider queue

                    foreach (Stand neighbor in crntStand.Neighbors)
                    {
                        if (!standsConsidered.Contains(neighbor) &&
                            !standsToConsiderAll.Contains(neighbor) &&
                            !neighbor.Harvested)
                        {
                            StandRanking neighborRanking = GetRanking(neighbor);
                            standsToConsiderAll.Add(neighbor);
                            if (neighborRanking.Rank <= 0)
                            {
                                continue;
                            }

                            int i;
                            for (i = 0; i < standsToConsiderRankings.Count; i++)
                            {
                                if (standsToConsiderRankings[i].Rank < neighborRanking.Rank)
                                {
                                    break;
                                }
                            }

                            standsToConsiderRankings.Insert(i, neighborRanking);
                        } // if(!standsConsidered.Contains(neighbor)
                    }     // foreach (Stand neighbor in crntStand.Neighbors)
                }         // if(areaSelected >= maxTargetSize)
            }             // while (standsToConsider.Count > 0 && ..

            // If we found enough to meet our goal, return true,
            // otherwise return the default of false.
            if (areaSelected >= minTargetSize)
            {
                rtrnVal = true;
            }

            return(rtrnVal);
        } // private bool spreadFromStand() {