diff --git a/src/main/java/net/berack/upo/valpre/Plot.java b/src/main/java/net/berack/upo/valpre/Plot.java index 8180a02..76b2867 100644 --- a/src/main/java/net/berack/upo/valpre/Plot.java +++ b/src/main/java/net/berack/upo/valpre/Plot.java @@ -150,7 +150,7 @@ public class Plot { for (int i = 0; i < model.getSize(); i++) { var entry = model.getElementAt(i); var value = summary.get(entry.name.getText()); - entry.value.setText(String.format("%8.3f ±% 9.3f", value.average, value.error95)); + entry.value.setText(String.format("%8.3f ±% 9.3f", value.average, value.calcError(0.95))); } } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/net/berack/upo/valpre/sim/stats/Result.java b/src/main/java/net/berack/upo/valpre/sim/stats/Result.java index 4643e9f..8d7150d 100644 --- a/src/main/java/net/berack/upo/valpre/sim/stats/Result.java +++ b/src/main/java/net/berack/upo/valpre/sim/stats/Result.java @@ -54,7 +54,7 @@ public class Result { fFormat.formatted(stats.avgQueueLength), fFormat.formatted(stats.avgWaitTime), fFormat.formatted(stats.avgResponse), - fFormat.formatted(stats.troughput), + fFormat.formatted(stats.throughput), fFormat.formatted(stats.utilization * 100), fFormat.formatted(stats.unavailable * 100), fFormat.formatted(stats.lastEventTime)); diff --git a/src/main/java/net/berack/upo/valpre/sim/stats/ResultSummary.java b/src/main/java/net/berack/upo/valpre/sim/stats/ResultSummary.java index 1e4bbba..23a2394 100644 --- a/src/main/java/net/berack/upo/valpre/sim/stats/ResultSummary.java +++ b/src/main/java/net/berack/upo/valpre/sim/stats/ResultSummary.java @@ -51,9 +51,16 @@ public class ResultSummary { * @param node the node to get the summary * @param stat the statistic to get the summary * @return the summary of the statistics of the node + * @throws IllegalArgumentException if the node or the statistic is not found */ public StatisticsSummary getSummaryOf(String node, String stat) { - return this.stats.get(node).get(stat); + var stats = this.getSummaryOf(node); + var value = stats.get(stat); + if (value == null) { + var arr = String.join(", ", stats.keySet().toArray(new String[0])); + throw new IllegalArgumentException("Statistic [" + stat + "] not found. Available: " + arr); + } + return value; } /** @@ -61,9 +68,13 @@ public class ResultSummary { * * @param node the node to get the summary * @return the summary of the statistics of the node + * @throws IllegalArgumentException if the node is not found */ public Map getSummaryOf(String node) { - return this.stats.get(node); + var stat = this.stats.get(node); + if (stat == null) + throw new IllegalArgumentException("Node not found"); + return stat; } /** @@ -99,7 +110,7 @@ public class ResultSummary { fFormat.formatted(stats.get("avgQueueLength").average), fFormat.formatted(stats.get("avgWaitTime").average), fFormat.formatted(stats.get("avgResponse").average), - fFormat.formatted(stats.get("troughput").average), + fFormat.formatted(stats.get("throughput").average), fFormat.formatted(stats.get("utilization").average * 100), fFormat.formatted(stats.get("unavailable").average * 100), fFormat.formatted(stats.get("lastEventTime").average)); diff --git a/src/main/java/net/berack/upo/valpre/sim/stats/Statistics.java b/src/main/java/net/berack/upo/valpre/sim/stats/Statistics.java index 5382a01..5b84915 100644 --- a/src/main/java/net/berack/upo/valpre/sim/stats/Statistics.java +++ b/src/main/java/net/berack/upo/valpre/sim/stats/Statistics.java @@ -24,7 +24,7 @@ public class Statistics { // derived stats, you can calculate them even at the end public double avgWaitTime = 0.0d; public double avgResponse = 0.0d; - public double troughput = 0.0d; + public double throughput = 0.0d; public double utilization = 0.0d; public double unavailable = 0.0d; @@ -75,7 +75,7 @@ public class Statistics { this.waitTime = this.responseTime - this.busyTime; this.avgWaitTime = this.waitTime / this.numDepartures; this.avgResponse = this.responseTime / this.numDepartures; - this.troughput = this.numDepartures / time; + this.throughput = this.numDepartures / time; this.utilization = this.busyTime / time; this.unavailable = this.unavailableTime / time; @@ -120,7 +120,7 @@ public class Statistics { */ public static String[] getOrderOfApply() { return new String[] { "numArrivals", "numDepartures", "avgQueueLength", "avgWaitTime", "avgResponse", - "busyTime", "waitTime", "unavailableTime", "responseTime", "lastEventTime", "troughput", "utilization", + "busyTime", "waitTime", "unavailableTime", "responseTime", "lastEventTime", "throughput", "utilization", "unavailable" }; } @@ -152,7 +152,7 @@ public class Statistics { save.unavailableTime = func.apply(val1.unavailableTime, val2.unavailableTime); save.responseTime = func.apply(val1.responseTime, val2.responseTime); save.lastEventTime = func.apply(val1.lastEventTime, val2.lastEventTime); - save.troughput = func.apply(val1.troughput, val2.troughput); + save.throughput = func.apply(val1.throughput, val2.throughput); save.utilization = func.apply(val1.utilization, val2.utilization); save.unavailable = func.apply(val1.unavailable, val2.unavailable); } diff --git a/src/main/java/net/berack/upo/valpre/sim/stats/StatisticsSummary.java b/src/main/java/net/berack/upo/valpre/sim/stats/StatisticsSummary.java index 9dc60f4..c41e9da 100644 --- a/src/main/java/net/berack/upo/valpre/sim/stats/StatisticsSummary.java +++ b/src/main/java/net/berack/upo/valpre/sim/stats/StatisticsSummary.java @@ -3,6 +3,7 @@ package net.berack.upo.valpre.sim.stats; import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import org.apache.commons.math3.distribution.TDistribution; /** * A summary of the values. @@ -14,8 +15,8 @@ public class StatisticsSummary { public final double min; public final double max; public final double stdDev; - public final double error95; public final double[] values; + private final TDistribution distr; /** * Create a summary of the values. @@ -41,7 +42,7 @@ public class StatisticsSummary { this.median = this.getPercentile(0.50); this.min = values[0]; this.max = values[values.length - 1]; - this.error95 = this.calcError(0.95); + this.distr = new TDistribution(null, values.length - 1); } /** @@ -55,11 +56,8 @@ public class StatisticsSummary { * @return the error of the values */ public double calcError(double alpha) { - var sampleSize = this.values.length; - var distr = new org.apache.commons.math3.distribution.TDistribution(sampleSize - 1); - var percentile = distr.inverseCumulativeProbability(alpha); - - return percentile * (this.stdDev / Math.sqrt(sampleSize)); + var percentile = this.distr.inverseCumulativeProbability(alpha); + return percentile * (this.stdDev / Math.sqrt(this.values.length)); } /** diff --git a/src/main/resources/example1.csv b/src/main/resources/example1.csv index 69d78a1..c436a32 100644 --- a/src/main/resources/example1.csv +++ b/src/main/resources/example1.csv @@ -1,4 +1,4 @@ -seed,node,numArrivals,numDepartures,avgQueueLength,avgWaitTime,avgResponse,busyTime,waitTime,unavailableTime,responseTime,lastEventTime,troughput,utilization,unavailable +seed,node,numArrivals,numDepartures,avgQueueLength,avgWaitTime,avgResponse,busyTime,waitTime,unavailableTime,responseTime,lastEventTime,throughput,utilization,unavailable 2007539552,Queue,10000.0,10000.0,2.5547999999999975,3.8562684946194414,7.052356499598063,31960.880049786218,38562.684946194415,0.0,70523.56499598063,45017.204422048795,0.22213729458291595,0.7099703426748603,0.0 2007539552,Source,10000.0,10000.0,1.0,0.0,4.50110887035251,45011.0887035251,0.0,0.0,45011.0887035251,45011.0887035251,0.2221674766826255,1.0,0.0 608249272,Queue,10000.0,10000.0,2.622700000000001,4.055936800250149,7.246822105620577,31908.85305370428,40559.36800250149,0.0,72468.22105620577,44586.77400295798,0.22428175672311657,0.7156573617904578,0.0 diff --git a/src/main/resources/example2.csv b/src/main/resources/example2.csv index 0ea18e0..e0162be 100644 --- a/src/main/resources/example2.csv +++ b/src/main/resources/example2.csv @@ -1,4 +1,4 @@ -seed,node,numArrivals,numDepartures,avgQueueLength,avgWaitTime,avgResponse,busyTime,waitTime,unavailableTime,responseTime,lastEventTime,troughput,utilization,unavailable +seed,node,numArrivals,numDepartures,avgQueueLength,avgWaitTime,avgResponse,busyTime,waitTime,unavailableTime,responseTime,lastEventTime,throughput,utilization,unavailable 2007539552,Queue Wait,10000.0,10000.0,5.489599999999986,17.346124087767144,20.539632459161886,31935.083713947417,173461.24087767146,8330.825787269936,205396.32459161888,44869.2194771762,0.22286993436751756,0.7117370011348639,0.18566905964360733 2007539552,Queue,10000.0,10000.0,2.5949999999999975,4.0089121710492,7.19854506664509,31896.328955958896,40089.121710492,0.0,71985.4506664509,44861.92110162648,0.22290619203192008,0.7109889227370266,0.0 2007539552,Source,10000.0,10000.0,1.0,0.0,4.485953006623596,44859.530066235966,0.0,0.0,44859.530066235966,44859.530066235966,0.22291807304344932,1.0,0.0 diff --git a/src/main/resources/example3.csv b/src/main/resources/example3.csv index bd26c81..17b360f 100644 --- a/src/main/resources/example3.csv +++ b/src/main/resources/example3.csv @@ -1,4 +1,4 @@ -seed,node,numArrivals,numDepartures,avgQueueLength,avgWaitTime,avgResponse,busyTime,waitTime,unavailableTime,responseTime,lastEventTime,troughput,utilization,unavailable +seed,node,numArrivals,numDepartures,avgQueueLength,avgWaitTime,avgResponse,busyTime,waitTime,unavailableTime,responseTime,lastEventTime,throughput,utilization,unavailable 2007539552,Service2,10000.0,10000.0,1.7866000000000017,0.2331784292519753,0.52110549294643,2879.2706369445477,2331.784292519753,94.20316085745478,5211.054929464301,6592.662919126549,1.5168377517054799,0.4367386399494572,0.014289091071857135 2007539552,Service1,10000.0,10000.0,4.279400000000001,1.6718563141608072,2.18125150580621,5093.951916454023,16718.563141608072,0.0,21812.515058062098,6592.2985442770205,1.5169215915867935,0.7727125648574035,0.0 2007539552,Source,10000.0,10000.0,1.0,0.0,0.6591891302649805,6591.891302649805,0.0,0.0,6591.891302649805,6591.891302649805,1.5170153057560591,1.0,0.0 diff --git a/src/test/java/net/berack/upo/valpre/sim/TestSimulation.java b/src/test/java/net/berack/upo/valpre/sim/TestSimulation.java index ddf84df..ec6b150 100644 --- a/src/test/java/net/berack/upo/valpre/sim/TestSimulation.java +++ b/src/test/java/net/berack/upo/valpre/sim/TestSimulation.java @@ -450,7 +450,7 @@ public class TestSimulation { assertEquals(1.0, nodeStat.maxQueueLength, DELTA); assertEquals(50.0, nodeStat.busyTime, DELTA); assertEquals(result.simulationTime, nodeStat.lastEventTime, DELTA); - assertEquals(1.0, nodeStat.troughput, DELTA); + assertEquals(1.0, nodeStat.throughput, DELTA); assertEquals(1.0, nodeStat.utilization, DELTA); assertEquals(0.0, nodeStat.unavailable, DELTA); @@ -468,7 +468,7 @@ public class TestSimulation { assertEquals(1.0, nodeStat.maxQueueLength, DELTA); assertEquals(50.0, nodeStat.busyTime, DELTA); assertEquals(result.simulationTime - 1, nodeStat.lastEventTime, DELTA); - assertEquals(1.0, nodeStat.troughput, DELTA); + assertEquals(1.0, nodeStat.throughput, DELTA); assertEquals(1.0, nodeStat.utilization, DELTA); assertEquals(0.0, nodeStat.unavailable, DELTA); nodeStat = result.nodes.get("Queue"); @@ -482,7 +482,7 @@ public class TestSimulation { assertEquals(result.simulationTime, nodeStat.lastEventTime, DELTA); assertEquals(nodeStat.busyTime / nodeStat.lastEventTime, nodeStat.utilization, DELTA); - assertEquals(nodeStat.numDepartures / nodeStat.lastEventTime, nodeStat.troughput, DELTA); + assertEquals(nodeStat.numDepartures / nodeStat.lastEventTime, nodeStat.throughput, DELTA); assertEquals(0.0, nodeStat.unavailable, DELTA); } }