Fix RR by removing random selection of the first user

This commit is contained in:
Quentin Legot 2023-03-30 08:24:25 +02:00
parent 59a58abc7c
commit aa9ea15beb
4 changed files with 19 additions and 38 deletions

View File

@ -37,6 +37,7 @@ def rb_available() -> np.ndarray:
nb += 1 nb += 1
return available return available
def delay() -> np.ndarray: def delay() -> np.ndarray:
delays = np.zeros((size, 2)) delays = np.zeros((size, 2))
nb = 0 nb = 0
@ -51,6 +52,7 @@ def delay() -> np.ndarray:
nb += 1 nb += 1
return delays return delays
averages = mean_mkn() averages = mean_mkn()
available = rb_available() available = rb_available()
delays = delay() delays = delay()

View File

@ -69,7 +69,6 @@ public class AccessPoint {
reset(); reset();
updateBandwidth(ticks); updateBandwidth(ticks);
schedule(ticks); schedule(ticks);
computePacketDelay(ticks);
// traite les données et les enregistre dans un fichier // traite les données et les enregistre dans un fichier
try { try {
analyseData(ticks); analyseData(ticks);
@ -91,7 +90,7 @@ public class AccessPoint {
// On régénère les sources toutes les 0-50 ms // On régénère les sources toutes les 0-50 ms
if(ticks % timeInterval == 0){ if(ticks % timeInterval == 0){
timeInterval = 50 + random.nextInt(51); timeInterval = Math.max(1, random.nextInt(51));
n = user.createPackets(n, ticks); n = user.createPackets(n, ticks);
} }
} }
@ -138,17 +137,6 @@ public class AccessPoint {
} }
} }
private void computePacketDelay(int ticks){
for(int i = 0; i < this.users.size(); i++){
User u = this.users.get(i);
if(!u.getPacketsToSend().isEmpty()){
for(Packets p : u.getPacketsToSend()){
}
}
}
}
public ResourceBlock[][] getFrame() { public ResourceBlock[][] getFrame() {
return frame; return frame;
} }

View File

@ -12,7 +12,7 @@ public class User {
private final List<Packets> packetsSent; private final List<Packets> packetsSent;
private int leftForNextSource; private int leftForNextSource;
private Random random = new Random(); private final Random random = new Random();
public User(double distance, int timeSlotNb, int subCarrierNb) { public User(double distance, int timeSlotNb, int subCarrierNb) {
this.distance = distance; this.distance = distance;
@ -25,10 +25,10 @@ public class User {
public void generateBandwidth() { public void generateBandwidth() {
for(int y = 0; y < bandwidthTable[0].length; y++) { for(int y = 0; y < bandwidthTable[0].length; y++) {
double random = this.random.nextDouble(); double rand = this.random.nextDouble();
for(int x = 0; x < bandwidthTable.length; x++) { for(int x = 0; x < bandwidthTable.length; x++) {
double h = 1 * Math.sqrt(-2 * Math.log(1 - random)); double h = 1 * Math.sqrt(-2 * Math.log(1 - rand));
double gain = h * h * Math.pow(10, random * 1/10) * Math.pow(1 / this.distance, 3.5); double gain = h * h * Math.pow(10, rand * 1/10) * Math.pow(1 / this.distance, 3.5);
double spectralEfficiency = (20 * gain) / (15000 * (3.9*Math.pow(10, -21))); double spectralEfficiency = (20 * gain) / (15000 * (3.9*Math.pow(10, -21)));
double mkn = Math.log(1 + spectralEfficiency) / Math.log(2); double mkn = Math.log(1 + spectralEfficiency) / Math.log(2);
this.bandwidthTable[x][y] = mkn; this.bandwidthTable[x][y] = mkn;
@ -43,7 +43,6 @@ public class User {
* @return * @return
*/ */
public int createPackets(int m, int ticks) { public int createPackets(int m, int ticks) {
Random random = new Random();
// On tire un nombre entre 0 et 2 * m // On tire un nombre entre 0 et 2 * m
int mbis = m == 0 ? 0 : random.nextInt(2 * (m + this.leftForNextSource)); int mbis = m == 0 ? 0 : random.nextInt(2 * (m + this.leftForNextSource));
// On calcule le nombre de paquets qu'on peut transmettre // On calcule le nombre de paquets qu'on peut transmettre

View File

@ -1,6 +1,7 @@
package fr.ntr.scheduler; package fr.ntr.scheduler;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.stream.Collectors;
import fr.ntr.AccessPoint; import fr.ntr.AccessPoint;
import fr.ntr.ResourceBlock; import fr.ntr.ResourceBlock;
@ -9,17 +10,12 @@ import fr.ntr.User;
public class RoundRobin extends Scheduler { public class RoundRobin extends Scheduler {
private final Random random;
private int index;
private final List<User> users; private final List<User> users;
private final ResourceBlock[][] frame; private final ResourceBlock[][] frame;
public RoundRobin(ResourceBlock[][] frame, List<User> users) { public RoundRobin(ResourceBlock[][] frame, List<User> users) {
this.index = 0;
this.frame = frame; this.frame = frame;
this.users = users; this.users = users;
this.random = new Random();
} }
/** /**
@ -29,15 +25,18 @@ public class RoundRobin extends Scheduler {
*/ */
@Override @Override
public void scheduling(int ticks) { public void scheduling(int ticks) {
//selection aléatoire du premier utilisateur List<User> userCopy = users.stream().filter(u -> !u.getPacketsToSend().isEmpty()).collect(Collectors.toList());
index = random.nextInt(users.size());
//Pour chaque time slot et sous porteuses //Pour chaque time slot et sous porteuses
for (int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++) { loop: for (int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++) {
for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++) { for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++) {
User userSelected = userSelection(); if(userCopy.isEmpty()) {
break loop;
}
User userSelected = userSelection(userCopy);
allocateRessource(userSelected, frame, ts, sp, ticks); allocateRessource(userSelected, frame, ts, sp, ticks);
if(!userSelected.getPacketsToSend().isEmpty())
userCopy.add(userSelected);
} }
} }
} }
@ -46,16 +45,9 @@ public class RoundRobin extends Scheduler {
* Entry Time slot (int), Sous porteuse(int), and users ( List<User>) * Entry Time slot (int), Sous porteuse(int), and users ( List<User>)
* Return the user in function of TS and SP selected * Return the user in function of TS and SP selected
* *
* @return the next user which have something to send, null otherwise * @return the next user which have something to send
*/ */
private User userSelection() { private User userSelection(List<User> users) {
for(int i = index; i < index + users.size(); i++) { return users.remove(0);
User user = users.get(index % (users.size()));
if(!user.getPacketsToSend().isEmpty()) {
index = i;
return user;
}
}
return null;
} }
} }