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]); }