From 768de9294830f20214bda1e8b6e5cfb1f45b2578 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Fri, 31 Mar 2023 09:53:05 +0200 Subject: [PATCH] Fix outFIle --- src/main/java/fr/ntr/Cell.java | 16 +++++----------- src/main/java/fr/ntr/Main.java | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main/java/fr/ntr/Cell.java b/src/main/java/fr/ntr/Cell.java index 741d043..7d1a924 100644 --- a/src/main/java/fr/ntr/Cell.java +++ b/src/main/java/fr/ntr/Cell.java @@ -28,20 +28,14 @@ public class Cell { */ private final ResourceBlock[][] frame; private final FileOutputStream outputDataFile; + private final int id; - public Cell(Scheduler scheduler, ResourceBlock[][] frame, List users, String filename) { + public Cell(int id, Scheduler scheduler, ResourceBlock[][] frame, List users, FileOutputStream fileOutputStream) { + this.id = id; this.users = users; this.scheduler = scheduler; this.frame = frame; - FileOutputStream output = null; - 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; + this.outputDataFile = fileOutputStream; } public void updateBandwidth(int ticks) { @@ -86,7 +80,7 @@ public class Cell { 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"); + String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";" + delayAverage +";" + id + "\n"); try{ outputDataFile.write(data.getBytes()); }catch(IOException e){ diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index 9d9631f..df7976a 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -1,10 +1,11 @@ package fr.ntr; -import fr.ntr.scheduler.MaxSNR; import fr.ntr.scheduler.RoundRobin; import fr.ntr.scheduler.Scheduler; import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -58,11 +59,18 @@ public class Main { //TODO : changes schedulers Scheduler schedulerCell1 = 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 cell2 = new Cell(schedulerCell2, frame, users, "export" + File.separator + users.size() + "_cell2" + ".csv"); - AccessPoint accessPoint = new AccessPoint(cell1, cell2); - executor.submit(() -> accessPoint.startSimulation(numberOfTicks, users)); + Cell cell1 = new Cell(0, schedulerCell1, frame, users, output); + Cell cell2 = new Cell(1, schedulerCell2, frame, users, output); + AccessPoint accessPoint = new AccessPoint(cell1, cell2); + executor.submit(() -> accessPoint.startSimulation(numberOfTicks, users)); + } catch(IOException e) { + System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage()); + System.exit(1); + } } } } else {