public AStarUtils(int numCols, int numRows, bool isFourWay = false) { Debug.Log("AStarUtils: " + numCols + ", " + numRows); this.numCols = numCols; this.numRows = numRows; this.isFourWay = isFourWay; this.iAStarHeuristic = new AStarManhattanHeuristic(); //this.iAStarHeuristic = new AStarDiagonalHeuristic (); AStarNode node = null; this.nodes = new Dictionary <string, AStarNode>(); for (int i = 0; i < this.numCols; i++) { for (int j = 0; j < this.numRows; j++) { node = new AStarNode(i, j); node.AddHeuristic(this.RefreshLinksOfAdjacentNodes, node); this.nodes.Add(this.GetNodeKey(i, j), node); } } this.RefreshLinksOfAllNodes(); //numCols * numRows / 2 只需要判断节点,不需要叶节点 this.binaryHeapUtils = new BinaryHeapUtils(numCols * numRows / 2); }
public AStarUtils(byte[] bytes, bool isFourWay = false) { ByteArray.StartRead(bytes); this.numCols = ByteArray.ReadInt(); this.numRows = ByteArray.ReadInt(); this.isFourWay = isFourWay; this.iAStarHeuristic = new AStarManhattanHeuristic(); AStarNode node = null; this.nodes = new Dictionary <int, AStarNode> (); int i, j; for (i = 0; i < this.numCols; i++) { for (j = 0; j < this.numRows; j++) { node = new AStarNode(i, j); node.walkable = ByteArray.ReadByte() == 0 ? true : false; node.AddHeuristic(this.RefreshLinksOfAdjacentNodes, node); this.nodes.Add(this.GetNodeKey(i, j), node); } } this.RefreshLinksOfAllNodes(); this.binaryHeapUtils = new BinaryHeapUtils(numCols * numRows / 2); }
public AStarUtils(int numCols, int numRows, bool isFourWay = false) { this.numCols = numCols; this.numRows = numRows; this.isFourWay = isFourWay; this.iAStarHeuristic = new AStarManhattanHeuristic(); AStarNode node = null; this.nodes = new Dictionary <int, AStarNode> (); int i, j; for (i = 0; i < this.numCols; i++) { for (j = 0; j < this.numRows; j++) { node = new AStarNode(i, j); node.AddHeuristic(this.RefreshLinksOfAdjacentNodes, node); this.nodes.Add(this.GetNodeKey(i, j), node); } } long startTime = GlobalTime.currentTimeMillis; this.RefreshLinksOfAllNodes(); this.binaryHeapUtils = new BinaryHeapUtils(numCols * numRows / 2); Debug.Log(GlobalTime.currentTimeMillis - startTime); }
public AStarSearch(IWeightedGraph <L, C> graph, IAStarHeuristic <L, C> heuristic) { defaultGraph = graph; defaultHeuristic = heuristic; frontier = new PriorityQueue <L, C>(); cameFrom = new Dictionary <L, L>(); costSoFar = new Dictionary <L, C>(); }
public AStarSearch(TNode start, TNode goal, IAStarHeuristic <TNode> heuristicImpl) { this.start = start; this.goal = goal; this.heuristicImpl = heuristicImpl; InitializeSets(); }
public L[] Search(L start, L goal, IWeightedGraph <L, C> graph, IAStarHeuristic <L, C> heuristic) { List <L> result; frontier.Clear(); cameFrom.Clear(); costSoFar.Clear(); frontier.Enqueue(start, default(C)); cameFrom.Add(start, start); costSoFar.Add(start, default(C)); while (frontier.Count() > 0) { var current = frontier.Dequeue(); if (current.Equals(goal)) { break; } var enumerator = graph.Neighbors(current).GetEnumerator(); L next; while (enumerator.MoveNext()) { next = enumerator.Current; C newCost = heuristic.Sum(costSoFar[current], graph.Cost(current, next)); if (!costSoFar.ContainsKey(next) || newCost.CompareTo(costSoFar[next]) < 0) { costSoFar[next] = newCost; C priority = heuristic.Sum(newCost, heuristic.Evaluate(next, goal)); frontier.Enqueue(next, priority); cameFrom[next] = current; } } } result = new List <L>(); L currentLocation = goal; bool pathNotFound = false; while (!pathNotFound && !currentLocation.Equals(start)) { result.Insert(0, currentLocation); if (!cameFrom.TryGetValue(currentLocation, out currentLocation)) { pathNotFound = true; result.Clear(); } } return(result.ToArray()); }
public AStarPathfinder(ITileMap map, int maxSearchDistance, bool allowDiagMovement, IAStarHeuristic heuristic) { m_Closed = new List <AStarNode>(); m_Open = new OrderedList <AStarNode>(); m_Heuristic = heuristic; m_Map = map; m_MaxSearchDistance = maxSearchDistance; m_AllowDiagMovement = allowDiagMovement; m_Nodes = new AStarMatrix(map.Width); }
public AStarPathfinder(ITileMap map, int maxSearchDistance, bool allowDiagMovement, IAStarHeuristic heuristic) { m_Closed = new List<AStarNode>(); m_Open = new OrderedList<AStarNode>(); m_Heuristic = heuristic; m_Map = map; m_MaxSearchDistance = maxSearchDistance; m_AllowDiagMovement = allowDiagMovement; m_Nodes = new AStarMatrix(map.Width); }
public void CompleteInsert() { if (iAStarHeuristic == null) { iAStarHeuristic = new AStarManhattanHeuristic(); } this.RefreshLinksOfAllNodes(); if (binaryHeapUtils == null) { binaryHeapUtils = new BinaryHeapUtils(nodes.Count / 2); } else { binaryHeapUtils.Reset(); } }
public AStarAlgorithm(INavigationGraphProvider2D graphProvider, IAStarHeuristic heuristic) { if (graphProvider == null) { Debug.LogError("A new instance of an AStarAlgorithm needs to initialized with a graph-provider!"); } this.graphProvider = graphProvider; if (heuristic == null) { this.heuristic = new EuclidianHeuristic(); } else { this.heuristic = heuristic; } }
/// <summary> /// Create a path finder /// </summary> /// <param name="map">The map to be searched</param> /// <param name="maxSearchDistance">The maximum depth we'll search before giving up</param> /// <param name="allowDiagMovement">True if the search should try diaganol movement</param> /// <param name="heuristic">The heuristic used to determine the search order of the map</param> public AStarPathFinder(ITileBasedMap map, int maxSearchDistance, bool allowDiagMovement, IAStarHeuristic heuristic) { Unit = GameMap.Soldier; _map = map; _maxSearchDistance = maxSearchDistance; _allowDiagMovement = allowDiagMovement; _heuristic = heuristic; _nodes = new Node[_map.GetWidthInTiles(), _map.GetHeightInTiles()]; for (var i = 0; i < _map.GetWidthInTiles(); i++) { for (var j = 0; j < _map.GetHeightInTiles(); j++) { _nodes[i, j] = new Node(i, j); } } }
public AStarUtils(int numCols, int numRows, bool isFourWay = false) { _numCols = numCols; _numRows = numRows; _isFourWay = isFourWay; _iAStarHeuristic = new AStarManhattanHeuristic(); //_iAStarHeuristic = new AStarDiagonalHeuristic (); _nodes = new Dictionary <string, AStarNode>(); for (var i = 0; i < _numCols; i++) { for (var j = 0; j < _numRows; j++) { var node = new AStarNode(i, j); node.AddHeuristic(RefreshLinksOfAdjacentNodes, node); _nodes.Add(GetNodeKey(i, j), node); } } RefreshLinksOfAllNodes(); _binaryHeapUtils = new BinaryHeapUtils(numCols * numRows / 2); }
public AStarUtils(byte[] bytes,bool isFourWay = false) { ByteArray.StartRead(bytes); this.numCols = ByteArray.ReadInt (); this.numRows = ByteArray.ReadInt (); this.isFourWay = isFourWay; this.iAStarHeuristic = new AStarManhattanHeuristic (); AStarNode node = null; this.nodes = new Dictionary<int, AStarNode> (); int i, j; for(i = 0; i < this.numCols; i++) { for(j = 0; j < this.numRows; j++) { node = new AStarNode(i, j); node.walkable = ByteArray.ReadByte() == 0 ? true : false; node.AddHeuristic(this.RefreshLinksOfAdjacentNodes, node); this.nodes.Add(this.GetNodeKey(i, j), node); } } this.RefreshLinksOfAllNodes(); this.binaryHeapUtils = new BinaryHeapUtils(numCols * numRows / 2); }
public DepthFirst(IAStarHeuristic <TNode> heuristicImpl) { this.heuristicImpl = heuristicImpl; visitedVertexes = new List <TNode>(); parentToNode = new Dictionary <TNode, TNode>(); }
public DepthFirst(IAStarHeuristic <TNode> heuristicImpl) { this.heuristicImpl = heuristicImpl; }
private void Initialize(GraphNode destination) { this._openList = new LinkedList<GraphNode>(); this._closedList = new LinkedList<GraphNode>(); this._destination = destination; this._heuristic = new EuclideanDistanceHeuristic(destination); }
public AStarShortestPath(IShortestPathOperators <W> @operator, IAStarHeuristic <T, W> heuristic) { this.@operator = @operator; this.heuristic = heuristic; }
public AStarUtils(int numCols, int numRows, bool isFourWay = false) { this.numCols = numCols; this.numRows = numRows; this.isFourWay = isFourWay; this.iAStarHeuristic = new AStarManhattanHeuristic (); //this.iAStarHeuristic = new AStarDiagonalHeuristic (); AStarNode node = null; this.nodes = new Dictionary<string, AStarNode> (); for(int i = 0; i < this.numCols; i++) { for(int j = 0; j < this.numRows; j++) { node = new AStarNode(i, j); node.AddHeuristic(this.RefreshLinksOfAdjacentNodes, node); this.nodes.Add(this.GetNodeKey(i, j), node); } } this.RefreshLinksOfAllNodes(); this.binaryHeapUtils = new BinaryHeapUtils(numCols * numRows / 2); }
public AStarShortestPath(IShortestPathOperators <W> operators, IAStarHeuristic <T, W> heuristic) { this.operators = operators; this.heuristic = heuristic; }
public AStarUtils(int numCols, int numRows, bool isFourWay = false) { this.numCols = numCols; this.numRows = numRows; this.isFourWay = isFourWay; this.iAStarHeuristic = new AStarManhattanHeuristic (); AStarNode node = null; this.nodes = new Dictionary<int, AStarNode> (); int i, j; for(i = 0; i < this.numCols; i++) { for(j = 0; j < this.numRows; j++) { node = new AStarNode(i, j); node.AddHeuristic(this.RefreshLinksOfAdjacentNodes, node); this.nodes.Add(this.GetNodeKey(i, j), node); } } long startTime = GlobalTime.currentTimeMillis; this.RefreshLinksOfAllNodes(); this.binaryHeapUtils = new BinaryHeapUtils(numCols * numRows / 2); Debug.Log (GlobalTime.currentTimeMillis-startTime); }
public AStarSearch(IGraph <V, int> graph, IVertex <V> source, IVertex <V> target, IAStarHeuristic <V> heuristic) : base(graph, source) { this.heuristic = heuristic; this.target = target; }
internal AStarWrap(IAStarHeuristic <T, W> heuristic, T destinationVertex) { this.heuristic = heuristic; this.destinationVertex = destinationVertex; }
public AStar(IAStarHeuristic <TNode> heuristicImpl) { this.heuristicImpl = heuristicImpl; }