Compare commits
4 Commits
ajout_cell
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
431248b0a4 | ||
|
cc73eb8a93 | ||
|
376c76b17c | ||
|
5b695174a6 |
@ -11,7 +11,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
run {
|
run {
|
||||||
args = ["10000", "40"]
|
args = ["10000", "17"]
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
|
45
plot/main.py
45
plot/main.py
@ -3,7 +3,7 @@ import matplotlib.pyplot as plt
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
nb_files = os.listdir("PF")
|
nb_files = os.listdir(".." + os.sep + "export")
|
||||||
|
|
||||||
size = len(nb_files)
|
size = len(nb_files)
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ def rb_available(arr: list[tuple[int, np.ndarray]]) -> np.ndarray:
|
|||||||
nb = 0
|
nb = 0
|
||||||
for nb_users, data in arr:
|
for nb_users, data in arr:
|
||||||
available[nb, 0] = nb_users
|
available[nb, 0] = nb_users
|
||||||
available[nb, 1] = (data.shape[0] / (200 * 20000)) * 100
|
available[nb, 1] = (data.shape[0] / (200 * 10000)) * 100
|
||||||
nb += 1
|
nb += 1
|
||||||
return available
|
return available
|
||||||
|
|
||||||
@ -45,7 +45,6 @@ def delay(arr: list[tuple[int, np.ndarray]]) -> np.ndarray:
|
|||||||
nb += 1
|
nb += 1
|
||||||
return delays
|
return delays
|
||||||
|
|
||||||
|
|
||||||
def rb_allocate_distance(arr: list[tuple[int, np.ndarray]], distance) -> np.ndarray:
|
def rb_allocate_distance(arr: list[tuple[int, np.ndarray]], distance) -> np.ndarray:
|
||||||
allocate = np.zeros((size, 2))
|
allocate = np.zeros((size, 2))
|
||||||
nb = 0
|
nb = 0
|
||||||
@ -57,60 +56,54 @@ def rb_allocate_distance(arr: list[tuple[int, np.ndarray]], distance) -> np.ndar
|
|||||||
n+=1
|
n+=1
|
||||||
allocate[nb, 0] = nb_users
|
allocate[nb, 0] = nb_users
|
||||||
allocate[nb, 1] = n
|
allocate[nb, 1] = n
|
||||||
# print(n/data.shape[0])
|
print(n/data.shape[0])
|
||||||
nb += 1
|
nb += 1
|
||||||
return allocate
|
return allocate
|
||||||
|
|
||||||
|
|
||||||
np_arr: list[tuple[int, np.ndarray]] = list()
|
np_arr: list[tuple[int, np.ndarray]] = list()
|
||||||
for i in nb_files:
|
for i in nb_files:
|
||||||
np_arr.append((int(i.split(".")[0]), pd.read_csv("PF" + os.sep + i, delimiter=';').to_numpy()))
|
np_arr.append((int(i.split(".")[0]), pd.read_csv(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy()))
|
||||||
|
|
||||||
averages = mean_mkn(np_arr)
|
averages = mean_mkn(np_arr)
|
||||||
available = rb_available(np_arr)
|
available = rb_available(np_arr)
|
||||||
|
|
||||||
allocate_lp1 = rb_allocate_distance(np_arr, 100)
|
allocate_lp1 = rb_allocate_distance(np_arr, 200)
|
||||||
allocate_lp2 = rb_allocate_distance(np_arr, 500)
|
allocate_lp2 = rb_allocate_distance(np_arr, 400)
|
||||||
allocate_total = allocate_lp1[:, 1] + allocate_lp2[:, 1]
|
allocate_total = allocate_lp1[:, 1] + allocate_lp2[:, 1]
|
||||||
|
|
||||||
|
print(allocate_total)
|
||||||
|
|
||||||
delays = delay(np_arr)
|
delays = delay(np_arr)
|
||||||
delays.sort(axis=0)
|
delays.sort(axis=0)
|
||||||
# Data for plotting
|
# Data for plotting
|
||||||
averages.sort(axis=0)
|
averages.sort(axis=0)
|
||||||
available.sort(axis=0)
|
|
||||||
|
|
||||||
del np_arr
|
|
||||||
|
|
||||||
fig, ax = plt.subplots(2, 2)
|
fig, ax = plt.subplots(2, 2)
|
||||||
ax[0, 0].plot(averages[:, 0], averages[:, 1], marker="o")
|
ax[0, 0].scatter(averages[:, 0], averages[:, 1])
|
||||||
ax[0, 0].set(xlabel='number of users', ylabel='% Spectral efficiency', title='Spectral efficiency PF')
|
ax[0, 0].set(xlabel='number of users', ylabel='Efficacité spectrale', title='Efficacité spectrale')
|
||||||
ax[0, 0].grid()
|
ax[0, 0].grid()
|
||||||
ax[0, 0].set_ylim([0, 40])
|
|
||||||
|
|
||||||
ax[0, 1].plot(available[:, 0], available[:, 1], marker="o")
|
ax[0, 1].scatter(available[:, 0], available[:, 1])
|
||||||
ax[0, 1].set(xlabel='number of users', ylabel=' % RB used', title='Percentage of RB used PF')
|
ax[0, 1].set(xlabel='number of users', ylabel='RB utilisés', title='Pourcentage de RB utilisés')
|
||||||
ax[0, 1].grid()
|
ax[0, 1].grid()
|
||||||
ax[0, 1].set_ylim([0, 105])
|
|
||||||
|
|
||||||
ax[1, 0].plot(delays[:, 0], delays[:, 1], marker="o")
|
ax[1, 0].scatter(delays[:, 0], delays[:, 1])
|
||||||
ax[1, 0].set(xlabel='number of users', ylabel='delay(ms)', title='Delay PF')
|
ax[1, 0].set(xlabel='number of users', ylabel='delays(ms)', title='Delay')
|
||||||
ax[1, 0].grid()
|
ax[1, 0].grid()
|
||||||
|
|
||||||
available.sort(axis=0)
|
available.sort(axis=0)
|
||||||
|
|
||||||
#ax[1, 1].scatter(allocate_lp1[:, 0], (allocate_lp1[:, 1]/(allocate_lp1[:, 1])+allocate_lp2[:, 1])*100)
|
#ax[1, 1].scatter(allocate_lp1[:, 0], (allocate_lp1[:, 1]/(allocate_lp1[:, 1])+allocate_lp2[:, 1])*100)
|
||||||
|
|
||||||
ax[1, 1].plot(available[:, 0], (allocate_lp1[:, 1]/(allocate_lp1[:, 1]+allocate_lp2[:, 1])*100), label="100 meters group")
|
ax[1, 1].plot(available[:, 0], (allocate_lp1[:, 1]/(allocate_lp1[:, 1]+allocate_lp2[:, 1])*100))
|
||||||
|
|
||||||
#ax[1, 1].scatter(allocate_lp2[:, 0], (allocate_lp2[:, 1]/(allocate_lp1[:, 1])+allocate_lp2[:, 1])*100)
|
#ax[1, 1].scatter(allocate_lp2[:, 0], (allocate_lp2[:, 1]/(allocate_lp1[:, 1])+allocate_lp2[:, 1])*100)
|
||||||
|
|
||||||
#ax[1, 1].plot(available[:, 0], available[:, 1], marker="o", label="RB used")
|
ax[1, 1].plot(available[:, 0], (allocate_lp2[:, 1]/(allocate_lp1[:, 1]+allocate_lp2[:, 1])*100))
|
||||||
|
|
||||||
ax[1, 1].plot(available[:, 0], (allocate_lp2[:, 1]/(allocate_lp1[:, 1]+allocate_lp2[:, 1])*100), label="500 meters group")
|
ax[1, 1].set(xlabel='number of users', ylabel='RB utilisés proche/loin/total', title='RB utilisés distance')
|
||||||
|
|
||||||
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].grid()
|
||||||
ax[1, 1].set_ylim([0, 105])
|
|
||||||
ax[1, 1].legend(loc="upper left")
|
|
||||||
|
|
||||||
plt.show()
|
plt.ylim(0, 100)
|
||||||
|
plt.show()
|
@ -1,61 +1,139 @@
|
|||||||
package fr.ntr;
|
package fr.ntr;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.ntr.scheduler.Scheduler;
|
||||||
|
|
||||||
public class AccessPoint {
|
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) {
|
||||||
private final boolean reuse3;
|
this.users = users;
|
||||||
|
this.scheduler = scheduler;
|
||||||
public AccessPoint (boolean reuse3, Cell... cells){
|
this.frame = frame;
|
||||||
this.reuse3 = reuse3;
|
|
||||||
this.cells = Arrays.stream(cells).toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lancer la simulation
|
* Lancer la simulation
|
||||||
* @param duration
|
* @param duration
|
||||||
*/
|
*/
|
||||||
public void startSimulation (int duration) {
|
public void startSimulation(int duration) {
|
||||||
|
try{
|
||||||
|
this.outputDataFile = new FileOutputStream("export" + File.separator + this.users.size() + ".csv", true);
|
||||||
|
outputDataFile.write("tick;x;y;user;bandwidth;delay;distance;\n".getBytes());
|
||||||
|
} catch(IOException e) {
|
||||||
|
System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage());
|
||||||
|
System.exit(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (int ticks = 0; ticks < duration; ++ticks) {
|
for (int ticks = 0; ticks < duration; ++ticks) {
|
||||||
// Simulation
|
// Simulation
|
||||||
cells.forEach(Cell::reset);
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int finalTicks = ticks;
|
int totalBits = 0;
|
||||||
cells.forEach(c -> c.updateBandwidth(finalTicks));
|
for(User u: this.users){
|
||||||
cells.forEach(Cell::preScheduling);
|
totalBits += u.totalbits;
|
||||||
for(int ts = 0; ts < Cell.getTimeSlotNb(); ts++) {
|
}
|
||||||
for (int sp = 0; sp < (reuse3 ? Cell.getSubCarrierNb() / 2 : Cell.getSubCarrierNb()); sp++) {
|
System.out.println("total bits / nb users = "+ (((float)totalBits)/this.users.size()/10_000));
|
||||||
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);
|
private void updateBandwidth(int ticks) {
|
||||||
//FIXME pour avoir 20
|
int m = 200;
|
||||||
boolean haveInterference = user1 == user2 && user1 != null;
|
for(User user : users) {
|
||||||
int finalTs = ts;
|
// On régénère les sources toutes les 50-100 ms
|
||||||
int finalSp = sp;
|
user.createPackets(m, ticks);
|
||||||
cells.forEach(c -> c.consumeResource(finalTicks, finalTs, finalSp, haveInterference));
|
// On régénère le tableau de débits toutes les 50 ms
|
||||||
cells.get(0).postScheduling(user1);
|
if(ticks % 50 == 0){
|
||||||
cells.get(1).postScheduling(user2);
|
user.generateBandwidth();
|
||||||
} else {
|
}
|
||||||
cells.get(0).consumeResource(ticks, ts, sp, false);
|
|
||||||
cells.get(0).postScheduling(user1);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,155 +0,0 @@
|
|||||||
package fr.ntr;
|
|
||||||
|
|
||||||
import fr.ntr.scheduler.Scheduler;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class Cell {
|
|
||||||
|
|
||||||
private final List<User> users;
|
|
||||||
/**
|
|
||||||
* Scheduler utilisé par la cellule
|
|
||||||
*/
|
|
||||||
private final Scheduler scheduler;
|
|
||||||
/**
|
|
||||||
* Nombre de slots
|
|
||||||
*/
|
|
||||||
private static int timeSlotNb;
|
|
||||||
/**
|
|
||||||
* Nombre de sous-porteuses
|
|
||||||
*/
|
|
||||||
private static int subCarrierNb;
|
|
||||||
/**
|
|
||||||
* Trame
|
|
||||||
*/
|
|
||||||
private final ResourceBlock[][] frame;
|
|
||||||
private final FileOutputStream outputDataFile;
|
|
||||||
private final int id;
|
|
||||||
|
|
||||||
public Cell(int id, Scheduler scheduler, ResourceBlock[][] frame, List<User> users, FileOutputStream fileOutputStream) {
|
|
||||||
this.id = id;
|
|
||||||
this.users = users;
|
|
||||||
this.scheduler = scheduler;
|
|
||||||
this.frame = frame;
|
|
||||||
this.outputDataFile = fileOutputStream;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateBandwidth(int ticks) {
|
|
||||||
int m = 200;
|
|
||||||
for(User user : users) {
|
|
||||||
// On régénère les sources toutes les 50-100 ms
|
|
||||||
user.createPackets(m, ticks);
|
|
||||||
// On régénère le tableau de débits toutes les 50 ms
|
|
||||||
if(ticks % 50 == 0){
|
|
||||||
user.generateBandwidth();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void reset() {
|
|
||||||
// TODO insert new UR
|
|
||||||
for(int i = 0; i < timeSlotNb; i++) {
|
|
||||||
for(int j = 0; j < subCarrierNb; j++) {
|
|
||||||
frame[i][j] = new ResourceBlock(0.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void preScheduling() {
|
|
||||||
scheduler.preScheduling();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void postScheduling(User userSelected) {
|
|
||||||
scheduler.postScheduling(userSelected);
|
|
||||||
}
|
|
||||||
|
|
||||||
public User schedule(int tick, int ts, int sp) {
|
|
||||||
return scheduler.scheduling(tick, ts, sp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void consumeResource(int tick, int ts, int sp, boolean haveInterference) {
|
|
||||||
ResourceBlock rb = frame[ts][sp];
|
|
||||||
User user = rb.getUser();
|
|
||||||
if(user != null && !user.getPacketsToSend().isEmpty()) {
|
|
||||||
Packets p = user.getPacketsToSend().get(0);
|
|
||||||
rb.setBandwidth(updateBandwidth(haveInterference, rb));
|
|
||||||
p.decreaseBitsNumberRemaining((int) rb.getBandwidth());
|
|
||||||
if(p.getBitsNumberRemaining() <= 0) {
|
|
||||||
if(tick == 0){
|
|
||||||
p.setDurationSending(1);
|
|
||||||
}else {
|
|
||||||
p.setDurationSending(tick);
|
|
||||||
}
|
|
||||||
user.getPacketsSent().add(p);
|
|
||||||
user.getPacketsToSend().remove(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private double updateBandwidth(boolean haveInterference, ResourceBlock rb) {
|
|
||||||
if(haveInterference) {
|
|
||||||
if(rb.getUser().getDistance() < 200d) {
|
|
||||||
// User proche
|
|
||||||
return rb.getBandwidth() / 2;
|
|
||||||
}
|
|
||||||
// User loin
|
|
||||||
return rb.getBandwidth() / 4;
|
|
||||||
} else {
|
|
||||||
return rb.getBandwidth();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void analyseData(int tick) throws IOException {
|
|
||||||
double delayAverage = 0.0;
|
|
||||||
int nbPacketsSent = 0;
|
|
||||||
for(User u: users){
|
|
||||||
List<Packets> packets = u.getPacketsSent();
|
|
||||||
nbPacketsSent += packets.size();
|
|
||||||
for (Packets p: packets){
|
|
||||||
delayAverage += p.getDurationSending();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
delayAverage = delayAverage/nbPacketsSent;
|
|
||||||
for(int i = 0; i < frame.length; i++) {
|
|
||||||
for(int j = 0; j < frame[i].length; j++) {
|
|
||||||
ResourceBlock ur = frame[i][j];
|
|
||||||
if(ur.getUser() != null) {
|
|
||||||
String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";" + delayAverage +";" + ur.getUser().getDistance() + ";" + id + "\n");
|
|
||||||
try{
|
|
||||||
outputDataFile.write(data.getBytes());
|
|
||||||
}catch(IOException e){
|
|
||||||
System.err.println("Cannot write the data in the output file");
|
|
||||||
System.exit(1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResourceBlock[][] getFrame() {
|
|
||||||
return frame;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getTimeSlotNb() {
|
|
||||||
return timeSlotNb;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getSubCarrierNb() {
|
|
||||||
return subCarrierNb;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setTimeSlotNb(int timeSlotNb) {
|
|
||||||
Cell.timeSlotNb = timeSlotNb;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setSubCarrierNb(int subCarrierNb) {
|
|
||||||
Cell.subCarrierNb = subCarrierNb;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +1,26 @@
|
|||||||
package fr.ntr;
|
package fr.ntr;
|
||||||
|
|
||||||
|
import fr.ntr.scheduler.MaxSNR;
|
||||||
|
import fr.ntr.scheduler.ProportionalFair;
|
||||||
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.io.File;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
//instancie numberOfTicks et maximumLoad
|
|
||||||
try {
|
try {
|
||||||
numberOfTicks = Integer.parseInt(args[0]);
|
numberOfTicks = Integer.parseInt(args[0]);
|
||||||
maximumLoad = Integer.parseInt(args[1]);
|
maximumLoad = Integer.parseInt(args[1]);
|
||||||
@ -32,19 +30,13 @@ public class Main {
|
|||||||
System.exit(1);
|
System.exit(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//instancie nombre de time slots et sous-porteuses
|
|
||||||
int timeSlotNb = 2;
|
int timeSlotNb = 2;
|
||||||
//nb subcarrier si reuse1 ou reuse3
|
|
||||||
int subCarrierNb = 100;
|
int subCarrierNb = 100;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//préparation pour exportation des données
|
|
||||||
File folder = new File("export");
|
File folder = new File("export");
|
||||||
if (!folder.exists() && !folder.mkdir()) {
|
if(!folder.exists() && !folder.mkdir()) {
|
||||||
System.err.println("Cannot create export folder");
|
System.err.println("Cannot create export folder");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
|
||||||
}
|
}
|
||||||
Arrays.stream(Objects.requireNonNull(new File("export").listFiles()))
|
Arrays.stream(Objects.requireNonNull(new File("export").listFiles()))
|
||||||
.filter(File::isFile)
|
.filter(File::isFile)
|
||||||
@ -53,66 +45,27 @@ public class Main {
|
|||||||
System.err.println("Cannot remove file " + f.getAbsolutePath());
|
System.err.println("Cannot remove file " + f.getAbsolutePath());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
AccessPoint.setTimeSlotNb(timeSlotNb);
|
||||||
//instanciation des cellules, schedulers et utilisateurs
|
AccessPoint.setSubCarrierNb(subCarrierNb);
|
||||||
Cell.setTimeSlotNb(timeSlotNb);
|
|
||||||
Cell.setSubCarrierNb(subCarrierNb);
|
|
||||||
ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||||
for (int i = 2; i <= maximumLoad; i += 2) {
|
for(int i = 2; i <= maximumLoad; i += 2) {
|
||||||
//génération des utilisateurs
|
List<User> users = generateUsers(i, timeSlotNb, subCarrierNb);
|
||||||
List<User> usersCell1 = generateUsers(i, timeSlotNb, subCarrierNb);
|
ResourceBlock[][] frame = new ResourceBlock[timeSlotNb][subCarrierNb];
|
||||||
List<User> usersCell2 = generateUsers(i, timeSlotNb, subCarrierNb);
|
//Scheduler scheduler = new MaxSNR(frame, users);
|
||||||
//copie de 1/4 des utilisateurs de cell1 vers cell2
|
//Scheduler scheduler = new ProportionalFair(frame, users);
|
||||||
Random r = new Random();
|
Scheduler scheduler = new RoundRobin(frame, users);
|
||||||
for(int j = 0; j < i/4; j++){
|
AccessPoint accessPoint = new AccessPoint(scheduler, frame, users);
|
||||||
int idxCopy = r.nextInt(i);
|
executor.submit(() -> accessPoint.startSimulation(numberOfTicks));
|
||||||
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();
|
executor.shutdown();
|
||||||
try {
|
try {
|
||||||
executor.awaitTermination(5, TimeUnit.MINUTES);
|
if(!executor.awaitTermination(2, TimeUnit.MINUTES)) {
|
||||||
}
|
executor.shutdownNow();
|
||||||
catch (InterruptedException e) {
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
executor.shutdownNow();
|
} else {
|
||||||
|
|
||||||
System.out.println("Executor closed");
|
|
||||||
}
|
|
||||||
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);
|
||||||
@ -122,17 +75,16 @@ public class Main {
|
|||||||
private static List<User> generateUsers(int nbUsers, int timeSlotNb, int subCarrierNb) {
|
private static List<User> generateUsers(int nbUsers, int timeSlotNb, int subCarrierNb) {
|
||||||
List<User> users = new ArrayList<>();
|
List<User> users = new ArrayList<>();
|
||||||
// 2 groupes d'utilisateurs, proches et éloignés
|
// 2 groupes d'utilisateurs, proches et éloignés
|
||||||
int half = nbUsers / 2;
|
double[] distance = { 200d, 400d };
|
||||||
for (int i = 0; i < nbUsers; i++) {
|
for (double v : distance) {
|
||||||
User user;
|
for (int j = 0; j < nbUsers; j++) {
|
||||||
if(i >= half){
|
User user = new User(v, timeSlotNb, subCarrierNb);
|
||||||
user = new User(500d, timeSlotNb, subCarrierNb);
|
users.add(user);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
user = new User(150d, timeSlotNb, subCarrierNb);
|
|
||||||
}
|
|
||||||
users.add(user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -17,16 +17,13 @@ public class ResourceBlock {
|
|||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setBandwidth(double bandwidth) {
|
public void setBandwidth(double bandwidth) {
|
||||||
this.bandwidth = bandwidth;
|
this.bandwidth = bandwidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
public double getBandwidth() {
|
public double getBandwidth() {
|
||||||
return bandwidth;
|
return bandwidth;
|
||||||
|
@ -12,7 +12,9 @@ public class User {
|
|||||||
private final List<Packets> packetsSent;
|
private final List<Packets> packetsSent;
|
||||||
private int leftForNextSource;
|
private int leftForNextSource;
|
||||||
private int timeInterval = 1;
|
private int timeInterval = 1;
|
||||||
|
|
||||||
public int totalbits = 0;
|
public int totalbits = 0;
|
||||||
|
|
||||||
private int mbis;
|
private int mbis;
|
||||||
|
|
||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
@ -45,9 +47,9 @@ public class User {
|
|||||||
public void createPackets(int m, int ticks) {
|
public void createPackets(int m, int ticks) {
|
||||||
timeInterval--;
|
timeInterval--;
|
||||||
if(timeInterval == 0) {
|
if(timeInterval == 0) {
|
||||||
timeInterval = 50 + random.nextInt(52);
|
timeInterval = random.nextInt(2, 102);
|
||||||
// On tire un nombre entre 0 et 2 * m
|
// On tire un nombre entre 0 et 2 * m
|
||||||
mbis = random.nextInt(2 * m + 1) ;
|
mbis = random.nextInt(0, 2 * m + 1) ;
|
||||||
|
|
||||||
}
|
}
|
||||||
// On calcule le nombre de paquets qu'on peut transmettre
|
// On calcule le nombre de paquets qu'on peut transmettre
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package fr.ntr.scheduler;
|
package fr.ntr.scheduler;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import fr.ntr.Cell;
|
import fr.ntr.AccessPoint;
|
||||||
import fr.ntr.ResourceBlock;
|
import fr.ntr.ResourceBlock;
|
||||||
import fr.ntr.User;
|
import fr.ntr.User;
|
||||||
|
|
||||||
@ -9,33 +9,27 @@ public class MaxSNR extends Scheduler {
|
|||||||
|
|
||||||
private final List<User> users;
|
private final List<User> users;
|
||||||
|
|
||||||
public MaxSNR(ResourceBlock[][] myFrame, List<User> users) {
|
private final ResourceBlock[][] frame;
|
||||||
super(myFrame);
|
|
||||||
|
|
||||||
|
public MaxSNR(ResourceBlock[][] frame, List<User> users) {
|
||||||
|
this.frame = frame;
|
||||||
this.users = users;
|
this.users = users;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User scheduling(int ticks, int ts, int sp) {
|
public void scheduling(int ticks) {
|
||||||
User user = userSelection(ts, sp);
|
User userMax;
|
||||||
allocateRessource(user, ts, sp, ticks);
|
for(int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++){
|
||||||
return user;
|
for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++){
|
||||||
|
userMax = userSelection(ts, sp);
|
||||||
}
|
allocateRessource(userMax, frame, ts, sp, ticks);
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public void postScheduling(User userSelected) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void preScheduling() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sélectionne le prochain utilisateur en fonction du contexte
|
* 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
|
* @return the user with the best bandwidth
|
||||||
*/
|
*/
|
||||||
private User userSelection(int ts, int sp) {
|
private User userSelection(int ts, int sp) {
|
||||||
@ -45,6 +39,7 @@ public class MaxSNR extends Scheduler {
|
|||||||
if (!u.getPacketsToSend().isEmpty() && (maxSnr < u.getBandwidthTable()[ts][sp])) {
|
if (!u.getPacketsToSend().isEmpty() && (maxSnr < u.getBandwidthTable()[ts][sp])) {
|
||||||
maxSnr = u.getBandwidthTable()[ts][sp];
|
maxSnr = u.getBandwidthTable()[ts][sp];
|
||||||
userMax = u;
|
userMax = u;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return userMax;
|
return userMax;
|
||||||
|
@ -3,37 +3,35 @@ package fr.ntr.scheduler;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.ntr.AccessPoint;
|
||||||
import fr.ntr.ResourceBlock;
|
import fr.ntr.ResourceBlock;
|
||||||
import fr.ntr.User;
|
import fr.ntr.User;
|
||||||
|
|
||||||
public class ProportionalFair extends Scheduler {
|
public class ProportionalFair extends Scheduler {
|
||||||
|
|
||||||
|
|
||||||
private final List<User> users;
|
private final List<User> users;
|
||||||
|
|
||||||
private ArrayList<Double> averageBandwidth;
|
private final ResourceBlock[][] frame;
|
||||||
|
|
||||||
public ProportionalFair(ResourceBlock[][] myFrame, List<User> users) {
|
public ProportionalFair(ResourceBlock[][] frame, List<User> users) {
|
||||||
super(myFrame);
|
this.frame = frame;
|
||||||
this.users = users;
|
this.users = users;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public User scheduling(int ticks, int ts, int sp) {
|
public void scheduling(int ticks) {
|
||||||
User user = userSelection(ts, sp, users);
|
for(int ts = 0; ts < AccessPoint.getTimeSlotNb(); ts++){
|
||||||
allocateRessource(user, ts, sp, ticks);
|
for(int sp = 0; sp < AccessPoint.getSubCarrierNb(); sp++){
|
||||||
return user;
|
User selectedUser = userSelection(ts, sp, users);
|
||||||
|
allocateRessource(selectedUser, frame, ts, sp, ticks);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private User userSelection(int ts, int sp, List<User> users) {
|
||||||
public void postScheduling(User userSelected) {
|
double PF = 0.0;
|
||||||
|
User selectedUser = null;
|
||||||
}
|
for (User u : users) {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void preScheduling() {
|
|
||||||
averageBandwidth = new ArrayList<>();
|
|
||||||
for(User u : users){
|
|
||||||
double avg = 0d;
|
double avg = 0d;
|
||||||
double[][] bandwidthTable = u.getBandwidthTable();
|
double[][] bandwidthTable = u.getBandwidthTable();
|
||||||
for (double[] doubles : bandwidthTable) {
|
for (double[] doubles : bandwidthTable) {
|
||||||
@ -42,19 +40,9 @@ public class ProportionalFair extends Scheduler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
avg = avg / (bandwidthTable.length * bandwidthTable[0].length);
|
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 mkn = u.getBandwidthTable()[ts][sp];
|
||||||
double averageMkn = averageBandwidth.get(i);
|
double pf = mkn / avg;
|
||||||
double pf = mkn / averageMkn;
|
if (PF < pf) {
|
||||||
if (PF < pf){
|
|
||||||
PF = pf;
|
PF = pf;
|
||||||
selectedUser = u;
|
selectedUser = u;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package fr.ntr.scheduler;
|
package fr.ntr.scheduler;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import fr.ntr.AccessPoint;
|
||||||
import fr.ntr.ResourceBlock;
|
import fr.ntr.ResourceBlock;
|
||||||
import fr.ntr.User;
|
import fr.ntr.User;
|
||||||
|
|
||||||
@ -10,11 +13,10 @@ import fr.ntr.User;
|
|||||||
public class RoundRobin extends Scheduler {
|
public class RoundRobin extends Scheduler {
|
||||||
|
|
||||||
private final List<User> users;
|
private final List<User> users;
|
||||||
private List<User> userCopy;
|
private final ResourceBlock[][] frame;
|
||||||
|
|
||||||
|
public RoundRobin(ResourceBlock[][] frame, List<User> users) {
|
||||||
public RoundRobin(ResourceBlock[][] myFrame, List<User> users) {
|
this.frame = frame;
|
||||||
super(myFrame);
|
|
||||||
this.users = users;
|
this.users = users;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,25 +26,22 @@ public class RoundRobin extends Scheduler {
|
|||||||
* Return
|
* Return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public User scheduling(int ticks, int ts, int sp) {
|
public void scheduling(int ticks) {
|
||||||
if(userCopy.isEmpty()) {
|
List<User> userCopy = users.stream().filter(u -> !u.getPacketsToSend().isEmpty()).collect(Collectors.toList());
|
||||||
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);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,23 +6,28 @@ import fr.ntr.User;
|
|||||||
|
|
||||||
public abstract class Scheduler {
|
public abstract class Scheduler {
|
||||||
|
|
||||||
protected final ResourceBlock[][] myFrame;
|
/**
|
||||||
|
* Entry
|
||||||
|
* Rempli la trame avec les utilisateurs
|
||||||
|
* Return
|
||||||
|
*/
|
||||||
|
public abstract void scheduling(int ticks);
|
||||||
|
|
||||||
public Scheduler(ResourceBlock[][] myFrame) {
|
protected void allocateRessource(User userMax, ResourceBlock[][] frame, int ts, int sp, int ticks) {
|
||||||
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()) {
|
if (userMax != null && !userMax.getPacketsToSend().isEmpty()) {
|
||||||
myFrame[ts][sp].setUser(userMax);
|
Packets p = userMax.getPacketsToSend().get(userMax.getPacketsToSend().size()-1);
|
||||||
myFrame[ts][sp].setBandwidth(userMax.getBandwidthTable()[ts][sp]);
|
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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user