本文整理汇总了C#中PriorityQueue.First方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.First方法的具体用法?C# PriorityQueue.First怎么用?C# PriorityQueue.First使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.First方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WorkPriorityQueue
public void WorkPriorityQueue()
{
var intPriorityQueue = new PriorityQueue<int>();
var stringPriorityQueue = new PriorityQueue<string>();
var userPriorityQueue = new PriorityQueue<User>();
try
{
intPriorityQueue.Enqueue(5, 1);
intPriorityQueue.Enqueue(40, 1);
Console.WriteLine("Number of elements of 1st order in queue = {0}", intPriorityQueue.GetCount(1));
Console.WriteLine("First element of 1st priority = {0}", intPriorityQueue.First());
Console.WriteLine("Last element of 1st priority = {0}", intPriorityQueue.Last());
intPriorityQueue.Dequeue();
intPriorityQueue.Enqueue(671, 2);
intPriorityQueue.Enqueue(30, 4);
intPriorityQueue.Enqueue(8932, 4);
Console.WriteLine("First element of 4th priority = {0}", intPriorityQueue.First(4));
Console.WriteLine("Last element of 4th priority = {0}", intPriorityQueue.Last(4));
Console.WriteLine("Queue length = {0}", intPriorityQueue.Count);
stringPriorityQueue.Enqueue("", 7);
stringPriorityQueue.Enqueue("40", 7);
//Console.WriteLine("Number of elements of 1st order in queue = {0}", stringPriorityQueue.GetCount(1));
Console.WriteLine("First element of 1st priority = {0}", stringPriorityQueue.First());
Console.WriteLine("Last element of 1st priority = {0}", stringPriorityQueue.Last());
stringPriorityQueue.Dequeue();
stringPriorityQueue.Enqueue("thirteen", 4);
stringPriorityQueue.Enqueue("god", 4);
Console.WriteLine("First element of 4th priority = {0}", stringPriorityQueue.First(4));
Console.WriteLine("Last element of 4th priority = {0}", stringPriorityQueue.Last(4));
Console.WriteLine("Queue length = {0}", stringPriorityQueue.Count);
userPriorityQueue.Enqueue(new User("Bardara", "Morgrad", new DateTime(1992, 12, 5)), 1);
userPriorityQueue.Enqueue(new User("Viki", "Crachkovic", new DateTime(1982, 2, 5)), 2);
Console.WriteLine("Number of elements of 1st order in queue = {0}", userPriorityQueue.GetCount(1));
Console.WriteLine("First element of 1st priority = {0}", userPriorityQueue.First().FullName);
Console.WriteLine("Last element of 1st priority = {0}", userPriorityQueue.Last().FullName);
userPriorityQueue.Dequeue();
userPriorityQueue.Enqueue(new User("Somalien", "Fred", new DateTime(1976, 12, 5)), 2);
//Console.WriteLine("First element of 4th priority = {0}", userPriorityQueue.First(4).FullName);
//Console.WriteLine("Last element of 4th priority = {0}", userPriorityQueue.Last(4).FullName);
Console.WriteLine("Queue length = {0}", userPriorityQueue.Count);
MySimpleCollectionTesting();
StudentDictionaryTesting();
}
catch (Exception e)
{
Console.WriteLine("Exception occured - {0}", e.Message);
}
Console.ReadKey();
}
示例2: FindPath
public static ArrayList FindPath(Node start, Node goal)
{
openList = new PriorityQueue();
openList.Push(start);
start.nodeTotalCost = 0.0f;
start.estimatedCost = HeuristicEstimateCost(start, goal);
closedList = new PriorityQueue();
Node node = null;
while (openList.Length != 0) {
node = openList.First();
//Check if the current node is the goal node
if (node.position == goal.position) {
return CalculatePath(node);
}
//Create an ArrayList to store the neighboring nodes
ArrayList neighbours = new ArrayList();
GridManager.instance.GetNeighbours(node, neighbours);
for (int i = 0; i < neighbours.Count; i++) {
Node neighbourNode = (Node)neighbours[i];
if (!closedList.Contains(neighbourNode)) {
float cost = HeuristicEstimateCost(node,
neighbourNode);
float totalCost = node.nodeTotalCost + cost;
float neighbourNodeEstCost = HeuristicEstimateCost(
neighbourNode, goal);
neighbourNode.nodeTotalCost = totalCost;
neighbourNode.parent = node;
neighbourNode.estimatedCost = totalCost +
neighbourNodeEstCost;
if (!openList.Contains(neighbourNode)) {
openList.Push(neighbourNode);
}
}
}
//Push the current node to the closed list
closedList.Push(node);
//and remove it from openList
openList.Remove(node);
}
if (node.position != goal.position) {
Debug.LogError("Goal Not Found");
return null;
}
return CalculatePath(node);
}
示例3: findPath
public static List<Node> findPath(Node start, Node goal)
{
openList = new PriorityQueue();
openList.Push(start);
start.nodeTotalCost = 0.0f;
start.estimatedCost = heuristicEstimateCost(start,goal);
closedList = new PriorityQueue();
Node node = null;
while (openList.Length != 0) {
node = openList.First();
if(node.position == goal.position){
return calculatePath(node);
}
List<Node> neighbours = new List<Node>();
gridManager.getNeighbours(node,neighbours);
for(int i=0;i<neighbours.Count;i++){
Node neighbour = neighbours[i];
if(!closedList.Contains(neighbour)){
float cost = heuristicEstimateCost(node,neighbour);
float totalCost = node.nodeTotalCost + cost;
float neighbourEstCost = heuristicEstimateCost(neighbour,goal);
neighbour.nodeTotalCost = totalCost;
neighbour.parent = node;
neighbour.estimatedCost = totalCost + neighbourEstCost;
if(!openList.Contains(neighbour)){
openList.Push(neighbour);
}
}
}
closedList.Push(node);
openList.Remove(node);
}
if (node.position != goal.position) {
Debug.LogError("Goal Not Found");
return null;
}
return calculatePath(node);
}
示例4: FindPath
/// <summary>
/// Find the path between start node and goal node using AStar Algorithm
/// </summary>
public static ArrayList FindPath(Shell start, Shell goal)
{
//Start Finding the path
openList = new PriorityQueue();
openList.Push(start);
start.nodeTotalCost = 0.0f;
start.estimatedCost = HeuristicEstimateCost(start, goal);
closedList = new PriorityQueue();
Shell node = null;
while (openList.Length != 0)
{
node = openList.First();
if (node.position == goal.position)
{
return CalculatePath(node);
}
ArrayList neighbours = new ArrayList();
GridManager.instance.GetNeighbours(node, neighbours);
#region CheckNeighbours
//Get the Neighbours
for (int i = 0; i < neighbours.Count; i++)
{
//Cost between neighbour nodes
Shell neighbourNode = (Shell)neighbours[i];
if (!closedList.Contains(neighbourNode))
{
//Cost from current node to this neighbour node
float cost = HeuristicEstimateCost(node, neighbourNode);
//Total Cost So Far from start to this neighbour node
float totalCost = node.nodeTotalCost + cost;
//Estimated cost for neighbour node to the goal
float neighbourNodeEstCost = HeuristicEstimateCost(neighbourNode, goal);
//Assign neighbour node properties
neighbourNode.nodeTotalCost = totalCost;
neighbourNode.parent = node;
neighbourNode.estimatedCost = totalCost + neighbourNodeEstCost;
//Add the neighbour node to the list if not already existed in the list
if (!openList.Contains(neighbourNode))
{
openList.Push(neighbourNode);
}
}
}
#endregion
closedList.Push(node);
openList.Remove(node);
}
//If finished looping and cannot find the goal then return null
if (node.position != goal.position)
{
Debug.LogError("Goal Not Found");
return null;
}
//Calculate the path based on the final node
return CalculatePath(node);
}