本文整理汇总了C#中PriorityQueue.Empty方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.Empty方法的具体用法?C# PriorityQueue.Empty怎么用?C# PriorityQueue.Empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.Empty方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRouteAstar
public AstarResponse GetRouteAstar(int pmStartId, List<int> pmTargets, int heuresticPoint)
{
//Queue<int> frontier = new Queue<int>();
PriorityQueue<int,int> frontier = new PriorityQueue<int, int>();
frontier.Enqueue (pmStartId, 0);
Dictionary<int,int> cameFrom = new Dictionary<int, int>();
Dictionary<int,int> costSoFar = new Dictionary<int, int> ();
costSoFar.Add (pmStartId, 0);
int foundTarget = 0;
while (!frontier.Empty()) {
int current = frontier.Dequeue ();
if (pmTargets.Contains (current)) {
foundTarget = current;
break;
}
List<int> neighbours = SelectFromGrid.instance.GetAdjacentNonBlockedFieldsWithDiagonalCheck (current);
foreach (int next in neighbours) {
int newCost = costSoFar [current] + this.GetCellMoveCost (next);
if (!costSoFar.ContainsKey (next) || newCost < costSoFar [next]) {
costSoFar [next] = newCost + Length (next, heuresticPoint);
int lvPriority = newCost;
frontier.Enqueue (next, newCost);
cameFrom [next] = current;
}
}
}
Debug.Log ("Reached in " + cameFrom.Count + " moves");
tab = cameFrom;
return new AstarResponse (cameFrom, pmStartId, foundTarget);
}
示例2: Dijkstra
static double Dijkstra(List<List<double>> t, List<List<int>> c, int x, int y, double speed)
{
int[] dx = new int[] {0, 1, 0, -1};
int[] dy = new int[] {1, 0, -1, 0};
int h = t.Count, w = t[0].Count;
bool[,,] seen = new bool[h, w, 2];
double[,,] dist = new double[h, w, 2];
foreach (int i in Enumerable.Range(0, h))
foreach (int j in Enumerable.Range(0, w))
foreach (int k in Enumerable.Range(0, 2))
dist[i, j, k] = 13;
foreach (int k in Enumerable.Range(0, 2))
{
dist[x, y, k] = 0;
PriorityQueue q = new PriorityQueue();
q.Enqueue(Tuple.Create(0.0, x, y));
while (!q.Empty())
{
var best = q.Top();
q.Dequeue();
if (seen[best.Item2, best.Item3, k]) continue;
seen[best.Item2, best.Item3, k] = true;
foreach (var z in Enumerable.Range(0, 4)
.Select(l => new {X = best.Item2 + dx[l], Y = best.Item3 + dy[l]})
.Where(z => z.X >= 0 && z.X < h && z.Y >= 0 && z.Y < w &&
Math.Abs(c[best.Item2][best.Item3] - c[z.X][z.Y]) <= 1000))
{
double ndist = speed +
Math.Max(t[z.X][z.Y] + Convert.ToInt32(k == 0), best.Item1);
if (ndist < dist[z.X, z.Y, k])
{
dist[z.X, z.Y, k] = ndist;
q.Enqueue(Tuple.Create(dist[z.X, z.Y, k], z.X, z.Y));
}
}
}
}
return (
from i in Enumerable.Range(0, h)
from j in Enumerable.Range(0, w)
where dist[i, j, 0] <= 12 - dist[i, j, 1]
select Math.Sqrt((i - x) * (i - x) + (j - y) * (j - y))
).Max();
}
示例3: FindPath
public static Vector3[] FindPath(int[] start, int[] end)
{
PathManager mgr = GetInstance ();
Vector3[] outPath;
if (mgr.QueryCache (start, end, out outPath)) {
return outPath;
}
int pathSearched = 0;
GridManager grid = GridManager.GetInstance ();
if (!grid.HasSurface (start) || !grid.HasSurface (end)) {
return null;
}
List<Node> closed = new List<Node> ();
PriorityQueue<Node> open = new PriorityQueue<Node> ();
open.comparator = Node.Comparison;
Vector3 goal = grid.GridCenter (end);
Node s = new Node ();
s.edge = null;
s.g_score = 0.0f;
s.h_score = mgr.SqDist (s.p, goal);
s.f_score = s.h_score;
s.p = grid.GridCenter (start);
open.Add (s);
while (!open.Empty ()) {
Node node = open.Top;
open.Remove (open.Top);
// if it ends, end.
if (node.p == goal) {
List<Vector3> path = new List<Vector3> ();
mgr.ReconstructPath (node, path);
Vector3[] outpath = path.ToArray ();
mgr.CachePath (start, end, outpath);
return outpath;
}
closed.Add (node);
List<Vector3> neighbors = mgr.Neighbors(node.p);
foreach (Vector3 n in neighbors) {
if (closed.FindIndex ((a) => a.p == n) >= 0) {
continue;
}
float temp_g = node.g_score + mgr.SqDist(node.p, n);
Node f = open.Find ((a) => a.p == n);
if (f == null) {
f = new Node ();
f.edge = node;
f.g_score = temp_g;
f.h_score = mgr.SqDist(n, goal);
f.f_score = f.g_score + f.h_score;
f.p = n;
open.Add (f);
} else if (temp_g < f.g_score) {
f.edge = node;
f.g_score = temp_g;
f.f_score = f.g_score + f.h_score;
open.Update (f);
}
}
if (pathSearched >= mgr.pathSearchLimit) {
return null;
} else {
pathSearched ++;
}
}
return null;
}
示例4: Awake
void Awake()
{
if (_instance != null) {
Debug.LogError ("Instance should be null");
}
_instance = this;
priorityQueue = new PriorityQueue<TimerMessage> ();
priorityQueue.comparator = Comparison;
for (int i = 0; i < messages.Length; i ++) {
messages[i].gameObject = null;
messages[i].nextTime = Time.time + messages[i].secondsBetween;
priorityQueue.Add (messages[i]);
}
if (!priorityQueue.Empty ()) {
// StartCoroutine (Schedule());
} else {
enabled = false;
}
}