From b597d6859718a2daaa087f85d8be50d26c6f62c7 Mon Sep 17 00:00:00 2001 From: Remi Boure Date: Fri, 24 Mar 2023 10:31:50 +0100 Subject: [PATCH 01/24] PF scheduling --- src/main/java/fr/ntr/Main.java | 4 +- .../fr/ntr/scheduler/ProportionalFair.java | 70 +++++++++++++------ 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index 2bd2327..c6a9662 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -1,6 +1,7 @@ package fr.ntr; import fr.ntr.scheduler.MaxSNR; +import fr.ntr.scheduler.ProportionalFair; import fr.ntr.scheduler.RoundRobin; import fr.ntr.scheduler.Scheduler; @@ -28,7 +29,8 @@ public class Main { 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); + //Scheduler scheduler = new MaxSNR(frame, users); + Scheduler scheduler = new ProportionalFair(frame, users); AccessPoint accessPoint = new AccessPoint(scheduler, frame, users, timeSlotNb, subCarrierNb, 0, 50); accessPoint.startSimulation(numberOfTicks); } diff --git a/src/main/java/fr/ntr/scheduler/ProportionalFair.java b/src/main/java/fr/ntr/scheduler/ProportionalFair.java index 5ffe2fd..4ef2757 100644 --- a/src/main/java/fr/ntr/scheduler/ProportionalFair.java +++ b/src/main/java/fr/ntr/scheduler/ProportionalFair.java @@ -1,33 +1,63 @@ package fr.ntr.scheduler; +import java.util.ArrayList; import java.util.List; +import fr.ntr.ResourceBlock; import fr.ntr.User; public class ProportionalFair extends Scheduler { + private List users; - private String name; - private int index; - - public ProportionalFair(String name, int index) { - this.name = name; - this.index = index; - } - - @Override - public void scheduling() { - } - - private void selectionUtilisateur(int Ts, int Sp, List Users) { - - } + private ResourceBlock[][] frame; - @Override - protected void TraitementDonnees() { - // TODO Auto-generated method stub - + public ProportionalFair(ResourceBlock[][] frame, List users) { + this.frame = frame; + this.users = users; + } + + @Override + public void scheduling() { + ArrayList averageBandwiths = new ArrayList(); + for(User u : users){ + double avg = 0d; + double[][] bandwidthTable = u.getBandwidthTable(); + for(int i = 0; i < bandwidthTable.length; i++){ + for(int j = 0; j < bandwidthTable[i].length; j++){ + avg += bandwidthTable[i][j]; + } + } + avg = avg / (bandwidthTable.length * bandwidthTable[0].length); + averageBandwiths.add(new Double(avg)); } - + User selectedUser = null; + for(int ts = 0; ts < 2; ts++){ + for(int sp = 0; sp < 100; sp++){ + selectedUser = selectionUtilisateur(ts, sp, users, averageBandwiths); + if (selectedUser.getPacketsToSend().size() != 0) { + selectedUser.getPacketsSent().add(selectedUser.getPacketsToSend().get(0)); + selectedUser.getPacketsToSend().remove(selectedUser.getPacketsToSend().get(0)); + frame[ts][sp].setUser(selectedUser); + frame[ts][sp].setBandwidth(selectedUser.getBandwidthTable()[ts][sp]); + } + } + } + } + private User selectionUtilisateur(int ts, int sp, List users, List averageBandwiths) { + double PF = 0.0; + User selectedUser = null; + for(int i = 0; i < users.size(); i++){ + User u = users.get(i); + double mkn = u.getBandwidthTable()[ts][sp]; + double averageMkn = averageBandwiths.get(i); + double pf = mkn / averageMkn; + if (PF < pf){ + PF = pf; + selectedUser = u; + } + } + return selectedUser; + } } From 72d150db066ac702e819b94df88c0d210ddb7cd8 Mon Sep 17 00:00:00 2001 From: Tr1xt4n Date: Fri, 24 Mar 2023 10:37:35 +0100 Subject: [PATCH 02/24] plot --- plot/main.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 plot/main.py diff --git a/plot/main.py b/plot/main.py new file mode 100644 index 0000000..2bfb0dc --- /dev/null +++ b/plot/main.py @@ -0,0 +1,47 @@ +import os +import matplotlib.pyplot as plt +import numpy as np +import pandas as pd + +""" +data = pd.read_csv("data.csv", delimiter=';').to_numpy() + +tick = data[:, 0] + +rb = data[:, 4] + +""" +nb_files = os.listdir('export/') + +size = len(nb_files) + +# main array +averages = np.empty((size, 2)) +nb = 0 +for i in nb_files: + data = pd.read_csv("export" + os.sep + i, delimiter=';').to_numpy() + rb = data[:, 4] + + total = 0.0 + for x in rb: + total = total + x + average = total / len(rb) + nb_users = i.split(".")[0] + averages[nb, 0] = int(nb_users) + averages[nb, 1] = average + nb += 1 + +# Data for plotting +averages.sort(axis=0) +x = averages[:, 0] +y = averages[:, 1] + +print(averages) +fig, ax = plt.subplots() +ax.scatter(x, y) + +ax.set(xlabel='users', ylabel='ressources (RB)', title='MaxSNR') +ax.grid() + +# fig.savefig("test.png") +plt.show() From e7b9f75035d6aa37577ad8d69191bb9606c7f6c3 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 24 Mar 2023 10:48:49 +0100 Subject: [PATCH 03/24] Fix integration of python with the java project --- build.gradle | 2 +- plot/main.py | 12 ++---------- src/main/java/fr/ntr/scheduler/ProportionalFair.java | 2 +- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index c64edef..fb0aa8c 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ plugins { } run { - args = ["1000", "250"] + args = ["10000", "50"] } application { diff --git a/plot/main.py b/plot/main.py index 2bfb0dc..a63b194 100644 --- a/plot/main.py +++ b/plot/main.py @@ -3,15 +3,7 @@ import matplotlib.pyplot as plt import numpy as np import pandas as pd -""" -data = pd.read_csv("data.csv", delimiter=';').to_numpy() - -tick = data[:, 0] - -rb = data[:, 4] - -""" -nb_files = os.listdir('export/') +nb_files = os.listdir(".." + os.sep + "export") size = len(nb_files) @@ -19,7 +11,7 @@ size = len(nb_files) averages = np.empty((size, 2)) nb = 0 for i in nb_files: - data = pd.read_csv("export" + os.sep + i, delimiter=';').to_numpy() + data = pd.read_csv(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy() rb = data[:, 4] total = 0.0 diff --git a/src/main/java/fr/ntr/scheduler/ProportionalFair.java b/src/main/java/fr/ntr/scheduler/ProportionalFair.java index 4ef2757..8ed0cb8 100644 --- a/src/main/java/fr/ntr/scheduler/ProportionalFair.java +++ b/src/main/java/fr/ntr/scheduler/ProportionalFair.java @@ -28,7 +28,7 @@ public class ProportionalFair extends Scheduler { } } avg = avg / (bandwidthTable.length * bandwidthTable[0].length); - averageBandwiths.add(new Double(avg)); + averageBandwiths.add(avg); } User selectedUser = null; for(int ts = 0; ts < 2; ts++){ From 8d50ce67258ebd2b28f20f2f0d80d7e1d7815071 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 24 Mar 2023 10:56:05 +0100 Subject: [PATCH 04/24] Fix a possible NullPointerException --- src/main/java/fr/ntr/scheduler/ProportionalFair.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/ntr/scheduler/ProportionalFair.java b/src/main/java/fr/ntr/scheduler/ProportionalFair.java index 8ed0cb8..4b0c411 100644 --- a/src/main/java/fr/ntr/scheduler/ProportionalFair.java +++ b/src/main/java/fr/ntr/scheduler/ProportionalFair.java @@ -30,11 +30,11 @@ public class ProportionalFair extends Scheduler { avg = avg / (bandwidthTable.length * bandwidthTable[0].length); averageBandwiths.add(avg); } - User selectedUser = null; + User selectedUser; for(int ts = 0; ts < 2; ts++){ for(int sp = 0; sp < 100; sp++){ selectedUser = selectionUtilisateur(ts, sp, users, averageBandwiths); - if (selectedUser.getPacketsToSend().size() != 0) { + if (selectedUser != null && !selectedUser.getPacketsToSend().isEmpty()) { selectedUser.getPacketsSent().add(selectedUser.getPacketsToSend().get(0)); selectedUser.getPacketsToSend().remove(selectedUser.getPacketsToSend().get(0)); frame[ts][sp].setUser(selectedUser); From 8a556e999ad8c5566db49f1dafb83a554dc3e5ea Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 24 Mar 2023 11:12:40 +0100 Subject: [PATCH 05/24] Encapsulate average_mkn --- plot/main.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/plot/main.py b/plot/main.py index a63b194..df36a68 100644 --- a/plot/main.py +++ b/plot/main.py @@ -7,22 +7,26 @@ nb_files = os.listdir(".." + os.sep + "export") size = len(nb_files) -# main array -averages = np.empty((size, 2)) -nb = 0 -for i in nb_files: - data = pd.read_csv(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy() - rb = data[:, 4] - total = 0.0 - for x in rb: - total = total + x - average = total / len(rb) - nb_users = i.split(".")[0] - averages[nb, 0] = int(nb_users) - averages[nb, 1] = average - nb += 1 +def mean_mkn() -> np.ndarray: + averages_mkn = np.empty((size, 2)) + nb = 0 + for i in nb_files: + data = pd.read_csv(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy() + rb = data[:, 4] + total = 0.0 + for x in rb: + total = total + x + average = total / len(rb) + nb_users = i.split(".")[0] + averages_mkn[nb, 0] = int(nb_users) + averages_mkn[nb, 1] = average + nb += 1 + return averages_mkn + + +averages = mean_mkn() # Data for plotting averages.sort(axis=0) x = averages[:, 0] From 9f2178ed4990c4f5883b32b7fc27cac8fbaea877 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 24 Mar 2023 11:41:34 +0100 Subject: [PATCH 06/24] Add percentage of RB usage --- plot/main.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/plot/main.py b/plot/main.py index df36a68..0c0c740 100644 --- a/plot/main.py +++ b/plot/main.py @@ -26,18 +26,43 @@ def mean_mkn() -> np.ndarray: return averages_mkn +def rb_available() -> np.ndarray: + available = np.zeros((size, 2)) + nb = 0 + for i in nb_files: + data = pd.read_csv(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy() + nb_users = i.split(".")[0] + available[nb, 0] = int(nb_users) + available[nb, 1] = data.shape[0] / (200 * 10000) + nb += 1 + + """for j in range(0, 2): + for k in range(0, 10000): + nb_users = i.split(".")[0] + available[nb, 0] = int(nb_users) + if j == data[nb, 1] and k == data[:, 2]: + available[nb, 1] += 1 + """ + return available + + averages = mean_mkn() +available = rb_available() # Data for plotting averages.sort(axis=0) -x = averages[:, 0] -y = averages[:, 1] print(averages) fig, ax = plt.subplots() -ax.scatter(x, y) +ax.scatter(averages[:, 0], averages[:, 1]) -ax.set(xlabel='users', ylabel='ressources (RB)', title='MaxSNR') +ax.set(xlabel='number of users', ylabel='Efficacité spectrale', title='Efficacité spectrale') ax.grid() # fig.savefig("test.png") plt.show() + +fig, ax = plt.subplots() +ax.scatter(available[:, 0], available[:, 1]) +ax.set(xlabel='number of users', ylabel='RB utilisés', title='Pourcentage de RB utilisés') +ax.grid() +plt.show() From cb7150e4441ea5a36fe24cac01b16085d7a0058a Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 24 Mar 2023 11:51:08 +0100 Subject: [PATCH 07/24] Move duplicate block --- src/main/java/fr/ntr/AccessPoint.java | 4 ++-- src/main/java/fr/ntr/scheduler/MaxSNR.java | 10 ++-------- src/main/java/fr/ntr/scheduler/ProportionalFair.java | 7 +------ src/main/java/fr/ntr/scheduler/RoundRobin.java | 2 +- src/main/java/fr/ntr/scheduler/Scheduler.java | 11 ++++++++++- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index c8955c7..4d31c3e 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -80,14 +80,14 @@ public class AccessPoint { private void updateBandwidth(int ticks) { int n = 200; - int timeInterval = 50 + random.nextInt(51); + int timeInterval = Math.max(1, random.nextInt(51)); // avoid div by 0 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 + // On régénère les sources toutes les 0-50 ms if(ticks % timeInterval == 0){ timeInterval = 50 + random.nextInt(51); n = user.createPackets(n, ticks); diff --git a/src/main/java/fr/ntr/scheduler/MaxSNR.java b/src/main/java/fr/ntr/scheduler/MaxSNR.java index 2d55916..d80b7c1 100644 --- a/src/main/java/fr/ntr/scheduler/MaxSNR.java +++ b/src/main/java/fr/ntr/scheduler/MaxSNR.java @@ -18,16 +18,10 @@ public class MaxSNR extends Scheduler { @Override public void scheduling() { - User userMax = null; for(int ts = 0; ts < 2; ts++){ for(int sp = 0; sp < 100; sp++){ - userMax = selectionUtilisateur(sp, ts, users); - if (userMax.getPacketsToSend().size() != 0) { - userMax.getPacketsSent().add(userMax.getPacketsToSend().get(0)); - userMax.getPacketsToSend().remove(userMax.getPacketsToSend().get(0)); - frame[ts][sp].setUser(userMax); - frame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]); - } + User userMax = selectionUtilisateur(sp, ts, users); + allocateRessource(userMax, frame, ts, sp); } } } diff --git a/src/main/java/fr/ntr/scheduler/ProportionalFair.java b/src/main/java/fr/ntr/scheduler/ProportionalFair.java index 4b0c411..7ce759e 100644 --- a/src/main/java/fr/ntr/scheduler/ProportionalFair.java +++ b/src/main/java/fr/ntr/scheduler/ProportionalFair.java @@ -34,12 +34,7 @@ public class ProportionalFair extends Scheduler { for(int ts = 0; ts < 2; ts++){ for(int sp = 0; sp < 100; sp++){ selectedUser = selectionUtilisateur(ts, sp, users, averageBandwiths); - if (selectedUser != null && !selectedUser.getPacketsToSend().isEmpty()) { - selectedUser.getPacketsSent().add(selectedUser.getPacketsToSend().get(0)); - selectedUser.getPacketsToSend().remove(selectedUser.getPacketsToSend().get(0)); - frame[ts][sp].setUser(selectedUser); - frame[ts][sp].setBandwidth(selectedUser.getBandwidthTable()[ts][sp]); - } + allocateRessource(selectedUser, frame, ts, sp); } } } diff --git a/src/main/java/fr/ntr/scheduler/RoundRobin.java b/src/main/java/fr/ntr/scheduler/RoundRobin.java index 4566fbc..db4a3e5 100644 --- a/src/main/java/fr/ntr/scheduler/RoundRobin.java +++ b/src/main/java/fr/ntr/scheduler/RoundRobin.java @@ -36,7 +36,7 @@ public class RoundRobin extends Scheduler { //Pour chaque time slot et sous porteuses for (int Ts = 0; Ts < AccessPoint.getTimeSlotNb(); Ts++) { for(int Sp = 0; Sp < AccessPoint.getSubCarrierNb(); Sp++) { - if (users.get(index).getPacketsToSend().size() != 0) { + if (!users.get(index).getPacketsToSend().isEmpty()) { // on enlève le packet transmis de la liste // TODO Verify sub the packet send need Set packet users.get(index).getPacketsSent().add(users.get(index).getPacketsToSend().get(0)); diff --git a/src/main/java/fr/ntr/scheduler/Scheduler.java b/src/main/java/fr/ntr/scheduler/Scheduler.java index e21432d..e277862 100644 --- a/src/main/java/fr/ntr/scheduler/Scheduler.java +++ b/src/main/java/fr/ntr/scheduler/Scheduler.java @@ -1,5 +1,8 @@ package fr.ntr.scheduler; +import fr.ntr.ResourceBlock; +import fr.ntr.User; + public abstract class Scheduler { /** @@ -8,7 +11,13 @@ public abstract class Scheduler { * Return */ public abstract void scheduling(); - protected void TraitementDonnees() { + protected void allocateRessource(User userMax, ResourceBlock[][] frame, int ts, int sp) { + if (userMax != null && !userMax.getPacketsToSend().isEmpty()) { + userMax.getPacketsSent().add(userMax.getPacketsToSend().get(0)); + userMax.getPacketsToSend().remove(userMax.getPacketsToSend().get(0)); + frame[ts][sp].setUser(userMax); + frame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]); + } } } From 28e4938750b3de7078f572f4e269be1be78de24c Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 24 Mar 2023 11:52:09 +0100 Subject: [PATCH 08/24] Change h to square h when generating bandwith --- src/main/java/fr/ntr/User.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index ec7e659..ba7d238 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -28,7 +28,7 @@ public class User { double random = this.random.nextDouble(); for(int x = 0; x < bandwidthTable.length; x++) { double h = 1 * Math.sqrt(-2 * Math.log(1 - random)); - double gain = h * Math.pow(10, random * 1/10) * Math.pow(1 / this.distance, 3.5); + double gain = h * h * Math.pow(10, random * 1/10) * Math.pow(1 / this.distance, 3.5); double spectralEfficiency = (20 * gain) / (15000 * (3.9*Math.pow(10, -21))); double mkn = Math.log(1 + spectralEfficiency) / Math.log(2); this.bandwidthTable[x][y] = mkn; From c06ada967977aa48b876bde96dbd40919c94cb3f Mon Sep 17 00:00:00 2001 From: Remi Boure Date: Fri, 24 Mar 2023 12:12:18 +0100 Subject: [PATCH 09/24] =?UTF-8?q?Calcul=20d=C3=A9lai=20paquet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/fr/ntr/AccessPoint.java | 19 ++++++++++++++++--- src/main/java/fr/ntr/Packets.java | 17 ++++++++++++----- src/main/java/fr/ntr/User.java | 9 --------- src/main/java/fr/ntr/scheduler/MaxSNR.java | 16 +++++++++++++--- src/main/java/fr/ntr/scheduler/Scheduler.java | 2 +- 5 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index c8955c7..14df64a 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -68,7 +68,8 @@ public class AccessPoint { // Simulation reset(); updateBandwidth(ticks); - schedule(); + schedule(ticks); + computePacketDelay(ticks); // traite les données et les enregistre dans un fichier try { analyseData(ticks); @@ -76,6 +77,7 @@ public class AccessPoint { System.out.println("Can't export data"); } } + } private void updateBandwidth(int ticks) { @@ -95,8 +97,8 @@ public class AccessPoint { } } - private void schedule() { - scheduler.scheduling(); + private void schedule(int ticks) { + scheduler.scheduling(ticks); } private void analyseData(int tick) throws IOException { @@ -126,6 +128,17 @@ public class AccessPoint { } } + private void computePacketDelay(int ticks){ + for(int i = 0; i < this.users.size(); i++){ + User u = this.users.get(i); + if(!u.getPacketsToSend().isEmpty()){ + for(Packets p : u.getPacketsToSend()){ + + } + } + } + } + public ResourceBlock[][] getFrame() { return frame; } diff --git a/src/main/java/fr/ntr/Packets.java b/src/main/java/fr/ntr/Packets.java index 01e1602..16b2cb3 100644 --- a/src/main/java/fr/ntr/Packets.java +++ b/src/main/java/fr/ntr/Packets.java @@ -5,12 +5,16 @@ public class Packets { private int startTimeSending; private int endTimeSending; private int durationSending; - private double bitsNumberRemaining; + private int bitsNumberRemaining; public Packets(int startTimeSending){ this.startTimeSending = startTimeSending; } + public double getBitsNumberRemaining() { + return bitsNumberRemaining; + } + public int getStartTimeSending() { return startTimeSending; } @@ -24,17 +28,20 @@ public class Packets { } public void setEndTimeSending(int endTimeSending) { - this.endTimeSending = endTimeSending; + this.endTimeSending = endTimeSending+1; } - public void setDurationSending(){ - int durationSending = endTimeSending - startTimeSending; - this.durationSending = durationSending; + public void setDurationSending(int ticks){ + this.durationSending = ticks - startTimeSending; } public int getDurationSending() { return durationSending; } + public void decreaseBitsNumberRemaining(int d) { + this.bitsNumberRemaining -= d; + } + } \ No newline at end of file diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index ec7e659..e6b2a36 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -57,15 +57,6 @@ public class User { return mbis; } - /** - * Calcul délais de transmission des paquets - */ - public void computeTimeSending() { - for(Packets p : packetsToSend){ - p.setDurationSending(); - } - } - public double getDistance() { return distance; } diff --git a/src/main/java/fr/ntr/scheduler/MaxSNR.java b/src/main/java/fr/ntr/scheduler/MaxSNR.java index 2d55916..a76961e 100644 --- a/src/main/java/fr/ntr/scheduler/MaxSNR.java +++ b/src/main/java/fr/ntr/scheduler/MaxSNR.java @@ -1,6 +1,7 @@ package fr.ntr.scheduler; import java.util.List; +import fr.ntr.Packets; import fr.ntr.ResourceBlock; import fr.ntr.User; @@ -17,16 +18,25 @@ public class MaxSNR extends Scheduler { } @Override - public void scheduling() { + public void scheduling(int ticks) { User userMax = null; for(int ts = 0; ts < 2; ts++){ for(int sp = 0; sp < 100; sp++){ userMax = selectionUtilisateur(sp, ts, users); if (userMax.getPacketsToSend().size() != 0) { - userMax.getPacketsSent().add(userMax.getPacketsToSend().get(0)); - userMax.getPacketsToSend().remove(userMax.getPacketsToSend().get(0)); + Packets p = userMax.getPacketsToSend().get(0); + userMax.getPacketsSent().add(p); + if(p.getDurationSending() != 0){ + if(p.getBitsNumberRemaining() > 0){ + p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]); + } else { + p.setDurationSending(ticks); + } + } + userMax.getPacketsToSend().remove(p); frame[ts][sp].setUser(userMax); frame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]); + } } } diff --git a/src/main/java/fr/ntr/scheduler/Scheduler.java b/src/main/java/fr/ntr/scheduler/Scheduler.java index e21432d..1a1c104 100644 --- a/src/main/java/fr/ntr/scheduler/Scheduler.java +++ b/src/main/java/fr/ntr/scheduler/Scheduler.java @@ -7,7 +7,7 @@ public abstract class Scheduler { * Rempli la trame avec les utilisateurs * Return */ - public abstract void scheduling(); + public abstract void scheduling(int ticks); protected void TraitementDonnees() { } From 2c5d1d2e94e83d6bd53a704a6c4cad01bed2df5b Mon Sep 17 00:00:00 2001 From: Tr1xt4n Date: Tue, 28 Mar 2023 08:32:26 +0200 Subject: [PATCH 10/24] +delay --- src/main/java/fr/ntr/AccessPoint.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index 5e92b91..e658633 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -58,7 +58,7 @@ public class AccessPoint { Files.deleteIfExists(Paths.get("export", this.users.size() + ".csv")); new File("export").mkdir(); this.outputDataFile = new FileOutputStream("export" + File.separator + this.users.size() + ".csv", true); - outputDataFile.write("tick;x;y;user;bandwidth;\n".getBytes()); + outputDataFile.write("tick;x;y;user;bandwidth;delay\n".getBytes()); } catch(IOException e) { System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage()); System.exit(1); @@ -102,11 +102,20 @@ public class AccessPoint { } private void analyseData(int tick) throws IOException { + double delayAverrage = 0.0; + double total = 0.0; + for(User u: this.users){ + List packets = u.getPacketsSent(); + for (Packets p: packets){ + total += p.getDurationSending(); + } + } + delayAverrage = total/this.users.size(); for(int i = 0; i < frame.length; i++) { for(int j = 0; j < frame[i].length; j++) { ResourceBlock ur = frame[i][j]; if(ur.getUser() != null) { - String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";\n"); + String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";" + delayAverrage +";\n"); try{ outputDataFile.write(data.getBytes()); }catch(IOException e){ From 3a438472d0fc26b40496fd72ede8122f0b6e0bfe Mon Sep 17 00:00:00 2001 From: Tr1xt4n Date: Tue, 28 Mar 2023 08:39:19 +0200 Subject: [PATCH 11/24] scheduleing +1param --- src/main/java/fr/ntr/scheduler/MaxSNR.java | 13 ++++++------- .../java/fr/ntr/scheduler/ProportionalFair.java | 4 +++- src/main/java/fr/ntr/scheduler/RoundRobin.java | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/fr/ntr/scheduler/MaxSNR.java b/src/main/java/fr/ntr/scheduler/MaxSNR.java index a76961e..d1f7e40 100644 --- a/src/main/java/fr/ntr/scheduler/MaxSNR.java +++ b/src/main/java/fr/ntr/scheduler/MaxSNR.java @@ -26,13 +26,12 @@ public class MaxSNR extends Scheduler { if (userMax.getPacketsToSend().size() != 0) { Packets p = userMax.getPacketsToSend().get(0); userMax.getPacketsSent().add(p); - if(p.getDurationSending() != 0){ - if(p.getBitsNumberRemaining() > 0){ - p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]); - } else { - p.setDurationSending(ticks); - } - } + if(p.getBitsNumberRemaining() > 0){ + p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]); + } else { + p.setDurationSending(ticks); + } + userMax.getPacketsToSend().remove(p); frame[ts][sp].setUser(userMax); frame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]); diff --git a/src/main/java/fr/ntr/scheduler/ProportionalFair.java b/src/main/java/fr/ntr/scheduler/ProportionalFair.java index 7ce759e..e7cd1fe 100644 --- a/src/main/java/fr/ntr/scheduler/ProportionalFair.java +++ b/src/main/java/fr/ntr/scheduler/ProportionalFair.java @@ -7,6 +7,8 @@ import fr.ntr.ResourceBlock; import fr.ntr.User; public class ProportionalFair extends Scheduler { + + private List users; private ResourceBlock[][] frame; @@ -17,7 +19,7 @@ public class ProportionalFair extends Scheduler { } @Override - public void scheduling() { + public void scheduling(int ticks) { ArrayList averageBandwiths = new ArrayList(); for(User u : users){ double avg = 0d; diff --git a/src/main/java/fr/ntr/scheduler/RoundRobin.java b/src/main/java/fr/ntr/scheduler/RoundRobin.java index db4a3e5..6ba2cb8 100644 --- a/src/main/java/fr/ntr/scheduler/RoundRobin.java +++ b/src/main/java/fr/ntr/scheduler/RoundRobin.java @@ -28,7 +28,7 @@ public class RoundRobin extends Scheduler { * Return */ @Override - public void scheduling() { + public void scheduling(int ticks) { //selection aleatoire du premier utilisateur Random random = new Random(); index = random.nextInt(users.size()); From 64423564506373551af938a6b8c0c2946a521c63 Mon Sep 17 00:00:00 2001 From: Remi Boure Date: Tue, 28 Mar 2023 09:15:30 +0200 Subject: [PATCH 12/24] Compute average delays --- src/main/java/fr/ntr/AccessPoint.java | 11 +++++---- src/main/java/fr/ntr/scheduler/MaxSNR.java | 19 +++------------ .../fr/ntr/scheduler/ProportionalFair.java | 7 +++--- .../java/fr/ntr/scheduler/RoundRobin.java | 23 ++++++------------- src/main/java/fr/ntr/scheduler/Scheduler.java | 17 +++++++++++--- 5 files changed, 33 insertions(+), 44 deletions(-) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index e658633..4eac135 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -102,20 +102,21 @@ public class AccessPoint { } private void analyseData(int tick) throws IOException { - double delayAverrage = 0.0; - double total = 0.0; + double delayAverage = 0.0; + int nbPacketsSent = 0; for(User u: this.users){ List packets = u.getPacketsSent(); + nbPacketsSent += packets.size(); for (Packets p: packets){ - total += p.getDurationSending(); + delayAverage += p.getDurationSending(); } } - delayAverrage = total/this.users.size(); + delayAverage = delayAverage/nbPacketsSent; for(int i = 0; i < frame.length; i++) { for(int j = 0; j < frame[i].length; j++) { ResourceBlock ur = frame[i][j]; if(ur.getUser() != null) { - String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";" + delayAverrage +";\n"); + String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";" + delayAverage +";\n"); try{ outputDataFile.write(data.getBytes()); }catch(IOException e){ diff --git a/src/main/java/fr/ntr/scheduler/MaxSNR.java b/src/main/java/fr/ntr/scheduler/MaxSNR.java index d1f7e40..d39a3ad 100644 --- a/src/main/java/fr/ntr/scheduler/MaxSNR.java +++ b/src/main/java/fr/ntr/scheduler/MaxSNR.java @@ -22,26 +22,13 @@ public class MaxSNR extends Scheduler { User userMax = null; for(int ts = 0; ts < 2; ts++){ for(int sp = 0; sp < 100; sp++){ - userMax = selectionUtilisateur(sp, ts, users); - if (userMax.getPacketsToSend().size() != 0) { - Packets p = userMax.getPacketsToSend().get(0); - userMax.getPacketsSent().add(p); - if(p.getBitsNumberRemaining() > 0){ - p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]); - } else { - p.setDurationSending(ticks); - } - - userMax.getPacketsToSend().remove(p); - frame[ts][sp].setUser(userMax); - frame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]); - - } + userMax = userSelection(ts, sp, users); + allocateRessource(userMax, frame, ts, sp, ticks); } } } - private User selectionUtilisateur(int sp, int ts, List Users) { + private User userSelection(int ts, int sp, List Users) { double MaxSnr = 0.0; User userMax = null; for(User u: Users){ diff --git a/src/main/java/fr/ntr/scheduler/ProportionalFair.java b/src/main/java/fr/ntr/scheduler/ProportionalFair.java index e7cd1fe..94e9403 100644 --- a/src/main/java/fr/ntr/scheduler/ProportionalFair.java +++ b/src/main/java/fr/ntr/scheduler/ProportionalFair.java @@ -32,16 +32,15 @@ public class ProportionalFair extends Scheduler { avg = avg / (bandwidthTable.length * bandwidthTable[0].length); averageBandwiths.add(avg); } - User selectedUser; for(int ts = 0; ts < 2; ts++){ for(int sp = 0; sp < 100; sp++){ - selectedUser = selectionUtilisateur(ts, sp, users, averageBandwiths); - allocateRessource(selectedUser, frame, ts, sp); + User selectedUser = userSelection(ts, sp, users, averageBandwiths); + allocateRessource(selectedUser, frame, ts, sp, ticks); } } } - private User selectionUtilisateur(int ts, int sp, List users, List averageBandwiths) { + private User userSelection(int ts, int sp, List users, List averageBandwiths) { double PF = 0.0; User selectedUser = null; for(int i = 0; i < users.size(); i++){ diff --git a/src/main/java/fr/ntr/scheduler/RoundRobin.java b/src/main/java/fr/ntr/scheduler/RoundRobin.java index 6ba2cb8..be32af5 100644 --- a/src/main/java/fr/ntr/scheduler/RoundRobin.java +++ b/src/main/java/fr/ntr/scheduler/RoundRobin.java @@ -34,19 +34,10 @@ 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++) { - if (!users.get(index).getPacketsToSend().isEmpty()) { - // on enlève le packet transmis de la liste - // TODO Verify sub the packet send need Set packet - users.get(index).getPacketsSent().add(users.get(index).getPacketsToSend().get(0)); - users.get(index).getPacketsToSend().remove(users.get(index).getPacketsToSend().get(0)); - //on ajoute l'utilisateur a la frame - User user = UserSelection(Ts, Sp, users); - frame[Ts][Sp].setUser(user); - frame[Ts][Sp].setBandwidth(user.getBandwidthTable()[Ts][Sp]); - } - + for (int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++) { + for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++) { + User userSelected = userSelection(ts, sp, users); + allocateRessource(userSelected, frame, ts, sp, ticks); } } } @@ -55,10 +46,10 @@ public class RoundRobin extends Scheduler { * 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) { + private User userSelection(int ts, int sp, List users) { //compte le nombre de bloc attribue - for (int i = 0; i < Ts; i++){ - for (int j = 0; j < Sp; j++) { + for (int i = 0; i < ts; i++){ + for (int j = 0; j < sp; j++) { index++; } } diff --git a/src/main/java/fr/ntr/scheduler/Scheduler.java b/src/main/java/fr/ntr/scheduler/Scheduler.java index 0652c50..418fcc1 100644 --- a/src/main/java/fr/ntr/scheduler/Scheduler.java +++ b/src/main/java/fr/ntr/scheduler/Scheduler.java @@ -1,5 +1,6 @@ package fr.ntr.scheduler; +import fr.ntr.Packets; import fr.ntr.ResourceBlock; import fr.ntr.User; @@ -12,10 +13,20 @@ public abstract class Scheduler { */ public abstract void scheduling(int ticks); - protected void allocateRessource(User userMax, ResourceBlock[][] frame, int ts, int sp) { + protected void allocateRessource(User userMax, ResourceBlock[][] frame, int ts, int sp, int ticks) { if (userMax != null && !userMax.getPacketsToSend().isEmpty()) { - userMax.getPacketsSent().add(userMax.getPacketsToSend().get(0)); - userMax.getPacketsToSend().remove(userMax.getPacketsToSend().get(0)); + Packets p = userMax.getPacketsToSend().get(0); + if(p.getBitsNumberRemaining() > 0){ + p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]); + } else { + if(ticks == 0){ + p.setDurationSending(1); + }else { + p.setDurationSending(ticks); + } + } + userMax.getPacketsSent().add(p); + userMax.getPacketsToSend().remove(p); frame[ts][sp].setUser(userMax); frame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]); } From 7295530501d1058dbe278c8d4a3b16184d8fe030 Mon Sep 17 00:00:00 2001 From: Tr1xt4n Date: Tue, 28 Mar 2023 09:25:04 +0200 Subject: [PATCH 13/24] delay --- plot/main.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plot/main.py b/plot/main.py index 0c0c740..f858958 100644 --- a/plot/main.py +++ b/plot/main.py @@ -45,6 +45,18 @@ def rb_available() -> np.ndarray: """ return available +def delay() -> np.ndarray: + delays = np.zeros((size, 2)) + nb = 0 + for i in nb_files: + data = pd.read_csv(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy() + nb_users = i.split(".")[0] + d = data[:, 5] + for x in d: + delays[nb, 0] = int(nb_users) + delays[nb, 1] = float(x) + nb += 1 + return delays averages = mean_mkn() available = rb_available() @@ -65,4 +77,4 @@ fig, ax = plt.subplots() ax.scatter(available[:, 0], available[:, 1]) ax.set(xlabel='number of users', ylabel='RB utilisés', title='Pourcentage de RB utilisés') ax.grid() -plt.show() +plt.show() \ No newline at end of file From c778fcb6da25ebf3d5b68cd95422212da2d77385 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 28 Mar 2023 09:30:21 +0200 Subject: [PATCH 14/24] Fix userSelection in RR --- plot/main.py | 10 +---- src/main/java/fr/ntr/Main.java | 5 ++- src/main/java/fr/ntr/scheduler/MaxSNR.java | 22 ++++++----- .../java/fr/ntr/scheduler/RoundRobin.java | 37 ++++++++++--------- 4 files changed, 36 insertions(+), 38 deletions(-) diff --git a/plot/main.py b/plot/main.py index 0c0c740..eaa30b6 100644 --- a/plot/main.py +++ b/plot/main.py @@ -33,16 +33,8 @@ def rb_available() -> np.ndarray: data = pd.read_csv(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy() nb_users = i.split(".")[0] available[nb, 0] = int(nb_users) - available[nb, 1] = data.shape[0] / (200 * 10000) + available[nb, 1] = (data.shape[0] / (200 * 10000)) * 100 nb += 1 - - """for j in range(0, 2): - for k in range(0, 10000): - nb_users = i.split(".")[0] - available[nb, 0] = int(nb_users) - if j == data[nb, 1] and k == data[:, 2]: - available[nb, 1] += 1 - """ return available diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index c6a9662..cccfd09 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -26,11 +26,12 @@ public class Main { } int timeSlotNb = 2; int subCarrierNb = 100; - for(int i = 2; i < maximumLoad; i+=2) { + 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); - Scheduler scheduler = new ProportionalFair(frame, users); + // Scheduler scheduler = new ProportionalFair(frame, users); + Scheduler scheduler = new RoundRobin(frame, users); AccessPoint accessPoint = new AccessPoint(scheduler, frame, users, timeSlotNb, subCarrierNb, 0, 50); accessPoint.startSimulation(numberOfTicks); } diff --git a/src/main/java/fr/ntr/scheduler/MaxSNR.java b/src/main/java/fr/ntr/scheduler/MaxSNR.java index d39a3ad..809cd99 100644 --- a/src/main/java/fr/ntr/scheduler/MaxSNR.java +++ b/src/main/java/fr/ntr/scheduler/MaxSNR.java @@ -19,21 +19,25 @@ public class MaxSNR extends Scheduler { @Override public void scheduling(int ticks) { - User userMax = null; + User userMax; for(int ts = 0; ts < 2; ts++){ for(int sp = 0; sp < 100; sp++){ - userMax = userSelection(ts, sp, users); + userMax = userSelection(ts, sp); allocateRessource(userMax, frame, ts, sp, ticks); } } - } - - private User userSelection(int ts, int sp, List Users) { - double MaxSnr = 0.0; + } + + /** + * Sélectionne le prochain utilisateur en fonction du contexte + * @return the user with the best bandwidth + */ + private User userSelection(int ts, int sp) { + double maxSnr = 0.0; User userMax = null; - for(User u: Users){ - if (MaxSnr < u.getBandwidthTable()[ts][sp]){ - MaxSnr = u.getBandwidthTable()[ts][sp]; + for(User u: users){ + if (maxSnr < u.getBandwidthTable()[ts][sp]) { + maxSnr = u.getBandwidthTable()[ts][sp]; userMax = u; } } diff --git a/src/main/java/fr/ntr/scheduler/RoundRobin.java b/src/main/java/fr/ntr/scheduler/RoundRobin.java index be32af5..91d916c 100644 --- a/src/main/java/fr/ntr/scheduler/RoundRobin.java +++ b/src/main/java/fr/ntr/scheduler/RoundRobin.java @@ -9,17 +9,17 @@ import fr.ntr.User; public class RoundRobin extends Scheduler { - private String name; + private final Random random; private int index; - private List users; - private ResourceBlock[][] frame; + private final List users; + private final ResourceBlock[][] frame; - public RoundRobin(String name, int index, ResourceBlock[][] frame, List users) { - this.name = name; - this.index = index; + public RoundRobin(ResourceBlock[][] frame, List users) { + this.index = 0; this.frame = frame; this.users = users; + this.random = new Random(); } /** @@ -29,14 +29,14 @@ public class RoundRobin extends Scheduler { */ @Override public void scheduling(int ticks) { - //selection aleatoire du premier utilisateur - Random random = new Random(); - index = random.nextInt(users.size()); + //selection aléatoire du premier utilisateur + + 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++) { - User userSelected = userSelection(ts, sp, users); + User userSelected = userSelection(); allocateRessource(userSelected, frame, ts, sp, ticks); } } @@ -45,16 +45,17 @@ public class RoundRobin extends Scheduler { /** * Entry Time slot (int), Sous porteuse(int), and users ( List) * Return the user in function of TS and SP selected + * + * @return the next user which have something to send, null otherwise */ - private User userSelection(int ts, int sp, List users) { - //compte le nombre de bloc attribue - for (int i = 0; i < ts; i++){ - for (int j = 0; j < sp; j++) { - index++; + private User userSelection() { + for(int i = index; i < index + users.size(); i++) { + User user = users.get(index % (users.size())); + if(!user.getPacketsToSend().isEmpty()) { + index = i; + return user; } } - //on retourne l'utilisateur - return users.get(index%(users.size() - 1)); - + return null; } } From fa14796c17d343c3012ee4e339ce12d6a8cff353 Mon Sep 17 00:00:00 2001 From: Tr1xt4n Date: Tue, 28 Mar 2023 09:35:26 +0200 Subject: [PATCH 15/24] delays --- plot/main.py | 12 +++++++++++- src/main/java/fr/ntr/AccessPoint.java | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/plot/main.py b/plot/main.py index f858958..6e339f9 100644 --- a/plot/main.py +++ b/plot/main.py @@ -55,15 +55,18 @@ def delay() -> np.ndarray: for x in d: delays[nb, 0] = int(nb_users) delays[nb, 1] = float(x) + print(float(x)) nb += 1 return delays averages = mean_mkn() available = rb_available() +delays = delay() +delays.sort(axis=0) # Data for plotting averages.sort(axis=0) -print(averages) +#print(averages) fig, ax = plt.subplots() ax.scatter(averages[:, 0], averages[:, 1]) @@ -77,4 +80,11 @@ fig, ax = plt.subplots() ax.scatter(available[:, 0], available[:, 1]) ax.set(xlabel='number of users', ylabel='RB utilisés', title='Pourcentage de RB utilisés') ax.grid() +plt.show() + + +fig, ax = plt.subplots() +ax.scatter(delays[:, 0], delays[:, 1]) +ax.set(xlabel='number of users', ylabel='delays(ms)', title='Delay') +ax.grid() plt.show() \ No newline at end of file diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index 4eac135..dd75f79 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -58,7 +58,7 @@ public class AccessPoint { Files.deleteIfExists(Paths.get("export", this.users.size() + ".csv")); new File("export").mkdir(); this.outputDataFile = new FileOutputStream("export" + File.separator + this.users.size() + ".csv", true); - outputDataFile.write("tick;x;y;user;bandwidth;delay\n".getBytes()); + outputDataFile.write("tick;x;y;user;bandwidth;delay;\n".getBytes()); } catch(IOException e) { System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage()); System.exit(1); From e627cf739722b317f581c36698337846cf424300 Mon Sep 17 00:00:00 2001 From: Remi Boure Date: Tue, 28 Mar 2023 09:43:31 +0200 Subject: [PATCH 16/24] Fix packets sent --- src/main/java/fr/ntr/scheduler/Scheduler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/ntr/scheduler/Scheduler.java b/src/main/java/fr/ntr/scheduler/Scheduler.java index 418fcc1..b2dc953 100644 --- a/src/main/java/fr/ntr/scheduler/Scheduler.java +++ b/src/main/java/fr/ntr/scheduler/Scheduler.java @@ -24,9 +24,9 @@ public abstract class Scheduler { }else { p.setDurationSending(ticks); } + userMax.getPacketsSent().add(p); + userMax.getPacketsToSend().remove(p); } - userMax.getPacketsSent().add(p); - userMax.getPacketsToSend().remove(p); frame[ts][sp].setUser(userMax); frame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]); } From 59a58abc7c1c980a255ef3fca86680050713b92c Mon Sep 17 00:00:00 2001 From: Remi Boure Date: Tue, 28 Mar 2023 09:51:20 +0200 Subject: [PATCH 17/24] Fix init of bitsRemaining --- src/main/java/fr/ntr/Packets.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/fr/ntr/Packets.java b/src/main/java/fr/ntr/Packets.java index 16b2cb3..35b0460 100644 --- a/src/main/java/fr/ntr/Packets.java +++ b/src/main/java/fr/ntr/Packets.java @@ -8,6 +8,7 @@ public class Packets { private int bitsNumberRemaining; public Packets(int startTimeSending){ + this.bitsNumberRemaining = packetSize; this.startTimeSending = startTimeSending; } From aa9ea15beb86c5e062a5dd429e9a397c3863fe64 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 30 Mar 2023 08:24:25 +0200 Subject: [PATCH 18/24] Fix RR by removing random selection of the first user --- plot/main.py | 2 ++ src/main/java/fr/ntr/AccessPoint.java | 14 +------- src/main/java/fr/ntr/User.java | 9 +++--- .../java/fr/ntr/scheduler/RoundRobin.java | 32 +++++++------------ 4 files changed, 19 insertions(+), 38 deletions(-) diff --git a/plot/main.py b/plot/main.py index 656bea7..69e3350 100644 --- a/plot/main.py +++ b/plot/main.py @@ -37,6 +37,7 @@ def rb_available() -> np.ndarray: nb += 1 return available + def delay() -> np.ndarray: delays = np.zeros((size, 2)) nb = 0 @@ -51,6 +52,7 @@ def delay() -> np.ndarray: nb += 1 return delays + averages = mean_mkn() available = rb_available() delays = delay() diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index dd75f79..748bc25 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -69,7 +69,6 @@ public class AccessPoint { reset(); updateBandwidth(ticks); schedule(ticks); - computePacketDelay(ticks); // traite les données et les enregistre dans un fichier try { analyseData(ticks); @@ -91,7 +90,7 @@ public class AccessPoint { // On régénère les sources toutes les 0-50 ms if(ticks % timeInterval == 0){ - timeInterval = 50 + random.nextInt(51); + timeInterval = Math.max(1, random.nextInt(51)); n = user.createPackets(n, ticks); } } @@ -138,17 +137,6 @@ public class AccessPoint { } } - private void computePacketDelay(int ticks){ - for(int i = 0; i < this.users.size(); i++){ - User u = this.users.get(i); - if(!u.getPacketsToSend().isEmpty()){ - for(Packets p : u.getPacketsToSend()){ - - } - } - } - } - public ResourceBlock[][] getFrame() { return frame; } diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index 2096cf5..0d41e13 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -12,7 +12,7 @@ public class User { private final List packetsSent; private int leftForNextSource; - private Random random = new Random(); + private final Random random = new Random(); public User(double distance, int timeSlotNb, int subCarrierNb) { this.distance = distance; @@ -25,10 +25,10 @@ public class User { public void generateBandwidth() { for(int y = 0; y < bandwidthTable[0].length; y++) { - double random = this.random.nextDouble(); + double rand = this.random.nextDouble(); for(int x = 0; x < bandwidthTable.length; x++) { - double h = 1 * Math.sqrt(-2 * Math.log(1 - random)); - double gain = h * h * Math.pow(10, random * 1/10) * Math.pow(1 / this.distance, 3.5); + double h = 1 * Math.sqrt(-2 * Math.log(1 - rand)); + double gain = h * h * Math.pow(10, rand * 1/10) * Math.pow(1 / this.distance, 3.5); double spectralEfficiency = (20 * gain) / (15000 * (3.9*Math.pow(10, -21))); double mkn = Math.log(1 + spectralEfficiency) / Math.log(2); this.bandwidthTable[x][y] = mkn; @@ -43,7 +43,6 @@ public class User { * @return */ public int createPackets(int m, int ticks) { - Random random = new Random(); // On tire un nombre entre 0 et 2 * m int mbis = m == 0 ? 0 : random.nextInt(2 * (m + this.leftForNextSource)); // On calcule le nombre de paquets qu'on peut transmettre diff --git a/src/main/java/fr/ntr/scheduler/RoundRobin.java b/src/main/java/fr/ntr/scheduler/RoundRobin.java index 91d916c..1605d91 100644 --- a/src/main/java/fr/ntr/scheduler/RoundRobin.java +++ b/src/main/java/fr/ntr/scheduler/RoundRobin.java @@ -1,6 +1,7 @@ package fr.ntr.scheduler; import java.util.List; import java.util.Random; +import java.util.stream.Collectors; import fr.ntr.AccessPoint; import fr.ntr.ResourceBlock; @@ -9,17 +10,12 @@ import fr.ntr.User; public class RoundRobin extends Scheduler { - private final Random random; - private int index; - private final List users; private final ResourceBlock[][] frame; public RoundRobin(ResourceBlock[][] frame, List users) { - this.index = 0; this.frame = frame; this.users = users; - this.random = new Random(); } /** @@ -29,15 +25,18 @@ public class RoundRobin extends Scheduler { */ @Override public void scheduling(int ticks) { - //selection aléatoire du premier utilisateur - - index = random.nextInt(users.size()); + List userCopy = users.stream().filter(u -> !u.getPacketsToSend().isEmpty()).collect(Collectors.toList()); //Pour chaque time slot et sous porteuses - for (int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++) { + loop: for (int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++) { for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++) { - User userSelected = userSelection(); + if(userCopy.isEmpty()) { + break loop; + } + User userSelected = userSelection(userCopy); allocateRessource(userSelected, frame, ts, sp, ticks); + if(!userSelected.getPacketsToSend().isEmpty()) + userCopy.add(userSelected); } } } @@ -46,16 +45,9 @@ public class RoundRobin extends Scheduler { * Entry Time slot (int), Sous porteuse(int), and users ( List) * Return the user in function of TS and SP selected * - * @return the next user which have something to send, null otherwise + * @return the next user which have something to send */ - private User userSelection() { - for(int i = index; i < index + users.size(); i++) { - User user = users.get(index % (users.size())); - if(!user.getPacketsToSend().isEmpty()) { - index = i; - return user; - } - } - return null; + private User userSelection(List users) { + return users.remove(0); } } From d6d54dbd84e59df20860d14369827facf8fa0fd3 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 30 Mar 2023 09:33:28 +0200 Subject: [PATCH 19/24] First fix of User#createPackets --- plot/main.py | 2 -- src/main/java/fr/ntr/AccessPoint.java | 17 ++++------------ src/main/java/fr/ntr/User.java | 29 ++++++++++++++++----------- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/plot/main.py b/plot/main.py index 69e3350..5f91b25 100644 --- a/plot/main.py +++ b/plot/main.py @@ -48,7 +48,6 @@ def delay() -> np.ndarray: for x in d: delays[nb, 0] = int(nb_users) delays[nb, 1] = float(x) - print(float(x)) nb += 1 return delays @@ -60,7 +59,6 @@ delays.sort(axis=0) # Data for plotting averages.sort(axis=0) -#print(averages) fig, ax = plt.subplots() ax.scatter(averages[:, 0], averages[:, 1]) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index 748bc25..d2ce6c7 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -25,17 +25,12 @@ public class AccessPoint { * 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 FileOutputStream outputDataFile; @@ -80,19 +75,15 @@ public class AccessPoint { } private void updateBandwidth(int ticks) { - int n = 200; - int timeInterval = Math.max(1, random.nextInt(51)); // avoid div by 0 + int m = 200; for(User user : users) { + // On régénère les sources toutes les 50-100 ms + user.createPackets(m, ticks); // 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 0-50 ms - if(ticks % timeInterval == 0){ - timeInterval = Math.max(1, random.nextInt(51)); - n = user.createPackets(n, ticks); - } } } diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index 0d41e13..7b28066 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -11,6 +11,7 @@ public class User { private final List packetsToSend; private final List packetsSent; private int leftForNextSource; + private int timeInterval = 1; private final Random random = new Random(); @@ -40,20 +41,24 @@ public class User { * * @param m * @param ticks qui va définir le temps auquel a été créé un paquet - * @return */ - public int createPackets(int m, int ticks) { - // On tire un nombre entre 0 et 2 * m - int mbis = m == 0 ? 0 : random.nextInt(2 * (m + this.leftForNextSource)); - // On calcule le nombre de paquets qu'on peut transmettre - int nbPacketsToSend = mbis / Packets.packetSize; - // On conserve le nombre de bits restants pour la prochaine génération - this.leftForNextSource = mbis % Packets.packetSize; - // On crée les paquets - for(int i = 0; i < nbPacketsToSend; i++){ - this.packetsToSend.add(new Packets(ticks)); + public void createPackets(int m, int ticks) { + timeInterval--; + if(timeInterval == 0) { + timeInterval = random.nextInt(50, 101); + // On tire un nombre entre 0 et 2 * m + int mbis = random.nextInt(1, 2 * m) + this.leftForNextSource; + // On calcule le nombre de paquets qu'on peut transmettre + int bitsToSend = random.nextInt(2 * mbis); + int nbPacketsToSend = bitsToSend / Packets.packetSize; + // On conserve le nombre de bits restants pour la prochaine génération + this.leftForNextSource = bitsToSend % Packets.packetSize; + // On crée les paquets + for(int i = 0; i < nbPacketsToSend; i++) { + this.packetsToSend.add(new Packets(ticks)); + } } - return mbis; + } public double getDistance() { From 4c2d0ccf5054bed4a2939748efc619b12ff92fe3 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Thu, 30 Mar 2023 09:58:13 +0200 Subject: [PATCH 20/24] Final fix of User#createPackets --- build.gradle | 2 +- src/main/java/fr/ntr/User.java | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/build.gradle b/build.gradle index fb0aa8c..b0052ff 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ plugins { } run { - args = ["10000", "50"] + args = ["10000", "17"] } application { diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index 7b28066..f0e10ba 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -13,6 +13,8 @@ public class User { private int leftForNextSource; private int timeInterval = 1; + private int mbis; + private final Random random = new Random(); public User(double distance, int timeSlotNb, int subCarrierNb) { @@ -47,18 +49,18 @@ public class User { if(timeInterval == 0) { timeInterval = random.nextInt(50, 101); // On tire un nombre entre 0 et 2 * m - int mbis = random.nextInt(1, 2 * m) + this.leftForNextSource; - // On calcule le nombre de paquets qu'on peut transmettre - int bitsToSend = random.nextInt(2 * mbis); - int nbPacketsToSend = bitsToSend / Packets.packetSize; - // On conserve le nombre de bits restants pour la prochaine génération - this.leftForNextSource = bitsToSend % Packets.packetSize; - // On crée les paquets - for(int i = 0; i < nbPacketsToSend; i++) { - this.packetsToSend.add(new Packets(ticks)); - } - } + mbis = random.nextInt(1, 2 * m) + this.leftForNextSource; + } + // On calcule le nombre de paquets qu'on peut transmettre + int bitsToSend = random.nextInt(2 * mbis); + int nbPacketsToSend = bitsToSend / Packets.packetSize; + // On conserve le nombre de bits restants pour la prochaine génération + this.leftForNextSource = bitsToSend % Packets.packetSize; + // On crée les paquets + for(int i = 0; i < nbPacketsToSend; i++) { + this.packetsToSend.add(new Packets(ticks)); + } } public double getDistance() { From eece2c1d3aae174e7db6c7844623851def1620e3 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 31 Mar 2023 08:15:44 +0200 Subject: [PATCH 21/24] Add parallelization of multiple simulations --- src/main/java/fr/ntr/Main.java | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index cccfd09..b5d412d 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -7,6 +7,8 @@ import fr.ntr.scheduler.Scheduler; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; public class Main { @@ -26,17 +28,18 @@ public class Main { } 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); - // Scheduler scheduler = new ProportionalFair(frame, users); - Scheduler scheduler = new RoundRobin(frame, users); - AccessPoint accessPoint = new AccessPoint(scheduler, frame, users, timeSlotNb, subCarrierNb, 0, 50); - accessPoint.startSimulation(numberOfTicks); + try(ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())) { + 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); + // Scheduler scheduler = new ProportionalFair(frame, users); + Scheduler scheduler = new RoundRobin(frame, users); + AccessPoint accessPoint = new AccessPoint(scheduler, frame, users, timeSlotNb, subCarrierNb, 0, 50); + executor.submit(() -> accessPoint.startSimulation(numberOfTicks)); + } } - } - else { + } else { System.err.println("Please give launch arguments"); System.err.println("gradle run --args=\" \""); System.exit(1); From 82c7ed700dbc906c5077d19c353f320853f9ac67 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 31 Mar 2023 08:27:43 +0200 Subject: [PATCH 22/24] Move the deletion of exported files in Main, move AccessPoint static parameters outside of loop(for concurrency propose) --- src/main/java/fr/ntr/AccessPoint.java | 32 ++++++++++----------------- src/main/java/fr/ntr/Main.java | 24 ++++++++++++++++---- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index d2ce6c7..45ee579 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -3,16 +3,13 @@ package fr.ntr; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.List; -import java.util.Random; import fr.ntr.scheduler.Scheduler; public class AccessPoint { - private List users; - private Scheduler scheduler; + private final List users; + private final Scheduler scheduler; /** * nombre de slots */ @@ -24,24 +21,14 @@ public class AccessPoint { /** * trame */ - private ResourceBlock[][] frame; - - /** - * Portée minimum et maximum de l'antenne - */ - private final double min, max; - + private final ResourceBlock[][] frame; 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; + public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, List users) { this.users = users; this.scheduler = scheduler; this.frame = frame; - this.timeSlotNb = timeSlotNb; - this.subCarrierNb = subCarrierNb; } /** @@ -50,8 +37,6 @@ public class AccessPoint { */ public void startSimulation(int duration) { try{ - Files.deleteIfExists(Paths.get("export", this.users.size() + ".csv")); - new File("export").mkdir(); this.outputDataFile = new FileOutputStream("export" + File.separator + this.users.size() + ".csv", true); outputDataFile.write("tick;x;y;user;bandwidth;delay;\n".getBytes()); } catch(IOException e) { @@ -120,7 +105,6 @@ 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); @@ -139,4 +123,12 @@ public class AccessPoint { public static int getSubCarrierNb() { return subCarrierNb; } + + public static void setTimeSlotNb(int timeSlotNb) { + AccessPoint.timeSlotNb = timeSlotNb; + } + + public static void setSubCarrierNb(int subCarrierNb) { + AccessPoint.subCarrierNb = subCarrierNb; + } } diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index b5d412d..50ada1b 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -1,12 +1,13 @@ package fr.ntr; -import fr.ntr.scheduler.MaxSNR; -import fr.ntr.scheduler.ProportionalFair; import fr.ntr.scheduler.RoundRobin; import fr.ntr.scheduler.Scheduler; +import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Objects; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -28,14 +29,29 @@ public class Main { } int timeSlotNb = 2; int subCarrierNb = 100; + 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) + .forEach(f -> { + if(!f.delete()) { + System.err.println("Cannot remove file " + f.getAbsolutePath()); + } + }); + AccessPoint.setTimeSlotNb(timeSlotNb); + AccessPoint.setSubCarrierNb(subCarrierNb); try(ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())) { 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); + // Scheduler scheduler = new MaxSNR(frame, users); // Scheduler scheduler = new ProportionalFair(frame, users); Scheduler scheduler = new RoundRobin(frame, users); - AccessPoint accessPoint = new AccessPoint(scheduler, frame, users, timeSlotNb, subCarrierNb, 0, 50); + AccessPoint accessPoint = new AccessPoint(scheduler, frame, users); executor.submit(() -> accessPoint.startSimulation(numberOfTicks)); } } From 22eead040f9f2e34d43e92a79c76bc3e965af112 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 31 Mar 2023 08:50:26 +0200 Subject: [PATCH 23/24] Fix User#generateBandwidth change packetSize name to PACKET_SIZE --- src/main/java/fr/ntr/Packets.java | 4 ++-- src/main/java/fr/ntr/User.java | 18 ++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/fr/ntr/Packets.java b/src/main/java/fr/ntr/Packets.java index 35b0460..f6c5a74 100644 --- a/src/main/java/fr/ntr/Packets.java +++ b/src/main/java/fr/ntr/Packets.java @@ -1,14 +1,14 @@ package fr.ntr; public class Packets { - static final int packetSize = 100; + static final int PACKET_SIZE = 100; private int startTimeSending; private int endTimeSending; private int durationSending; private int bitsNumberRemaining; public Packets(int startTimeSending){ - this.bitsNumberRemaining = packetSize; + this.bitsNumberRemaining = PACKET_SIZE; this.startTimeSending = startTimeSending; } diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index f0e10ba..e932b04 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -26,16 +26,14 @@ public class User { } public void generateBandwidth() { - for(int y = 0; y < bandwidthTable[0].length; y++) { double rand = this.random.nextDouble(); - for(int x = 0; x < bandwidthTable.length; x++) { - double h = 1 * Math.sqrt(-2 * Math.log(1 - rand)); - double gain = h * h * Math.pow(10, rand * 1/10) * Math.pow(1 / this.distance, 3.5); - double spectralEfficiency = (20 * gain) / (15000 * (3.9*Math.pow(10, -21))); - double mkn = Math.log(1 + spectralEfficiency) / Math.log(2); - this.bandwidthTable[x][y] = mkn; - } + double h = 1 * Math.sqrt(-2 * Math.log(1 - rand)); + double gain = h * h * Math.pow(10, rand * 1/10) * Math.pow(1 / this.distance, 3.5); + double spectralEfficiency = (20 * gain) / (15000 * (3.9*Math.pow(10, -21))); + double mkn = Math.log(1 + spectralEfficiency) / Math.log(2); + this.bandwidthTable[0][y] = mkn; + this.bandwidthTable[1][y] = mkn; } } @@ -54,9 +52,9 @@ public class User { } // On calcule le nombre de paquets qu'on peut transmettre int bitsToSend = random.nextInt(2 * mbis); - int nbPacketsToSend = bitsToSend / Packets.packetSize; + int nbPacketsToSend = bitsToSend / Packets.PACKET_SIZE; // On conserve le nombre de bits restants pour la prochaine génération - this.leftForNextSource = bitsToSend % Packets.packetSize; + this.leftForNextSource = bitsToSend % Packets.PACKET_SIZE; // On crée les paquets for(int i = 0; i < nbPacketsToSend; i++) { this.packetsToSend.add(new Packets(ticks)); From ddb3ab6eaa2c1cea9453a966e1f37ddbef28950d Mon Sep 17 00:00:00 2001 From: Tr1xt4n Date: Fri, 31 Mar 2023 08:51:58 +0200 Subject: [PATCH 24/24] fix createpackets --- src/main/java/fr/ntr/User.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index f0e10ba..517f8ba 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -49,12 +49,12 @@ public class User { if(timeInterval == 0) { timeInterval = random.nextInt(50, 101); // On tire un nombre entre 0 et 2 * m - mbis = random.nextInt(1, 2 * m) + this.leftForNextSource; + mbis = random.nextInt(1, 2 * m + 1) ; } // On calcule le nombre de paquets qu'on peut transmettre - int bitsToSend = random.nextInt(2 * mbis); - int nbPacketsToSend = bitsToSend / Packets.packetSize; + int bitsToSend = random.nextInt(2 * mbis + 1) + this.leftForNextSource; + int nbPacketsToSend = bitsToSend / Packets.packetSize ; // On conserve le nombre de bits restants pour la prochaine génération this.leftForNextSource = bitsToSend % Packets.packetSize; // On crée les paquets