From af11fa37f3833386a3b92b3c0705db95ee6ae48c Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 4 Apr 2023 08:20:54 +0200 Subject: [PATCH] Lint in MaxSNR and removed useless condition on Scheduler --- src/main/java/fr/ntr/Main.java | 6 +++--- src/main/java/fr/ntr/scheduler/MaxSNR.java | 21 +++++++++---------- src/main/java/fr/ntr/scheduler/Scheduler.java | 14 ++----------- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index 68c86ff..bc78260 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -1,6 +1,6 @@ package fr.ntr; -import fr.ntr.scheduler.RoundRobin; +import fr.ntr.scheduler.MaxSNR; import fr.ntr.scheduler.Scheduler; import java.io.File; @@ -48,9 +48,9 @@ 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); - Scheduler scheduler = new RoundRobin(frame, users); + // Scheduler scheduler = new RoundRobin(frame, users); AccessPoint accessPoint = new AccessPoint(scheduler, frame, users); executor.submit(() -> accessPoint.startSimulation(numberOfTicks)); } diff --git a/src/main/java/fr/ntr/scheduler/MaxSNR.java b/src/main/java/fr/ntr/scheduler/MaxSNR.java index c56f9e5..7530bda 100644 --- a/src/main/java/fr/ntr/scheduler/MaxSNR.java +++ b/src/main/java/fr/ntr/scheduler/MaxSNR.java @@ -1,18 +1,18 @@ package fr.ntr.scheduler; import java.util.List; -import fr.ntr.Packets; +import fr.ntr.AccessPoint; import fr.ntr.ResourceBlock; import fr.ntr.User; public class MaxSNR extends Scheduler { - private List users; + private final List users; - private ResourceBlock[][] frame; + private final ResourceBlock[][] frame; - public MaxSNR( ResourceBlock[][] frame, List users) { + public MaxSNR(ResourceBlock[][] frame, List users) { this.frame = frame; this.users = users; } @@ -20,8 +20,8 @@ public class MaxSNR extends Scheduler { @Override public void scheduling(int ticks) { User userMax; - for(int ts = 0; ts < 2; ts++){ - for(int sp = 0; sp < 100; sp++){ + for(int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++){ + for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++){ userMax = userSelection(ts, sp); allocateRessource(userMax, frame, ts, sp, ticks); } @@ -36,11 +36,10 @@ public class MaxSNR extends Scheduler { double maxSnr = 0.0; User userMax = null; for(User u: users) { - if (!u.getPacketsToSend().isEmpty()) { - if (maxSnr < u.getBandwidthTable()[ts][sp]) { - maxSnr = u.getBandwidthTable()[ts][sp]; - userMax = u; - } + if (!u.getPacketsToSend().isEmpty() && (maxSnr < u.getBandwidthTable()[ts][sp])) { + maxSnr = u.getBandwidthTable()[ts][sp]; + userMax = u; + } } return userMax; diff --git a/src/main/java/fr/ntr/scheduler/Scheduler.java b/src/main/java/fr/ntr/scheduler/Scheduler.java index 29e2fe6..e3cb738 100644 --- a/src/main/java/fr/ntr/scheduler/Scheduler.java +++ b/src/main/java/fr/ntr/scheduler/Scheduler.java @@ -16,18 +16,8 @@ public abstract class Scheduler { protected void allocateRessource(User userMax, ResourceBlock[][] frame, int ts, int sp, int ticks) { if (userMax != null && !userMax.getPacketsToSend().isEmpty()) { Packets p = userMax.getPacketsToSend().get(userMax.getPacketsToSend().size()-1); - if(p.getBitsNumberRemaining() >= 0){ - p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]); - if(p.getBitsNumberRemaining() <= 0) { - if(ticks == 0){ - p.setDurationSending(1); - }else { - p.setDurationSending(ticks); - } - userMax.getPacketsSent().add(p); - userMax.getPacketsToSend().remove(p); - } - } else { + p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]); + if(p.getBitsNumberRemaining() <= 0) { if(ticks == 0){ p.setDurationSending(1); }else {