(^198) | Chapter 7: Path Finding in AI
Figure 7-12. Sample ASearch tree in 8-puzzle using WeakEvaluator f(n)
Example 7-5. A*Search implementation
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( )) {
Algorithms in a Nutshell
Algorithms in a Nutshell By Gary Pollice, George T. Heineman, Stanley Selkow ISBN:
9780596516246 Publisher: O'Reilly Media, Inc.
Prepared for Ming Yi, Safari ID: [email protected]
Licensed by Ming Yi
Print Publication Date: 2008/10/21 User number: 594243
© 2009 Safari Books Online, LLC. This PDF is made available for personal use only during the relevant subscription term, subject to the Safari Terms of Service. Any other use
tina meador
(Tina Meador)
#1