Multi Run Threads

This commit is contained in:
2025-01-19 23:57:15 +01:00
parent d7b968d0a2
commit 89e89108a9
6 changed files with 372 additions and 161 deletions

View File

@@ -3,7 +3,7 @@ package net.berack.upo.valpre;
import net.berack.upo.valpre.rand.Distribution;
public class Main {
public static void main(String[] args) {
public static void main(String[] args) throws Exception {
// Parameters for the simulation
var seed = System.nanoTime();
var total = 100000;
@@ -17,28 +17,13 @@ public class Main {
node1.addChild(node2, 1.0);
/// Run the simulation
var sim = new NetSimulation(seed);
var sim = new NetSimulation();
sim.addNode(node1);
sim.addNode(node2);
var maxDepartures = new EndSimulationCriteria.MaxDepartures("Queue", total);
//var maxTime = new EndSimulationCriteria.MaxTime(1000.0);
var results = sim.run(maxDepartures);
// Display the results
for (var entry : results.entrySet()) {
var stats = entry.getValue();
var size = (int) Math.ceil(Math.max(Math.log10(stats.numArrivals), Math.log10(stats.lastEventTime)));
var iFormat = "%" + size + "d";
var fFormat = "%" + (size + 4) + ".3f";
System.out.println("===== " + entry.getKey() + " =====");
System.out.printf(" Arrivals: \t" + iFormat + "\n", stats.numArrivals);
System.out.printf(" Departures:\t" + iFormat + "\n", stats.numDepartures);
System.out.printf(" Max Queue: \t" + iFormat + "\n", stats.maxQueueLength);
System.out.printf(" Response: \t" + fFormat + "\n", stats.responseTime / stats.numDepartures);
System.out.printf(" Busy %%: \t" + fFormat + "\n", stats.busyTime * 100 / stats.lastEventTime);
System.out.printf(" Last Event:\t" + fFormat + "\n", stats.lastEventTime);
}
// var maxDepartures = new EndSimulationCriteria.MaxDepartures("Queue", total);
// var maxTime = new EndSimulationCriteria.MaxTime(1000.0);
var results = sim.runParallel(seed, 100);
results.runs[80].printSummary();
}
}