From 11312992326f3d3763d1ee9ce80a2addd2255373 Mon Sep 17 00:00:00 2001 From: Remi Boure Date: Mon, 6 Mar 2023 17:48:22 +0100 Subject: [PATCH 1/7] =?UTF-8?q?D=C3=A9but=20d'initialisation=20et=20Calcul?= =?UTF-8?q?=20du=20d=C3=A9bit=20pour=20un=20utilisateur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/fr/ntr/AccessPoint.java | 45 +++++++++++++++++++++++---- src/main/java/fr/ntr/User.java | 7 ++++- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index ce47e14..9b943d1 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -2,6 +2,7 @@ package fr.ntr; import java.util.ArrayList; import java.util.List; +import java.util.Random; import fr.ntr.scheduler.Scheduler; @@ -24,26 +25,58 @@ public class AccessPoint { * reste pour la prochaine source */ private double leftForNextSource; + /** + * portée minimum et maximum de l'antenne + */ + private final double min, max; - public AccessPoint(Scheduler scheduler) { + public AccessPoint(Scheduler scheduler, double min, double max) { + this.min = min; + this.max = max; this.users = new ArrayList(); this.scheduler = scheduler; this.frame = new ResourceBlock[timeSlotNb][subCarrierNb]; } - public void startSimulation(int duration){ - + /** + * Lancer la simulation + * @param duration + */ + public void startSimulation(int duration, int nbUsers){ + for(int ticks = 0; ticks < duration; ++ticks){ + // Simulation + reset(); + init(nbUsers); + schedule(); + // traite les données et les enregistre dans un fichier + analyseData(); + } } /** * Génération du débit et des paquets */ - private void init(){ - + private void init(int nbUsers){ + for(int i = 0; i < nbUsers; i++){ + Random random = new Random(); + double randomDist = this.min + random.nextDouble() * (this.max - this.min); + User user = new User(randomDist); + user.generateBandwidth(); + user.createPackets(); + this.users.add(user); + } } - private void dataAnalysis(){ + private void schedule(){ + + } + + private void analyseData(){ + + } + + private void plotData(){ } diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index ad45b57..9e30065 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -19,7 +19,12 @@ public class User { } public void generateBandwidth() { - + double X = Math.random(); + double h = 8 * Math.sqrt(-2 * Math.log(1 - X)); + double gain = h * Math.pow(10, X*8/10) * Math.pow(1/this.distance, 3.5); + double spectralEfficacity = (43 * gain)/(15000*(-174)); + double mkn = Math.log1p(spectralEfficacity); + this.bandwidthTable[][] = mkn; // Voir comment remplir le tableau } public void createPackets() { From 60c2e5c69b536db175b937b97c84ac852decd5c7 Mon Sep 17 00:00:00 2001 From: iboyeau Date: Thu, 9 Mar 2023 11:04:42 +0100 Subject: [PATCH 2/7] UserSelection Round Robin --- .../java/fr/ntr/scheduler/RoundRobin.java | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/src/main/java/fr/ntr/scheduler/RoundRobin.java b/src/main/java/fr/ntr/scheduler/RoundRobin.java index 1db8218..331661f 100644 --- a/src/main/java/fr/ntr/scheduler/RoundRobin.java +++ b/src/main/java/fr/ntr/scheduler/RoundRobin.java @@ -1,33 +1,39 @@ package fr.ntr.scheduler; import java.util.List; -import java.util.Random; import fr.ntr.User; public class RoundRobin extends Scheduler { - private String name; - private int index; - - public RoundRobin(String name, int index) { - this.name = name; - this.index = index; - } - - @Override - public void scheduling() { - } - - //Ts = Time Slot - //Sp =sous porteuse - private void selectionUtilisateur(int Ts, int Sp, List Users) { - int random = new Random().nextInt(0, Users.size()-1); - - - } + private String name; + private int index; - + public RoundRobin(String name, int index) { + this.name = name; + this.index = index; + } - - + /** + * Entry + * Return + */ + @Override + public void scheduling() { + index = 0; + + } + + /** + * Entry Time slot (int), Sous porteuse(int), and users ( List) + * Return the user in function of TS and SP selected + */ + private User UserSelection(int Ts, int Sp, List Users) { + for (int i = 0; i < Ts; i++) { + for (int j = 0; j < Sp; j++) { + index++; + } + } + return Users.get(index%(Users.size() - 1)); + + } } From f9cea33e9f6c6d29b10d76c54bb9dc38f72b96b8 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 10 Mar 2023 08:06:56 +0100 Subject: [PATCH 3/7] Add launch arguments --- .classpath | 12 ------------ build.gradle | 7 +++++-- src/main/java/fr/ntr/Main.java | 20 +++++++++++++++++--- 3 files changed, 22 insertions(+), 17 deletions(-) delete mode 100644 .classpath diff --git a/.classpath b/.classpath deleted file mode 100644 index 4857be4..0000000 --- a/.classpath +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/build.gradle b/build.gradle index c009bd7..b851d38 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,10 @@ plugins { id 'application' } -application { - mainClassName = 'fr.ntr.Main' +run { + args = ["5000", "20"] } +application { + mainClassName = 'fr.ntr.Main' +} \ 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 06e6613..228d05e 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -1,22 +1,36 @@ package fr.ntr; public class Main { + public static void main(String[] args) { /** - * nombre de ticks de la simulation + * Nombre de ticks de la simulation * -> durée de la simulation */ int numberOfTicks = 5000; /** - * nombre maximal d'utilisateurs dans le système + * Nombre maximal d'utilisateurs dans le système */ int maximumLoad = 20; //TODO ajouter accès à AccessPoint - System.out.println("Hello World"); + if(args.length == 2) { + try { + numberOfTicks = Integer.parseInt(args[0]); + maximumLoad = Integer.parseInt(args[1]); + System.out.println("ticks: " + numberOfTicks + ", users: " + maximumLoad); + } catch (NumberFormatException e) { + System.err.println("Cannot parse launch argument to integer"); + System.exit(1); + } + } else { + System.err.println("Please give launch arguments"); + System.err.println("gradle run --args=\" \""); + System.exit(1); + } } } From 01b82d7ef4cc96b6354add4e971c8f4c7044d67a Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 10 Mar 2023 08:19:07 +0100 Subject: [PATCH 4/7] Main now call AccessPoint and start the simulation --- src/main/java/fr/ntr/AccessPoint.java | 8 ++++---- src/main/java/fr/ntr/Main.java | 20 +++++++------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index 9b943d1..7e3a7f2 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -14,7 +14,7 @@ public class AccessPoint { */ private static int timeSlotNb; /** - * nombre de sous-porteuses + * Nombre de sous-porteuses */ private static int subCarrierNb; /** @@ -22,11 +22,11 @@ public class AccessPoint { */ private ResourceBlock[][] frame; /** - * reste pour la prochaine source + * Reste pour la prochaine source */ private double leftForNextSource; /** - * portée minimum et maximum de l'antenne + * Portée minimum et maximum de l'antenne */ private final double min, max; @@ -34,7 +34,7 @@ public class AccessPoint { public AccessPoint(Scheduler scheduler, double min, double max) { this.min = min; this.max = max; - this.users = new ArrayList(); + this.users = new ArrayList<>(); this.scheduler = scheduler; this.frame = new ResourceBlock[timeSlotNb][subCarrierNb]; } diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index 228d05e..aecb829 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -1,24 +1,15 @@ package fr.ntr; +import fr.ntr.scheduler.RoundRobin; + public class Main { public static void main(String[] args) { - - /** - * Nombre de ticks de la simulation - * -> durée de la simulation - */ - int numberOfTicks = 5000; - - /** - * Nombre maximal d'utilisateurs dans le système - */ - int maximumLoad = 20; - - //TODO ajouter accès à AccessPoint 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 { numberOfTicks = Integer.parseInt(args[0]); maximumLoad = Integer.parseInt(args[1]); @@ -26,7 +17,10 @@ public class Main { } catch (NumberFormatException e) { System.err.println("Cannot parse launch argument to integer"); System.exit(1); + return; } + AccessPoint accessPoint = new AccessPoint(new RoundRobin("round robin", 0), 0, 50); + accessPoint.startSimulation(numberOfTicks, maximumLoad); } else { System.err.println("Please give launch arguments"); System.err.println("gradle run --args=\" \""); From 28f14a5447a53c43c2d17f1e7963751b2d23395e Mon Sep 17 00:00:00 2001 From: iboyeau Date: Fri, 10 Mar 2023 08:30:28 +0100 Subject: [PATCH 5/7] get/set RessourceBock --- src/main/java/fr/ntr/AccessPoint.java | 29 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index 7e3a7f2..976ab7d 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -1,5 +1,6 @@ package fr.ntr; +import java.lang.reflect.Array; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -30,7 +31,7 @@ public class AccessPoint { */ private final double min, max; - + public AccessPoint(Scheduler scheduler, double min, double max) { this.min = min; this.max = max; @@ -41,10 +42,11 @@ public class AccessPoint { /** * Lancer la simulation + * * @param duration */ - public void startSimulation(int duration, int nbUsers){ - for(int ticks = 0; ticks < duration; ++ticks){ + public void startSimulation(int duration, int nbUsers) { + for (int ticks = 0; ticks < duration; ++ticks) { // Simulation reset(); init(nbUsers); @@ -57,8 +59,8 @@ public class AccessPoint { /** * Génération du débit et des paquets */ - private void init(int nbUsers){ - for(int i = 0; i < nbUsers; i++){ + private void init(int nbUsers) { + for (int i = 0; i < nbUsers; i++) { Random random = new Random(); double randomDist = this.min + random.nextDouble() * (this.max - this.min); User user = new User(randomDist); @@ -68,23 +70,30 @@ public class AccessPoint { } } - private void schedule(){ + private void schedule() { } - private void analyseData(){ + private void analyseData() { } - private void plotData(){ + private void plotData() { } - private void reset(){ + private void reset() { } - public int getFrameSize(){ + public int getFrameSize() { return this.timeSlotNb * this.subCarrierNb; } + + public ResourceBlock[][] getFrame() { + return frame; + } + public void setFrame(ResourceBlock[][] frame) { + this.frame = frame; + } } From 26c187149076329d5eb524019a50ea8079e88f1b Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 10 Mar 2023 08:50:28 +0100 Subject: [PATCH 6/7] Fix user --- src/main/java/fr/ntr/AccessPoint.java | 3 ++- src/main/java/fr/ntr/User.java | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index 7e3a7f2..15c481d 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -61,7 +61,7 @@ public class AccessPoint { for(int i = 0; i < nbUsers; i++){ Random random = new Random(); double randomDist = this.min + random.nextDouble() * (this.max - this.min); - User user = new User(randomDist); + User user = new User(randomDist, timeSlotNb, subCarrierNb); user.generateBandwidth(); user.createPackets(); this.users.add(user); @@ -87,4 +87,5 @@ public class AccessPoint { public int getFrameSize(){ return this.timeSlotNb * this.subCarrierNb; } + } diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index 9e30065..54581d4 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -10,21 +10,25 @@ public class User { private final List packetsToSend; private final List packetsSent; - public User(double distance) { + public User(double distance, int timeSlotNb, int subCarrierNb) { this.distance = distance; - this.bandwidthTable = new double[1][1]; // TODO: 03/03/2023 Changer valeurs + this.bandwidthTable = new double[timeSlotNb][subCarrierNb]; this.packetsToSend = new ArrayList<>(); this.packetsSent = new ArrayList<>(); } public void generateBandwidth() { - double X = Math.random(); - double h = 8 * Math.sqrt(-2 * Math.log(1 - X)); - double gain = h * Math.pow(10, X*8/10) * Math.pow(1/this.distance, 3.5); - double spectralEfficacity = (43 * gain)/(15000*(-174)); - double mkn = Math.log1p(spectralEfficacity); - this.bandwidthTable[][] = mkn; // Voir comment remplir le tableau + double random = Math.random(); + for(int i = 0; i < bandwidthTable.length; i++) { + for(int j = 0; j < bandwidthTable[i].length; j++) { + double h = 8 * Math.sqrt(-2 * Math.log(1 - random)); + double gain = h * Math.pow(10, random*8/10) * Math.pow(1/this.distance, 3.5); + double spectralEfficiency = (43 * gain)/(15000*(-174)); + double mkn = Math.log1p(spectralEfficiency); + this.bandwidthTable[i][j] = mkn; + } + } } public void createPackets() { From 7cfad0a81c3c999d874c14101b53bbcebd64b6bd Mon Sep 17 00:00:00 2001 From: Remi Boure Date: Fri, 10 Mar 2023 09:12:36 +0100 Subject: [PATCH 7/7] set fixed distance values --- build.gradle | 2 +- src/main/java/fr/ntr/AccessPoint.java | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index b851d38..079c0fe 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ plugins { } run { - args = ["5000", "20"] + args = ["5000", "2"] } application { diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index 976ab7d..d532729 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -60,10 +60,9 @@ public class AccessPoint { * Génération du débit et des paquets */ private void init(int nbUsers) { + double[] distance = { 200d, 500d }; for (int i = 0; i < nbUsers; i++) { - Random random = new Random(); - double randomDist = this.min + random.nextDouble() * (this.max - this.min); - User user = new User(randomDist); + User user = new User(distance[i]); user.generateBandwidth(); user.createPackets(); this.users.add(user);