Move the deletion of exported files in Main, move AccessPoint static parameters outside of loop(for concurrency propose)
This commit is contained in:
parent
eece2c1d3a
commit
82c7ed700d
@ -3,16 +3,13 @@ package fr.ntr;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
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.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import fr.ntr.scheduler.Scheduler;
|
import fr.ntr.scheduler.Scheduler;
|
||||||
|
|
||||||
public class AccessPoint {
|
public class AccessPoint {
|
||||||
private List<User> users;
|
private final List<User> users;
|
||||||
private Scheduler scheduler;
|
private final Scheduler scheduler;
|
||||||
/**
|
/**
|
||||||
* nombre de slots
|
* nombre de slots
|
||||||
*/
|
*/
|
||||||
@ -24,24 +21,14 @@ public class AccessPoint {
|
|||||||
/**
|
/**
|
||||||
* trame
|
* trame
|
||||||
*/
|
*/
|
||||||
private ResourceBlock[][] frame;
|
private final ResourceBlock[][] frame;
|
||||||
|
|
||||||
/**
|
|
||||||
* Portée minimum et maximum de l'antenne
|
|
||||||
*/
|
|
||||||
private final double min, max;
|
|
||||||
|
|
||||||
private FileOutputStream outputDataFile;
|
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) {
|
||||||
this.min = min;
|
|
||||||
this.max = max;
|
|
||||||
this.users = users;
|
this.users = users;
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
this.frame = frame;
|
this.frame = frame;
|
||||||
this.timeSlotNb = timeSlotNb;
|
|
||||||
this.subCarrierNb = subCarrierNb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,8 +37,6 @@ public class AccessPoint {
|
|||||||
*/
|
*/
|
||||||
public void startSimulation(int duration) {
|
public void startSimulation(int duration) {
|
||||||
try{
|
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);
|
this.outputDataFile = new FileOutputStream("export" + File.separator + this.users.size() + ".csv", true);
|
||||||
outputDataFile.write("tick;x;y;user;bandwidth;delay;\n".getBytes());
|
outputDataFile.write("tick;x;y;user;bandwidth;delay;\n".getBytes());
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
@ -120,7 +105,6 @@ public class AccessPoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reset() {
|
private void reset() {
|
||||||
// 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.0);
|
frame[i][j] = new ResourceBlock(0.0);
|
||||||
@ -139,4 +123,12 @@ public class AccessPoint {
|
|||||||
public static int getSubCarrierNb() {
|
public static int getSubCarrierNb() {
|
||||||
return subCarrierNb;
|
return subCarrierNb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setTimeSlotNb(int timeSlotNb) {
|
||||||
|
AccessPoint.timeSlotNb = timeSlotNb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setSubCarrierNb(int subCarrierNb) {
|
||||||
|
AccessPoint.subCarrierNb = subCarrierNb;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package fr.ntr;
|
package fr.ntr;
|
||||||
|
|
||||||
import fr.ntr.scheduler.MaxSNR;
|
|
||||||
import fr.ntr.scheduler.ProportionalFair;
|
|
||||||
import fr.ntr.scheduler.RoundRobin;
|
import fr.ntr.scheduler.RoundRobin;
|
||||||
import fr.ntr.scheduler.Scheduler;
|
import fr.ntr.scheduler.Scheduler;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
@ -28,14 +29,29 @@ public class Main {
|
|||||||
}
|
}
|
||||||
int timeSlotNb = 2;
|
int timeSlotNb = 2;
|
||||||
int subCarrierNb = 100;
|
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())) {
|
try(ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())) {
|
||||||
for(int i = 2; i <= maximumLoad; i += 2) {
|
for(int i = 2; i <= maximumLoad; i += 2) {
|
||||||
List<User> users = generateUsers(i, timeSlotNb, subCarrierNb);
|
List<User> users = generateUsers(i, timeSlotNb, subCarrierNb);
|
||||||
ResourceBlock[][] frame = new ResourceBlock[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 ProportionalFair(frame, users);
|
||||||
Scheduler scheduler = new RoundRobin(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));
|
executor.submit(() -> accessPoint.startSimulation(numberOfTicks));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user