Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- public class SimulationRunner {
- public static void main(String[] args) {
- for (int n = 0; n < 6; n++) {
- int currSize = 0;
- int totalAnfragen = 0;
- try {
- Scanner s = new Scanner(new File(System.getProperty("user.dir") + "/data/initial-collectors-" + n + ".csv"), "UTF-8");
- Trie trie = new Trie();
- while (s.hasNext()) {
- String line = s.nextLine();
- if (!line.contains(";")) continue;
- String[] split = line.split(";");
- String id = split[0];
- int gesamtAnfragen = Integer.parseInt(split[1]);
- totalAnfragen += gesamtAnfragen;
- int anfragenSeitLetzterTeilung = Integer.parseInt(split[2]);
- trie.insert(new Sensor(id, gesamtAnfragen, anfragenSeitLetzterTeilung));
- currSize++;
- }
- s.close();
- try {
- s = new Scanner(new File(System.getProperty("user.dir") + "/data/queries-" + n + ".txt"), "UTF-8");
- System.out.println();
- int min_size = Integer.MAX_VALUE, max_size = Integer.MIN_VALUE;
- String last_deactivated = "", last_activated = "";
- while(s.hasNext())
- {
- String query = s.next();
- Sensor sammelpunkt = trie.findSammelpunkt(query);
- sammelpunkt.anfragenGesamt++;
- sammelpunkt.anfragenSeitLetzterTeilung++;
- if (!sammelpunkt.answeredSinceLastRule3) sammelpunkt.answeredSinceLastRule3 = true;
- totalAnfragen++;
- //System.out.print(query + " -> " + sammelpunkt.id + ";" + sammelpunkt.anfragenGesamt + ";" + sammelpunkt.anfragenSeitLetzterTeilung);
- if (sammelpunkt.checkRule1())
- {
- last_deactivated = sammelpunkt.id;
- currSize--;
- trie.remove(sammelpunkt);
- last_activated = query;
- currSize++;
- trie.insert(new Sensor(query, 0, 0));
- //System.out.print(" (Rule 1)");
- }
- else
- {
- if (sammelpunkt.checkRule2())
- {
- last_activated = query;
- currSize++;
- trie.insert(new Sensor(query, 0, 0));
- //System.out.print(" (Rule 2)");
- }
- }
- if (totalAnfragen == 500000) // RULE 3
- {
- totalAnfragen = 0;
- currSize -= trie.rule3();
- System.out.println(" (Rule 3)");
- }
- //System.out.println();
- if (currSize < min_size) min_size = currSize;
- if (currSize > max_size) max_size = currSize;
- }
- System.out.println("Simulation of 'initial-collectors-" + n + ".csv and 'queries-" + n + ".txt'");
- System.out.println("minimal size of network: " + min_size);
- System.out.println("maximal size of network: " + max_size);
- System.out.println("last deactivated collector: " + last_deactivated);
- System.out.println("last activated collector: " + last_activated);
- s.close();
- }
- catch (FileNotFoundException e) {
- System.exit(1);
- }
- } catch (FileNotFoundException e) {
- System.exit(1);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement