From 98a1222f7121ba54cc3a11fd123d1754693848fa Mon Sep 17 00:00:00 2001 From: Loris Date: Fri, 24 Mar 2023 10:28:45 +0100 Subject: [PATCH] extracted Cell from AccessPoint cell instantiation in main --- src/main/java/fr/ntr/AccessPoint.java | 90 ++++--------------- src/main/java/fr/ntr/Cell.java | 75 +++++++++++++++- src/main/java/fr/ntr/Main.java | 34 +++++-- .../java/fr/ntr/scheduler/RoundRobin.java | 6 +- 4 files changed, 119 insertions(+), 86 deletions(-) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index c8955c7..985fea3 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -11,42 +11,17 @@ import java.util.Random; import fr.ntr.scheduler.Scheduler; public class AccessPoint { - private List users; - private Scheduler scheduler; - /** - * nombre de slots - */ - private static int timeSlotNb; - /** - * Nombre de sous-porteuses - */ - private static int subCarrierNb; - /** - * trame - */ - private ResourceBlock[][] frame; - /** - * Reste pour la prochaine source - */ - private double leftForNextSource; - /** - * Portée minimum et maximum de l'antenne - */ - private final double min, max; - private Random random = new Random(); + private Cell cell1; + private Cell cell2; + + private List users; private FileOutputStream outputDataFile; - - public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, List users, int timeSlotNb, int subCarrierNb, double min, double max) { - this.min = min; - this.max = max; - this.users = users; - this.scheduler = scheduler; - this.frame = frame; - this.timeSlotNb = timeSlotNb; - this.subCarrierNb = subCarrierNb; + public AccessPoint(Cell cell1, Cell cell2){ + this.cell1 = cell1; + this.cell2 = cell2; } /** @@ -66,39 +41,26 @@ public class AccessPoint { } for (int ticks = 0; ticks < duration; ++ticks) { // Simulation - reset(); - updateBandwidth(ticks); - schedule(); + cell1.reset(); + cell2.reset(); + cell1.updateBandwidth(ticks); + cell2.updateBandwidth(ticks); + cell1.schedule(); + cell2.schedule(); // traite les données et les enregistre dans un fichier + /* try { analyseData(ticks); } catch (IOException e) { System.out.println("Can't export data"); } + */ } } - private void updateBandwidth(int ticks) { - int n = 200; - int timeInterval = 50 + random.nextInt(51); - for(User user : users) { - // On régénère le tableau de débits toutes les 50 ms - if(ticks % 50 == 0){ - user.generateBandwidth(); - } - // On régénère les sources toutes les 50-100 ms - if(ticks % timeInterval == 0){ - timeInterval = 50 + random.nextInt(51); - n = user.createPackets(n, ticks); - } - } - } - - private void schedule() { - scheduler.scheduling(); - } + /* private void analyseData(int tick) throws IOException { for(int i = 0; i < frame.length; i++) { for(int j = 0; j < frame[i].length; j++) { @@ -116,25 +78,7 @@ public class AccessPoint { } } } +*/ - private void reset() { - // TODO insert new UR - for(int i = 0; i < timeSlotNb; i++) { - for(int j = 0; j < subCarrierNb; j++) { - frame[i][j] = new ResourceBlock(0.0); - } - } - } - public ResourceBlock[][] getFrame() { - return frame; - } - - public static int getTimeSlotNb() { - return timeSlotNb; - } - - public static int getSubCarrierNb() { - return subCarrierNb; - } } diff --git a/src/main/java/fr/ntr/Cell.java b/src/main/java/fr/ntr/Cell.java index 64229e0..db3ecdb 100644 --- a/src/main/java/fr/ntr/Cell.java +++ b/src/main/java/fr/ntr/Cell.java @@ -5,10 +5,83 @@ import fr.ntr.scheduler.Scheduler; import java.util.ArrayList; import java.util.List; +import java.util.Random; public class Cell { - public static void createCell() { + private List users; + private Scheduler scheduler; + /** + * nombre de slots + */ + private static int timeSlotNb; + /** + * Nombre de sous-porteuses + */ + private static int subCarrierNb; + /** + * trame + */ + private ResourceBlock[][] frame; + /** + * Reste pour la prochaine source + */ + private double leftForNextSource; + /** + * Portée minimum et maximum de l'antenne + */ + private final double min, max; + private Random random = new Random(); + + public Cell(Scheduler scheduler, ResourceBlock[][] frame, List users, int timeSlotNb, int subCarrierNb, double min, double max) { + this.min = min; + this.max = max; + this.users = users; + this.scheduler = scheduler; + this.frame = frame; + this.timeSlotNb = timeSlotNb; + this.subCarrierNb = subCarrierNb; + } + public void updateBandwidth(int ticks) { + int n = 200; + int timeInterval = 50 + random.nextInt(51); + for(User user : users) { + // On régénère le tableau de débits toutes les 50 ms + if(ticks % 50 == 0){ + user.generateBandwidth(); + } + + // On régénère les sources toutes les 50-100 ms + if(ticks % timeInterval == 0){ + timeInterval = 50 + random.nextInt(51); + n = user.createPackets(n, ticks); + } + } + } + + public void reset() { + // TODO insert new UR + for(int i = 0; i < timeSlotNb; i++) { + for(int j = 0; j < subCarrierNb; j++) { + frame[i][j] = new ResourceBlock(0.0); + } + } + } + + public void schedule() { + scheduler.scheduling(); + } + + public ResourceBlock[][] getFrame() { + return frame; + } + + public static int getTimeSlotNb() { + return timeSlotNb; + } + + public static int getSubCarrierNb() { + return subCarrierNb; } } \ No newline at end of file diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index a37612a..cd498eb 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -3,19 +3,14 @@ package fr.ntr; import fr.ntr.scheduler.MaxSNR; import fr.ntr.scheduler.RoundRobin; import fr.ntr.scheduler.Scheduler; -import fr.ntr.Cell; import java.util.ArrayList; import java.util.List; -import fr.ntr.Cell; - - public class Main { public static void main(String[] args) { if(args.length == 2) { - int numberOfTicks; // Nombre de ticks de la simulation -> durée de la simulation int maximumLoad; // Nombre maximal d'utilisateurs dans le système try { @@ -27,10 +22,18 @@ public class Main { System.exit(1); return; } - - //TODO Verify this - Cell cell1= new Cell(); - cell1 = cell1.createCell(maximumLoad,numberOfTicks); + int timeSlotNb = 2; + int subCarrierNb = 100; + for(int i = 2; i < maximumLoad; i+=2) { + List users = generateUsers(i, timeSlotNb, subCarrierNb); + ResourceBlock[][] frame = new ResourceBlock[timeSlotNb][subCarrierNb]; + Scheduler scheduler = new MaxSNR(frame, users); + //TODO : modify cells parameters ? + Cell cell1 = new Cell(scheduler, frame, users, timeSlotNb, subCarrierNb, 0, 50); + Cell cell2 = new Cell(scheduler, frame, users, timeSlotNb, subCarrierNb, 0, 50); + AccessPoint accessPoint = new AccessPoint(cell1, cell2); + accessPoint.startSimulation(numberOfTicks); + } } else { System.err.println("Please give launch arguments"); @@ -38,4 +41,17 @@ public class Main { System.exit(1); } } + + private static List generateUsers(int nbUsers, int timeSlotNb, int subCarrierNb) { + List users = new ArrayList<>(); + // 2 groupes d'utilisateurs, proches et éloignés + double[] distance = { 200d, 1000d }; + for (double v : distance) { + for (int j = 0; j < nbUsers; j++) { + User user = new User(v, timeSlotNb, subCarrierNb); + users.add(user); + } + } + return users; + } } \ No newline at end of file diff --git a/src/main/java/fr/ntr/scheduler/RoundRobin.java b/src/main/java/fr/ntr/scheduler/RoundRobin.java index 4566fbc..d1e138b 100644 --- a/src/main/java/fr/ntr/scheduler/RoundRobin.java +++ b/src/main/java/fr/ntr/scheduler/RoundRobin.java @@ -2,7 +2,7 @@ package fr.ntr.scheduler; import java.util.List; import java.util.Random; -import fr.ntr.AccessPoint; +import fr.ntr.Cell; import fr.ntr.ResourceBlock; import fr.ntr.User; @@ -34,8 +34,8 @@ public class RoundRobin extends Scheduler { index = random.nextInt(users.size()); //Pour chaque time slot et sous porteuses - for (int Ts = 0; Ts < AccessPoint.getTimeSlotNb(); Ts++) { - for(int Sp = 0; Sp < AccessPoint.getSubCarrierNb(); Sp++) { + for (int Ts = 0; Ts < Cell.getTimeSlotNb(); Ts++) { + for(int Sp = 0; Sp < Cell.getSubCarrierNb(); Sp++) { if (users.get(index).getPacketsToSend().size() != 0) { // on enlève le packet transmis de la liste // TODO Verify sub the packet send need Set packet