Fixes
- enhance Result and ResultSummary - added new example - added new launch configuration - fixed RNG with seed 0 not correclty generating streams
This commit is contained in:
7
.vscode/launch.json
vendored
7
.vscode/launch.json
vendored
@@ -18,6 +18,13 @@
|
|||||||
"mainClass": "net.berack.upo.valpre.Main",
|
"mainClass": "net.berack.upo.valpre.Main",
|
||||||
"args": "simulation -net example2.net -runs 1000 -p -seed 0"
|
"args": "simulation -net example2.net -runs 1000 -p -seed 0"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "Run1k Complex EXP",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "net.berack.upo.valpre.Main",
|
||||||
|
"args": "simulation -net example3.net -runs 1000 -p -seed 0"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "java",
|
"type": "java",
|
||||||
"name": "Run10",
|
"name": "Run10",
|
||||||
|
|||||||
@@ -22,14 +22,14 @@ Esistono vari tipi di argomenti per scegliere come fare la simulazione:
|
|||||||
* `-csv <file>` per salvare i risultati delle run in un file csv
|
* `-csv <file>` per salvare i risultati delle run in un file csv
|
||||||
* `-p` per fare le simulazioni in parallelo (ovvero su più thread)
|
* `-p` per fare le simulazioni in parallelo (ovvero su più thread)
|
||||||
* `-end <criteria>` per scegliere quando la simulazione finisce nel caso non ci siano dei source limitati nella creazione di arrivi. La tipologia di fine simulazione la si può trovare dentro `EndCriteria` (ovvero MaxArrivals, MaxDepartures, MaxTime) e la formattazione da usare per passare il parametro è la seguente:\
|
* `-end <criteria>` per scegliere quando la simulazione finisce nel caso non ci siano dei source limitati nella creazione di arrivi. La tipologia di fine simulazione la si può trovare dentro `EndCriteria` (ovvero MaxArrivals, MaxDepartures, MaxTime) e la formattazione da usare per passare il parametro è la seguente:\
|
||||||
`[Tipo1:param1,..,paramN];[..];[TipoN:param1,..,paramN]`
|
**\[Tipo1:param1,..,paramN\];\[..\];\[TipoN:param1,..,paramN\]**
|
||||||
* `java -jar upo-valpre.jar plot -csv <file>`\
|
* `java -jar upo-valpre.jar plot -csv <file>`\
|
||||||
Mostra (con un ambiente grafico) una finestra nella quale si può scegliere quale nodo vedere e ogni statistica associata ad esso. Di seguito un'immagine di esempio:
|
Mostra (con un ambiente grafico) una finestra nella quale si può scegliere quale nodo vedere e ogni statistica associata ad esso. Di seguito un'immagine di esempio:
|
||||||

|

