Compute average delays

This commit is contained in:
Remi Boure 2023-03-28 09:15:30 +02:00
parent 3a438472d0
commit 6442356450
5 changed files with 33 additions and 44 deletions

View File

@ -102,20 +102,21 @@ public class AccessPoint {
}
private void analyseData(int tick) throws IOException {
double delayAverrage = 0.0;
double total = 0.0;
double delayAverage = 0.0;
int nbPacketsSent = 0;
for(User u: this.users){
List<Packets> packets = u.getPacketsSent();
nbPacketsSent += packets.size();
for (Packets p: packets){
total += p.getDurationSending();
delayAverage += p.getDurationSending();
}
}
delayAverrage = total/this.users.size();
delayAverage = delayAverage/nbPacketsSent;
for(int i = 0; i < frame.length; i++) {
for(int j = 0; j < frame[i].length; j++) {
ResourceBlock ur = frame[i][j];
if(ur.getUser() != null) {
String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";" + delayAverrage +";\n");
String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";" + delayAverage +";\n");
try{
outputDataFile.write(data.getBytes());
}catch(IOException e){

View File

@ -22,26 +22,13 @@ public class MaxSNR extends Scheduler {
User userMax = null;
for(int ts = 0; ts < 2; ts++){
for(int sp = 0; sp < 100; sp++){
userMax = selectionUtilisateur(sp, ts, users);
if (userMax.getPacketsToSend().size() != 0) {
Packets p = userMax.getPacketsToSend().get(0);
userMax.getPacketsSent().add(p);
if(p.getBitsNumberRemaining() > 0){
p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]);
} else {
p.setDurationSending(ticks);
}
userMax.getPacketsToSend().remove(p);
frame[ts][sp].setUser(userMax);
frame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]);
}
userMax = userSelection(ts, sp, users);
allocateRessource(userMax, frame, ts, sp, ticks);
}
}
}
private User selectionUtilisateur(int sp, int ts, List<User> Users) {
private User userSelection(int ts, int sp, List<User> Users) {
double MaxSnr = 0.0;
User userMax = null;
for(User u: Users){

View File

@ -32,16 +32,15 @@ public class ProportionalFair extends Scheduler {
avg = avg / (bandwidthTable.length * bandwidthTable[0].length);
averageBandwiths.add(avg);
}
User selectedUser;
for(int ts = 0; ts < 2; ts++){
for(int sp = 0; sp < 100; sp++){
selectedUser = selectionUtilisateur(ts, sp, users, averageBandwiths);
allocateRessource(selectedUser, frame, ts, sp);
User selectedUser = userSelection(ts, sp, users, averageBandwiths);
allocateRessource(selectedUser, frame, ts, sp, ticks);
}
}
}
private User selectionUtilisateur(int ts, int sp, List<User> users, List<Double> averageBandwiths) {
private User userSelection(int ts, int sp, List<User> users, List<Double> averageBandwiths) {
double PF = 0.0;
User selectedUser = null;
for(int i = 0; i < users.size(); i++){

View File

@ -34,19 +34,10 @@ public class RoundRobin extends Scheduler {
index = random.nextInt(users.size());
//Pour chaque time slot et sous porteuses
for (int Ts = 0; Ts < AccessPoint.getTimeSlotNb(); Ts++) {
for(int Sp = 0; Sp < AccessPoint.getSubCarrierNb(); Sp++) {
if (!users.get(index).getPacketsToSend().isEmpty()) {
// on enlève le packet transmis de la liste
// TODO Verify sub the packet send need Set packet
users.get(index).getPacketsSent().add(users.get(index).getPacketsToSend().get(0));
users.get(index).getPacketsToSend().remove(users.get(index).getPacketsToSend().get(0));
//on ajoute l'utilisateur a la frame
User user = UserSelection(Ts, Sp, users);
frame[Ts][Sp].setUser(user);
frame[Ts][Sp].setBandwidth(user.getBandwidthTable()[Ts][Sp]);
}
for (int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++) {
for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++) {
User userSelected = userSelection(ts, sp, users);
allocateRessource(userSelected, frame, ts, sp, ticks);
}
}
}
@ -55,10 +46,10 @@ 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
*/
private User UserSelection(int Ts, int Sp, List<User> users) {
private User userSelection(int ts, int sp, List<User> users) {
//compte le nombre de bloc attribue
for (int i = 0; i < Ts; i++){
for (int j = 0; j < Sp; j++) {
for (int i = 0; i < ts; i++){
for (int j = 0; j < sp; j++) {
index++;
}
}

View File

@ -1,5 +1,6 @@
package fr.ntr.scheduler;
import fr.ntr.Packets;
import fr.ntr.ResourceBlock;
import fr.ntr.User;
@ -12,10 +13,20 @@ public abstract class Scheduler {
*/
public abstract void scheduling(int ticks);
protected void allocateRessource(User userMax, ResourceBlock[][] frame, int ts, int sp) {
protected void allocateRessource(User userMax, ResourceBlock[][] frame, int ts, int sp, int ticks) {
if (userMax != null && !userMax.getPacketsToSend().isEmpty()) {
userMax.getPacketsSent().add(userMax.getPacketsToSend().get(0));
userMax.getPacketsToSend().remove(userMax.getPacketsToSend().get(0));
Packets p = userMax.getPacketsToSend().get(0);
if(p.getBitsNumberRemaining() > 0){
p.decreaseBitsNumberRemaining((int) userMax.getBandwidthTable()[ts][sp]);
} else {
if(ticks == 0){
p.setDurationSending(1);
}else {
p.setDurationSending(ticks);
}
}
userMax.getPacketsSent().add(p);
userMax.getPacketsToSend().remove(p);
frame[ts][sp].setUser(userMax);
frame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]);
}