Delete the file if it exists before starting simulation

This commit is contained in:
Remi Boure 2023-03-17 20:31:42 +01:00
parent 590f0e49b9
commit 631ad01bfc
4 changed files with 31 additions and 20 deletions

View File

@ -11,7 +11,7 @@ plugins {
} }
run { run {
args = ["5000", "2"] args = ["1000", "20"]
} }
application { application {

View File

@ -3,6 +3,8 @@ package fr.ntr;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@ -35,6 +37,8 @@ public class AccessPoint {
private Random random = new Random(); private Random random = new Random();
private FileOutputStream outputDataFile;
public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, List<User> users, int timeSlotNb, int subCarrierNb, double min, double max) { public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, List<User> users, int timeSlotNb, int subCarrierNb, double min, double max) {
this.min = min; this.min = min;
@ -50,7 +54,16 @@ public class AccessPoint {
* Lancer la simulation * Lancer la simulation
* @param duration * @param duration
*/ */
public void startSimulation(int duration, int nbUsers) { public void startSimulation(int duration) {
try{
Files.deleteIfExists(Paths.get("data.csv"));
this.outputDataFile = new FileOutputStream("data.csv", true);
}catch(IOException e){
System.err.println("Cannot create the output file");
System.exit(1);
return;
}
for (int ticks = 0; ticks < duration; ++ticks) { for (int ticks = 0; ticks < duration; ++ticks) {
// Simulation // Simulation
reset(); reset();
@ -101,34 +114,30 @@ public class AccessPoint {
} }
private void analyseData() throws IOException { private void analyseData() throws IOException {
try(FileOutputStream file = new FileOutputStream("data.csv", true)) { for(int i = 0; i < frame.length; i++) {
for(int i = 0; i < frame.length; i++) { 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]; String data = (i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";\n");
String data = (i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";\n"); try{
file.write(data.getBytes()); outputDataFile.write(data.getBytes());
}catch(IOException e){
System.err.println("Cannot write the data in the output file");
System.exit(1);
return;
} }
} }
} }
} }
private void plotData() {
}
private void reset() { private void reset() {
// TODO insert new UR // TODO insert new UR
for(int i = 0; i < timeSlotNb; i++) { for(int i = 0; i < timeSlotNb; i++) {
for(int j = 0; j < subCarrierNb; j++) { for(int j = 0; j < subCarrierNb; j++) {
frame[i][j] = new ResourceBlock(0); frame[i][j] = new ResourceBlock(0.0);
} }
} }
} }
public int getFrameSize() {
return this.timeSlotNb * this.subCarrierNb;
}
public ResourceBlock[][] getFrame() { public ResourceBlock[][] getFrame() {
return frame; return frame;
} }

View File

@ -24,11 +24,11 @@ public class Main {
} }
int timeSlotNb = 2; int timeSlotNb = 2;
int subCarrierNb = 100; int subCarrierNb = 100;
List<User> users = generateUsers(20, timeSlotNb, subCarrierNb); List<User> users = generateUsers(maximumLoad, timeSlotNb, subCarrierNb);
ResourceBlock[][] frame = new ResourceBlock[timeSlotNb][subCarrierNb]; ResourceBlock[][] frame = new ResourceBlock[timeSlotNb][subCarrierNb];
Scheduler scheduler = new RoundRobin("round robin", 0, frame, users); Scheduler scheduler = new RoundRobin("round robin", 0, frame, users);
AccessPoint accessPoint = new AccessPoint(scheduler, frame, users, timeSlotNb, subCarrierNb, 0, 50); AccessPoint accessPoint = new AccessPoint(scheduler, frame, users, timeSlotNb, subCarrierNb, 0, 50);
accessPoint.startSimulation(numberOfTicks, maximumLoad); accessPoint.startSimulation(numberOfTicks);
} }
else { else {
System.err.println("Please give launch arguments"); System.err.println("Please give launch arguments");

View File

@ -42,7 +42,9 @@ public class RoundRobin extends Scheduler {
users.get(index).getPacketsSent().add(users.get(index).getPacketsToSend().get(0)); users.get(index).getPacketsSent().add(users.get(index).getPacketsToSend().get(0));
users.get(index).getPacketsToSend().remove(users.get(index).getPacketsToSend().get(0)); users.get(index).getPacketsToSend().remove(users.get(index).getPacketsToSend().get(0));
//on ajoute l'utilisateur a la frame //on ajoute l'utilisateur a la frame
frame[Ts][Sp].setUser(UserSelection(Ts, Sp, users)); User user = UserSelection(Ts, Sp, users);
frame[Ts][Sp].setUser(user);
frame[Ts][Sp].setBandwidth(user.getBandwidthTable()[Ts][Sp]);
} }
} }