EnergyMinToMaxComparator.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package classes.comparator;
  2. import java.util.Comparator;
  3. import classes.HolonObject;
  4. /**
  5. * Comparator of the Energy Difference between Total Energy Consumption and Min Consumption
  6. * of a Holon Objects.
  7. *
  8. * @author Andreas T. Meyer-Berg
  9. */
  10. public class EnergyMinToMaxComparator implements Comparator<HolonObject> {
  11. private int timeStep = 0;
  12. /**
  13. * Comparator for the totalEnergy of HolonObjects
  14. * @param timeStep
  15. */
  16. public EnergyMinToMaxComparator(int timeStep) {
  17. this.timeStep = timeStep;
  18. }
  19. @Override
  20. public int compare(HolonObject o1, HolonObject o2) {
  21. float minEnergy1 = o1.getMinimumConsumingElementEnergy(timeStep);
  22. float minEnergy2 = o2.getMinimumConsumingElementEnergy(timeStep);
  23. float totalEnergy1 = o1.getEnergyAtTimeStep(timeStep);
  24. float totalEnergy2 = o2.getEnergyAtTimeStep(timeStep);
  25. float difference1 = totalEnergy1 - minEnergy1;
  26. float difference2 = totalEnergy2 - minEnergy2;
  27. if(difference1 < difference2)
  28. return 1;
  29. else if (difference1 == difference2)
  30. return 0;
  31. else
  32. return -1;
  33. }
  34. }