Compare commits

...
This repository has been archived on 2023-08-28. You can view files and clone it, but cannot push or open issues or pull requests.

66 Commits

Author SHA1 Message Date
iboyeau
d114314ba1 to Fix 2023-04-17 11:40:49 +02:00
Tr1xt4n
4f110cc7cb plot legend 2023-04-14 21:01:23 +02:00
2307fd2567 Add distance to csv, backport changes to python script from master branch 2023-04-13 12:40:34 +02:00
753b1b5ead Remove Reuse classes 2023-04-13 12:07:08 +02:00
519fa92aef Add support for 1 or 2 cells 2023-04-13 11:54:34 +02:00
47755c46b7 Edit main.py -> use of plot instead of scatter and added ylim 2023-04-13 11:37:13 +02:00
0fceb13d48 Add more time to workers to finish executions 2023-04-07 11:50:49 +02:00
825f4f26c7 Fix reuse 2023-04-07 11:39:35 +02:00
54f5c1636f Fix for older jdk versions 2023-04-07 11:32:41 +02:00
28d3596eb9 lint: Fix indentation 2023-04-07 10:37:03 +02:00
797b2a17f7 Merge branch 'ajout_cellule' of gitlab.istic.univ-rennes1.fr:18008147/ntr into ajout_cellule 2023-04-07 10:31:48 +02:00
b7f69498ee Delete data after processing, using less memory 2023-04-07 10:31:29 +02:00
iboyeau
d00e5d70de reuse3 selector 2023-04-07 10:22:06 +02:00
Legot Quentin
ede383eab8 Merge branch 'interference' into 'ajout_cellule'
Interference

