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


C# PriorityQueue.queue方法代码示例

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


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

示例1: determinePath

        // <summary>
        // Given two Node objects, determines a path between the startNode and the endNode
        // </summary>
        // <param name="startNode"> the start Node </param>
        // <param name="endNode"> the end Node </param>
        public void determinePath(GenerateGraph.Node startNode, GenerateGraph.Node endNode)
        {
            if (startNode == null || endNode == null)
                return;
            PriorityQueue<GenerateGraph.Node> pq = new PriorityQueue<GenerateGraph.Node>(map.nodes.Count);
            pq.queue(startNode);
            Dictionary<GenerateGraph.Node, GenerateGraph.Node> came_from = new Dictionary<GenerateGraph.Node, GenerateGraph.Node>();
            Dictionary<GenerateGraph.Node, float> cost_so_far = new Dictionary<GenerateGraph.Node, float> ();
            came_from.Add(startNode, null);
            cost_so_far.Add (startNode, 0);

            Dictionary<GenerateGraph.Node, int> nodeToId = new Dictionary<GenerateGraph.Node, int>();
            for (int i = 0; i < map.nodes.Count; i++) {
                nodeToId.Add (map.nodes[i], i);
            }
            GenerateGraph.Node current;

            while (pq.getSize() > 0) {
                current = pq.dequeue();
                print(current.point.ToString());
                print("Neighbor Count: " + current.neighbors.Count);
                if (current.Equals(endNode)) {
                    print ("True");
                    break;
                }

                for (int i = 0; i < current.neighbors.Count; i++) {
                    print("Current Neighbor: " + current.neighbors[i].point.ToString());
                    float new_cost = cost_so_far[current] +
                        distanceBetweenNodes(current, current.neighbors[i]);
                    if (cost_so_far.ContainsKey(current.neighbors[i]) == false ||
                        new_cost < cost_so_far[current.neighbors[i]]) {
                        cost_so_far[current.neighbors[i]] = new_cost;
                        current.neighbors[i].priority = new_cost;
                        pq.queue(current.neighbors[i]);
                        came_from[current.neighbors[i]] = current;
                    }
                }
            }

            //Put nodes of the path into the list
            path = new List<GenerateGraph.Node> ();
            GenerateGraph.Node currentNode = endNode;
            path.Add (currentNode);
            while (currentNode.Equals(startNode) == false) {
                currentNode = came_from[currentNode];
                path.Add (currentNode);
            }

            path.Reverse();
            print ("Path Nodes: ");
            for (int i = 0; i < path.Count; i++) {
                print(nodeToId[path[i]] + "\n");
            }
        }
开发者ID:maZang,项目名称:ModbotPathPlan,代码行数:60,代码来源:PathPlanning.cs

示例2: ThreadFunction

    // <summary>
    // Performs an A* traversal from the start node to the end node; however, the end node
    // only provides a direction for the path finding, as once the current node in the
    // traversal is pathLength away from the start node, the traversal is complete
    // </summary>
    protected override void ThreadFunction()
    {
        PriorityQueue<Node> open = new PriorityQueue<Node> (PathPlanningDataStructures.graph.Size ());
        HashSet<Node> closed = new HashSet<Node> ();
        Dictionary<Node, Node> came_from = new Dictionary<Node, Node> ();
        Dictionary<Node, float> cost_so_far = new Dictionary<Node, float> ();
        came_from.Add (startNode, null);
        cost_so_far.Add (startNode, 0);
        Debug.Log ("the start node: " + startNode);
        open.queue (PathPlanningDataStructures.heuristic.Estimate (startNode), startNode);
        while (open.getSize() > 0) {
            Node current = open.dequeue ();

            if (current.Equals (PathPlanningDataStructures.graph.endNode) ||
                Node.distanceBetweenNodes (startNode, current) >= pathLength) {
                if (came_from[current] == null) {
                    came_from[current] = startNode;
                }
                destinationNode = current;
                break;
            }

            foreach (Node n in current.neighbors) {
                float graph_cost = cost_so_far [current] + Node.distanceBetweenNodes (current, n);
                if (cost_so_far.ContainsKey (n) == false || graph_cost < cost_so_far [n]) {
                    cost_so_far [n] = graph_cost;
                    float priority = graph_cost + PathPlanningDataStructures.heuristic.Estimate (n);
                    open.queue (priority, n);
                    came_from [n] = current;
                }
            }
        }

        //Put nodes of the path into the list
        pathWayPoints = new List<Vector3> ();
        Node currentNode = destinationNode;
        pathWayPoints.Add (currentNode.position);
        while (currentNode.Equals(startNode) == false) {
            currentNode = came_from [currentNode];
            pathWayPoints.Add (currentNode.position);
            Debug.Log (currentNode.ToString());
        }
        pathWayPoints.Reverse ();
    }
开发者ID:maZang,项目名称:ModbotPathPlan,代码行数:49,代码来源:DynamicPathThreadJob.cs

示例3: GetPath

    public static List<Node> GetPath(Vector3 start)
    {
        Node startNode = graph.getClosestNode(start);
        PriorityQueue<Node> open = new PriorityQueue<Node>(graph.Size());
        HashSet<Node> closed = new HashSet<Node>();
        Dictionary<Node, Node> came_from = new Dictionary<Node, Node>();
        Dictionary<Node, float> cost_so_far = new Dictionary<Node, float>();
        came_from.Add(startNode, null);
        cost_so_far.Add(startNode, 0);
        open.queue(heuristic.Estimate(startNode), startNode);

        while (open.getSize() > 0) {
            Node current = open.dequeue();

            if (current.Equals(graph.endNode)) {
                break;
            }

            foreach (Node n in current.neighbors) {

                float graph_cost = cost_so_far[current] + Node.distanceBetweenNodes(current, n);

                if (cost_so_far.ContainsKey(n) == false ||  graph_cost < cost_so_far[n]) {
                    cost_so_far[n] = graph_cost;
                    float priority = graph_cost + heuristic.Estimate(n);
                    open.queue(priority, n);
                    came_from[n] = current;
                }
            }
        }

        //Put nodes of the path into the list
        List<Node> path = new List<Node> ();
        Node currentNode = graph.endNode;
        path.Add (currentNode);
        while (currentNode.Equals(startNode) == false) {
            currentNode = came_from[currentNode];
            path.Add (currentNode);
        }
        path.Reverse();
        return path;
    }
开发者ID:maZang,项目名称:ModbotPathPlan,代码行数:42,代码来源:AStar.cs

示例4: HeuristicD

    public HeuristicD(GenerateGraph graph)
    {
        heuristicCost = new Dictionary<Node, float>();

        PriorityQueue<Node> pq = new PriorityQueue<Node>(graph.Size ());
        Dictionary<Node, float> cost_so_far = new Dictionary<Node, float> ();
        pq.queue(0.0f, graph.endNode);
        cost_so_far.Add (graph.endNode, 0.0f);
        while (pq.getSize() > 0) {
            Node current = pq.dequeue();
            heuristicCost[current] = cost_so_far[current];
            for (int i = 0; i < current.neighbors.Count; i++) {
                float new_cost = cost_so_far[current] + Node.distanceBetweenNodes(current, current.neighbors[i]);
                if (!cost_so_far.ContainsKey(current.neighbors[i]) || new_cost < cost_so_far[current.neighbors[i]]) {
                    cost_so_far[current.neighbors[i]] = new_cost;
                    pq.queue(new_cost, current.neighbors[i]);
                }
            }
        }
    }
开发者ID:intel-cornellcup,项目名称:mini-modbot-simulation,代码行数:20,代码来源:Heuristic.cs


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