public List<Integer> generateShoppingList(List<Integer> inventory, int numWeeksLeft) { State current; // current state Map<Integer, Integer> purchases = new HashMap<Integer, Integer>(); // Purchases Map<Integer, Integer> map = new HashMap<Integer, Integer>(); // Mapping of integers List<Integer> shopping = new ArrayList<Integer>(); // Shopping items for (int i = 0; i < inventory.size(); ++i) { map.put(i, inventory.get(i)); } current = new State(map); purchases = this.policy.get(current).getPurchases(); for (int i = 0; i < inventory.size(); ++i) { shopping.add(purchases.get(i)); } return shopping; }
/** * Value generation * * @param state - The current state * @param action - The current action * @param Set<State> lookup - The set of states we are looking up * @return The total value for that state */ private Double valueGeneration(State state, Action action, Set<State> lookup) { Double maxValue = null; // The maximum value double currentVal = 0.0; // The current value List<Double> currentProb = new ArrayList<Double>(); for (State possible : this.possibleStates) { currentProb = transition(state, action, possible); for (int i = 0; i < currentProb.size(); ++i) { currentVal += currentProb.get(i) * (reward(possible) + this.spec.getDiscountFactor() * possible.getCost()); } if (maxValue == null) { // First time generating value maxValue = currentVal; } else { // Need to sum up these values maxValue += currentVal; } } return maxValue; }