|
||||||
|
|
||||||
Esistono dei file prefatti per vedere eventuali simulazioni:
|
Esistono dei file prefatti per vedere eventuali simulazioni che, nel caso vengano passati come parametri, automaticamente vengono usati:
|
||||||
* `example1.net` e `example2.net` per `simulation -net`
|
* `example1.net`, `example2.net` e `example3.net` per `simulation -net`
|
||||||
* `example1.csv` e `example2.csv` per `plot -csv`
|
* `example1.csv`, `example2.csv` e `example3.csv` per `plot -csv`
|
||||||
|
|
||||||
### Classi Interne
|
### Classi Interne
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ public class Main {
|
|||||||
try {
|
try {
|
||||||
var program = args[0];
|
var program = args[0];
|
||||||
var subArgs = Arrays.copyOfRange(args, 1, args.length);
|
var subArgs = Arrays.copyOfRange(args, 1, args.length);
|
||||||
var param = Main.getParameters(program, subArgs);
|
|
||||||
switch (program) {
|
switch (program) {
|
||||||
case "simulation" -> {
|
case "simulation" -> {
|
||||||
|
var param = Main.getParameters(program, subArgs);
|
||||||
new SimulationBuilder(param.get("net"))
|
new SimulationBuilder(param.get("net"))
|
||||||
.setCsv(param.get("csv"))
|
.setCsv(param.get("csv"))
|
||||||
.setRuns(param.getOrDefault("runs", Integer::parseInt, 100))
|
.setRuns(param.getOrDefault("runs", Integer::parseInt, 100))
|
||||||
@@ -27,6 +27,7 @@ public class Main {
|
|||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
case "plot" -> {
|
case "plot" -> {
|
||||||
|
var param = Main.getParameters(program, subArgs);
|
||||||
var csv = param.get("csv");
|
var csv = param.get("csv");
|
||||||
var plot = new Plot(csv);
|
var plot = new Plot(csv);
|
||||||
plot.show();
|
plot.show();
|
||||||
@@ -72,8 +73,6 @@ public class Main {
|
|||||||
};
|
};
|
||||||
descriptions.put("csv", csvDesc);
|
descriptions.put("csv", csvDesc);
|
||||||
|
|
||||||
if (program.equals("net"))
|
|
||||||
return null;
|
|
||||||
return Parameters.getArgsOrHelper(args, "-", arguments, descriptions);
|
return Parameters.getArgsOrHelper(args, "-", arguments, descriptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ public class Rng {
|
|||||||
var streams = new Rng[total];
|
var streams = new Rng[total];
|
||||||
for (int i = 0; i < total; i++) {
|
for (int i = 0; i < total; i++) {
|
||||||
streams[i] = new Rng(seed);
|
streams[i] = new Rng(seed);
|
||||||
seed = (seed * mult) % MODULUS;
|
seed = (streams[i].seed * mult) % MODULUS;
|
||||||
}
|
}
|
||||||
return streams;
|
return streams;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,4 +29,38 @@ public class Result {
|
|||||||
this.timeElapsedMS = elapsed;
|
this.timeElapsedMS = elapsed;
|
||||||
this.nodes = nodes;
|
this.nodes = nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
var size = (int) Math.ceil(Math.max(Math.log10(this.simulationTime), 1));
|
||||||
|
var iFormat = "%" + size + ".0f";
|
||||||
|
var fFormat = "%" + (size + 4) + ".3f";
|
||||||
|
|
||||||
|
var builder = new StringBuilder();
|
||||||
|
builder.append("===== Net Stats =====\n");
|
||||||
|
builder.append(String.format("Seed: \t%d\n", this.seed));
|
||||||
|
builder.append(String.format("Simulation: \t" + fFormat + "\n", this.simulationTime));
|
||||||
|
builder.append(String.format("Elapsed: \t" + fFormat + "ms\n", this.timeElapsedMS / 1e6));
|
||||||
|
// return builder.toString();
|
||||||
|
|
||||||
|
var table = new ConsoleTable("Node", "Departures", "Avg Queue", "Avg Wait", "Avg Response", "Throughput",
|
||||||
|
"Utilization %", "Unavailable %", "Last Event");
|
||||||
|
|
||||||
|
for (var entry : this.nodes.entrySet()) {
|
||||||
|
var stats = entry.getValue();
|
||||||
|
table.addRow(
|
||||||
|
entry.getKey(),
|
||||||
|
iFormat.formatted(stats.numDepartures),
|
||||||
|
fFormat.formatted(stats.avgQueueLength),
|
||||||
|
fFormat.formatted(stats.avgWaitTime),
|
||||||
|
fFormat.formatted(stats.avgResponse),
|
||||||
|
fFormat.formatted(stats.troughput),
|
||||||
|
fFormat.formatted(stats.utilization * 100),
|
||||||
|
fFormat.formatted(stats.unavailable * 100),
|
||||||
|
fFormat.formatted(stats.lastEventTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.append(table);
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,24 +42,7 @@ public class ResultSummary {
|
|||||||
this.seed = runs[0].seed;
|
this.seed = runs[0].seed;
|
||||||
this.simulationTime = avgTime / runs.length;
|
this.simulationTime = avgTime / runs.length;
|
||||||
this.timeElapsedMS = avgElapsed / runs.length;
|
this.timeElapsedMS = avgElapsed / runs.length;
|
||||||
|
this.stats = ResultSummary.getSummary(runs);
|
||||||
// Get the statistics of the nodes
|
|
||||||
var nodeStats = new HashMap<String, Statistics[]>();
|
|
||||||
for (var i = 0; i < runs.length; i++) {
|
|
||||||
for (var entry : runs[i].nodes.entrySet()) {
|
|
||||||
var node = entry.getKey();
|
|
||||||
var stats = nodeStats.computeIfAbsent(node, _ -> new Statistics[runs.length]);
|
|
||||||
stats[i] = entry.getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the summary of the statistics of the nodes
|
|
||||||
this.stats = new HashMap<>();
|
|
||||||
for (var entry : nodeStats.entrySet()) {
|
|
||||||
var node = entry.getKey();
|
|
||||||
var summary = StatisticsSummary.getSummary(entry.getValue());
|
|
||||||
this.stats.put(node, summary);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -125,4 +108,33 @@ public class ResultSummary {
|
|||||||
builder.append(table);
|
builder.append(table);
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the summary of the statistics of the nodes.
|
||||||
|
* The first map is the node name, the second map is the statistic name.
|
||||||
|
*
|
||||||
|
* @param runs the runs to get the summary
|
||||||
|
* @return the summary of the statistics of the nodes
|
||||||
|
*/
|
||||||
|
public static Map<String, Map<String, StatisticsSummary>> getSummary(Result[] runs) {
|
||||||
|
// Get the statistics of the nodes
|
||||||
|
var nodeStats = new HashMap<String, Statistics[]>();
|
||||||
|
for (var i = 0; i < runs.length; i++) {
|
||||||
|
for (var entry : runs[i].nodes.entrySet()) {
|
||||||
|
var node = entry.getKey();
|
||||||
|
var stats = nodeStats.computeIfAbsent(node, _ -> new Statistics[runs.length]);
|
||||||
|
stats[i] = entry.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the summary of the statistics of the nodes
|
||||||
|
var stats = new HashMap<String, Map<String, StatisticsSummary>>();
|
||||||
|
for (var entry : nodeStats.entrySet()) {
|
||||||
|
var node = entry.getKey();
|
||||||
|
var summary = StatisticsSummary.getSummary(entry.getValue());
|
||||||
|
stats.put(node, summary);
|
||||||
|
}
|
||||||
|
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3001
src/main/resources/example3.csv
Normal file
3001
src/main/resources/example3.csv
Normal file
File diff suppressed because it is too large
Load Diff
BIN
src/main/resources/example3.net
Normal file
BIN
src/main/resources/example3.net
Normal file
Binary file not shown.
Reference in New Issue
Block a user