From 6b816534d750fa5a2eec2eec2c452fb4a0afcea0 Mon Sep 17 00:00:00 2001 From: loris Date: Tue, 4 Apr 2023 16:45:13 +0200 Subject: [PATCH] Main readability is over 9000 --- src/main/java/fr/ntr/AccessPoint.java | 4 ++-- src/main/java/fr/ntr/Main.java | 23 +++++++++++++++++------ src/main/java/fr/ntr/User.java | 2 -- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index 5a9e2c0..792b207 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -27,8 +27,8 @@ public class AccessPoint { cell2.updateBandwidth(ticks); cell1.schedule(ticks); cell2.schedule(ticks); - //simulation des interférences - computeInterference(); + // simulation des interférences + // computeInterference(); // traite les données et les enregistre dans un fichier try { cell1.analyseData(ticks); diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index 46fafe5..7753cf0 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -41,12 +41,11 @@ public class Main { int timeSlotNb = 2; int subCarrierNb = 100; - + //préparation pour exportation des données File folder = new File("export"); if(!folder.exists() && !folder.mkdir()) { System.err.println("Cannot create export folder"); System.exit(1); - } Arrays.stream(Objects.requireNonNull(new File("export").listFiles())) .filter(File::isFile) @@ -56,28 +55,38 @@ public class Main { } }); + //instanciation des cellules, schedulers et utilisateurs Cell.setTimeSlotNb(timeSlotNb); Cell.setSubCarrierNb(subCarrierNb); ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); for(int i = 2; i <= maximumLoad; i += 2) { + //génération des utilisateurs List usersCell1 = generateUsers(i, timeSlotNb, subCarrierNb); List usersCell2 = generateUsers(i, timeSlotNb, subCarrierNb); + //génération des trames ResourceBlock[][] frame1 = new ResourceBlock[timeSlotNb][subCarrierNb]; ResourceBlock[][] frame2 = new ResourceBlock[timeSlotNb][subCarrierNb]; //TODO : changes schedulers + //génération des schedulers Scheduler schedulerCell1 = new RoundRobin(frame1, frame2, usersCell1); Scheduler schedulerCell2 = new RoundRobin(frame2, frame1, usersCell2); - try{ + + try { + //préparation à exportation des données de chaque cellule FileOutputStream output = new FileOutputStream("export" + File.separator + (usersCell1.size()+usersCell2.size()) + ".csv", true); output.write("tick;x;y;user;bandwidth;delay;cell;\n".getBytes()); + //création des cellules Cell cell1 = new Cell(0, schedulerCell1, frame1, usersCell1, output); Cell cell2 = new Cell(1, schedulerCell2, frame2, usersCell2, output); + + //création de l'AccessPoint AccessPoint accessPoint = new AccessPoint(cell1, cell2); executor.submit(() -> accessPoint.startSimulation(numberOfTicks)); - } catch(IOException e) { + } + catch(IOException e) { System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage()); System.exit(1); } @@ -85,11 +94,13 @@ public class Main { executor.shutdown(); try { executor.awaitTermination(2, TimeUnit.MINUTES); - } catch (InterruptedException e) { + } + catch (InterruptedException e) { e.printStackTrace(); } executor.shutdownNow(); - } else { + } + else { System.err.println("Please give launch arguments"); System.err.println("gradle run --args=\" \""); System.exit(1); diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index 8b73f2a..dc48728 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -12,9 +12,7 @@ public class User { private final List packetsSent; private int leftForNextSource; private int timeInterval = 1; - public int totalbits = 0; - private int mbis; private final Random random = new Random();