Fix outFIle

This commit is contained in:
Quentin Legot 2023-03-31 09:53:05 +02:00
parent d78d422a07
commit 768de92948
2 changed files with 18 additions and 16 deletions

View File

@ -28,20 +28,14 @@ public class Cell {
*/ */
private final ResourceBlock[][] frame; private final ResourceBlock[][] frame;
private final FileOutputStream outputDataFile; private final FileOutputStream outputDataFile;
private final int id;
public Cell(Scheduler scheduler, ResourceBlock[][] frame, List<User> users, String filename) { public Cell(int id, Scheduler scheduler, ResourceBlock[][] frame, List<User> users, FileOutputStream fileOutputStream) {
this.id = id;
this.users = users; this.users = users;
this.scheduler = scheduler; this.scheduler = scheduler;
this.frame = frame; this.frame = frame;
FileOutputStream output = null; this.outputDataFile = fileOutputStream;
try{
output = new FileOutputStream(filename, true);
output.write("tick;x;y;user;bandwidth;delay;\n".getBytes());
} catch(IOException e) {
System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage());
System.exit(1);
}
this.outputDataFile = output;
} }
public void updateBandwidth(int ticks) { public void updateBandwidth(int ticks) {
@ -86,7 +80,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 +";\n"); String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";" + delayAverage +";" + id + "\n");
try{ try{
outputDataFile.write(data.getBytes()); outputDataFile.write(data.getBytes());
}catch(IOException e){ }catch(IOException e){

View File

@ -1,10 +1,11 @@
package fr.ntr; package fr.ntr;
import fr.ntr.scheduler.MaxSNR;
import fr.ntr.scheduler.RoundRobin; import fr.ntr.scheduler.RoundRobin;
import fr.ntr.scheduler.Scheduler; import fr.ntr.scheduler.Scheduler;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -58,11 +59,18 @@ public class Main {
//TODO : changes schedulers //TODO : changes schedulers
Scheduler schedulerCell1 = new RoundRobin(frame, users); Scheduler schedulerCell1 = new RoundRobin(frame, users);
Scheduler schedulerCell2 = new RoundRobin(frame, users); Scheduler schedulerCell2 = new RoundRobin(frame, users);
try{
FileOutputStream output = new FileOutputStream("export" + File.separator + users.size() + ".csv", true);
output.write("tick;x;y;user;bandwidth;delay;cell;\n".getBytes());
Cell cell1 = new Cell(schedulerCell1, frame, users, "export" + File.separator + users.size() + "_cell1" + ".csv"); Cell cell1 = new Cell(0, schedulerCell1, frame, users, output);
Cell cell2 = new Cell(schedulerCell2, frame, users, "export" + File.separator + users.size() + "_cell2" + ".csv"); Cell cell2 = new Cell(1, schedulerCell2, frame, users, output);
AccessPoint accessPoint = new AccessPoint(cell1, cell2); AccessPoint accessPoint = new AccessPoint(cell1, cell2);
executor.submit(() -> accessPoint.startSimulation(numberOfTicks, users)); executor.submit(() -> accessPoint.startSimulation(numberOfTicks, users));
} catch(IOException e) {
System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage());
System.exit(1);
}
} }
} }
} else { } else {