本文整理汇总了C#中System.Collections.Generic.PriorityQueue.RemoveMin方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.RemoveMin方法的具体用法?C# PriorityQueue.RemoveMin怎么用?C# PriorityQueue.RemoveMin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.RemoveMin方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AStarSearch
public void AStarSearch(Vector2 sourcePoint, Vector2 destinationPoint, out Vector2 nextNode)
{
//Console.WriteLine("Going from (" + sourcePoint.X + ", " + sourcePoint.Y + ") to (" + destinationPoint.X + ", " + destinationPoint.Y + ")");
Node source = adjacencyList[(int)(columns * sourcePoint.X + sourcePoint.Y)];
Node destination = adjacencyList[(int)(columns * destinationPoint.X + destinationPoint.Y)];
PriorityQueue <Node> Q = new PriorityQueue<Node>();
source.Distance = 0;
Q.Add(source.Priority, source);
while (Q.Count > 0)
{
Node current = Q.RemoveMin();
if (current == destination)
{
Node pathParent = current.Parent;
Stack<Node> path = new Stack<Node>();
path.Push(current);
while (pathParent != null)
{
path.Push(pathParent);
pathParent = pathParent.Parent;
}
Thread t = new Thread(new ParameterizedThreadStart(DrawPath));
t.Start(path);
path.Pop();
nextNode = new Vector2(path.Peek().X * 32, path.Peek().Y * 32);
return;
}
List<Node> allAdjacent = new List<Node>();
allAdjacent.AddRange(current.AdjacentNodes);
allAdjacent.AddRange(current.CornerNodes);
foreach (Node n in allAdjacent)
{
Node node = adjacencyList[columns * n.X + n.Y];
if (node.Distance == int.MaxValue)
{
node.Distance = current.Distance + 1;
node.Parent = current;
node.Visited = true;
node.Priority = (int)(destinationPoint - sourcePoint).Length() + node.Distance;
Q.Add(node.Priority, node);
}
}
}
nextNode = new Vector2(-1);
}
示例2: findPath
public static Path findPath(Node startNode, Node destination)
{
List<Node> closedList = new List<Node>();
PriorityQueue<Node> openList = new PriorityQueue<Node>();
Dictionary<Node, int> gScore = new Dictionary<Node,int>();
gScore[startNode] = 0;
Dictionary<Node, int> fScore = new Dictionary<Node,int>();
fScore[startNode] = startNode.HeuristicDistance(destination);
Dictionary<Node, Node> prevNode = new Dictionary<Node, Node>();
openList.Add(fScore[startNode], startNode);
while (openList.Count > 0)
{
Node current = openList.RemoveMin();
if (current.Equals(destination))
{
return getPath(prevNode, destination);
}
else
{
closedList.Add(current);
Node[] neighbours = current.GetNeighbours();
foreach (Node next in neighbours)
{
if (closedList.Contains(next))
continue;
int newGScore = gScore[current] + current.distanceBetween(next);
if (!openList.Contains(next) || newGScore < gScore[next])
{
prevNode[next] = current;
gScore[next] = newGScore;
fScore[next] = gScore[next] + next.HeuristicDistance(destination);
if (!openList.Contains(next))
openList.Add(fScore[next], next);
}
}
}
}
return null;
}