Compare commits

...

10 Commits

6 changed files with 98 additions and 74 deletions

View File

@ -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(".." + os.sep + "export") nb_files = os.listdir("PF")
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 * 10000)) * 100 available[nb, 1] = (data.shape[0] / (200 * 20000)) * 100
nb += 1 nb += 1
return available return available
@ -46,30 +46,71 @@ def delay(arr: list[tuple[int, np.ndarray]]) -> np.ndarray:
return delays 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() 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(".." + 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) averages = mean_mkn(np_arr)
available = rb_available(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 = 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 del np_arr
fig, ax = plt.subplots(2, 2) fig, ax = plt.subplots(2, 2)
ax[0, 0].scatter(averages[:, 0], averages[:, 1]) ax[0, 0].plot(averages[:, 0], averages[:, 1], marker="o")
ax[0, 0].set(xlabel='number of users', ylabel='Efficacité spectrale', title='Efficacité spectrale') ax[0, 0].set(xlabel='number of users', ylabel='% Spectral efficiency', title='Spectral efficiency PF')
ax[0, 0].grid() ax[0, 0].grid()
ax[0, 0].set_ylim([0, 40])
ax[0, 1].scatter(available[:, 0], available[:, 1]) ax[0, 1].plot(available[:, 0], available[:, 1], marker="o")
ax[0, 1].set(xlabel='number of users', ylabel='RB utilisés', title='Pourcentage de RB utilisés') ax[0, 1].set(xlabel='number of users', ylabel=' % RB used', title='Percentage of RB used PF')
ax[0, 1].grid() ax[0, 1].grid()
ax[0, 1].set_ylim([0, 105])
ax[1, 0].scatter(delays[:, 0], delays[:, 1]) ax[1, 0].plot(delays[:, 0], delays[:, 1], marker="o")
ax[1, 0].set(xlabel='number of users', ylabel='delays(ms)', title='Delay') ax[1, 0].set(xlabel='number of users', ylabel='delay(ms)', title='Delay PF')
ax[1, 0].grid() 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()

View File

@ -1,17 +1,18 @@
package fr.ntr; package fr.ntr;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class AccessPoint { public class AccessPoint {
private final Cell cell1; private final List<Cell> cells;
private final Cell cell2;
private final Boolean reuse3 = false; private final boolean reuse3;
public AccessPoint (Cell cell1, Cell cell2){ public AccessPoint (boolean reuse3, Cell... cells){
this.cell1 = cell1; this.reuse3 = reuse3;
this.cell2 = cell2; this.cells = Arrays.stream(cells).toList();
} }
/** /**
@ -21,35 +22,40 @@ public class AccessPoint {
public void startSimulation (int duration) { public void startSimulation (int duration) {
for (int ticks = 0; ticks < duration; ++ticks) { for (int ticks = 0; ticks < duration; ++ticks) {
// Simulation // Simulation
cell1.reset(); cells.forEach(Cell::reset);
cell2.reset();
cell1.updateBandwidth(ticks); int finalTicks = ticks;
cell2.updateBandwidth(ticks); cells.forEach(c -> c.updateBandwidth(finalTicks));
cell1.preScheduling(); cells.forEach(Cell::preScheduling);
cell2.preScheduling();
for(int ts = 0; ts < Cell.getTimeSlotNb(); ts++) { for(int ts = 0; ts < Cell.getTimeSlotNb(); ts++) {
for (int sp = 0; sp < (reuse3 ? Cell.getSubCarrierNb() : Cell.getSubCarrierNb()/2); sp++) { for (int sp = 0; sp < (reuse3 ? Cell.getSubCarrierNb() / 2 : Cell.getSubCarrierNb()); sp++) {
User user1 = cell1.schedule(ticks, ts, sp); User user1 = cells.get(0).schedule(ticks, ts, sp);
User user2 = cell2.schedule(ticks, ts, reuse3 ? 0 : 50 + 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; boolean haveInterference = user1 == user2 && user1 != null;
cell1.consumeResource(ticks, ts, sp, haveInterference); int finalTs = ts;
cell2.consumeResource(ticks, ts, sp, haveInterference); int finalSp = sp;
cells.forEach(c -> c.consumeResource(finalTicks, finalTs, finalSp, haveInterference));
cell1.postScheduling(user1); cells.get(0).postScheduling(user1);
cell2.postScheduling(user2); 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 // traite les données et les enregistre dans un fichier
try { int finalTicks1 = ticks;
cell1.analyseData(ticks); cells.forEach(c -> {
cell2.analyseData(ticks); try {
} catch (IOException e) { c.analyseData(finalTicks1);
System.out.println("Can't export data"); } catch (IOException e) {
} System.err.println("IO Error: " + e.getMessage());
System.exit(1);
}
});
} }
} }
} }

View File

@ -120,7 +120,7 @@ public class Cell {
for(int j = 0; j < frame[i].length; j++) { for(int j = 0; j < frame[i].length; j++) {
ResourceBlock ur = frame[i][j]; ResourceBlock ur = frame[i][j];
if(ur.getUser() != null) { 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{ try{
outputDataFile.write(data.getBytes()); outputDataFile.write(data.getBytes());
}catch(IOException e){ }catch(IOException e){

View File

@ -13,6 +13,7 @@ import java.util.Objects;
import java.util.Random; 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;
public class Main { public class Main {
@ -85,14 +86,14 @@ public class Main {
try { try {
//préparation à exportation des données de chaque cellule //préparation à exportation des données de chaque cellule
FileOutputStream output = new FileOutputStream("export" + File.separator + (usersCell1.size()) + ".csv", true); 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 //création des cellules
Cell cell1 = new Cell(0, schedulerCell1, frame1, usersCell1, output); Cell cell1 = new Cell(0, schedulerCell1, frame1, usersCell1, output);
Cell cell2 = new Cell(1, schedulerCell2, frame2, usersCell2, output); Cell cell2 = new Cell(1, schedulerCell2, frame2, usersCell2, output);
//création de l'AccessPoint //création de l'AccessPoint
AccessPoint accessPoint = new AccessPoint(cell1, cell2); AccessPoint accessPoint = new AccessPoint(false, cell1, cell2);
executor.submit(() -> accessPoint.startSimulation(numberOfTicks)); executor.submit(() -> accessPoint.startSimulation(numberOfTicks));
} }
catch (IOException e) { catch (IOException e) {
@ -100,7 +101,15 @@ public class Main {
System.exit(1); 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"); System.out.println("Executor closed");
} }
else { else {

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}