Merge branch 'master' into ajout_cellule

This commit is contained in:
Quentin Legot 2023-03-31 11:49:11 +02:00
commit 06f3e82c4a
4 changed files with 24 additions and 8 deletions

View File

@ -90,7 +90,7 @@ public class Main {
private static List<User> generateUsers(int nbUsers, int timeSlotNb, int subCarrierNb) {
List<User> 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);

View File

@ -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;

View File

@ -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<User> 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++) {

View File

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