/** * Add the given map to the respective list * * @param int generateType - The type of item to add * @param Map<Integer, Integer> toAdd - The map to add */ private void addToList(int generateType, Map<Integer, Integer> toAdd) { /* Containers for various types */ State stateContainer; Action actionContainer; Consumption consumptionContainer; switch (generateType) { case 0: stateContainer = new State(toAdd); if (!this.possibleStates.contains(stateContainer)) { stateContainer.setCost(sumOf(toAdd)); this.policy.put(stateContainer, null); this.possibleStates.add(stateContainer); } break; case 1: actionContainer = new Action(toAdd); if (!this.possibleActions.contains(actionContainer)) { this.possibleActions.add(actionContainer); } break; case 2: consumptionContainer = new Consumption(toAdd); if (!this.possibleConsumptions.contains(consumptionContainer)) { this.possibleConsumptions.add(consumptionContainer); } break; default: System.err.println("Invalid generation type"); System.exit(13); } }
/** * Make a copy of a policy * * @param Map<State, Action> newPolicy - The new policy */ private void copyPolicy(Map<State, Action> newPolicy) { /* Containers for clones */ State current; Action currentAction; this.policy = new HashMap<State, Action>(); for (State newState : newPolicy.keySet()) { current = new State(newState.getState()); current.setCost(newState.getTemporaryCost()); currentAction = new Action(newPolicy.get(newState).getPurchases()); this.policy.put(current, currentAction); } }