diff --git a/src/main/java/fr/ntr/scheduler/MaxSNR.java b/src/main/java/fr/ntr/scheduler/MaxSNR.java index 9a8ab40..069ed83 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.Cell; import fr.ntr.ResourceBlock; import fr.ntr.User; @@ -9,7 +10,7 @@ public class MaxSNR extends Scheduler { private final List users; private final ResourceBlock[][] frame; - public MaxSNR( ResourceBlock[][] frame, List users) { + public MaxSNR(ResourceBlock[][] frame, List users) { this.frame = frame; this.users = users; } @@ -17,8 +18,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 < Cell.getTimeSlotNb(); ts++){ + for(int sp = 0; sp < Cell.getSubCarrierNb(); sp++){ userMax = userSelection(ts, sp); allocateRessource(userMax, frame, ts, sp, ticks); } @@ -34,12 +35,11 @@ public class MaxSNR extends Scheduler { private User userSelection(int ts, int sp) { 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; - } + for(User u: users) { + 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/ProportionalFair.java b/src/main/java/fr/ntr/scheduler/ProportionalFair.java index 6865746..331dfa9 100644 --- a/src/main/java/fr/ntr/scheduler/ProportionalFair.java +++ b/src/main/java/fr/ntr/scheduler/ProportionalFair.java @@ -20,7 +20,7 @@ public class ProportionalFair extends Scheduler { @Override public void scheduling(int ticks) { - ArrayList averageBandwiths = new ArrayList(); + ArrayList averageBandwiths = new ArrayList<>(); for(User u : users){ double avg = 0d; double[][] bandwidthTable = u.getBandwidthTable(); @@ -55,5 +55,5 @@ public class ProportionalFair extends Scheduler { } return selectedUser; } - + } 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 {