See merge request 18008147/ntr!2
2023-04-07 08:02:28 +00:00
d534f3f61b Add interference 2023-04-07 09:58:54 +02:00
de59bc8047 Fix execution 2023-04-07 09:28:10 +02:00
4093336d40 Modification schedulers pour gérer les interférences 2023-04-07 08:57:56 +02:00
Remi Boure
ec7f265940 Copie utilisateurs cell1 vers cell2 pour les interférences 2023-04-05 13:22:45 +02:00
iboyeau
f93b1c4c22 add space and maj reuse3 2023-04-04 16:59:45 +02:00
loris
6b816534d7 Main readability is over 9000 2023-04-04 16:45:13 +02:00
loris
80b77f7c6d meilleure lisibilité de Main 2023-04-04 16:06:55 +02:00
Remi Boure
d5413db0b3 Merge branch 'ajout_cellule' of gitlab.istic.univ-rennes1.fr:18008147/ntr into ajout_cellule 2023-04-04 10:05:52 +02:00
Remi Boure
41f50c9e83 Changements par rapport à l'ajout d'une 2ème cellule 2023-04-04 10:04:36 +02:00
3b012adf61 Merge branch 'master' into ajout_cellule 2023-04-04 09:52:02 +02:00
be9dd99b39 Re compute interference and change distances 2023-04-04 08:30:21 +02:00
7831bc2d2b Display plots in one window 2023-04-04 08:29:23 +02:00
06f3e82c4a Merge branch 'master' into ajout_cellule 2023-03-31 11:49:11 +02:00
faeb49eb32 Remove interferences for testing, optimize main.py 2023-03-31 10:21:49 +02:00
Remi Boure
9936d4f1b9 Fix for jdk 1.8 2023-03-31 10:01:11 +02:00
df77238cc9 Merge remote-tracking branch 'origin/ajout_cellule' into ajout_cellule 2023-03-31 09:53:26 +02:00
768de92948 Fix outFIle 2023-03-31 09:53:05 +02:00
Tr1xt4n
21815c03da fix SNR 2023-03-31 09:49:42 +02:00
d78d422a07 Fix analyzeData 2023-03-31 09:41:50 +02:00
5f18a8f3ea Change scheduler to RR 2023-03-31 09:33:10 +02:00
d646be8a6e Merge origin/master into ajout_cellule 2023-03-31 09:25:02 +02:00
iboyeau
dbdad667d5 correct 2023-03-31 06:24:43 +02:00
iboyeau
1430d4afe5 dirty reuse 2023-03-31 06:18:40 +02:00
iboyeau
51b578036d Merge remote-tracking branch 'origin/ajout_cellule' into ajout_cellule 2023-03-30 09:53:55 +02:00
iboyeau
b2862c9a9f update 2023-03-30 09:53:41 +02:00
Remi Boure
a654621085 Merge branch 'ajout_cellule' of gitlab.istic.univ-rennes1.fr:18008147/ntr into ajout_cellule 2023-03-30 09:41:15 +02:00
Remi Boure
6619812a84 Check if user is not null in computeInterference 2023-03-30 09:41:10 +02:00
iboyeau
0794e02a8b TODO Reuse 3 2023-03-30 09:36:46 +02:00
iboyeau
b5525d0462 Reuse 1 2023-03-30 09:02:12 +02:00
iboyeau
aa87a868a1 Merge remote-tracking branch 'origin/ajout_cellule' into ajout_cellule 2023-03-30 09:00:54 +02:00
iboyeau
89867ad20b Reuse 1 2023-03-30 09:00:35 +02:00
Remi Boure
b3507b09eb Merge branch 'ajout_cellule' of gitlab.istic.univ-rennes1.fr:18008147/ntr into ajout_cellule 2023-03-30 08:40:04 +02:00
Remi Boure
7620459a40 Modifying bandwith of the user when interference 2023-03-30 08:38:35 +02:00
iboyeau
21ae722975 correct "<" 2023-03-30 08:13:48 +02:00
Loris
f6407b1584 fixed comparison in computeInterference 2023-03-30 06:30:37 +02:00
Loris
6ce0e63e9c moved interference simulation in its own method 2023-03-28 09:02:45 +02:00
Loris
3e0a2056c0 Merge remote-tracking branch 'origin/ajout_cellule' into ajout_cellule 2023-03-28 08:59:30 +02:00
Loris
ebba05aa0a added interference simulation in startSimulation() 2023-03-28 08:59:16 +02:00
iboyeau
07036da11f add Reuse 2023-03-28 08:49:46 +02:00
iboyeau
5c533d37cc acces point maj 2023-03-28 08:21:38 +02:00
iboyeau
b76c836ca4 few warning suppression 2023-03-24 12:06:55 +01:00
iboyeau
5572ae7aab few warning suppression 2023-03-24 12:01:39 +01:00
iboyeau
5586326358 Merge remote-tracking branch 'origin/ajout_cellule' into ajout_cellule 2023-03-24 11:56:00 +01:00
iboyeau
81f9739a8c javadoc and few warning suppression 2023-03-24 11:55:39 +01:00
iboyeau
b816e3d93e =roll back 2023-03-24 11:31:46 +01:00
Loris
12fc8e3a80 un peu de javadoc plaisir 2023-03-24 10:52:33 +01:00
Loris
b0f96e4173 independent cell scheduler 2023-03-24 10:39:46 +01:00
Loris
98a1222f71 extracted Cell from AccessPoint
cell instantiation in main
2023-03-24 10:29:16 +01:00
iboyeau
613510c6d0 =roll back 2023-03-24 11:14:28 +01:00
iboyeau
4c33dac028 try to create cell (to verify) 2023-03-24 10:52:39 +01:00
iboyeau
0d5044c4f7 starting separate cell and main 2023-03-24 10:00:56 +01:00
iboyeau
ee09401244 starting cell 2023-03-24 09:40:05 +01:00
11 changed files with 425 additions and 240 deletions

View File

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

View File

