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

View File

@ -69,7 +69,6 @@ public class AccessPoint {
reset();
updateBandwidth(ticks);
schedule(ticks);
computePacketDelay(ticks);
// traite les données et les enregistre dans un fichier
try {
analyseData(ticks);
@ -91,7 +90,7 @@ public class AccessPoint {
// On régénère les sources toutes les 0-50 ms
if(ticks % timeInterval == 0){
timeInterval = 50 + random.nextInt(51);
timeInterval = Math.max(1, random.nextInt(51));
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() {
return frame;
}

View File

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

View File

@ -1,6 +1,7 @@
package fr.ntr.scheduler;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import fr.ntr.AccessPoint;
import fr.ntr.ResourceBlock;
@ -9,17 +10,12 @@ import fr.ntr.User;
public class RoundRobin extends Scheduler {
private final Random random;
private int index;
private final List<User> users;
private final ResourceBlock[][] frame;
public RoundRobin(ResourceBlock[][] frame, List<User> users) {
this.index = 0;
this.frame = frame;
this.users = users;
this.random = new Random();
}
/**
@ -29,15 +25,18 @@ public class RoundRobin extends Scheduler {
*/
@Override
public void scheduling(int ticks) {
//selection aléatoire du premier utilisateur
index = random.nextInt(users.size());
List<User> userCopy = users.stream().filter(u -> !u.getPacketsToSend().isEmpty()).collect(Collectors.toList());
//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++) {
User userSelected = userSelection();
if(userCopy.isEmpty()) {
break loop;
}
User userSelected = userSelection(userCopy);
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>)
* 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() {
for(int i = index; i < index + users.size(); i++) {
User user = users.get(index % (users.size()));
if(!user.getPacketsToSend().isEmpty()) {
index = i;
return user;
}
}
return null;
private User userSelection(List<User> users) {
return users.remove(0);
}
}