001    package aima.probability.decision;
002    
003    import java.util.Hashtable;
004    
005    /**
006     * @author Ravi Mohan
007     * 
008     */
009    
010    public class MDPRewardFunction<STATE_TYPE> {
011            Hashtable<STATE_TYPE, Double> stateToReward;
012    
013            public MDPRewardFunction() {
014                    stateToReward = new Hashtable<STATE_TYPE, Double>();
015            }
016    
017            public double getRewardFor(STATE_TYPE state) {
018                    return stateToReward.get(state);
019            }
020    
021            public void setReward(STATE_TYPE state, Double reward) {
022                    stateToReward.put(state, reward);
023            }
024    
025            @Override
026            public String toString() {
027                    return stateToReward.toString();
028            }
029    
030            public MDPUtilityFunction<STATE_TYPE> asUtilityFunction() {
031                    MDPUtilityFunction<STATE_TYPE> uf = new MDPUtilityFunction<STATE_TYPE>();
032                    for (STATE_TYPE state : stateToReward.keySet()) {
033                            uf.setUtility(state, getRewardFor(state));
034                    }
035                    return uf;
036            }
037    }