/** * 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); } }
/** * Checks if the difference between the values of the previous policy and the new policy are <= * val. * * <p>Also reassigns the old policy * * @param double val - The difference * @param Map<State, Action> newPolicy - The new policy * @return true if the minimum difference > val. false otherwise */ private boolean CheckDifference(double val, Map<State, Action> newPolicy) { Double currDiff, minDiff = null; // The minimum and current difference if (this.policy.size() != this.possibleStates.size()) { // Previous policy wasn't assigned yet return true; } for (State current : newPolicy.keySet()) { for (State old : this.policy.keySet()) { if (current.equals(old)) { currDiff = Math.abs(current.getTemporaryCost() - old.getCost()); if (minDiff == null || currDiff <= minDiff) { minDiff = currDiff; } break; } } } if (minDiff > val) { return true; } return false; }