From c778fcb6da25ebf3d5b68cd95422212da2d77385 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 28 Mar 2023 09:30:21 +0200 Subject: [PATCH] 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; } }