Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.Scanner;
  4.  
  5. public class SimulationRunner {
  6. public static void main(String[] args) {
  7. for (int n = 0; n < 6; n++) {
  8. int currSize = 0;
  9. int totalAnfragen = 0;
  10.  
  11. try {
  12. Scanner s = new Scanner(new File(System.getProperty("user.dir") + "/data/initial-collectors-" + n + ".csv"), "UTF-8");
  13.  
  14. Trie trie = new Trie();
  15.  
  16. while (s.hasNext()) {
  17. String line = s.nextLine();
  18. if (!line.contains(";")) continue;
  19. String[] split = line.split(";");
  20.  
  21. String id = split[0];
  22. int gesamtAnfragen = Integer.parseInt(split[1]);
  23. totalAnfragen += gesamtAnfragen;
  24. int anfragenSeitLetzterTeilung = Integer.parseInt(split[2]);
  25.  
  26. trie.insert(new Sensor(id, gesamtAnfragen, anfragenSeitLetzterTeilung));
  27. currSize++;
  28. }
  29.  
  30. s.close();
  31.  
  32. try {
  33. s = new Scanner(new File(System.getProperty("user.dir") + "/data/queries-" + n + ".txt"), "UTF-8");
  34.  
  35. System.out.println();
  36.  
  37. int min_size = Integer.MAX_VALUE, max_size = Integer.MIN_VALUE;
  38. String last_deactivated = "", last_activated = "";
  39.  
  40. while(s.hasNext())
  41. {
  42. String query = s.next();
  43. Sensor sammelpunkt = trie.findSammelpunkt(query);
  44.  
  45. sammelpunkt.anfragenGesamt++;
  46. sammelpunkt.anfragenSeitLetzterTeilung++;
  47. if (!sammelpunkt.answeredSinceLastRule3) sammelpunkt.answeredSinceLastRule3 = true;
  48.  
  49. totalAnfragen++;
  50.  
  51. //System.out.print(query + " -> " + sammelpunkt.id + ";" + sammelpunkt.anfragenGesamt + ";" + sammelpunkt.anfragenSeitLetzterTeilung);
  52.  
  53. if (sammelpunkt.checkRule1())
  54. {
  55. last_deactivated = sammelpunkt.id;
  56. currSize--;
  57. trie.remove(sammelpunkt);
  58.  
  59. last_activated = query;
  60. currSize++;
  61. trie.insert(new Sensor(query, 0, 0));
  62.  
  63. //System.out.print(" (Rule 1)");
  64. }
  65. else
  66. {
  67. if (sammelpunkt.checkRule2())
  68. {
  69. last_activated = query;
  70. currSize++;
  71. trie.insert(new Sensor(query, 0, 0));
  72.  
  73. //System.out.print(" (Rule 2)");
  74. }
  75. }
  76.  
  77. if (totalAnfragen == 500000) // RULE 3
  78. {
  79. totalAnfragen = 0;
  80. currSize -= trie.rule3();
  81.  
  82. System.out.println(" (Rule 3)");
  83. }
  84.  
  85. //System.out.println();
  86.  
  87. if (currSize < min_size) min_size = currSize;
  88. if (currSize > max_size) max_size = currSize;
  89. }
  90.  
  91. System.out.println("Simulation of 'initial-collectors-" + n + ".csv and 'queries-" + n + ".txt'");
  92. System.out.println("minimal size of network: " + min_size);
  93. System.out.println("maximal size of network: " + max_size);
  94. System.out.println("last deactivated collector: " + last_deactivated);
  95. System.out.println("last activated collector: " + last_activated);
  96.  
  97. s.close();
  98. }
  99. catch (FileNotFoundException e) {
  100. System.exit(1);
  101. }
  102. } catch (FileNotFoundException e) {
  103. System.exit(1);
  104. }
  105. }
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement