Compare commits

..

4 Commits

Author SHA1 Message Date
Tr1xt4n
431248b0a4 update main 2023-04-13 10:56:15 +02:00
Tr1xt4n
cc73eb8a93 maj 2023-04-07 08:12:46 +02:00
Tr1xt4n
376c76b17c Merge branch 'master' of https://gitlab.istic.univ-rennes1.fr/18008147/ntr 2023-04-04 11:08:48 +02:00
Tr1xt4n
5b695174a6 4eme courbe 2023-04-04 09:56:16 +02:00
11 changed files with 248 additions and 394 deletions

View File

@ -11,7 +11,7 @@ plugins {
}
run {
args = ["10000", "40"]
args = ["10000", "17"]
}
application {

View File

@ -3,7 +3,7 @@ import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
nb_files = os.listdir("PF")
nb_files = os.listdir(".." + os.sep + "export")
size = len(nb_files)
@ -29,7 +29,7 @@ def rb_available(arr: list[tuple[int, np.ndarray]]) -> np.ndarray:
nb = 0
for nb_users, data in arr:
available[nb, 0] = nb_users
available[nb, 1] = (data.shape[0] / (200 * 20000)) * 100
available[nb, 1] = (data.shape[0] / (200 * 10000)) * 100
nb += 1
return available
@ -45,7 +45,6 @@ def delay(arr: list[tuple[int, np.ndarray]]) -> np.ndarray:
nb += 1
return delays
def rb_allocate_distance(arr: list[tuple[int, np.ndarray]], distance) -> np.ndarray:
allocate = np.zeros((size, 2))
nb = 0
@ -57,60 +56,54 @@ def rb_allocate_distance(arr: list[tuple[int, np.ndarray]], distance) -> np.ndar
n+=1
allocate[nb, 0] = nb_users
allocate[nb, 1] = n
# print(n/data.shape[0])
print(n/data.shape[0])
nb += 1
return allocate
np_arr: list[tuple[int, np.ndarray]] = list()
for i in nb_files:
np_arr.append((int(i.split(".")[0]), pd.read_csv("PF" + os.sep + i, delimiter=';').to_numpy()))
np_arr.append((int(i.split(".")[0]), pd.read_csv(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy()))
averages = mean_mkn(np_arr)
available = rb_available(np_arr)
allocate_lp1 = rb_allocate_distance(np_arr, 100)
allocate_lp2 = rb_allocate_distance(np_arr, 500)
allocate_lp1 = rb_allocate_distance(np_arr, 200)
allocate_lp2 = rb_allocate_distance(np_arr, 400)
allocate_total = allocate_lp1[:, 1] + allocate_lp2[:, 1]
print(allocate_total)
delays = delay(np_arr)
delays.sort(axis=0)
# Data for plotting
averages.sort(axis=0)
available.sort(axis=0)
del np_arr
fig, ax = plt.subplots(2, 2)
ax[0, 0].plot(averages[:, 0], averages[:, 1], marker="o")
ax[0, 0].set(xlabel='number of users', ylabel='% Spectral efficiency', title='Spectral efficiency PF')
ax[0, 0].scatter(averages[:, 0], averages[:, 1])
ax[0, 0].set(xlabel='number of users', ylabel='Efficacité spectrale', title='Efficacité spectrale')
ax[0, 0].grid()
ax[0, 0].set_ylim([0, 40])
ax[0, 1].plot(available[:, 0], available[:, 1], marker="o")
ax[0, 1].set(xlabel='number of users', ylabel=' % RB used', title='Percentage of RB used PF')
ax[0, 1].scatter(available[:, 0], available[:, 1])
ax[0, 1].set(xlabel='number of users', ylabel='RB utilisés', title='Pourcentage de RB utilisés')
ax[0, 1].grid()
ax[0, 1].set_ylim([0, 105])
ax[1, 0].plot(delays[:, 0], delays[:, 1], marker="o")
ax[1, 0].set(xlabel='number of users', ylabel='delay(ms)', title='Delay PF')
ax[1, 0].scatter(delays[:, 0], delays[:, 1])
ax[1, 0].set(xlabel='number of users', ylabel='delays(ms)', title='Delay')
ax[1, 0].grid()
available.sort(axis=0)
#ax[1, 1].scatter(allocate_lp1[:, 0], (allocate_lp1[:, 1]/(allocate_lp1[:, 1])+allocate_lp2[:, 1])*100)
ax[1, 1].plot(available[:, 0], (allocate_lp1[:, 1]/(allocate_lp1[:, 1]+allocate_lp2[:, 1])*100), label="100 meters group")
ax[1, 1].plot(available[:, 0], (allocate_lp1[:, 1]/(allocate_lp1[:, 1]+allocate_lp2[:, 1])*100))
#ax[1, 1].scatter(allocate_lp2[:, 0], (allocate_lp2[:, 1]/(allocate_lp1[:, 1])+allocate_lp2[:, 1])*100)
#ax[1, 1].plot(available[:, 0], available[:, 1], marker="o", label="RB used")
ax[1, 1].plot(available[:, 0], (allocate_lp2[:, 1]/(allocate_lp1[:, 1]+allocate_lp2[:, 1])*100))
ax[1, 1].plot(available[:, 0], (allocate_lp2[:, 1]/(allocate_lp1[:, 1]+allocate_lp2[:, 1])*100), label="500 meters group")
ax[1, 1].set(xlabel='number of users', ylabel='% RB used', title='RB used depending on the distance PF')
ax[1, 1].set(xlabel='number of users', ylabel='RB utilisés proche/loin/total', title='RB utilisés distance')
ax[1, 1].grid()
ax[1, 1].set_ylim([0, 105])
ax[1, 1].legend(loc="upper left")
plt.ylim(0, 100)
plt.show()

View File

@ -1,61 +1,139 @@
package fr.ntr;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import fr.ntr.scheduler.Scheduler;
public class AccessPoint {
private final List<User> users;
private final Scheduler scheduler;
/**
* nombre de slots
*/
private static int timeSlotNb;
/**
* Nombre de sous-porteuses
*/
private static int subCarrierNb;
/**
* trame
*/
private final ResourceBlock[][] frame;
private FileOutputStream outputDataFile;
private final List<Cell> cells;
private final boolean reuse3;
public AccessPoint (boolean reuse3, Cell... cells){
this.reuse3 = reuse3;
this.cells = Arrays.stream(cells).toList();
public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, List<User> users) {
this.users = users;
this.scheduler = scheduler;
this.frame = frame;
}
/**
* Lancer la simulation
* @param duration
*/
public void startSimulation (int duration) {
public void startSimulation(int duration) {
try{
this.outputDataFile = new FileOutputStream("export" + File.separator + this.users.size() + ".csv", true);
outputDataFile.write("tick;x;y;user;bandwidth;delay;distance;\n".getBytes());
} catch(IOException e) {
System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage());
System.exit(1);
return;
}
for (int ticks = 0; ticks < duration; ++ticks) {
// Simulation
cells.forEach(Cell::reset);
int finalTicks = ticks;
cells.forEach(c -> c.updateBandwidth(finalTicks));
cells.forEach(Cell::preScheduling);
for(int ts = 0; ts < Cell.getTimeSlotNb(); ts++) {
for (int sp = 0; sp < (reuse3 ? Cell.getSubCarrierNb() / 2 : Cell.getSubCarrierNb()); sp++) {
User user1 = cells.get(0).schedule(ticks, ts, sp);
if(cells.size() > 1) {
User user2 = cells.get(1).schedule(ticks, ts, (reuse3 ? 50 : 0) + sp);
//FIXME pour avoir 20
boolean haveInterference = user1 == user2 && user1 != null;
int finalTs = ts;
int finalSp = sp;
cells.forEach(c -> c.consumeResource(finalTicks, finalTs, finalSp, haveInterference));
cells.get(0).postScheduling(user1);
cells.get(1).postScheduling(user2);
} else {
cells.get(0).consumeResource(ticks, ts, sp, false);
cells.get(0).postScheduling(user1);
}
}
}
reset();
updateBandwidth(ticks);
schedule(ticks);
// traite les données et les enregistre dans un fichier
int finalTicks1 = ticks;
cells.forEach(c -> {
try {
c.analyseData(finalTicks1);
analyseData(ticks);
} catch (IOException e) {
System.err.println("IO Error: " + e.getMessage());
System.out.println("Can't export data");
}
}
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) {
int m = 200;
for(User user : users) {
// On régénère les sources toutes les 50-100 ms
user.createPackets(m, ticks);
// On régénère le tableau de débits toutes les 50 ms
if(ticks % 50 == 0){
user.generateBandwidth();
}
}
}
private void schedule(int ticks) {
scheduler.scheduling(ticks);
}
private void analyseData(int tick) throws IOException {
double delayAverage = 0.0;
int nbPacketsSent = 0;
for(User u: this.users){
List<Packets> packets = u.getPacketsSent();
nbPacketsSent += packets.size();
for (Packets p: packets){
delayAverage += p.getDurationSending();
}
}
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() + ";" + delayAverage +";" + ur.getUser().getDistance() + ";" + "\n");
try{
outputDataFile.write(data.getBytes());
}catch(IOException e){
System.err.println("Cannot write the data in the output file");
System.exit(1);
return;
}
});
}
}
}
}
private void reset() {
for(int i = 0; i < timeSlotNb; i++) {
for(int j = 0; j < subCarrierNb; j++) {
frame[i][j] = new ResourceBlock(0.0);
}
}
}
public ResourceBlock[][] getFrame() {
return frame;
}
public static int getTimeSlotNb() {
return timeSlotNb;
}
public static int getSubCarrierNb() {
return subCarrierNb;
}
public static void setTimeSlotNb(int timeSlotNb) {
AccessPoint.timeSlotNb = timeSlotNb;
}
public static void setSubCarrierNb(int subCarrierNb) {
AccessPoint.subCarrierNb = subCarrierNb;
}
}

View File

@ -1,155 +0,0 @@
package fr.ntr;
import fr.ntr.scheduler.Scheduler;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Random;
public class Cell {
private final List<User> users;
/**
* Scheduler utilisé par la cellule
*/
private final Scheduler scheduler;
/**
* Nombre de slots
*/
private static int timeSlotNb;
/**
* Nombre de sous-porteuses
*/
private static int subCarrierNb;
/**
* Trame
*/
private final ResourceBlock[][] frame;
private final FileOutputStream outputDataFile;
private final int id;
public Cell(int id, Scheduler scheduler, ResourceBlock[][] frame, List<User> users, FileOutputStream fileOutputStream) {
this.id = id;
this.users = users;
this.scheduler = scheduler;
this.frame = frame;
this.outputDataFile = fileOutputStream;
}
public void updateBandwidth(int ticks) {
int m = 200;
for(User user : users) {
// On régénère les sources toutes les 50-100 ms
user.createPackets(m, ticks);
// On régénère le tableau de débits toutes les 50 ms
if(ticks % 50 == 0){
user.generateBandwidth();
}
}
}
public void reset() {
// TODO insert new UR
for(int i = 0; i < timeSlotNb; i++) {
for(int j = 0; j < subCarrierNb; j++) {
frame[i][j] = new ResourceBlock(0.0);
}
}
}
public void preScheduling() {
scheduler.preScheduling();
}
public void postScheduling(User userSelected) {
scheduler.postScheduling(userSelected);
}
public User schedule(int tick, int ts, int sp) {
return scheduler.scheduling(tick, ts, sp);
}
public void consumeResource(int tick, int ts, int sp, boolean haveInterference) {
ResourceBlock rb = frame[ts][sp];
User user = rb.getUser();
if(user != null && !user.getPacketsToSend().isEmpty()) {
Packets p = user.getPacketsToSend().get(0);
rb.setBandwidth(updateBandwidth(haveInterference, rb));
p.decreaseBitsNumberRemaining((int) rb.getBandwidth());
if(p.getBitsNumberRemaining() <= 0) {
if(tick == 0){
p.setDurationSending(1);
}else {
p.setDurationSending(tick);
}
user.getPacketsSent().add(p);
user.getPacketsToSend().remove(p);
}
}
}
private double updateBandwidth(boolean haveInterference, ResourceBlock rb) {
if(haveInterference) {
if(rb.getUser().getDistance() < 200d) {
// User proche
return rb.getBandwidth() / 2;
}
// User loin
return rb.getBandwidth() / 4;
} else {
return rb.getBandwidth();
}
}
public void analyseData(int tick) throws IOException {
double delayAverage = 0.0;
int nbPacketsSent = 0;
for(User u: users){
List<Packets> packets = u.getPacketsSent();
nbPacketsSent += packets.size();
for (Packets p: packets){
delayAverage += p.getDurationSending();
}
}
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() + ";" + delayAverage +";" + ur.getUser().getDistance() + ";" + id + "\n");
try{
outputDataFile.write(data.getBytes());
}catch(IOException e){
System.err.println("Cannot write the data in the output file");
System.exit(1);
return;
}
}
}
}
}
public ResourceBlock[][] getFrame() {
return frame;
}
public static int getTimeSlotNb() {
return timeSlotNb;
}
public static int getSubCarrierNb() {
return subCarrierNb;
}
public static void setTimeSlotNb(int timeSlotNb) {
Cell.timeSlotNb = timeSlotNb;
}
public static void setSubCarrierNb(int subCarrierNb) {
Cell.subCarrierNb = subCarrierNb;
}
}

