2023-03-03 10:38:35 +01:00
|
|
|
package fr.ntr;
|
|
|
|
|
2023-03-24 09:05:44 +01:00
|
|
|
import java.io.File;
|
2023-03-17 10:55:45 +01:00
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
2023-03-17 20:31:42 +01:00
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Paths;
|
2023-03-03 11:28:16 +01:00
|
|
|
import java.util.List;
|
2023-03-06 17:48:22 +01:00
|
|
|
import java.util.Random;
|
2023-03-03 11:28:16 +01:00
|
|
|
|
2023-03-30 09:00:35 +02:00
|
|
|
import fr.ntr.Reuse.Reuse1;
|
|
|
|
import fr.ntr.Reuse.Reuse3;
|
2023-03-03 11:28:16 +01:00
|
|
|
import fr.ntr.scheduler.Scheduler;
|
|
|
|
|
2023-03-03 10:38:35 +01:00
|
|
|
public class AccessPoint {
|
2023-03-03 11:28:16 +01:00
|
|
|
|
2023-03-30 06:30:37 +02:00
|
|
|
private final Cell cell1;
|
|
|
|
private final Cell cell2;
|
2023-03-24 10:28:45 +01:00
|
|
|
private List<User> users;
|
2023-03-17 20:31:42 +01:00
|
|
|
private FileOutputStream outputDataFile;
|
|
|
|
|
2023-03-24 10:28:45 +01:00
|
|
|
public AccessPoint(Cell cell1, Cell cell2){
|
|
|
|
this.cell1 = cell1;
|
|
|
|
this.cell2 = cell2;
|
2023-03-03 11:28:16 +01:00
|
|
|
}
|
|
|
|
|
2023-03-06 17:48:22 +01:00
|
|
|
/**
|
|
|
|
* Lancer la simulation
|
|
|
|
* @param duration
|
|
|
|
*/
|
2023-03-17 20:31:42 +01:00
|
|
|
public void startSimulation(int duration) {
|
2023-03-24 10:52:33 +01:00
|
|
|
/*
|
2023-03-17 20:31:42 +01:00
|
|
|
try{
|
2023-03-24 09:05:44 +01:00
|
|
|
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);
|
2023-03-24 08:33:43 +01:00
|
|
|
outputDataFile.write("tick;x;y;user;bandwidth;\n".getBytes());
|
2023-03-24 09:05:44 +01:00
|
|
|
} catch(IOException e) {
|
|
|
|
System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage());
|
2023-03-17 20:31:42 +01:00
|
|
|
System.exit(1);
|
|
|
|
return;
|
|
|
|
}
|
2023-03-24 10:52:33 +01:00
|
|
|
*/
|
2023-03-10 08:30:28 +01:00
|
|
|
for (int ticks = 0; ticks < duration; ++ticks) {
|
2023-03-06 17:48:22 +01:00
|
|
|
// Simulation
|
2023-03-24 10:28:45 +01:00
|
|
|
cell1.reset();
|
|
|
|
cell2.reset();
|
2023-03-30 09:00:35 +02:00
|
|
|
List<Cell> cellList = null;
|
|
|
|
cellList.add(cell1);
|
|
|
|
cellList.add(cell2);
|
|
|
|
Reuse1.BandwithReuse1(cellList,ticks);
|
|
|
|
//Reuse3.BandwithReuse3(cellList,ticks);
|
2023-03-24 10:28:45 +01:00
|
|
|
cell1.schedule();
|
|
|
|
cell2.schedule();
|
2023-03-28 08:59:16 +02:00
|
|
|
|
2023-03-30 09:02:12 +02:00
|
|
|
|
2023-03-28 08:59:16 +02:00
|
|
|
//simulation des interférences
|
2023-03-28 09:02:45 +02:00
|
|
|
computeInterference();
|
2023-03-28 08:59:16 +02:00
|
|
|
|
2023-03-06 17:48:22 +01:00
|
|
|
// traite les données et les enregistre dans un fichier
|
2023-03-28 08:21:38 +02:00
|
|
|
|
|
|
|
/* try {
|
2023-03-24 08:19:41 +01:00
|
|
|
analyseData(ticks);
|
2023-03-17 10:55:45 +01:00
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("Can't export data");
|
2023-03-28 08:21:38 +02:00
|
|
|
}*/
|
|
|
|
|
2023-03-06 17:48:22 +01:00
|
|
|
}
|
2023-03-03 11:28:16 +01:00
|
|
|
}
|
|
|
|
|
2023-03-28 09:02:45 +02:00
|
|
|
public void computeInterference () {
|
|
|
|
ResourceBlock[][] frameCell1 = cell1.getFrame();
|
|
|
|
ResourceBlock[][] frameCell2 = cell2.getFrame();
|
|
|
|
|
2023-03-30 08:13:48 +02:00
|
|
|
for (int k = 0; k < frameCell1.length; k++ ) {
|
2023-03-28 09:02:45 +02:00
|
|
|
for (int l = 0; l < frameCell1[k].length; l++) {
|
|
|
|
//interférences si les deux cellules parlent au même UE sur le même time slot
|
|
|
|
User user1 = frameCell1[k][l].getUser();
|
|
|
|
User user2 = frameCell2[k][l].getUser();
|
2023-03-30 09:41:10 +02:00
|
|
|
if (user1 == user2 && (user1 != null || user2 != null)) {
|
2023-03-28 09:02:45 +02:00
|
|
|
double bandwidth1 = frameCell1[k][l].getBandwidth();
|
|
|
|
double bandwidth2 = frameCell2[k][l].getBandwidth();
|
|
|
|
//User proche
|
2023-03-30 06:30:37 +02:00
|
|
|
if (user1.getDistance() < 200d) {
|
2023-03-30 08:38:35 +02:00
|
|
|
frameCell1[k][l].getUser().getBandwidthTable()[k][l] = bandwidth1 / 2;
|
|
|
|
frameCell2[k][l].getUser().getBandwidthTable()[k][l] = bandwidth2 / 2;
|
2023-03-30 09:41:10 +02:00
|
|
|
//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]);
|
2023-03-28 09:02:45 +02:00
|
|
|
}
|
|
|
|
//User loin
|
|
|
|
else {
|
2023-03-30 08:38:35 +02:00
|
|
|
frameCell1[k][l].getUser().getBandwidthTable()[k][l] = bandwidth1 / 4;
|
|
|
|
frameCell2[k][l].getUser().getBandwidthTable()[k][l] = bandwidth2 / 4;
|
2023-03-30 09:41:10 +02:00
|
|
|
//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]);
|
2023-03-28 09:02:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-30 08:13:48 +02:00
|
|
|
|
|
|
|
// traite les données et les enregistre dans un fichier
|
|
|
|
|
|
|
|
/* try {
|
|
|
|
analyseData(ticks);
|
|
|
|
} catch (IOException e) {
|
|
|
|
System.out.println("Can't export data");
|
|
|
|
}*/
|
|
|
|
|
2023-03-28 09:02:45 +02:00
|
|
|
}
|
|
|
|
}
|
2023-03-30 08:13:48 +02:00
|
|
|
|
2023-03-28 08:21:38 +02:00
|
|
|
/*
|
2023-03-24 08:19:41 +01:00
|
|
|
private void analyseData(int tick) throws IOException {
|
2023-03-30 08:13:48 +02:00
|
|
|
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();
|
2023-03-17 11:04:32 +01:00
|
|
|
}
|
|
|
|
}
|
2023-03-30 08:13:48 +02:00
|
|
|
/*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;
|
|
|
|
}
|
|
|
|
}
|
2023-03-30 09:00:35 +02:00
|
|
|
}
|
|
|
|
}*/
|
2023-03-03 10:38:35 +01:00
|
|
|
}
|