diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index f71e144..86dbeed 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -90,7 +90,7 @@ public class Main { private static List generateUsers(int nbUsers, int timeSlotNb, int subCarrierNb) { List users = new ArrayList<>(); // 2 groupes d'utilisateurs, proches et éloignés - double[] distance = { 200d, 1000d }; + double[] distance = { 200d, 400d }; for (double v : distance) { for (int j = 0; j < nbUsers; j++) { User user = new User(v, timeSlotNb, subCarrierNb); diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index e32cacd..8b73f2a 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -13,6 +13,8 @@ public class User { private int leftForNextSource; private int timeInterval = 1; + public int totalbits = 0; + private int mbis; private final Random random = new Random(); @@ -45,13 +47,17 @@ public class User { public void createPackets(int m, int ticks) { timeInterval--; if(timeInterval == 0) { - timeInterval = 50 + random.nextInt(51); + timeInterval = 50 + random.nextInt(52); // On tire un nombre entre 0 et 2 * m - mbis = 1 + random.nextInt(2 * m + 1) ; + mbis = random.nextInt(2 * m + 1) ; } // On calcule le nombre de paquets qu'on peut transmettre - int bitsToSend = random.nextInt(2 * mbis + 1) + this.leftForNextSource; + int bitsToSend = random.nextInt(2 * mbis + 1); + this.totalbits += bitsToSend; + // totalbits/duree (200) + // somme total bits/duree (linéaire) + bitsToSend+=this.leftForNextSource; int nbPacketsToSend = bitsToSend / Packets.PACKET_SIZE; // On conserve le nombre de bits restants pour la prochaine génération this.leftForNextSource = bitsToSend % Packets.PACKET_SIZE; diff --git a/src/main/java/fr/ntr/scheduler/RoundRobin.java b/src/main/java/fr/ntr/scheduler/RoundRobin.java index 71c9fd4..aeadccb 100644 --- a/src/main/java/fr/ntr/scheduler/RoundRobin.java +++ b/src/main/java/fr/ntr/scheduler/RoundRobin.java @@ -1,6 +1,6 @@ package fr.ntr.scheduler; +import java.util.Collections; import java.util.List; -import java.util.Random; import java.util.stream.Collectors; import fr.ntr.Cell; @@ -26,6 +26,7 @@ public class RoundRobin extends Scheduler { @Override public void scheduling(int ticks) { List userCopy = users.stream().filter(u -> !u.getPacketsToSend().isEmpty()).collect(Collectors.toList()); + Collections.shuffle(userCopy); //Pour chaque time slot et sous porteuses loop: for (int ts = 0; ts < Cell.getTimeSlotNb(); ts++) { diff --git a/src/main/java/fr/ntr/scheduler/Scheduler.java b/src/main/java/fr/ntr/scheduler/Scheduler.java index b2dc953..29e2fe6 100644 --- a/src/main/java/fr/ntr/scheduler/Scheduler.java +++ b/src/main/java/fr/ntr/scheduler/Scheduler.java @@ -15,9 +15,18 @@ 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(0); - if(p.getBitsNumberRemaining() > 0){ + 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 { if(ticks == 0){ p.setDurationSending(1); @@ -31,4 +40,4 @@ public abstract class Scheduler { frame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]); } } -} +} \ No newline at end of file