Delete the file if it exists before starting simulation
This commit is contained in:
parent
590f0e49b9
commit
631ad01bfc
@ -11,7 +11,7 @@ plugins {
|
||||
}
|
||||
|
||||
run {
|
||||
args = ["5000", "2"]
|
||||
args = ["1000", "20"]
|
||||
}
|
||||
|
||||
application {
|
||||
|
@ -3,6 +3,8 @@ package fr.ntr;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
@ -35,6 +37,8 @@ public class AccessPoint {
|
||||
|
||||
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) {
|
||||
this.min = min;
|
||||
@ -50,7 +54,16 @@ public class AccessPoint {
|
||||
* Lancer la simulation
|
||||
* @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) {
|
||||
// Simulation
|
||||
reset();
|
||||
@ -101,34 +114,30 @@ public class AccessPoint {
|
||||
}
|
||||
|
||||
private void analyseData() throws IOException {
|
||||
try(FileOutputStream file = new FileOutputStream("data.csv", true)) {
|
||||
for(int i = 0; i < frame.length; i++) {
|
||||
for(int j = 0; j < frame[i].length; j++) {
|
||||
ResourceBlock ur = frame[i][j];
|
||||
String data = (i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";\n");
|
||||
file.write(data.getBytes());
|
||||
for(int i = 0; i < frame.length; i++) {
|
||||
for(int j = 0; j < frame[i].length; j++) {
|
||||
ResourceBlock ur = frame[i][j];
|
||||
String data = (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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void plotData() {
|
||||
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
// TODO insert new UR
|
||||
for(int i = 0; i < timeSlotNb; i++) {
|
||||
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() {
|
||||
return frame;
|
||||
}
|
||||
|
@ -24,11 +24,11 @@ public class Main {
|
||||
}
|
||||
int timeSlotNb = 2;
|
||||
int subCarrierNb = 100;
|
||||
List<User> users = generateUsers(20, timeSlotNb, subCarrierNb);
|
||||
List<User> users = generateUsers(maximumLoad, timeSlotNb, subCarrierNb);
|
||||
ResourceBlock[][] frame = new ResourceBlock[timeSlotNb][subCarrierNb];
|
||||
Scheduler scheduler = new RoundRobin("round robin", 0, frame, users);
|
||||
AccessPoint accessPoint = new AccessPoint(scheduler, frame, users, timeSlotNb, subCarrierNb, 0, 50);
|
||||
accessPoint.startSimulation(numberOfTicks, maximumLoad);
|
||||
accessPoint.startSimulation(numberOfTicks);
|
||||
}
|
||||
else {
|
||||
System.err.println("Please give launch arguments");
|
||||
|
@ -42,7 +42,9 @@ public class RoundRobin extends Scheduler {
|
||||
users.get(index).getPacketsSent().add(users.get(index).getPacketsToSend().get(0));
|
||||
users.get(index).getPacketsToSend().remove(users.get(index).getPacketsToSend().get(0));
|
||||
//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]);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user