This repository has been archived on 2023-08-28. You can view files and clone it, but cannot push or open issues or pull requests.
ntr-interferences/src/main/java/fr/ntr/AccessPoint.java

111 lines
3.7 KiB
Java
Raw Normal View History

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;
import java.nio.file.Files;
import java.nio.file.Paths;
2023-03-03 11:28:16 +01:00
import java.util.List;
import java.util.Random;
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
private Cell cell1;
private Cell cell2;
private List<User> users;
private FileOutputStream outputDataFile;
public AccessPoint(Cell cell1, Cell cell2){
this.cell1 = cell1;
this.cell2 = cell2;
2023-03-03 11:28:16 +01:00
}
/**
* Lancer la simulation
* @param duration
*/
public void startSimulation(int duration) {
2023-03-24 10:52:33 +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);
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());
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) {
// Simulation
cell1.reset();
cell2.reset();
cell1.updateBandwidth(ticks);
cell2.updateBandwidth(ticks);
cell1.schedule();
cell2.schedule();
//simulation des interférences
computeInterference();
// traite les données et les enregistre dans un fichier
2023-03-28 08:21:38 +02:00
/* try {
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-03 11:28:16 +01:00
}
public void computeInterference () {
ResourceBlock[][] frameCell1 = cell1.getFrame();
ResourceBlock[][] frameCell2 = cell2.getFrame();
for (int k = 0; k > frameCell1.length; k++ ) {
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();
if (user1 == user2) {
double bandwidth1 = frameCell1[k][l].getBandwidth();
double bandwidth2 = frameCell2[k][l].getBandwidth();
//User proche
if (user1.getDistance() > 200d) {
frameCell1[k][l].setBandwidth(bandwidth1 / 2);
frameCell2[k][l].setBandwidth(bandwidth2 / 2);
}
//User loin
else {
frameCell1[k][l].setBandwidth(bandwidth1 / 4);
frameCell2[k][l].setBandwidth(bandwidth2 / 4);
}
}
}
}
}
2023-03-28 08:21:38 +02:00
/*
private void analyseData(int tick) throws IOException {
2023-03-28 08:21:38 +02:00
for(int i = 0; i < cell1.getFrame().length; i++) {
for(int j = 0; j < cell1.getFrame()[i].length; j++) {
ResourceBlock ur = cell1.getFrame()[i][j];
if(ur.getUser() != null) {
String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";\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-17 11:04:32 +01:00
}
}
}
2023-03-03 11:28:16 +01:00
}
2023-03-28 08:21:38 +02:00
*/
2023-03-03 10:38:35 +01:00
}