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


C# PriorityQueue.DeleteMinimum方法代码示例

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


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

示例1: BranchAndBound

        public ArrayList BranchAndBound(City[] Cities, ArrayList Route, double BSSF)
        {
            Node startNode = new Node(Cities);
            startNode.initStaticMembers();
            PriorityQueue pQ = new PriorityQueue(startNode);
            ArrayList bbRoute = null;
            Stopwatch timer = new Stopwatch();
            timer.Start();

            //while ((pQ.Size() > 0) && (pQ.Peek() < BSSF) && (timer.Elapsed.TotalMinutes < 10))
            while ((pQ.Size() > 0) && (pQ.Peek() < BSSF) && (timer.Elapsed.TotalSeconds < 30))
            {
                // Keep track of the largest size of the queue
                if (pQ.Size() > Node.maxNodesCreated)
                {
                    Node.maxNodesCreated = pQ.Size();
                }

                startNode = pQ.DeleteMinimum();
                //startNode.matrix2Table();

                // Check for a solution
                if (startNode.includedEdges == Cities.Length)
                {
                    ArrayList tempRoute = new ArrayList();

                    if (!startNode.exited.Contains(-1))
                    {
                        int index = 0;

                        while (tempRoute.Count < Cities.Length)
                        {
                            tempRoute.Add(Cities[startNode.exited[index]]);
                            index = startNode.exited[index];
                        }

                        BSSF = startNode.lowerBound;
                        bbRoute = tempRoute;
                        Node.numSolutions++;
                    }
                }

                Node incNode = new Node(startNode);
                Node excNode = new Node(startNode);
                Node maxInclude = null;
                Node maxExclude = null;

                double maxDiff = -1;
                double diff = 0;
                int maxRow = 0;
                int maxCol = 0;

                for (int row = 0; row < startNode.matrixSize; row++)
                {
                    for (int col = 0; col < startNode.matrixSize; col++)
                    {
                        if (startNode.rcMatrix[row, col] == 0)
                        {
                            Node includeNode = new Node(incNode, true, row, col);
                            Node excludeNode = new Node(excNode, false, row, col);
                            diff = excludeNode.lowerBound - includeNode.lowerBound;
                            Node.numStatesCreated += 2;

                            if (diff > maxDiff)
                            {
                                maxDiff = diff;
                                maxRow = row;
                                maxCol = col;
                                maxInclude = new Node(includeNode);
                                maxExclude = new Node(excludeNode);
                            }
                        }
                    }
                }

                if (maxInclude != null && maxInclude.lowerBound < BSSF)
                {
                    pQ.Insert(maxInclude);
                }
                else
                {
                    Node.pruneCount++;
                }

                if (maxExclude != null && maxExclude.lowerBound < BSSF)
                {
                    pQ.Insert(maxExclude);
                }
                else
                {
                    Node.pruneCount++;
                }
            }

            timer.Stop();
            Node.timeElapsed = timer.ElapsedMilliseconds;

            if (bbRoute == null)
            {
                return Route;
//.........这里部分代码省略.........
开发者ID:belteshazzar543,项目名称:TSP,代码行数:101,代码来源:Algorithms.cs


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