001    package aima.search.framework;
002    
003    /**
004     * @author Ravi Mohan
005     * 
006     */
007    
008    /**
009     * Artificial Intelligence A Modern Approach (2nd Edition): page 62.
010     * 
011     * A problem can be defined formally by four components: 1) Initial State. 2)
012     * Successor Function. 3) Goal Test. 4) Path Cost.
013     */
014    
015    public class Problem {
016    
017            protected Object initialState;
018    
019            protected SuccessorFunction successorFunction;
020    
021            protected GoalTest goalTest;
022    
023            protected StepCostFunction stepCostFunction;
024    
025            protected HeuristicFunction heuristicFunction;
026    
027            protected Problem() {
028            }
029    
030            public Problem(Object initialState, SuccessorFunction successorFunction,
031                            GoalTest goalTest) {
032    
033                    this.initialState = initialState;
034                    this.successorFunction = successorFunction;
035                    this.goalTest = goalTest;
036                    this.stepCostFunction = new DefaultStepCostFunction();
037                    this.heuristicFunction = new DefaultHeuristicFunction();
038            }
039    
040            public Problem(Object initialState, SuccessorFunction successorFunction,
041                            GoalTest goalTest, StepCostFunction stepCostFunction) {
042                    this(initialState, successorFunction, goalTest);
043                    this.stepCostFunction = stepCostFunction;
044            }
045    
046            public Problem(Object initialState, SuccessorFunction successorFunction,
047                            GoalTest goalTest, HeuristicFunction heuristicFunction) {
048                    this(initialState, successorFunction, goalTest);
049                    this.heuristicFunction = heuristicFunction;
050            }
051    
052            public Problem(Object initialState, SuccessorFunction successorFunction,
053                            GoalTest goalTest, StepCostFunction stepCostFunction,
054                            HeuristicFunction heuristicFunction) {
055                    this(initialState, successorFunction, goalTest, stepCostFunction);
056                    this.heuristicFunction = heuristicFunction;
057            }
058    
059            public Object getInitialState() {
060    
061                    return initialState;
062            }
063    
064            public boolean isGoalState(Object state) {
065    
066                    return goalTest.isGoalState(state);
067            }
068    
069            public StepCostFunction getStepCostFunction() {
070                    return stepCostFunction;
071            }
072    
073            public SuccessorFunction getSuccessorFunction() {
074                    return successorFunction;
075            }
076    
077            public HeuristicFunction getHeuristicFunction() {
078                    return heuristicFunction;
079            }
080    }