[英]Fastest cross-platform A* implementation?
有這么多可用的實現,使用小網格的C ++最快執行(最少CPU密集,最小二進制),跨平台(Linux,Mac,Windows,iPhone)A *實現是什么?
實現
谷歌回歸:
還有其他人?
車輪
正如所提出的,問題涉及重用(插入游戲),而不是重新發明(至少在性能顯示為問題之前)。 可能會發現Dijkstra實現(或通用尋路算法)更適合,或者最快的實現速度不夠快。 我很欣賞替代算法的建議,但問題不是,“我應該自己推出A *嗎?”
當你有可以使用的特定邊界時,你通常最好自己編寫算法。 特別是您的小狀態空間有助於優化前置內存以減少CPU時間,並且您使用網格而不是任意狀態空間這一事實允許您執行諸如優化后繼節點生成之類的事情,或者能夠將所有在同一網格平方上結束的部分路徑視為等效(正常A *搜索不會也不能假設)。
(PS.OpenSteer,轉向行為的集合,與A *無關,這是一種搜索算法,除了你可以理論上使用一個,另一個或兩者來遍歷一個空間。一個不是替代在最合理的情況下另一個。)
查看其他路徑尋找算法(如Breath-First,Depth-First,Minimax,Negmax等)並權衡您的場景的正面和負面。
Boost還有一個A-star實現 。 嘗試按照這些說明在iPhone上構建boost,但它可能對你不起作用:它不是boost的“完整端口”,它可能會出錯。
以下是來自Nutshell中的算法 (Java,而不是C ++,但也許你想要移植它):
public Solution search( INode initial, INode goal ) {
// Start from the initial state
INodeSet open = StateStorageFactory.create( StateStorageFactory.TREE );
INode copy = initial.copy();
scoringFunction.score( copy );
open.insert( copy );
// Use Hashtable to store states we have already visited.
INodeSet closed = StateStorageFactory.create( StateStorageFactory. HASH );
while( !open.isEmpty() ) {
// Remove node with smallest evaluation function and mark closed.
INode n = open.remove();
closed.insert( n );
// Return if goal state reached.
if( n.equals( goal ) ) { return new Solution( initial, n ); }
// Compute successor moves and update OPEN/CLOSED lists.
DepthTransition trans = (DepthTransition)n.storedData();
int depth = 1;
if( trans ! = null ) { depth = trans.depth + 1; }
DoubleLinkedList<IMove> moves = n.validMoves();
for( Iterator<IMove> it = moves.iterator(); it.hasNext(); ) {
IMove move = it.next();
// Make move and score the new board state.
INode successor = n.copy();
move.execute( successor );
// Record previous move for solution trace and compute
// evaluation function to see if we have improved upon
// a state already closed
successor.storedData( new DepthTransition( move, n, depth ) );
scoringFunction.score( successor );
// If already visited, see if we are revisiting with lower
// cost. If not, just continue; otherwise, pull out of closed
// and process
INode past = closed.contains( successor );
if( past ! = null ) {
if( successor.score() >= past.score() ) {
continue;
}
// we revisit with our lower cost.
closed.remove( past );
}
// place into open.
open.insert( successor );
}
}
// No solution.
return new Solution( initial, goal, false );
}
我建議你自己實現算法。 遵循以下的偽代碼: A *搜索算法 ,它應該是直截了當的。 “openset”應該實現為min-heap,這也是微不足道的; 或者你可以使用STL的priority_queue。
我有兩條一般建議:
在http://www.ceng.metu.edu.tr/~cuneyt/codes.html上有一個通用的C ++ A *實現。 它看起來像是所有跨平台的標准C ++。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.