Compare commits
10 Commits
797b2a17f7
...
d114314ba1
Author | SHA1 | Date | |
---|---|---|---|
|
d114314ba1 | ||
|
4f110cc7cb | ||
2307fd2567 | |||
753b1b5ead | |||
519fa92aef | |||
47755c46b7 | |||
0fceb13d48 | |||
825f4f26c7 | |||
54f5c1636f | |||
28d3596eb9 |
59
plot/main.py
59
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,30 +46,71 @@ def delay(arr: list[tuple[int, np.ndarray]]) -> np.ndarray:
|
||||
return delays
|
||||
|
||||
|
||||
def rb_allocate_distance(arr: list[tuple[int, np.ndarray]], distance) -> np.ndarray:
|
||||
allocate = np.zeros((size, 2))
|
||||
nb = 0
|
||||
arr.sort()
|
||||
for nb_users, data in arr:
|
||||
n = 0
|
||||
for x in data[:,6]:
|
||||
if int(x) == distance:
|
||||
n+=1
|
||||
allocate[nb, 0] = nb_users
|
||||
allocate[nb, 1] = n
|
||||
# print(n/data.shape[0])
|
||||
nb += 1
|
||||
return allocate
|
||||
|
||||
|
||||
np_arr: list[tuple[int, np.ndarray]] = list()
|
||||
for i in nb_files:
|
||||
np_arr.append((int(i.split(".")[0]), pd.read_csv(".." + os.sep + "export" + os.sep + i, delimiter=';').to_numpy()))
|
||||
np_arr.append((int(i.split(".")[0]), pd.read_csv("PF" + os.sep + i, delimiter=';').to_numpy()))
|
||||
|
||||
averages = mean_mkn(np_arr)
|
||||
available = rb_available(np_arr)
|
||||
|
||||
allocate_lp1 = rb_allocate_distance(np_arr, 100)
|
||||
allocate_lp2 = rb_allocate_distance(np_arr, 500)
|
||||
allocate_total = allocate_lp1[:, 1] + allocate_lp2[:, 1]
|
||||
|
||||
delays = delay(np_arr)
|
||||
delays.sort(axis=0)
|
||||
# Data for plotting
|
||||
averages.sort(axis=0)
|
||||
available.sort(axis=0)
|
||||
|
||||
del np_arr
|
||||
|
||||
fig, ax = plt.subplots(2, 2)
|
||||
ax[0, 0].scatter(averages[:, 0], averages[:, 1])
|
||||
ax[0, 0].set(xlabel='number of users', ylabel='Efficacité spectrale', title='Efficacité spectrale')
|
||||
ax[0, 0].plot(averages[:, 0], averages[:, 1], marker="o")
|
||||
ax[0, 0].set(xlabel='number of users', ylabel='% Spectral efficiency', title='Spectral efficiency PF')
|
||||
ax[0, 0].grid()
|
||||
ax[0, 0].set_ylim([0, 40])
|
||||
|
||||
ax[0, 1].scatter(available[:, 0], available[:, 1])
|
||||
ax[0, 1].set(xlabel='number of users', ylabel='RB utilisés', title='Pourcentage de RB utilisés')
|
||||
ax[0, 1].plot(available[:, 0], available[:, 1], marker="o")
|
||||
ax[0, 1].set(xlabel='number of users', ylabel=' % RB used', title='Percentage of RB used PF')
|
||||
ax[0, 1].grid()
|
||||
ax[0, 1].set_ylim([0, 105])
|
||||
|
||||
ax[1, 0].scatter(delays[:, 0], delays[:, 1])
|
||||
ax[1, 0].set(xlabel='number of users', ylabel='delays(ms)', title='Delay')
|
||||
ax[1, 0].plot(delays[:, 0], delays[:, 1], marker="o")
|
||||
ax[1, 0].set(xlabel='number of users', ylabel='delay(ms)', title='Delay PF')
|
||||
ax[1, 0].grid()
|
||||
|
||||
available.sort(axis=0)
|
||||
|
||||
#ax[1, 1].scatter(allocate_lp1[:, 0], (allocate_lp1[:, 1]/(allocate_lp1[:, 1])+allocate_lp2[:, 1])*100)
|
||||
|
||||
ax[1, 1].plot(available[:, 0], (allocate_lp1[:, 1]/(allocate_lp1[:, 1]+allocate_lp2[:, 1])*100), label="100 meters group")
|
||||
|
||||
#ax[1, 1].scatter(allocate_lp2[:, 0], (allocate_lp2[:, 1]/(allocate_lp1[:, 1])+allocate_lp2[:, 1])*100)
|
||||
|
||||
#ax[1, 1].plot(available[:, 0], available[:, 1], marker="o", label="RB used")
|
||||
|
||||
ax[1, 1].plot(available[:, 0], (allocate_lp2[:, 1]/(allocate_lp1[:, 1]+allocate_lp2[:, 1])*100), label="500 meters group")
|
||||
|
||||
ax[1, 1].set(xlabel='number of users', ylabel='% RB used', title='RB used depending on the distance PF')
|
||||
ax[1, 1].grid()
|
||||
ax[1, 1].set_ylim([0, 105])
|
||||
ax[1, 1].legend(loc="upper left")
|
||||
|
||||
plt.show()
|
@ -1,17 +1,18 @@
|
||||
package fr.ntr;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class AccessPoint {
|
||||
|
||||
private final Cell cell1;
|
||||
private final Cell cell2;
|
||||
private final List<Cell> cells;
|
||||
|
||||
private final Boolean reuse3 = false;
|
||||
private final boolean reuse3;
|
||||
|
||||
public AccessPoint (Cell cell1, Cell cell2){
|
||||
this.cell1 = cell1;
|
||||
this.cell2 = cell2;
|
||||
public AccessPoint (boolean reuse3, Cell... cells){
|
||||
this.reuse3 = reuse3;
|
||||
this.cells = Arrays.stream(cells).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -21,35 +22,40 @@ public class AccessPoint {
|
||||
public void startSimulation (int duration) {
|
||||
for (int ticks = 0; ticks < duration; ++ticks) {
|
||||
// Simulation
|
||||
cell1.reset();
|
||||
cell2.reset();
|
||||
cells.forEach(Cell::reset);
|
||||
|
||||
cell1.updateBandwidth(ticks);
|
||||
cell2.updateBandwidth(ticks);
|
||||
cell1.preScheduling();
|
||||
cell2.preScheduling();
|
||||
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() : Cell.getSubCarrierNb()/2); sp++) {
|
||||
User user1 = cell1.schedule(ticks, ts, sp);
|
||||
User user2 = cell2.schedule(ticks, ts, reuse3 ? 0 : 50 + sp);
|
||||
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;
|
||||
cell1.consumeResource(ticks, ts, sp, haveInterference);
|
||||
cell2.consumeResource(ticks, ts, sp, haveInterference);
|
||||
|
||||
cell1.postScheduling(user1);
|
||||
cell2.postScheduling(user2);
|
||||
|
||||
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
|
||||
try {
|
||||
cell1.analyseData(ticks);
|
||||
cell2.analyseData(ticks);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Can't export data");
|
||||
}
|
||||
|
||||
int finalTicks1 = ticks;
|
||||
cells.forEach(c -> {
|
||||
try {
|
||||
c.analyseData(finalTicks1);
|
||||
} catch (IOException e) {
|
||||
System.err.println("IO Error: " + e.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class Cell {
|
||||
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 +";" + id + "\n");
|
||||
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){
|
||||
|
@ -13,6 +13,7 @@ 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 {
|
||||
|
||||
@ -85,14 +86,14 @@ public class Main {
|
||||
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;cell;\n".getBytes());
|
||||
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(cell1, cell2);
|
||||
AccessPoint accessPoint = new AccessPoint(false, cell1, cell2);
|
||||
executor.submit(() -> accessPoint.startSimulation(numberOfTicks));
|
||||
}
|
||||
catch (IOException e) {
|
||||
@ -100,7 +101,15 @@ public class Main {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
executor.close();
|
||||
executor.shutdown();
|
||||
try {
|
||||
executor.awaitTermination(5, TimeUnit.MINUTES);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
executor.shutdownNow();
|
||||
|
||||
System.out.println("Executor closed");
|
||||
}
|
||||
else {
|
||||
|
@ -1,16 +0,0 @@
|
||||
package fr.ntr.Reuse;
|
||||
|
||||
import fr.ntr.Cell;
|
||||
import fr.ntr.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Reuse1 {
|
||||
|
||||
public static void BandwithReuse1(List<Cell> cellList, int tick) {
|
||||
for (Cell cell : cellList) {
|
||||
cell.updateBandwidth(tick);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package fr.ntr.Reuse;
|
||||
import fr.ntr.Cell;
|
||||
import fr.ntr.ResourceBlock;
|
||||
import fr.ntr.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class Reuse3 {
|
||||
|
||||
public static void BandwithReuse3(List<Cell> cellList, int tick) {
|
||||
for (Cell cell : cellList) {
|
||||
|
||||
cell.updateBandwidth(tick);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user