@ -3,7 +3,7 @@ import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
nb_files = os.listdir(".." + os.sep + "export")
nb_files = os.listdir("PF")
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 * 10000)) * 100
available[nb, 1] = (data.shape[0] / (200 * 20000)) * 100
nb += 1
return available
@ -46,28 +46,71 @@ def delay(arr: list[tuple[int, np.ndarray]]) -> np.ndarray:
return delays
def rb_allocate_distance(arr: list[tuple[int, np.ndarray]], distance) -> np.ndarray:
allocate = np.zeros((size, 2))
nb = 0
arr.sort()
for nb_users, data in arr:
n = 0
for x in data[:,6]:
if int(x) == distance:
n+=1
allocate[nb, 0] = nb_users
allocate[nb, 1] = n
# 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(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy()))
np_arr.append((int(i.split(".")[0]), pd.read_csv("PF" + 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_total = allocate_lp1[:, 1] + allocate_lp2[:, 1]
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].scatter(averages[:, 0], averages[:, 1])
ax[0, 0].set(xlabel='number of users', ylabel='Efficacité spectrale', title='Efficacité spectrale')
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].grid()
ax[0, 0].set_ylim([0, 40])
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].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].grid()
ax[0, 1].set_ylim([0, 105])
ax[1, 0].scatter(delays[:, 0], delays[:, 1])
ax[1, 0].set(xlabel='number of users', ylabel='delays(ms)', title='Delay')
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].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].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), 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].grid()
ax[1, 1].set_ylim([0, 105])
ax[1, 1].legend(loc="upper left")
plt.show()

View File

