class EpsilonMappingAdditive implements EpsilonMapping {

	@Override
	public Map<Objective, Double> findObjectiveAmplitudes(Set<Individual> individuals) {
		Map<Objective, Double> maximumMap = new HashMap<>();
		Map<Objective, Double> minimumMap = new HashMap<>();
		Map<Objective, Double> amplitudeMap = new HashMap<>();
		for (Individual indi : individuals) {
			Objectives objectives = indi.getObjectives();
			Iterator<Objective> iterator = objectives.getKeys().iterator();
			double[] values = objectives.array();
			for (int i = 0; i < objectives.size(); i++) {
				Objective obj = iterator.next();
				if (objectives.get(obj).getValue() == Objective.INFEASIBLE) {
					continue;
				}
				double value = values[i];
				if (!maximumMap.containsKey(obj) || maximumMap.get(obj) < value) {
					maximumMap.put(obj, value);
				}
				if (!minimumMap.containsKey(obj) || minimumMap.get(obj) > value) {
					minimumMap.put(obj, value);
				}
			}
		}
		for (Entry<Objective, Double> maxEntry : maximumMap.entrySet()) {
			Objective obj = maxEntry.getKey();
			Double maximum = maxEntry.getValue();
			Double minimum = minimumMap.get(obj);
			amplitudeMap.put(obj, maximum - minimum);
		}
		return amplitudeMap;
	}

}