diff --git a/src/main/java/fr/ntr/AccessPoint.java b/src/main/java/fr/ntr/AccessPoint.java index d2ce6c7..45ee579 100644 --- a/src/main/java/fr/ntr/AccessPoint.java +++ b/src/main/java/fr/ntr/AccessPoint.java @@ -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 users; - private Scheduler scheduler; + private final List 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 users, int timeSlotNb, int subCarrierNb, double min, double max) { - this.min = min; - this.max = max; + public AccessPoint(Scheduler scheduler, ResourceBlock[][] frame, List 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; + } } diff --git a/src/main/java/fr/ntr/Main.java b/src/main/java/fr/ntr/Main.java index b5d412d..50ada1b 100644 --- a/src/main/java/fr/ntr/Main.java +++ b/src/main/java/fr/ntr/Main.java @@ -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,14 +29,29 @@ 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 users = generateUsers(i, timeSlotNb, subCarrierNb); ResourceBlock[][] frame = new ResourceBlock[timeSlotNb][subCarrierNb]; - //Scheduler scheduler = new MaxSNR(frame, users); + // 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)); } }