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


C# PriorityQueue.pop方法代码示例

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


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

示例1: findDist

        private int findDist(UniverseGraph.SystemId source, UniverseGraph.SystemId dest)
        {
            open = new PriorityQueue<int, Node>();
            closed = new HashSet<UniverseGraph.SystemId>();

            open.push(0, new Node(null, source));

            Node current = null;
            int currentPriority = 0;
            while ((open.count() > 0) && (closed.Count < maxClosedSize))
            {
                //pop top
                PriorityQueue<int, Node>.Pair head = open.pop();
                current = head.value;
                currentPriority = head.key;

                //check if we've reached the destination
                if (current.sysid.id == dest.id)
                    return currentPriority*-1;

                if (!closed.Contains(current.sysid))
                {
                    //mark that we've already expanded it
                    closed.Add(current.sysid);
                    //expand it
                    foreach (UniverseGraph.SystemId neighbour in graph.systemEdges[current.sysid])
                    {
                        if (graph.idToInfo[neighbour].security > minSecurity)
                        {
                            Node nNode = new Node(current, neighbour);
                            //decrease priority by number of jumps so far - ie breadth first search
                            //some a* like heuristic would be nice....
                            int nPriority = currentPriority - 1;
                            open.push(nPriority, nNode);
                        }
                    }
                }
            }

            //some kind of failure state - either no path, or seach size exceeded (too far)
            return -1;
        }
开发者ID:fcostin,项目名称:eve_space_trucker,代码行数:42,代码来源:Pathfinder.cs

示例2: CreateTree

 private static Node CreateTree(PriorityQueue<Node> priorityQueue)
 {
     //Terminating node
     priorityQueue.push(new Node(System.Byte.MinValue, 0, null, null, true));
     while (priorityQueue.Count != 1)
     {
         Node first = priorityQueue.pop();
         Node second = priorityQueue.pop();
         Node newNode = new Node(System.Byte.MinValue, first.frequency + second.frequency, first, second, false);
         priorityQueue.push(newNode);
     }
     Node root = priorityQueue.pop();
     return root;
 }
开发者ID:ZilvinasAbr,项目名称:HuffmanCompression,代码行数:14,代码来源:Compressor.cs

示例3: computePlan

        public PlannerState computePlan(double initialWallet,
            double initialCargoCap,
            string initialSystemName,
            int maxJumps)
        {
            //reset lists
            this.open = new PriorityQueue<double, PlannerState>();
            this.closed = new SpaceTimeProfitCache();

            //compute a heuristic for the max possible profit rate
            double bestProfitRate = 0.0;
            double candidateProfitRate = 0.0;
            foreach(List<TradeRouteMiner.Route> lr in trm.systemRoutes.Values)
            {
                foreach (TradeRouteMiner.Route r in lr)
                {
                    candidateProfitRate = Math.Min(r.profitDensityRate * initialCargoCap, r.bulkProfitRate);
                    bestProfitRate = Math.Max(bestProfitRate, candidateProfitRate);
                }
            }

            //hence we can order PlannerStates by state.wallet + bestProfitRate*(maxJumps-state.jumpsElapsed)
            //and use a*

            Console.WriteLine("best profit rate heuristic : " + bestProfitRate);

            //establish the initial state
            PlannerState initialState = new PlannerState(initialCargoCap, initialWallet, initialSystemName);
            open.push(getPriority(initialState, bestProfitRate, maxJumps), initialState);

            //stat tracking
            int statTouchedStates = 0;
            int statAddedStates = 0;
            int progressUpdateFrequency = 10000;

            //use a* to find the optimal plan up to max specified number of jumps
            while (open.count() > 0)
            {
                PriorityQueue<double, PlannerState>.Pair pair = open.pop();
                ++statTouchedStates;

                //Console.WriteLine("!tradeplanner : open count = " + open.count()
                //    + "; jumpsElapsed = " + pair.value.jumpsElapsed
                //    + "; priority = "+pair.key);

                if (statTouchedStates % progressUpdateFrequency == 0)
                {
                    //display search progress update for user
                    Console.WriteLine("TradePlanner Stats : WORKING");
                    Console.WriteLine("\ttouched states = " + statTouchedStates);
                    Console.WriteLine("\tadded states = " + statAddedStates);
                    Console.WriteLine("\tstates in open list = " + open.count());
                    Console.WriteLine("\thighest priority = " + pair.key);
                    Console.WriteLine("\trecent jumps elapsed = " + pair.value.jumpsElapsed);
                }

                //check for stopping condition
                if (pair.value.jumpsElapsed >= maxJumps)
                {
                    Console.WriteLine("TradePlanner Stats : FINISHED!");
                    Console.WriteLine("\ttouched states = " + statTouchedStates);
                    Console.WriteLine("\tadded states = " + statAddedStates);
                    Console.WriteLine("\tstates in open list = " + open.count());
                    Console.WriteLine("\thighest priority = " + pair.key);
                    Console.WriteLine("\trecent jumps elapsed = " + pair.value.jumpsElapsed);
                    return pair.value;
                }

                //otherwise, expand planner state and pop children back into the open list
                foreach (PlannerState childState in pair.value.expandStates(trm, graph))
                {
                    //only add the child state if it gives us an improved profit upon what we've already seen
                    if(closed.achievesBetterProfit(childState.sysName, childState.jumpsElapsed, childState.wallet))
                    {
                        open.push(getPriority(childState,bestProfitRate, maxJumps), childState);
                        ++statAddedStates;
                    }
                }

            }

            //we've failed, for some reason, to find a plan
            return null;
        }
开发者ID:fcostin,项目名称:eve_space_trucker,代码行数:84,代码来源:TradePlanner.cs


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