View File

@ -1,28 +1,26 @@
package fr.ntr;
import fr.ntr.scheduler.MaxSNR;
import fr.ntr.scheduler.ProportionalFair;
import fr.ntr.scheduler.RoundRobin;
import fr.ntr.scheduler.Scheduler;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class Main {
public static void main (String[] args) {
if (args.length == 2) {
public static void main(String[] args) {
if(args.length == 2) {
int numberOfTicks; // Nombre de ticks de la simulation -> durée de la simulation
int maximumLoad; // Nombre maximal d'utilisateurs dans le système
//instancie numberOfTicks et maximumLoad
try {
numberOfTicks = Integer.parseInt(args[0]);
maximumLoad = Integer.parseInt(args[1]);
@ -32,19 +30,13 @@ public class Main {
System.exit(1);
return;
}
//instancie nombre de time slots et sous-porteuses
int timeSlotNb = 2;
//nb subcarrier si reuse1 ou reuse3
int subCarrierNb = 100;
//préparation pour exportation des données
File folder = new File("export");
if (!folder.exists() && !folder.mkdir()) {
if(!folder.exists() && !folder.mkdir()) {
System.err.println("Cannot create export folder");
System.exit(1);
}
Arrays.stream(Objects.requireNonNull(new File("export").listFiles()))
.filter(File::isFile)
@ -53,66 +45,27 @@ public class Main {
System.err.println("Cannot remove file " + f.getAbsolutePath());
}
});
//instanciation des cellules, schedulers et utilisateurs
Cell.setTimeSlotNb(timeSlotNb);
Cell.setSubCarrierNb(subCarrierNb);
AccessPoint.setTimeSlotNb(timeSlotNb);
AccessPoint.setSubCarrierNb(subCarrierNb);
ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
for (int i = 2; i <= maximumLoad; i += 2) {
//génération des utilisateurs
List<User> usersCell1 = generateUsers(i, timeSlotNb, subCarrierNb);
List<User> usersCell2 = generateUsers(i, timeSlotNb, subCarrierNb);
//copie de 1/4 des utilisateurs de cell1 vers cell2
Random r = new Random();
for(int j = 0; j < i/4; j++){
int idxCopy = r.nextInt(i);
User copiedUser = usersCell1.get(idxCopy);
// On vérifie qu'on ne l'a pas déjà copié dans cell2
if(usersCell2.contains(copiedUser)) {
idxCopy = r.nextInt(i);
copiedUser = usersCell1.get(idxCopy);
}
usersCell2.set(idxCopy, copiedUser);
}
//génération des trames
ResourceBlock[][] frame1 = new ResourceBlock[timeSlotNb][subCarrierNb];
ResourceBlock[][] frame2 = new ResourceBlock[timeSlotNb][subCarrierNb];
//génération des schedulers
Scheduler schedulerCell1 = new RoundRobin(frame1, usersCell1);
Scheduler schedulerCell2 = new RoundRobin(frame2, usersCell2);
try {
//préparation à exportation des données de chaque cellule
FileOutputStream output = new FileOutputStream("export" + File.separator + (usersCell1.size()) + ".csv", true);
output.write("tick;x;y;user;bandwidth;delay;distance;cell;\n".getBytes());
//création des cellules
Cell cell1 = new Cell(0, schedulerCell1, frame1, usersCell1, output);
Cell cell2 = new Cell(1, schedulerCell2, frame2, usersCell2, output);
//création de l'AccessPoint
AccessPoint accessPoint = new AccessPoint(false, cell1, cell2);
for(int i = 2; i <= maximumLoad; i += 2) {
List<User> users = generateUsers(i, timeSlotNb, subCarrierNb);
ResourceBlock[][] frame = new ResourceBlock[timeSlotNb][subCarrierNb];
//Scheduler scheduler = new MaxSNR(frame, users);
//Scheduler scheduler = new ProportionalFair(frame, users);
Scheduler scheduler = new RoundRobin(frame, users);
AccessPoint accessPoint = new AccessPoint(scheduler, frame, users);
executor.submit(() -> accessPoint.startSimulation(numberOfTicks));
}
catch (IOException e) {
System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage());
System.exit(1);
}
}
executor.shutdown();
try {
executor.awaitTermination(5, TimeUnit.MINUTES);
if(!executor.awaitTermination(2, TimeUnit.MINUTES)) {
executor.shutdownNow();
}
catch (InterruptedException e) {
} catch (InterruptedException e) {
e.printStackTrace();
}
executor.shutdownNow();
System.out.println("Executor closed");
}
else {
} else {
System.err.println("Please give launch arguments");
System.err.println("gradle run --args=\"<number of ticks> <number of users>\"");
System.exit(1);
@ -122,17 +75,16 @@ 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
int half = nbUsers / 2;
for (int i = 0; i < nbUsers; i++) {
User user;
if(i >= half){
user = new User(500d, timeSlotNb, subCarrierNb);
}
else {
user = new User(150d, timeSlotNb, subCarrierNb);
}
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;
}
}

View File

@ -17,16 +17,13 @@ public class ResourceBlock {
this.user = user;
}
public User getUser() {
return user;
}
public void setBandwidth(double bandwidth) {
this.bandwidth = bandwidth;
}
public User getUser() {
return user;
}
public double getBandwidth() {
return bandwidth;

View File

@ -12,7 +12,9 @@ public class User {
private final List<Packets> packetsSent;
private int leftForNextSource;
private int timeInterval = 1;
public int totalbits = 0;
private int mbis;
private final Random random = new Random();
@ -45,9 +47,9 @@ public class User {
public void createPackets(int m, int ticks) {
timeInterval--;
if(timeInterval == 0) {
timeInterval = 50 + random.nextInt(52);
timeInterval = random.nextInt(2, 102);
// On tire un nombre entre 0 et 2 * m
mbis = random.nextInt(2 * m + 1) ;
mbis = random.nextInt(0, 2 * m + 1) ;
}
// On calcule le nombre de paquets qu'on peut transmettre

View File

@ -1,7 +1,7 @@
package fr.ntr.scheduler;
import java.util.List;
import fr.ntr.Cell;
import fr.ntr.AccessPoint;
import fr.ntr.ResourceBlock;
import fr.ntr.User;
@ -9,33 +9,27 @@ public class MaxSNR extends Scheduler {
private final List<User> users;
public MaxSNR(ResourceBlock[][] myFrame, List<User> users) {
super(myFrame);
private final ResourceBlock[][] frame;
public MaxSNR(ResourceBlock[][] frame, List<User> users) {
this.frame = frame;
this.users = users;
}
@Override
public User scheduling(int ticks, int ts, int sp) {
User user = userSelection(ts, sp);
allocateRessource(user, ts, sp, ticks);
return user;
public void scheduling(int ticks) {
User userMax;
for(int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++){
for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++){
userMax = userSelection(ts, sp);
allocateRessource(userMax, frame, ts, sp, ticks);
}
@Override
public void postScheduling(User userSelected) {
}
@Override
public void preScheduling() {
}
/**
* Sélectionne le prochain utilisateur en fonction du contexte
* @param ts Time slot (int)
* @param sp Sous porteuse(int)
* @return the user with the best bandwidth
*/
private User userSelection(int ts, int sp) {
@ -45,6 +39,7 @@ public class MaxSNR extends Scheduler {
if (!u.getPacketsToSend().isEmpty() && (maxSnr < u.getBandwidthTable()[ts][sp])) {
maxSnr = u.getBandwidthTable()[ts][sp];
userMax = u;
}
}
return userMax;

View File

@ -3,37 +3,35 @@ package fr.ntr.scheduler;
import java.util.ArrayList;
import java.util.List;
import fr.ntr.AccessPoint;
import fr.ntr.ResourceBlock;
import fr.ntr.User;
public class ProportionalFair extends Scheduler {
private final List<User> users;
private ArrayList<Double> averageBandwidth;
private final ResourceBlock[][] frame;
public ProportionalFair(ResourceBlock[][] myFrame, List<User> users) {
super(myFrame);
public ProportionalFair(ResourceBlock[][] frame, List<User> users) {
this.frame = frame;
this.users = users;
}
@Override
public User scheduling(int ticks, int ts, int sp) {
User user = userSelection(ts, sp, users);
allocateRessource(user, ts, sp, ticks);
return user;
public void scheduling(int ticks) {
for(int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++){
for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++){
User selectedUser = userSelection(ts, sp, users);
allocateRessource(selectedUser, frame, ts, sp, ticks);
}
}
}
@Override
public void postScheduling(User userSelected) {
}
@Override
public void preScheduling() {
averageBandwidth = new ArrayList<>();
for(User u : users){
private User userSelection(int ts, int sp, List<User> users) {
double PF = 0.0;
User selectedUser = null;
for (User u : users) {
double avg = 0d;
double[][] bandwidthTable = u.getBandwidthTable();
for (double[] doubles : bandwidthTable) {
@ -42,19 +40,9 @@ public class ProportionalFair extends Scheduler {
}
}
avg = avg / (bandwidthTable.length * bandwidthTable[0].length);
averageBandwidth.add(avg);
}
}
private User userSelection(int ts, int sp, List<User> users) {
double PF = 0.0;
User selectedUser = null;
for(int i = 0; i < users.size(); i++){
User u = users.get(i);
double mkn = u.getBandwidthTable()[ts][sp];
double averageMkn = averageBandwidth.get(i);
double pf = mkn / averageMkn;
if (PF < pf){
double pf = mkn / avg;
if (PF < pf) {
PF = pf;
selectedUser = u;
}

View File

@ -1,8 +1,11 @@
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;
import fr.ntr.AccessPoint;
import fr.ntr.ResourceBlock;
import fr.ntr.User;
@ -10,11 +13,10 @@ import fr.ntr.User;
public class RoundRobin extends Scheduler {
private final List<User> users;
private List<User> userCopy;
private final ResourceBlock[][] frame;
public RoundRobin(ResourceBlock[][] myFrame, List<User> users) {
super(myFrame);
public RoundRobin(ResourceBlock[][] frame, List<User> users) {
this.frame = frame;
this.users = users;
}
@ -24,25 +26,22 @@ public class RoundRobin extends Scheduler {
* Return
*/
@Override
public User scheduling(int ticks, int ts, int sp) {
if(userCopy.isEmpty()) {
return null;
}
User user = userSelection(userCopy);
allocateRessource(user, ts, sp, ticks);
return user;
}
public void scheduling(int ticks) {
List<User> userCopy = users.stream().filter(u -> !u.getPacketsToSend().isEmpty()).collect(Collectors.toList());
Collections.shuffle(userCopy);
@Override
public void postScheduling(User userSelected) {
if(userSelected != null && !userSelected.getPacketsToSend().isEmpty())
//Pour chaque time slot et sous porteuses
loop: for (int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++) {
for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++) {
if(userCopy.isEmpty()) {
break loop;
}
User userSelected = userSelection(userCopy);
allocateRessource(userSelected, frame, ts, sp, ticks);
if(!userSelected.getPacketsToSend().isEmpty())
userCopy.add(userSelected);
}
@Override
public void preScheduling() {
userCopy = users.stream().filter(u -> !u.getPacketsToSend().isEmpty()).collect(Collectors.toList());
Collections.shuffle(userCopy);
}
}
/**

View File

@ -6,23 +6,28 @@ import fr.ntr.User;
public abstract class Scheduler {
protected final ResourceBlock[][] myFrame;
/**
* Entry
* Rempli la trame avec les utilisateurs
* Return
*/
public abstract void scheduling(int ticks);
public Scheduler(ResourceBlock[][] myFrame) {
this.myFrame = myFrame;
}
public abstract User scheduling(int ticks, int ts, int sp);
public abstract void postScheduling(User userSelected);
public abstract void preScheduling();
public void allocateRessource(User userMax, int ts, int sp, int ticks) {
protected void allocateRessource(User userMax, ResourceBlock[][] frame, int ts, int sp, int ticks) {
if (userMax != null && !userMax.getPacketsToSend().isEmpty()) {
myFrame[ts][sp].setUser(userMax);
myFrame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]);
Packets p = userMax.getPacketsToSend().get(userMax.getPacketsToSend().size()-1);
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);
}
frame[ts][sp].setUser(userMax);
frame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]);
}
}
}