@ -1,139 +1,61 @@
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;
public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, List<User> users) {
this.users = users;
this.scheduler = scheduler;
this.frame = frame;
private final boolean reuse3;
public AccessPoint (boolean reuse3, Cell... cells){
this.reuse3 = reuse3;
this.cells = Arrays.stream(cells).toList();
}
/**
* Lancer la simulation
* @param 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;
}
public void startSimulation (int duration) {
for (int ticks = 0; ticks < duration; ++ticks) {
// Simulation
reset();
updateBandwidth(ticks);
schedule(ticks);
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);
}
}
}
// traite les données et les enregistre dans un fichier
int finalTicks1 = ticks;
cells.forEach(c -> {
try {
analyseData(ticks);
c.analyseData(finalTicks1);
} catch (IOException e) {
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.err.println("IO Error: " + e.getMessage());
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

@ -0,0 +1,155 @@
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,25 +1,28 @@
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]);
@ -29,13 +32,19 @@ 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)
@ -44,27 +53,66 @@ public class Main {
System.err.println("Cannot remove file " + f.getAbsolutePath());
}
});
AccessPoint.setTimeSlotNb(timeSlotNb);
AccessPoint.setSubCarrierNb(subCarrierNb);
//instanciation des cellules, schedulers et utilisateurs
Cell.setTimeSlotNb(timeSlotNb);
Cell.setSubCarrierNb(subCarrierNb);
ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
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);
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);
executor.submit(() -> accessPoint.startSimulation(numberOfTicks));
}
catch (IOException e) {
System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage());
System.exit(1);
}
}
executor.shutdown();
try {
if(!executor.awaitTermination(2, TimeUnit.MINUTES)) {
executor.shutdownNow();
executor.awaitTermination(5, TimeUnit.MINUTES);
}
} catch (InterruptedException e) {
catch (InterruptedException e) {
e.printStackTrace();
}
} else {
executor.shutdownNow();
System.out.println("Executor closed");
}
else {
System.err.println("Please give launch arguments");
System.err.println("gradle run --args=\"<number of ticks> <number of users>\"");
System.exit(1);
@ -74,14 +122,17 @@ 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, 400d };
for (double v : distance) {
for (int j = 0; j < nbUsers; j++) {
User user = new User(v, timeSlotNb, subCarrierNb);
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);
}
users.add(user);
}
}
return users;
}
}

View File

@ -17,13 +17,16 @@ 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,9 +12,7 @@ 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();
@ -47,9 +45,9 @@ public class User {
public void createPackets(int m, int ticks) {
timeInterval--;
if(timeInterval == 0) {
timeInterval = random.nextInt(2, 102);
timeInterval = 50 + random.nextInt(52);
// On tire un nombre entre 0 et 2 * m
mbis = random.nextInt(0, 2 * m + 1) ;
mbis = random.nextInt(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.AccessPoint;
import fr.ntr.Cell;
import fr.ntr.ResourceBlock;
import fr.ntr.User;
@ -9,27 +9,33 @@ public class MaxSNR extends Scheduler {
private final List<User> users;
private final ResourceBlock[][] frame;
public MaxSNR(ResourceBlock[][] frame, List<User> users) {
this.frame = frame;
public MaxSNR(ResourceBlock[][] myFrame, List<User> users) {
super(myFrame);
this.users = users;
}
@Override
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);
public User scheduling(int ticks, int ts, int sp) {
User user = userSelection(ts, sp);
allocateRessource(user, ts, sp, ticks);
return user;
}
@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) {
@ -39,7 +45,6 @@ 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,35 +3,37 @@ 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 final ResourceBlock[][] frame;
private ArrayList<Double> averageBandwidth;
public ProportionalFair(ResourceBlock[][] frame, List<User> users) {
this.frame = frame;
public ProportionalFair(ResourceBlock[][] myFrame, List<User> users) {
super(myFrame);
this.users = users;
}
@Override
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);
}
}
public User scheduling(int ticks, int ts, int sp) {
User user = userSelection(ts, sp, users);
allocateRessource(user, ts, sp, ticks);
return user;
}
private User userSelection(int ts, int sp, List<User> users) {
double PF = 0.0;
User selectedUser = null;
for (User u : users) {
@Override
public void postScheduling(User userSelected) {
}
@Override
public void preScheduling() {
averageBandwidth = new ArrayList<>();
for(User u : users){
double avg = 0d;
double[][] bandwidthTable = u.getBandwidthTable();
for (double[] doubles : bandwidthTable) {
@ -40,9 +42,19 @@ 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 pf = mkn / avg;
if (PF < pf) {
double averageMkn = averageBandwidth.get(i);
double pf = mkn / averageMkn;
if (PF < pf){
PF = pf;
selectedUser = u;
}

View File

@ -1,11 +1,8 @@
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;
@ -13,10 +10,11 @@ import fr.ntr.User;
public class RoundRobin extends Scheduler {
private final List<User> users;
private final ResourceBlock[][] frame;
private List<User> userCopy;
public RoundRobin(ResourceBlock[][] frame, List<User> users) {
this.frame = frame;
public RoundRobin(ResourceBlock[][] myFrame, List<User> users) {
super(myFrame);
this.users = users;
}
@ -26,22 +24,25 @@ public class RoundRobin extends Scheduler {
* Return
*/
@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 < AccessPoint.getTimeSlotNb(); ts++) {
for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++) {
public User scheduling(int ticks, int ts, int sp) {
if(userCopy.isEmpty()) {
break loop;
return null;
}
User userSelected = userSelection(userCopy);
allocateRessource(userSelected, frame, ts, sp, ticks);
if(!userSelected.getPacketsToSend().isEmpty())
User user = userSelection(userCopy);
allocateRessource(user, ts, sp, ticks);
return user;
}
@Override
public void postScheduling(User userSelected) {
if(userSelected != null && !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,28 +6,23 @@ import fr.ntr.User;
public abstract class Scheduler {
/**
* Entry
* Rempli la trame avec les utilisateurs
* Return
*/
public abstract void scheduling(int ticks);
protected final ResourceBlock[][] myFrame;
protected void allocateRessource(User userMax, ResourceBlock[][] frame, int ts, int sp, 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) {
if (userMax != null && !userMax.getPacketsToSend().isEmpty()) {
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]);
myFrame[ts][sp].setUser(userMax);
myFrame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]);
}
}
}