001    package aima.search.map;
002    
003    import aima.search.framework.HeuristicFunction;
004    
005    /**
006     * This class extends heuristic functions in two ways: It maintains a goal and a
007     * map to estimate distance to goal for states in route planning problems, and
008     * it provides a method to adapt to different goals.
009     * @author R. Lunde
010     */
011    public abstract class AdaptableHeuristicFunction implements HeuristicFunction,
012                    Cloneable {
013            /** The Current Goal. */
014            protected Object goal;
015            /** The map to be used for distance to goal estimates. */
016            protected Map map;
017    
018            /**
019             * Creates a clone and stores goal and map in the corresponding attributes.
020             * This method MUST be called before using the heuristic!
021             */
022            public AdaptableHeuristicFunction getAdaptation(Object goal, Map map) {
023                    AdaptableHeuristicFunction result = null;
024                    try {
025                            result = (AdaptableHeuristicFunction) this.clone();
026                            result.goal = goal;
027                            result.map = map;
028                    } catch (CloneNotSupportedException e) {
029                            e.printStackTrace();
030                    }
031                    return result;
032            }
033    
034            // when subclassing: Don't forget to implement the most important method
035            // public double getHeuristicValue(Object state)
036    }