Merge origin/master into ajout_cellule
This commit is contained in:
commit
d646be8a6e
@ -11,7 +11,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
run {
|
run {
|
||||||
args = ["1000", "250"]
|
args = ["10000", "17"]
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
|
82
plot/main.py
Normal file
82
plot/main.py
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
import os
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
nb_files = os.listdir(".." + os.sep + "export")
|
||||||
|
|
||||||
|
size = len(nb_files)
|
||||||
|
|
||||||
|
|
||||||
|
def mean_mkn() -> np.ndarray:
|
||||||
|
averages_mkn = np.empty((size, 2))
|
||||||
|
nb = 0
|
||||||
|
for i in nb_files:
|
||||||
|
data = pd.read_csv(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy()
|
||||||
|
rb = data[:, 4]
|
||||||
|
|
||||||
|
total = 0.0
|
||||||
|
for x in rb:
|
||||||
|
total = total + x
|
||||||
|
average = total / len(rb)
|
||||||
|
nb_users = i.split(".")[0]
|
||||||
|
averages_mkn[nb, 0] = int(nb_users)
|
||||||
|
averages_mkn[nb, 1] = average
|
||||||
|
nb += 1
|
||||||
|
return averages_mkn
|
||||||
|
|
||||||
|
|
||||||
|
def rb_available() -> np.ndarray:
|
||||||
|
available = np.zeros((size, 2))
|
||||||
|
nb = 0
|
||||||
|
for i in nb_files:
|
||||||
|
data = pd.read_csv(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy()
|
||||||
|
nb_users = i.split(".")[0]
|
||||||
|
available[nb, 0] = int(nb_users)
|
||||||
|
available[nb, 1] = (data.shape[0] / (200 * 10000)) * 100
|
||||||
|
nb += 1
|
||||||
|
return available
|
||||||
|
|
||||||
|
|
||||||
|
def delay() -> np.ndarray:
|
||||||
|
delays = np.zeros((size, 2))
|
||||||
|
nb = 0
|
||||||
|
for i in nb_files:
|
||||||
|
data = pd.read_csv(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy()
|
||||||
|
nb_users = i.split(".")[0]
|
||||||
|
d = data[:, 5]
|
||||||
|
for x in d:
|
||||||
|
delays[nb, 0] = int(nb_users)
|
||||||
|
delays[nb, 1] = float(x)
|
||||||
|
nb += 1
|
||||||
|
return delays
|
||||||
|
|
||||||
|
|
||||||
|
averages = mean_mkn()
|
||||||
|
available = rb_available()
|
||||||
|
delays = delay()
|
||||||
|
delays.sort(axis=0)
|
||||||
|
# Data for plotting
|
||||||
|
averages.sort(axis=0)
|
||||||
|
|
||||||
|
fig, ax = plt.subplots()
|
||||||
|
ax.scatter(averages[:, 0], averages[:, 1])
|
||||||
|
|
||||||
|
ax.set(xlabel='number of users', ylabel='Efficacité spectrale', title='Efficacité spectrale')
|
||||||
|
ax.grid()
|
||||||
|
|
||||||
|
# fig.savefig("test.png")
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
fig, ax = plt.subplots()
|
||||||
|
ax.scatter(available[:, 0], available[:, 1])
|
||||||
|
ax.set(xlabel='number of users', ylabel='RB utilisés', title='Pourcentage de RB utilisés')
|
||||||
|
ax.grid()
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
fig, ax = plt.subplots()
|
||||||
|
ax.scatter(delays[:, 0], delays[:, 1])
|
||||||
|
ax.set(xlabel='number of users', ylabel='delays(ms)', title='Delay')
|
||||||
|
ax.grid()
|
||||||
|
plt.show()
|
@ -3,25 +3,34 @@ package fr.ntr;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.util.ArrayList;
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import fr.ntr.Reuse.Reuse1;
|
|
||||||
import fr.ntr.Reuse.Reuse3;
|
|
||||||
import fr.ntr.scheduler.Scheduler;
|
import fr.ntr.scheduler.Scheduler;
|
||||||
|
|
||||||
public class AccessPoint {
|
public class AccessPoint {
|
||||||
|
/**
|
||||||
|
* nombre de slots
|
||||||
|
*/
|
||||||
|
private static int timeSlotNb;
|
||||||
|
/**
|
||||||
|
* Nombre de sous-porteuses
|
||||||
|
*/
|
||||||
|
private static int subCarrierNb;
|
||||||
|
|
||||||
private final Cell cell1;
|
private final Cell cell1;
|
||||||
private final Cell cell2;
|
private final Cell cell2;
|
||||||
private List<User> users;
|
|
||||||
private FileOutputStream outputDataFile;
|
private FileOutputStream outputDataFile;
|
||||||
|
|
||||||
|
private final List<Cell> cellList;
|
||||||
|
|
||||||
public AccessPoint(Cell cell1, Cell cell2){
|
public AccessPoint(Cell cell1, Cell cell2){
|
||||||
this.cell1 = cell1;
|
this.cell1 = cell1;
|
||||||
this.cell2 = cell2;
|
this.cell2 = cell2;
|
||||||
|
cellList = new ArrayList<>();
|
||||||
|
cellList.add(cell1);
|
||||||
|
cellList.add(cell2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,41 +38,30 @@ public class AccessPoint {
|
|||||||
* @param duration
|
* @param duration
|
||||||
*/
|
*/
|
||||||
public void startSimulation(int duration) {
|
public void startSimulation(int duration) {
|
||||||
/*
|
/*try{
|
||||||
try{
|
|
||||||
Files.deleteIfExists(Paths.get("export", this.users.size() + ".csv"));
|
|
||||||
new File("export").mkdir();
|
|
||||||
this.outputDataFile = new FileOutputStream("export" + File.separator + this.users.size() + ".csv", true);
|
this.outputDataFile = new FileOutputStream("export" + File.separator + this.users.size() + ".csv", true);
|
||||||
outputDataFile.write("tick;x;y;user;bandwidth;\n".getBytes());
|
outputDataFile.write("tick;x;y;user;bandwidth;delay;\n".getBytes());
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage());
|
System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage());
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
return;
|
return;
|
||||||
}
|
} */
|
||||||
*/
|
|
||||||
for (int ticks = 0; ticks < duration; ++ticks) {
|
for (int ticks = 0; ticks < duration; ++ticks) {
|
||||||
// Simulation
|
// Simulation
|
||||||
cell1.reset();
|
cell1.reset();
|
||||||
cell2.reset();
|
cell2.reset();
|
||||||
List<Cell> cellList = null;
|
|
||||||
cellList.add(cell1);
|
|
||||||
cellList.add(cell2);
|
|
||||||
cell1.updateBandwidth(ticks);
|
cell1.updateBandwidth(ticks);
|
||||||
cell2.updateBandwidth(ticks);
|
cell2.updateBandwidth(ticks);
|
||||||
cell1.schedule();
|
cell1.schedule(ticks);
|
||||||
cell2.schedule();
|
cell2.schedule(ticks);
|
||||||
|
|
||||||
|
|
||||||
//simulation des interférences
|
//simulation des interférences
|
||||||
computeInterference();
|
computeInterference();
|
||||||
|
|
||||||
// traite les données et les enregistre dans un fichier
|
// traite les données et les enregistre dans un fichier
|
||||||
|
try {
|
||||||
/* try {
|
|
||||||
analyseData(ticks);
|
analyseData(ticks);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println("Can't export data");
|
System.out.println("Can't export data");
|
||||||
}*/
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,62 +75,49 @@ public class AccessPoint {
|
|||||||
//interférences si les deux cellules parlent au même UE sur le même time slot
|
//interférences si les deux cellules parlent au même UE sur le même time slot
|
||||||
User user1 = frameCell1[k][l].getUser();
|
User user1 = frameCell1[k][l].getUser();
|
||||||
User user2 = frameCell2[k][l].getUser();
|
User user2 = frameCell2[k][l].getUser();
|
||||||
if (user1 == user2 && (user1 != null || user2 != null)) {
|
if ((user1 != null || user2 != null) && user1 == user2) {
|
||||||
double bandwidth1 = frameCell1[k][l].getBandwidth();
|
double bandwidth1 = frameCell1[k][l].getBandwidth();
|
||||||
double bandwidth2 = frameCell2[k][l].getBandwidth();
|
double bandwidth2 = frameCell2[k][l].getBandwidth();
|
||||||
//User proche
|
//User proche
|
||||||
if (user1.getDistance() < 200d) {
|
if (user1.getDistance() < 200d) {
|
||||||
frameCell1[k][l].getUser().getBandwidthTable()[k][l] = bandwidth1 / 2;
|
frameCell1[k][l].getUser().getBandwidthTable()[k][l] = bandwidth1 / 2;
|
||||||
frameCell2[k][l].getUser().getBandwidthTable()[k][l] = bandwidth2 / 2;
|
frameCell2[k][l].getUser().getBandwidthTable()[k][l] = bandwidth2 / 2;
|
||||||
//System.out.println("Interference Cell1 /2 ="+frameCell1[k][l].getUser().getBandwidthTable()[k][l]);
|
|
||||||
//System.out.println("Interference Cell2 /2 ="+frameCell2[k][l].getUser().getBandwidthTable()[k][l]);
|
|
||||||
}
|
}
|
||||||
//User loin
|
//User loin
|
||||||
else {
|
else {
|
||||||
frameCell1[k][l].getUser().getBandwidthTable()[k][l] = bandwidth1 / 4;
|
frameCell1[k][l].getUser().getBandwidthTable()[k][l] = bandwidth1 / 4;
|
||||||
frameCell2[k][l].getUser().getBandwidthTable()[k][l] = bandwidth2 / 4;
|
frameCell2[k][l].getUser().getBandwidthTable()[k][l] = bandwidth2 / 4;
|
||||||
//System.out.println("Interference Cell1 /4 ="+frameCell1[k][l].getUser().getBandwidthTable()[k][l]);
|
|
||||||
//System.out.println("Interference Cell2 /4 ="+frameCell2[k][l].getUser().getBandwidthTable()[k][l]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// traite les données et les enregistre dans un fichier
|
|
||||||
|
|
||||||
/* try {
|
|
||||||
analyseData(ticks);
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println("Can't export data");
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
private void analyseData(int tick) throws IOException {
|
private void analyseData(int tick) throws IOException {
|
||||||
double delayAverage = 0.0;
|
/*double delayAverage = 0.0;
|
||||||
int nbPacketsSent = 0;
|
int nbPacketsSent = 0;
|
||||||
for(User u: this.users){
|
for(User u: this.users){
|
||||||
List<Packets> packets = u.getPacketsSent();
|
List<Packets> packets = u.getPacketsSent();
|
||||||
nbPacketsSent += packets.size();
|
nbPacketsSent += packets.size();
|
||||||
for (Packets p: packets){
|
for (Packets p: packets){
|
||||||
delayAverage += p.getDurationSending();
|
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 +";\n");
|
||||||
|
try{
|
||||||
|
outputDataFile.write(data.getBytes());
|
||||||
|
}catch(IOException e){
|
||||||
|
System.err.println("Cannot write the data in the output file");
|
||||||
|
System.exit(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*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 +";\n");
|
|
||||||
try{
|
|
||||||
outputDataFile.write(data.getBytes());
|
|
||||||
}catch(IOException e){
|
|
||||||
System.err.println("Cannot write the data in the output file");
|
|
||||||
System.exit(1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
@ -23,44 +23,34 @@ public class Cell {
|
|||||||
/**
|
/**
|
||||||
* Trame
|
* Trame
|
||||||
*/
|
*/
|
||||||
private ResourceBlock[][] frame;
|
private final ResourceBlock[][] frame;
|
||||||
/**
|
/**
|
||||||
* Reste pour la prochaine source
|
* Reste pour la prochaine source
|
||||||
*/
|
*/
|
||||||
private double leftForNextSource;
|
private double leftForNextSource;
|
||||||
/**
|
|
||||||
* Portée minimum et maximum de l'antenne
|
|
||||||
*/
|
|
||||||
private final double min, max;
|
|
||||||
|
|
||||||
private Random random = new Random();
|
private final Random random = new Random();
|
||||||
|
|
||||||
public Cell(Scheduler scheduler, ResourceBlock[][] frame, List<User> users, int timeSlotNb, int subCarrierNb, double min, double max) {
|
public Cell(Scheduler scheduler, ResourceBlock[][] frame, List<User> users) {
|
||||||
this.min = min;
|
|
||||||
this.max = max;
|
|
||||||
this.users = users;
|
this.users = users;
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
this.frame = frame;
|
this.frame = frame;
|
||||||
this.timeSlotNb = timeSlotNb;
|
|
||||||
this.subCarrierNb = subCarrierNb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateBandwidth(int ticks) {
|
public void updateBandwidth(int ticks) {
|
||||||
int n = 200;
|
int m = 200;
|
||||||
int timeInterval = 50 + random.nextInt(51);
|
|
||||||
for(User user : users) {
|
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
|
// On régénère le tableau de débits toutes les 50 ms
|
||||||
if(ticks % 50 == 0){
|
if(ticks % 50 == 0){
|
||||||
user.generateBandwidth();
|
user.generateBandwidth();
|
||||||
}
|
}
|
||||||
|
|
||||||
// On régénère les sources toutes les 50-100 ms
|
|
||||||
if(ticks % timeInterval == 0){
|
|
||||||
timeInterval = 50 + random.nextInt(51);
|
|
||||||
n = user.createPackets(n, ticks);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
// TODO insert new UR
|
// TODO insert new UR
|
||||||
for(int i = 0; i < timeSlotNb; i++) {
|
for(int i = 0; i < timeSlotNb; i++) {
|
||||||
@ -70,8 +60,8 @@ public class Cell {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void schedule() {
|
public void schedule(int tick) {
|
||||||
scheduler.scheduling();
|
scheduler.scheduling(tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceBlock[][] getFrame() {
|
public ResourceBlock[][] getFrame() {
|
||||||
@ -85,4 +75,12 @@ public class Cell {
|
|||||||
public static int getSubCarrierNb() {
|
public static int getSubCarrierNb() {
|
||||||
return subCarrierNb;
|
return subCarrierNb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setTimeSlotNb(int timeSlotNb) {
|
||||||
|
Cell.timeSlotNb = timeSlotNb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setSubCarrierNb(int subCarrierNb) {
|
||||||
|
Cell.subCarrierNb = subCarrierNb;
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,20 +4,25 @@ import fr.ntr.scheduler.MaxSNR;
|
|||||||
import fr.ntr.scheduler.RoundRobin;
|
import fr.ntr.scheduler.RoundRobin;
|
||||||
import fr.ntr.scheduler.Scheduler;
|
import fr.ntr.scheduler.Scheduler;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
if(args.length == 2) {
|
|
||||||
|
|
||||||
|
if(args.length == 2) {
|
||||||
int numberOfTicks; // Nombre de ticks de la simulation -> durée de la simulation
|
int numberOfTicks; // Nombre de ticks de la simulation -> durée de la simulation
|
||||||
int maximumLoad; // Nombre maximal d'utilisateurs dans le système
|
int maximumLoad; // Nombre maximal d'utilisateurs dans le système
|
||||||
|
|
||||||
//TODO make this cleanly
|
//TODO make this cleanly
|
||||||
boolean reuse3=false;//reuse 1 par def sinon reuse 3
|
boolean reuse3=false; //reuse 1 par def sinon reuse 3
|
||||||
int nbcell = 2; //nombre de cellule que l'on va utilise
|
int nbcell = 2; //nombre de cellules que l'on va utilise
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -31,29 +36,36 @@ public class Main {
|
|||||||
}
|
}
|
||||||
int timeSlotNb = 2;
|
int timeSlotNb = 2;
|
||||||
int subCarrierNb = 100;
|
int subCarrierNb = 100;
|
||||||
for(int i = 2; i < maximumLoad; i += 2) {
|
File folder = new File("export");
|
||||||
List<User> users = generateUsers(i, timeSlotNb, subCarrierNb);
|
if(!folder.exists() && !folder.mkdir()) {
|
||||||
|
System.err.println("Cannot create export folder");
|
||||||
|
System.exit(1);
|
||||||
|
|
||||||
//reuse choise
|
|
||||||
ResourceBlock[][] frame;
|
|
||||||
if(reuse3){
|
|
||||||
frame = new ResourceBlock[timeSlotNb][subCarrierNb/nbcell];
|
|
||||||
} else {
|
|
||||||
frame = new ResourceBlock[timeSlotNb][subCarrierNb];
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO : changes schedulers
|
|
||||||
Scheduler schedulerCell1 = new MaxSNR(frame, users);
|
|
||||||
Scheduler schedulerCell2 = new MaxSNR(frame, users);
|
|
||||||
//TODO : modify cells parameters ?
|
|
||||||
|
|
||||||
Cell cell1 = new Cell(schedulerCell1, frame, users, timeSlotNb, subCarrierNb, 0, 50);
|
|
||||||
Cell cell2 = new Cell(schedulerCell2, frame, users, timeSlotNb, subCarrierNb, 0, 50);
|
|
||||||
AccessPoint accessPoint = new AccessPoint(cell1, cell2);
|
|
||||||
accessPoint.startSimulation(numberOfTicks);
|
|
||||||
}
|
}
|
||||||
}
|
Arrays.stream(Objects.requireNonNull(new File("export").listFiles()))
|
||||||
else {
|
.filter(File::isFile)
|
||||||
|
.forEach(f -> {
|
||||||
|
if(!f.delete()) {
|
||||||
|
System.err.println("Cannot remove file " + f.getAbsolutePath());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Cell.setTimeSlotNb(timeSlotNb);
|
||||||
|
Cell.setSubCarrierNb(subCarrierNb);
|
||||||
|
try(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];
|
||||||
|
//TODO : changes schedulers
|
||||||
|
Scheduler schedulerCell1 = new MaxSNR(frame, users);
|
||||||
|
Scheduler schedulerCell2 = new MaxSNR(frame, users);
|
||||||
|
|
||||||
|
Cell cell1 = new Cell(schedulerCell1, frame, users);
|
||||||
|
Cell cell2 = new Cell(schedulerCell2, frame, users);
|
||||||
|
AccessPoint accessPoint = new AccessPoint(cell1, cell2);
|
||||||
|
executor.submit(() -> accessPoint.startSimulation(numberOfTicks));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
System.err.println("Please give launch arguments");
|
System.err.println("Please give launch arguments");
|
||||||
System.err.println("gradle run --args=\"<number of ticks> <number of users>\"");
|
System.err.println("gradle run --args=\"<number of ticks> <number of users>\"");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
@ -1,16 +1,21 @@
|
|||||||
package fr.ntr;
|
package fr.ntr;
|
||||||
|
|
||||||
public class Packets {
|
public class Packets {
|
||||||
static final int packetSize = 100;
|
static final int PACKET_SIZE = 100;
|
||||||
private int startTimeSending;
|
private int startTimeSending;
|
||||||
private int endTimeSending;
|
private int endTimeSending;
|
||||||
private int durationSending;
|
private int durationSending;
|
||||||
private double bitsNumberRemaining;
|
private int bitsNumberRemaining;
|
||||||
|
|
||||||
public Packets(int startTimeSending){
|
public Packets(int startTimeSending){
|
||||||
|
this.bitsNumberRemaining = PACKET_SIZE;
|
||||||
this.startTimeSending = startTimeSending;
|
this.startTimeSending = startTimeSending;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getBitsNumberRemaining() {
|
||||||
|
return bitsNumberRemaining;
|
||||||
|
}
|
||||||
|
|
||||||
public int getStartTimeSending() {
|
public int getStartTimeSending() {
|
||||||
return startTimeSending;
|
return startTimeSending;
|
||||||
}
|
}
|
||||||
@ -24,17 +29,20 @@ public class Packets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setEndTimeSending(int endTimeSending) {
|
public void setEndTimeSending(int endTimeSending) {
|
||||||
this.endTimeSending = endTimeSending;
|
this.endTimeSending = endTimeSending+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDurationSending(){
|
public void setDurationSending(int ticks){
|
||||||
int durationSending = endTimeSending - startTimeSending;
|
this.durationSending = ticks - startTimeSending;
|
||||||
this.durationSending = durationSending;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDurationSending() {
|
public int getDurationSending() {
|
||||||
return durationSending;
|
return durationSending;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void decreaseBitsNumberRemaining(int d) {
|
||||||
|
this.bitsNumberRemaining -= d;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -11,6 +11,9 @@ public class User {
|
|||||||
private final List<Packets> packetsToSend;
|
private final List<Packets> packetsToSend;
|
||||||
private final List<Packets> packetsSent;
|
private final List<Packets> packetsSent;
|
||||||
private int leftForNextSource;
|
private int leftForNextSource;
|
||||||
|
private int timeInterval = 1;
|
||||||
|
|
||||||
|
private int mbis;
|
||||||
|
|
||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
|
|
||||||
@ -23,46 +26,38 @@ public class User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void generateBandwidth() {
|
public void generateBandwidth() {
|
||||||
|
|
||||||
for(int y = 0; y < bandwidthTable[0].length; y++) {
|
for(int y = 0; y < bandwidthTable[0].length; y++) {
|
||||||
double random = this.random.nextDouble();
|
double rand = this.random.nextDouble();
|
||||||
for(int x = 0; x < bandwidthTable.length; x++) {
|
double h = 1 * Math.sqrt(-2 * Math.log(1 - rand));
|
||||||
double h = 1 * Math.sqrt(-2 * Math.log(1 - random));
|
double gain = h * h * Math.pow(10, rand * 1/10) * Math.pow(1 / this.distance, 3.5);
|
||||||
double gain = h * Math.pow(10, random * 1/10) * Math.pow(1 / this.distance, 3.5);
|
double spectralEfficiency = (20 * gain) / (15000 * (3.9*Math.pow(10, -21)));
|
||||||
double spectralEfficiency = (20 * gain) / (15000 * (3.9*Math.pow(10, -21)));
|
double mkn = Math.log(1 + spectralEfficiency) / Math.log(2);
|
||||||
double mkn = Math.log(1 + spectralEfficiency) / Math.log(2);
|
this.bandwidthTable[0][y] = mkn;
|
||||||
this.bandwidthTable[x][y] = mkn;
|
this.bandwidthTable[1][y] = mkn;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param m un truc
|
* @param m
|
||||||
* @param ticks qui va définir le temps auquel a été créé un paquet
|
* @param ticks qui va définir le temps auquel a été créé un paquet
|
||||||
* @return mbis
|
|
||||||
*/
|
*/
|
||||||
public int createPackets(int m, int ticks) {
|
public void createPackets(int m, int ticks) {
|
||||||
Random random = new Random();
|
timeInterval--;
|
||||||
// On tire un nombre entre 0 et 2 * m
|
if(timeInterval == 0) {
|
||||||
int mbis = m == 0 ? 0 : random.nextInt(2 * (m + this.leftForNextSource));
|
timeInterval = random.nextInt(50, 101);
|
||||||
// On calcule le nombre de paquets qu'on peut transmettre
|
// On tire un nombre entre 0 et 2 * m
|
||||||
int nbPacketsToSend = mbis / Packets.packetSize;
|
mbis = random.nextInt(1, 2 * m + 1) ;
|
||||||
// On conserve le nombre de bits restants pour la prochaine génération
|
|
||||||
this.leftForNextSource = mbis % Packets.packetSize;
|
|
||||||
// On crée les paquets
|
|
||||||
for(int i = 0; i < nbPacketsToSend; i++){
|
|
||||||
this.packetsToSend.add(new Packets(ticks));
|
|
||||||
}
|
|
||||||
return mbis;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
}
|
||||||
* Calcul délais de transmission des paquets
|
// On calcule le nombre de paquets qu'on peut transmettre
|
||||||
*/
|
int bitsToSend = random.nextInt(2 * mbis + 1) + this.leftForNextSource;
|
||||||
public void computeTimeSending() {
|
int nbPacketsToSend = bitsToSend / Packets.PACKET_SIZE;
|
||||||
for(Packets p : packetsToSend){
|
// On conserve le nombre de bits restants pour la prochaine génération
|
||||||
p.setDurationSending();
|
this.leftForNextSource = bitsToSend % Packets.PACKET_SIZE;
|
||||||
|
// On crée les paquets
|
||||||
|
for(int i = 0; i < nbPacketsToSend; i++) {
|
||||||
|
this.packetsToSend.add(new Packets(ticks));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,33 +15,28 @@ public class MaxSNR extends Scheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void scheduling() {
|
public void scheduling(int ticks) {
|
||||||
User userMax;
|
User userMax;
|
||||||
for(int ts = 0; ts < 2; ts++){
|
for(int ts = 0; ts < 2; ts++){
|
||||||
for(int sp = 0; sp < 100; sp++){
|
for(int sp = 0; sp < 100; sp++){
|
||||||
userMax = selectionUtilisateur(sp, ts, users);
|
userMax = userSelection(ts, sp);
|
||||||
if (userMax.getPacketsToSend().size() != 0) {
|
allocateRessource(userMax, frame, ts, sp, ticks);
|
||||||
userMax.getPacketsSent().add(userMax.getPacketsToSend().get(0));
|
|
||||||
userMax.getPacketsToSend().remove(userMax.getPacketsToSend().get(0));
|
|
||||||
frame[ts][sp].setUser(userMax);
|
|
||||||
frame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Sélectionne le prochain utilisateur en fonction du contexte
|
||||||
* @param ts Time slot (int)
|
* @param ts Time slot (int)
|
||||||
* @param sp Sous porteuse(int)
|
* @param sp Sous porteuse(int)
|
||||||
* @param Users (List<User>)
|
* @return the user with the best bandwidth
|
||||||
* Return
|
|
||||||
*/
|
*/
|
||||||
private User selectionUtilisateur(int sp, int ts, List<User> Users) {
|
private User userSelection(int ts, int sp) {
|
||||||
double MaxSnr = 0.0;
|
double maxSnr = 0.0;
|
||||||
User userMax = null;
|
User userMax = null;
|
||||||
for(User u: Users){
|
for(User u: users){
|
||||||
if (MaxSnr < u.getBandwidthTable()[ts][sp]){
|
if (maxSnr < u.getBandwidthTable()[ts][sp]) {
|
||||||
MaxSnr = u.getBandwidthTable()[ts][sp];
|
maxSnr = u.getBandwidthTable()[ts][sp];
|
||||||
userMax = u;
|
userMax = u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package fr.ntr.scheduler;
|
package fr.ntr.scheduler;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import fr.ntr.ResourceBlock;
|
import fr.ntr.ResourceBlock;
|
||||||
@ -7,29 +8,52 @@ import fr.ntr.User;
|
|||||||
|
|
||||||
public class ProportionalFair extends Scheduler {
|
public class ProportionalFair extends Scheduler {
|
||||||
|
|
||||||
private final String name;
|
|
||||||
private final List<User> users;
|
private final List<User> users;
|
||||||
|
|
||||||
private final ResourceBlock[][] frame;
|
private final ResourceBlock[][] frame;
|
||||||
|
|
||||||
public ProportionalFair(String name, ResourceBlock[][] frame, List<User> users) {
|
public ProportionalFair(ResourceBlock[][] frame, List<User> users) {
|
||||||
this.name = name;
|
|
||||||
this.frame = frame;
|
this.frame = frame;
|
||||||
this.users = users;
|
this.users = users;
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public void scheduling() {
|
|
||||||
}
|
|
||||||
|
|
||||||
private void selectionUtilisateur(int Ts, int Sp, List<User> Users) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void TraitementDonnees() {
|
public void scheduling(int ticks) {
|
||||||
// TODO Auto-generated method stub
|
ArrayList<Double> averageBandwiths = new ArrayList<Double>();
|
||||||
|
for(User u : users){
|
||||||
|
double avg = 0d;
|
||||||
|
double[][] bandwidthTable = u.getBandwidthTable();
|
||||||
|
for (double[] doubles : bandwidthTable) {
|
||||||
|
for (double aDouble : doubles) {
|
||||||
|
avg += aDouble;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
avg = avg / (bandwidthTable.length * bandwidthTable[0].length);
|
||||||
|
averageBandwiths.add(avg);
|
||||||
}
|
}
|
||||||
|
for(int ts = 0; ts < 2; ts++){
|
||||||
|
for(int sp = 0; sp < 100; sp++){
|
||||||
|
User selectedUser = userSelection(ts, sp, users, averageBandwiths);
|
||||||
|
allocateRessource(selectedUser, frame, ts, sp, ticks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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++){
|
||||||
|
User u = users.get(i);
|
||||||
|
double mkn = u.getBandwidthTable()[ts][sp];
|
||||||
|
double averageMkn = averageBandwiths.get(i);
|
||||||
|
double pf = mkn / averageMkn;
|
||||||
|
if (PF < pf){
|
||||||
|
PF = pf;
|
||||||
|
selectedUser = u;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return selectedUser;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package fr.ntr.scheduler;
|
package fr.ntr.scheduler;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import fr.ntr.Cell;
|
import fr.ntr.Cell;
|
||||||
import fr.ntr.ResourceBlock;
|
import fr.ntr.ResourceBlock;
|
||||||
@ -9,13 +10,10 @@ import fr.ntr.User;
|
|||||||
|
|
||||||
public class RoundRobin extends Scheduler {
|
public class RoundRobin extends Scheduler {
|
||||||
|
|
||||||
private int index;
|
|
||||||
|
|
||||||
private final List<User> users;
|
private final List<User> users;
|
||||||
private final ResourceBlock[][] frame;
|
private final ResourceBlock[][] frame;
|
||||||
|
|
||||||
public RoundRobin(int index, ResourceBlock[][] frame, List<User> users) {
|
public RoundRobin(ResourceBlock[][] frame, List<User> users) {
|
||||||
this.index = index;
|
|
||||||
this.frame = frame;
|
this.frame = frame;
|
||||||
this.users = users;
|
this.users = users;
|
||||||
}
|
}
|
||||||
@ -26,43 +24,30 @@ public class RoundRobin extends Scheduler {
|
|||||||
* Return
|
* Return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void scheduling() {
|
public void scheduling(int ticks) {
|
||||||
//selection aleatoire du premier utilisateur
|
List<User> userCopy = users.stream().filter(u -> !u.getPacketsToSend().isEmpty()).collect(Collectors.toList());
|
||||||
Random random = new Random();
|
|
||||||
index = random.nextInt(users.size());
|
|
||||||
|
|
||||||
//Pour chaque time slot et sous porteuses
|
//Pour chaque time slot et sous porteuses
|
||||||
for (int ts = 0; ts < Cell.getTimeSlotNb(); ts++) {
|
loop: for (int ts = 0; ts < Cell.getTimeSlotNb(); ts++) {
|
||||||
for(int sp = 0; sp < Cell.getSubCarrierNb(); sp++) {
|
for(int sp = 0; sp < Cell.getSubCarrierNb(); sp++) {
|
||||||
if (users.get(index).getPacketsToSend().size() != 0) {
|
if(userCopy.isEmpty()) {
|
||||||
// on enlève le packet transmis de la liste
|
break loop;
|
||||||
// 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);
|
|
||||||
frame[ts][sp].setUser(user);
|
|
||||||
frame[ts][sp].setBandwidth(user.getBandwidthTable()[ts][sp]);
|
|
||||||
}
|
}
|
||||||
|
User userSelected = userSelection(userCopy);
|
||||||
|
allocateRessource(userSelected, frame, ts, sp, ticks);
|
||||||
|
if(!userSelected.getPacketsToSend().isEmpty())
|
||||||
|
userCopy.add(userSelected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ts Time slot (int)
|
* Entry Time slot (int), Sous porteuse(int), and users ( List<User>)
|
||||||
* @param sp Sous porteuse(int)
|
|
||||||
* Return the user in function of TS and SP selected
|
* Return the user in function of TS and SP selected
|
||||||
|
*
|
||||||
|
* @return the next user which have something to send
|
||||||
*/
|
*/
|
||||||
private User UserSelection(int ts, int sp) {
|
private User userSelection(List<User> users) {
|
||||||
//compte le nombre de bloc attribue
|
return users.remove(0);
|
||||||
for (int i = 0; i < ts; i++){
|
|
||||||
for (int j = 0; j < sp; j++) {
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//on retourne l'utilisateur
|
|
||||||
return users.get(index%(users.size() - 1));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package fr.ntr.scheduler;
|
package fr.ntr.scheduler;
|
||||||
|
|
||||||
|
import fr.ntr.Packets;
|
||||||
|
import fr.ntr.ResourceBlock;
|
||||||
|
import fr.ntr.User;
|
||||||
|
|
||||||
public abstract class Scheduler {
|
public abstract class Scheduler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -7,8 +11,24 @@ public abstract class Scheduler {
|
|||||||
* Rempli la trame avec les utilisateurs
|
* Rempli la trame avec les utilisateurs
|
||||||
* Return
|
* Return
|
||||||
*/
|
*/
|
||||||
public abstract void scheduling();
|
public abstract void scheduling(int ticks);
|
||||||
protected void TraitementDonnees() {
|
|
||||||
|
|
||||||
|
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){
|
||||||
|
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]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user