From 671ccd2b1863ab12fb2f331b94ddc5f84e9cb3a4 Mon Sep 17 00:00:00 2001 From: Tr1xt4n Date: Fri, 31 Mar 2023 09:34:51 +0200 Subject: [PATCH 1/4] fix MaxSNR --- src/main/java/fr/ntr/scheduler/MaxSNR.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/fr/ntr/scheduler/MaxSNR.java b/src/main/java/fr/ntr/scheduler/MaxSNR.java index 809cd99..c56f9e5 100644 --- a/src/main/java/fr/ntr/scheduler/MaxSNR.java +++ b/src/main/java/fr/ntr/scheduler/MaxSNR.java @@ -35,10 +35,12 @@ public class MaxSNR extends Scheduler { 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]; - userMax = u; + for(User u: users) { + if (!u.getPacketsToSend().isEmpty()) { + if (maxSnr < u.getBandwidthTable()[ts][sp]) { + maxSnr = u.getBandwidthTable()[ts][sp]; + userMax = u; + } } } return userMax; From 71464a15d7a94f75c1941e2b31509b20157a8b05 Mon Sep 17 00:00:00 2001 From: Tr1xt4n Date: Fri, 31 Mar 2023 11:01:00 +0200 Subject: [PATCH 2/4] average --- src/main/java/fr/ntr/AccessPoint.java | 5 +++++ src/main/java/fr/ntr/Main.java | 3 ++- src/main/java/fr/ntr/User.java | 10 ++++++++-- src/main/java/fr/ntr/scheduler/RoundRobin.java | 3 +++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index 45ee579..91e85bb 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -57,6 +57,11 @@ public class AccessPoint { } } + int totalBits = 0; + for(User u: this.users){ + totalBits += u.totalbits; + } + System.out.println("total bits / nb users = "+ (((float)totalBits)/this.users.size()/10_000)); } private void updateBandwidth(int ticks) { diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index 50ada1b..68c86ff 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -65,13 +65,14 @@ 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); users.add(user); } } + return users; } } \ No newline at end of file diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index d80be5d..5106ba0 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 = random.nextInt(50, 101); + timeInterval = random.nextInt(2, 102); // On tire un nombre entre 0 et 2 * m mbis = random.nextInt(1, 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 1605d91..718a470 100644 --- a/src/main/java/fr/ntr/scheduler/RoundRobin.java +++ b/src/main/java/fr/ntr/scheduler/RoundRobin.java @@ -1,4 +1,6 @@ package fr.ntr.scheduler; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Random; import java.util.stream.Collectors; @@ -26,6 +28,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 < AccessPoint.getTimeSlotNb(); ts++) { From 077ef9aca823046996514e5eaeb5fbffe1606019 Mon Sep 17 00:00:00 2001 From: Tr1xt4n Date: Fri, 31 Mar 2023 11:27:12 +0200 Subject: [PATCH 3/4] fix packet --- src/main/java/fr/ntr/scheduler/Scheduler.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/ntr/scheduler/Scheduler.java b/src/main/java/fr/ntr/scheduler/Scheduler.java index b2dc953..d19015f 100644 --- a/src/main/java/fr/ntr/scheduler/Scheduler.java +++ b/src/main/java/fr/ntr/scheduler/Scheduler.java @@ -15,7 +15,7 @@ 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); + Packets p = userMax.getPacketsToSend().get(userMax.getPacketsToSend().size()-1); if(p.getBitsNumberRemaining() > 0){ p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]); } else { @@ -31,4 +31,4 @@ public abstract class Scheduler { frame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]); } } -} +} \ No newline at end of file From b3201ff7a5388b1a08e26c5db1dcca318a1cf03a Mon Sep 17 00:00:00 2001 From: Tr1xt4n Date: Fri, 31 Mar 2023 11:42:01 +0200 Subject: [PATCH 4/4] fix allocation --- src/main/java/fr/ntr/User.java | 2 +- src/main/java/fr/ntr/scheduler/Scheduler.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/ntr/User.java b/src/main/java/fr/ntr/User.java index 5106ba0..70750d7 100644 --- a/src/main/java/fr/ntr/User.java +++ b/src/main/java/fr/ntr/User.java @@ -49,7 +49,7 @@ public class User { if(timeInterval == 0) { timeInterval = random.nextInt(2, 102); // On tire un nombre entre 0 et 2 * m - mbis = random.nextInt(1, 2 * m + 1) ; + mbis = random.nextInt(0, 2 * m + 1) ; } // On calcule le nombre de paquets qu'on peut transmettre diff --git a/src/main/java/fr/ntr/scheduler/Scheduler.java b/src/main/java/fr/ntr/scheduler/Scheduler.java index d19015f..29e2fe6 100644 --- a/src/main/java/fr/ntr/scheduler/Scheduler.java +++ b/src/main/java/fr/ntr/scheduler/Scheduler.java @@ -16,8 +16,17 @@ 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){ + 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);