当前位置: 首页>>代码示例>>C#>>正文


C# IMap.GetHeuristic方法代码示例

本文整理汇总了C#中IMap.GetHeuristic方法的典型用法代码示例。如果您正苦于以下问题:C# IMap.GetHeuristic方法的具体用法?C# IMap.GetHeuristic怎么用?C# IMap.GetHeuristic使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IMap的用法示例。


在下文中一共展示了IMap.GetHeuristic方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindPath

 public bool FindPath(IMap map, int start, int target)
 {
     openList = new SimplePriorityQueue<int>();
     openListLookup = new AStarNode?[map.NrNodes];
     this.map = map;
     this.isGoal = nodeId => nodeId == target;
     this.getHeuristic = nodeId => map.GetHeuristic(nodeId, target);
     Path = new List<int>();
     FindPathAstar(start);
     return true;
 }
开发者ID:Rydra,项目名称:HierarchicalPathfinder,代码行数:11,代码来源:ISearch.cs

示例2: FindPath

		/// <summary>
		/// Performs an A* search following the Node Array A* implementation
		/// </summary>
		public Path FindPath(IMap map, int start, int target)
        {
			this.isGoal = nodeId => nodeId == target;
			this.calculateHeuristic = nodeId => map.GetHeuristic(nodeId, target);
			this.map = map;

			var heuristic = calculateHeuristic(start);

            var startNode = new AStarNode(start, 0, heuristic, CellStatus.Open);
			var openQueue = new SimplePriorityQueue<int>();
			openQueue.Enqueue(start, startNode.F);

			// The open list lookup is indexed by the number of nodes in the graph/map,
			// and it is useful to check quickly the status of any node that has been processed
			var nodeLookup = new AStarNode?[map.NrNodes];
			nodeLookup[start] = startNode;

            while (openQueue.Count != 0)
            {
                var nodeId = openQueue.Dequeue();
                var node = nodeLookup[nodeId].Value;
				
                if (isGoal(nodeId))
                {
                    return ReconstructPath(nodeId, nodeLookup);
                }

                ProcessNeighbours(nodeId, node, nodeLookup, openQueue);

				// Close the node. I hope some day the will implement something
				// like the records in F# with the "with" keyword
				nodeLookup[nodeId] = new AStarNode(node.Parent, node.G, node.H, CellStatus.Closed);
			}

			// No path found. We could return a null, but since I read the book "Code Complete" I decided
			// its best to return an empty path, and I'll return a -1 as PathCost
			// TODO: Additionally, all those magic numbers like this -1 should be converted to explicit,
			// clearer constants
	        return new Path(new List<int>(), -1);
        }
开发者ID:Rydra,项目名称:HierarchicalPathfinder,代码行数:43,代码来源:AStar.cs


注:本文中的IMap.GetHeuristic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。