- 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:
2025-02-05 09:40:38 +01:00
parent c7d9c05dc3
commit f591de5a06
8 changed files with 3079 additions and 26 deletions

View File

@@ -29,4 +29,38 @@ public class Result {
this.timeElapsedMS = elapsed;
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();
}
}

View File

@@ -42,24 +42,7 @@ public class ResultSummary {
this.seed = runs[0].seed;
this.simulationTime = avgTime / runs.length;
this.timeElapsedMS = avgElapsed / runs.length;
// 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);
}
this.stats = ResultSummary.getSummary(runs);
}
/**
@@ -125,4 +108,33 @@ public class ResultSummary {
builder.append(table);
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;
}
}