package fr.ntr; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; import java.util.Random; import fr.ntr.Reuse.Reuse1; import fr.ntr.Reuse.Reuse3; import fr.ntr.scheduler.Scheduler; public class AccessPoint { private final Cell cell1; private final Cell cell2; private List users; private FileOutputStream outputDataFile; public AccessPoint(Cell cell1, Cell cell2){ this.cell1 = cell1; this.cell2 = cell2; } /** * Lancer la simulation * @param duration */ public void startSimulation(int duration) { /* try{ 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()); } catch(IOException e) { System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage()); System.exit(1); return; } */ for (int ticks = 0; ticks < duration; ++ticks) { // Simulation cell1.reset(); cell2.reset(); List cellList = null; cellList.add(cell1); cellList.add(cell2); Reuse1.BandwithReuse1(cellList,ticks); //Reuse3.BandwithReuse3(cellList,ticks); cell1.schedule(); cell2.schedule(); //simulation des interférences computeInterference(); // traite les données et les enregistre dans un fichier /* try { analyseData(ticks); } catch (IOException e) { System.out.println("Can't export data"); }*/ } } 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].getUser().getBandwidthTable()[k][l] = bandwidth1 / 2; frameCell2[k][l].getUser().getBandwidthTable()[k][l] = bandwidth2 / 2; } //User loin else { frameCell1[k][l].getUser().getBandwidthTable()[k][l] = bandwidth1 / 4; frameCell2[k][l].getUser().getBandwidthTable()[k][l] = bandwidth2 / 4; } } } // traite les données et les enregistre dans un fichier /* try { analyseData(ticks); } catch (IOException e) { System.out.println("Can't export data"); }*/ } } /* private void analyseData(int tick) throws IOException { double delayAverage = 0.0; int nbPacketsSent = 0; for(User u: this.users){ List 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 +";\n"); try{ outputDataFile.write(data.getBytes()); }catch(IOException e){ System.err.println("Cannot write the data in the output file"); System.exit(1); return; } } } }*/ }