Guest User

Untitled

a guest
Jun 21st, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. private void findEntityCount(List<Inputs> input) {
  2. // Find the smallest exponent based upon the natural log
  3. double smallest = Double.MAX_VALUE;
  4. for (Inputs entry : input) {
  5. double exp = Math.log(entry.raw);
  6. if (exp < smallest) {
  7. smallest = exp;
  8. }
  9. }
  10.  
  11. // Calculate the scaling, note that this is closely related to finding the
  12. // mantissa of the input value, but subtracting one from the value helps
  13. // pack things a bit better
  14. long total = 0;
  15. double scaling = Math.pow(10, Math.abs(smallest) - 1);
  16. for (Inputs entry : input) {
  17. entry.count = (long)Math.ceil(entry.raw * scaling);
  18. total += entry.count;
  19. }
  20.  
  21. // Use the initial total to find a multiplier that we can use to adjust
  22. // the initial counts to the final count for the simulation
  23. double multiplier = MAX_ENTITY_COUNT / total;
  24. for (Inputs entry : input) {
  25. entry.count *= multiplier;
  26. }
  27. }
Add Comment
Please, Sign In to add comment