public void CalculateMin() { Reset(); var open = new IntrusiveMinHeap <Edge>(); foreach (var node in nodes) { if (node.connected) { continue; } foreach (var edge in node.edges) { if (edge.target.connected) { continue; } open.Add(edge); } node.connected = true; while (!open.Empty) { var edge = open.Pop(); var target = edge.target; if (target.connected) { continue; } target.connected = true; foreach (var connection in target.edges) { if (connection.target == edge.source) { edge = connection; } if (connection.target.connected) { continue; } open.Add(connection); } edges.Add(edge); } } }
private PathFinder.Node FindPathReversed(List <PathFinder.Point> startList, List <PathFinder.Point> endList, int depth = 2147483647) { if (this.visited != null) { Array.Clear(this.visited, 0, this.visited.Length); } else { this.visited = new bool[this.costmap.GetLength(0), this.costmap.GetLength(1)]; } int num = 0; int length = this.costmap.GetLength(0) - 1; int num1 = 0; int length1 = this.costmap.GetLength(1) - 1; IntrusiveMinHeap <PathFinder.Node> intrusiveMinHeap = new IntrusiveMinHeap <PathFinder.Node>(); foreach (PathFinder.Point point in startList) { int num2 = this.costmap[point.y, point.x]; int num3 = this.Heuristic(point, endList); intrusiveMinHeap.Add(new PathFinder.Node(point, num2, num3, null)); this.visited[point.y, point.x] = true; } while (!intrusiveMinHeap.Empty) { int num4 = depth; depth = num4 - 1; if (num4 <= 0) { break; } PathFinder.Node node = intrusiveMinHeap.Pop(); if (node.heuristic == 0) { return(node); } for (int i = 0; i < (int)this.neighbors.Length; i++) { PathFinder.Point point1 = node.point + this.neighbors[i]; if (point1.x >= num && point1.x <= length && point1.y >= num1 && point1.y <= length1 && !this.visited[point1.y, point1.x]) { this.visited[point1.y, point1.x] = true; int num5 = this.costmap[point1.y, point1.x]; if (num5 != 2147483647) { int num6 = node.cost + num5; int num7 = this.Heuristic(point1, endList); intrusiveMinHeap.Add(new PathFinder.Node(point1, num6, num7, node)); } } } } return(null); }
private PathFinder.Node FindPathReversed( List <PathFinder.Point> startList, List <PathFinder.Point> endList, int depth = 2147483647) { if (this.visited == null) { this.visited = new bool[this.costmap.GetLength(0), this.costmap.GetLength(1)]; } else { Array.Clear((Array)this.visited, 0, this.visited.Length); } int num1 = 0; int num2 = this.costmap.GetLength(0) - 1; int num3 = 0; int num4 = this.costmap.GetLength(1) - 1; IntrusiveMinHeap <PathFinder.Node> intrusiveMinHeap = (IntrusiveMinHeap <PathFinder.Node>)null; foreach (PathFinder.Point start in startList) { int cost = this.costmap[start.y, start.x]; int heuristic = this.Heuristic(start, endList); ((IntrusiveMinHeap <PathFinder.Node>) ref intrusiveMinHeap).Add(new PathFinder.Node(start, cost, heuristic, (PathFinder.Node)null)); this.visited[start.y, start.x] = true; } while (!((IntrusiveMinHeap <PathFinder.Node>) ref intrusiveMinHeap).get_Empty() && depth-- > 0) { PathFinder.Node next = ((IntrusiveMinHeap <PathFinder.Node>) ref intrusiveMinHeap).Pop(); if (next.heuristic == 0) { return(next); } for (int index = 0; index < this.neighbors.Length; ++index) { PathFinder.Point point = next.point + this.neighbors[index]; if (point.x >= num1 && point.x <= num2 && (point.y >= num3 && point.y <= num4) && !this.visited[point.y, point.x]) { this.visited[point.y, point.x] = true; int num5 = this.costmap[point.y, point.x]; if (num5 != int.MaxValue) { int cost = next.cost + num5; int heuristic = this.Heuristic(point, endList); ((IntrusiveMinHeap <PathFinder.Node>) ref intrusiveMinHeap).Add(new PathFinder.Node(point, cost, heuristic, next)); } } } } return((PathFinder.Node)null); }
public PathFinder.Node FindClosestWalkable(PathFinder.Point start, int depth = 2147483647) { if (this.visited != null) { Array.Clear(this.visited, 0, this.visited.Length); } else { this.visited = new bool[this.costmap.GetLength(0), this.costmap.GetLength(1)]; } int num = 0; int length = this.costmap.GetLength(0) - 1; int num1 = 0; int length1 = this.costmap.GetLength(1) - 1; IntrusiveMinHeap <PathFinder.Node> intrusiveMinHeap = new IntrusiveMinHeap <PathFinder.Node>(); int num2 = 1; int num3 = this.Heuristic(start); intrusiveMinHeap.Add(new PathFinder.Node(start, num2, num3, null)); this.visited[start.y, start.x] = true; while (!intrusiveMinHeap.Empty) { int num4 = depth; depth = num4 - 1; if (num4 <= 0) { break; } PathFinder.Node node = intrusiveMinHeap.Pop(); if (node.heuristic == 0) { return(node); } for (int i = 0; i < (int)this.neighbors.Length; i++) { PathFinder.Point point = node.point + this.neighbors[i]; if (point.x >= num && point.x <= length && point.y >= num1 && point.y <= length1 && !this.visited[point.y, point.x]) { this.visited[point.y, point.x] = true; int num5 = node.cost + 1; int num6 = this.Heuristic(point); intrusiveMinHeap.Add(new PathFinder.Node(point, num5, num6, node)); } } } return(null); }
public void CalculateMin() { this.Reset(); IntrusiveMinHeap <SpanningTree <T> .Edge> intrusiveMinHeap = new IntrusiveMinHeap <SpanningTree <T> .Edge>(); foreach (SpanningTree <T> .Node node in this.nodes) { if (node.connected) { continue; } foreach (SpanningTree <T> .Edge edge in node.edges) { if (edge.target.connected) { continue; } intrusiveMinHeap.Add(edge); } node.connected = true; while (!intrusiveMinHeap.Empty) { SpanningTree <T> .Edge edge1 = intrusiveMinHeap.Pop(); SpanningTree <T> .Node node1 = edge1.target; if (node1.connected) { continue; } node1.connected = true; foreach (SpanningTree <T> .Edge edge2 in node1.edges) { if (edge2.target == edge1.source) { edge1 = edge2; } if (edge2.target.connected) { continue; } intrusiveMinHeap.Add(edge2); } this.edges.Add(edge1); } } }
public PathFinder.Node FindClosestWalkable(PathFinder.Point start, int depth = 2147483647) { if (this.visited == null) { this.visited = new bool[this.costmap.GetLength(0), this.costmap.GetLength(1)]; } else { Array.Clear((Array)this.visited, 0, this.visited.Length); } int num1 = 0; int num2 = this.costmap.GetLength(0) - 1; int num3 = 0; int num4 = this.costmap.GetLength(1) - 1; IntrusiveMinHeap <PathFinder.Node> intrusiveMinHeap = (IntrusiveMinHeap <PathFinder.Node>)null; int cost1 = 1; int heuristic1 = this.Heuristic(start); ((IntrusiveMinHeap <PathFinder.Node>) ref intrusiveMinHeap).Add(new PathFinder.Node(start, cost1, heuristic1, (PathFinder.Node)null)); this.visited[start.y, start.x] = true; while (!((IntrusiveMinHeap <PathFinder.Node>) ref intrusiveMinHeap).get_Empty() && depth-- > 0) { PathFinder.Node next = ((IntrusiveMinHeap <PathFinder.Node>) ref intrusiveMinHeap).Pop(); if (next.heuristic == 0) { return(next); } for (int index = 0; index < this.neighbors.Length; ++index) { PathFinder.Point point = next.point + this.neighbors[index]; if (point.x >= num1 && point.x <= num2 && (point.y >= num3 && point.y <= num4) && !this.visited[point.y, point.x]) { this.visited[point.y, point.x] = true; int cost2 = next.cost + 1; int heuristic2 = this.Heuristic(point); ((IntrusiveMinHeap <PathFinder.Node>) ref intrusiveMinHeap).Add(new PathFinder.Node(point, cost2, heuristic2, next)); } } } return((PathFinder.Node)null); }