Compare commits
66 Commits
master
...
ajout_cell
Author | SHA1 | Date | |
---|---|---|---|
|
d114314ba1 | ||
|
4f110cc7cb | ||
2307fd2567 | |||
753b1b5ead | |||
519fa92aef | |||
47755c46b7 | |||
0fceb13d48 | |||
825f4f26c7 | |||
54f5c1636f | |||
28d3596eb9 | |||
797b2a17f7 | |||
b7f69498ee | |||
|
d00e5d70de | ||
|
ede383eab8 | ||
d534f3f61b | |||
de59bc8047 | |||
4093336d40 | |||
|
ec7f265940 | ||
|
f93b1c4c22 | ||
|
6b816534d7 | ||
|
80b77f7c6d | ||
|
d5413db0b3 | ||
|
41f50c9e83 | ||
3b012adf61 | |||
be9dd99b39 | |||
7831bc2d2b | |||
06f3e82c4a | |||
faeb49eb32 | |||
|
9936d4f1b9 | ||
df77238cc9 | |||
768de92948 | |||
|
21815c03da | ||
d78d422a07 | |||
5f18a8f3ea | |||
d646be8a6e | |||
|
dbdad667d5 | ||
|
1430d4afe5 | ||
|
51b578036d | ||
|
b2862c9a9f | ||
|
a654621085 | ||
|
6619812a84 | ||
|
0794e02a8b | ||
|
b5525d0462 | ||
|
aa87a868a1 | ||
|
89867ad20b | ||
|
b3507b09eb | ||
|
7620459a40 | ||
|
21ae722975 | ||
|
f6407b1584 | ||
|
6ce0e63e9c | ||
|
3e0a2056c0 | ||
|
ebba05aa0a | ||
|
07036da11f | ||
|
5c533d37cc | ||
|
b76c836ca4 | ||
|
5572ae7aab | ||
|
5586326358 | ||
|
81f9739a8c | ||
|
b816e3d93e | ||
|
12fc8e3a80 | ||
|
b0f96e4173 | ||
|
98a1222f71 | ||
|
613510c6d0 | ||
|
4c33dac028 | ||
|
0d5044c4f7 | ||
|
ee09401244 |
@ -11,7 +11,7 @@ plugins {
|
||||
}
|
||||
|
||||
run {
|
||||
args = ["10000", "17"]
|
||||
args = ["10000", "40"]
|
||||
}
|
||||
|
||||
application {
|
||||
|
63
plot/main.py
63
plot/main.py
@ -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()
|
||||
|
||||
plt.show()
|
||||
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()
|
||||
|
@ -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;
|
||||
|
||||
|
||||
public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, List<User> users) {
|
||||
this.users = users;
|
||||
this.scheduler = scheduler;
|
||||
this.frame = frame;
|
||||
private final List<Cell> cells;
|
||||
|
||||
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);
|
||||
// traite les données et les enregistre dans un fichier
|
||||
try {
|
||||
analyseData(ticks);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Can't export data");
|
||||
}
|
||||
}
|
||||
cells.forEach(Cell::reset);
|
||||
|
||||
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;
|
||||
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 {
|
||||
c.analyseData(finalTicks1);
|
||||
} catch (IOException e) {
|
||||
System.err.println("IO Error: " + e.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
155
src/main/java/fr/ntr/Cell.java
Normal file
155
src/main/java/fr/ntr/Cell.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
int timeSlotNb = 2;
|
||||
int subCarrierNb = 100;
|
||||
File folder = new File("export");
|
||||
if(!folder.exists() && !folder.mkdir()) {
|
||||
System.err.println("Cannot create export folder");
|
||||
System.exit(1);
|
||||
|
||||
//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()) {
|
||||
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);
|
||||
executor.submit(() -> accessPoint.startSimulation(numberOfTicks));
|
||||
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();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
executor.awaitTermination(5, TimeUnit.MINUTES);
|
||||
}
|
||||
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);
|
||||
users.add(user);
|
||||
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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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++) {
|
||||
if(userCopy.isEmpty()) {
|
||||
break loop;
|
||||
}
|
||||
User userSelected = userSelection(userCopy);
|
||||
allocateRessource(userSelected, frame, ts, sp, ticks);
|
||||
if(!userSelected.getPacketsToSend().isEmpty())
|
||||
userCopy.add(userSelected);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user