001    package aima.search.framework;
002    
003    import java.util.Comparator;
004    
005    /**
006     * Artificial Intelligence A Modern Approach (2nd Edition): page 94.
007     * 
008     * best-first search.
009     */
010    
011    /**
012     * @author Ciaran O'Reilly
013     * 
014     */
015    public class BestFirstSearch extends PrioritySearch {
016    
017            private final EvaluationFunction evaluationFunction;
018    
019            public BestFirstSearch(QueueSearch search, EvaluationFunction ef) {
020                    this.search = search;
021                    evaluationFunction = ef;
022            }
023    
024            //
025            // PROTECTED METHODS
026            //
027            @Override
028            protected Comparator<Node> getComparator(final Problem p) {
029                    return new Comparator<Node>() {
030                            public int compare(Node one, Node two) {
031                                    Double f1 = evaluationFunction.getValue(p, one);
032                                    Double f2 = evaluationFunction.getValue(p, two);
033    
034                                    return f1.compareTo(f2);
035                            }
036                    };
037            }
038    }