From 8d50ce67258ebd2b28f20f2f0d80d7e1d7815071 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 24 Mar 2023 10:56:05 +0100 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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;