public SampleWorkload() { // This sample file contains a poisson distributed workload var json = File.ReadAllText("workload.json"); var workload = (SampleEvent[])JsonConvert.DeserializeObject(json, typeof(SampleEvent[])); // Determine individual customer classes var workloadPerTypes = workload.GroupBy(e => e.Type, e => e).ToDictionary(g => g.Key, g => g.ToArray()); _queueingTheoryInfos = new Dictionary <FeatureIdentifier, QueueingTheoryInfo>(); // Calculate the queueing theory representation for every customer class foreach (var workloadTypePair in workloadPerTypes) { var events = workloadTypePair.Value; var timeBetweenArrivals = new List <int>(); var serviceTimes = new List <int>(); for (var i = 1; i < events.Length; i++) { timeBetweenArrivals.Add(events[i].ArrivalTime - events[i - 1].ArrivalTime); serviceTimes.Add(events[i].ServiceTime); } var meanInterArrivalTime = (int)Math.Round(timeBetweenArrivals.Average()); var meanServiceTime = (int)Math.Round(serviceTimes.Average()); var featureId = new FeatureIdentifier(workloadTypePair.Key); var chanceOfOccurance = (double)events.Length / workload.Length; _queueingTheoryInfos[featureId] = new QueueingTheoryInfo(meanInterArrivalTime, meanServiceTime, chanceOfOccurance, new [] { workloadTypePair.Key }); } }
public void Constructor_WithUtilizationLargerThan1_ThrowsException() { Assert.Throws <ArgumentException>(() => { var types = new[] { "test" }; var sot = new QueueingTheoryInfo(5, 10, 1, types); }); }
public void Constructor_Sets_Fields_Correctly() { var types = new[] { "test" }; var sot = new QueueingTheoryInfo(10, 5, 1, types); Assert.AreEqual(10, sot.MeanInterArrivalTime); Assert.AreEqual(5, sot.MeanServiceTime); Assert.AreEqual(1, sot.ChanceOfOccurance); Assert.AreEqual(0.1d, sot.MeanArrivalRate); Assert.AreEqual(0.2d, sot.MeanServiceRate); Assert.AreEqual(10, sot.MeanWaitingTime); Assert.AreEqual(15, sot.SojournTime); CollectionAssert.AreEqual(types.Select(t => new FeatureIdentifier(t)), sot.Types); }
public void PlusOperator_Returns_CorrectResult() { var firstTypes = new[] { "first" }; var firstClass = new QueueingTheoryInfo(50, 5, 0.5, firstTypes); var secondTypes = new[] { "second" }; var secondClass = new QueueingTheoryInfo(20, 10, 0.5, secondTypes); var result = firstClass + secondClass; Assert.AreEqual(35, result.MeanInterArrivalTime); Assert.AreEqual(7.5d, result.MeanServiceTime); var newTypes = new[] { new FeatureIdentifier("first"), new FeatureIdentifier("second") }; CollectionAssert.AreEqual(newTypes, result.Types); }