Move the deletion of exported files in Main, move AccessPoint static parameters outside of loop(for concurrency propose)

This commit is contained in:
Quentin Legot 2023-03-31 08:27:43 +02:00
parent eece2c1d3a
commit 82c7ed700d
2 changed files with 32 additions and 24 deletions

View File

@ -3,16 +3,13 @@ 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.scheduler.Scheduler;
public class AccessPoint {
private List<User> users;
private Scheduler scheduler;
private final List<User> users;
private final Scheduler scheduler;
/**
* nombre de slots
*/
@ -24,24 +21,14 @@ public class AccessPoint {
/**
* trame
*/
private ResourceBlock[][] frame;
/**
* Portée minimum et maximum de l'antenne
*/
private final double min, max;
private final ResourceBlock[][] frame;
private FileOutputStream outputDataFile;
public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, List<User> users, int timeSlotNb, int subCarrierNb, double min, double max) {
this.min = min;
this.max = max;
public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, List<User> users) {
this.users = users;
this.scheduler = scheduler;
this.frame = frame;
this.timeSlotNb = timeSlotNb;
this.subCarrierNb = subCarrierNb;
}
/**
@ -50,8 +37,6 @@ public class AccessPoint {
*/
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;delay;\n".getBytes());
} catch(IOException e) {
@ -120,7 +105,6 @@ public class AccessPoint {
}
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.0);
@ -139,4 +123,12 @@ public class AccessPoint {
public static int getSubCarrierNb() {
return subCarrierNb;
}
public static void setTimeSlotNb(int timeSlotNb) {
AccessPoint.timeSlotNb = timeSlotNb;
}
public static void setSubCarrierNb(int subCarrierNb) {
AccessPoint.subCarrierNb = subCarrierNb;
}
}

View File

@ -1,12 +1,13 @@
package fr.ntr;
import fr.ntr.scheduler.MaxSNR;
import fr.ntr.scheduler.ProportionalFair;
import fr.ntr.scheduler.RoundRobin;
import fr.ntr.scheduler.Scheduler;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -28,6 +29,21 @@ public class Main {
}
int timeSlotNb = 2;
int subCarrierNb = 100;
File folder = new File("export");
if(!folder.exists() && !folder.mkdir()) {
System.err.println("Cannot create export folder");
System.exit(1);
}
Arrays.stream(Objects.requireNonNull(new File("export").listFiles()))
.filter(File::isFile)
.forEach(f -> {
if(!f.delete()) {
System.err.println("Cannot remove file " + f.getAbsolutePath());
}
});
AccessPoint.setTimeSlotNb(timeSlotNb);
AccessPoint.setSubCarrierNb(subCarrierNb);
try(ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())) {
for(int i = 2; i <= maximumLoad; i += 2) {
List<User> users = generateUsers(i, timeSlotNb, subCarrierNb);
@ -35,7 +51,7 @@ public class Main {
// Scheduler scheduler = new MaxSNR(frame, users);
// Scheduler scheduler = new ProportionalFair(frame, users);
Scheduler scheduler = new RoundRobin(frame, users);
AccessPoint accessPoint = new AccessPoint(scheduler, frame, users, timeSlotNb, subCarrierNb, 0, 50);
AccessPoint accessPoint = new AccessPoint(scheduler, frame, users);
executor.submit(() -> accessPoint.startSimulation(numberOfTicks));
}
}