/**
   * Transition function. Currently, we only get the list of probabilities of each item.
   *
   * @param current - The current state
   * @param action - The action
   * @param possible - The possible state
   * @return The list of probabilities where each index refers to the probability of that item
   */
  private List<Double> transition(State current, Action action, State possible) {
    List<Double> probs = new ArrayList<Double>(); // Probabilities
    Map<Integer, Integer> currentStock, purchase, possibleStock; // Maps
    double currentProb; // The current probability
    Matrix currentMatrix; // The current probability matrix
    int row, column; // The row and column

    for (int i = 0; i < current.getState().size(); ++i) {
      currentProb = 0.0;
      currentStock = current.getState();
      purchase = action.getPurchases();
      possibleStock = possible.getState();
      row = currentStock.get(i) + purchase.get(i);
      column = row - possible.getState().get(i);
      currentMatrix = this.probabilities.get(i);
      if (column < 0
          || column >= currentMatrix.getNumCols()
          || row >= currentMatrix.getNumRows()) { // Invalid state
        probs.add(0.0);
        continue;
      }
      if (possibleStock.get(i) > 0
          || (possibleStock.get(i) == 0 && column == 0)) { // Sufficiently provided
        currentProb = currentMatrix.get(row, column);
      } else if (possibleStock.get(i) == 0 && column > 0) {
        // Range of probabilities because user could have eaten plenty
        for (int j = column; j < currentMatrix.getNumCols(); ++j) {
          currentProb += currentMatrix.get(row, j);
        }
      }
      probs.add(currentProb);
    }
    return probs;
  }
  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;
 }