001    package aima.probability.decision;
002    
003    import java.util.Hashtable;
004    
005    /**
006     * @author Ravi Mohan
007     * 
008     */
009    
010    public class MDPUtilityFunction<STATE_TYPE> {
011            private Hashtable<STATE_TYPE, Double> hash;
012    
013            public MDPUtilityFunction() {
014                    hash = new Hashtable<STATE_TYPE, Double>();
015            }
016    
017            public Double getUtility(STATE_TYPE state) {
018                    Double d = hash.get(state);
019                    if (d == null) {
020                            System.out.println("no value for " + state);
021                    }
022                    return d;
023            }
024    
025            public void setUtility(STATE_TYPE state, double utility) {
026                    hash.put(state, utility);
027            }
028    
029            public MDPUtilityFunction<STATE_TYPE> copy() {
030                    MDPUtilityFunction<STATE_TYPE> other = new MDPUtilityFunction<STATE_TYPE>();
031                    for (STATE_TYPE state : hash.keySet()) {
032                            other.setUtility(state, hash.get(state));
033                    }
034                    return other;
035            }
036    
037            @Override
038            public String toString() {
039                    return hash.toString();
040            }
041    
042            public boolean hasUtilityFor(STATE_TYPE state) {
043    
044                    return hash.keySet().contains(state);
045            }
046    }