Ejemplo n.º 1
0
        public void TestDistributionTimeSpanExponential()
        {
            IDoubleDistribution   dist = new ExponentialDistribution(m_model, "ExponentialDistribution", Guid.NewGuid(), 3.0, 3.0);
            ITimeSpanDistribution tsd  = new TimeSpanDistribution(m_model, "TSD:" + dist.Name, Guid.NewGuid(), dist, TimeSpanDistribution.Units.Minutes);

            tsd.SetCDFInterval(0.5, 0.5);
            Assert.IsTrue(tsd.GetNext().Equals(TimeSpan.FromMinutes(5.0794415416798362)));
            tsd.SetCDFInterval(0.0, 1.0);

            System.IO.StreamWriter tw = new System.IO.StreamWriter(Environment.GetEnvironmentVariable("TEMP") + "\\TimeSpanDistributionExponential.csv");
            Debug.WriteLine("Generating raw data.");
            int DATASETSIZE = 1500000;

            double[] rawData = new double[DATASETSIZE];
            for (int x = 0; x < DATASETSIZE; x++)
            {
                rawData[x] = tsd.GetNext().TotalMinutes;
                //tw.WriteLine(rawData[x]);
            }

            Debug.WriteLine("Performing histogram analysis.");
            Histogram1D_Double hist = new Histogram1D_Double(rawData, 0, 120.0, 100, "distribution");

            hist.LabelProvider = new LabelProvider(((Histogram1D_Double)hist).DefaultLabelProvider);
            hist.Recalculate();

            Debug.WriteLine("Writing data dump file.");
            int[] bins = (int[])hist.Bins;
            for (int i = 0; i < bins.Length; i++)
            {
                //Debug.WriteLine(hist.GetLabel(new int[]{i}) + ", " + bins[i]);
                tw.WriteLine(hist.GetLabel(new int[] { i }) + ", " + bins[i]);
            }

            tw.WriteLine("Sum of off-scale-high : " + (((double)hist.SumEntries(HistogramBinCategory.OffScaleHigh))));
            tw.WriteLine("Average value : " + (((double)hist.SumEntries(HistogramBinCategory.All)) / ((double)hist.RawData.Length)));
            tw.Flush();
            tw.Close();

            if (m_visuallyVerify)
            {
                System.Diagnostics.Process.Start("excel.exe", Environment.GetEnvironmentVariable("TEMP") + "\\TimeSpanDistributionExponential.csv");
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a Server that accepts service objects on its input port, and holds them for a duration
 /// specified by a TimeSpanDistribution before emitting them from its output port. It currently is
 /// designed always to be "in service."<para/>
 /// </summary>
 /// <param name="model">The model in which this buffered server will operate.</param>
 /// <param name="name">The name given to this server.</param>
 /// <param name="guid">The guid that this server will be known by.</param>
 /// <param name="timeSpanDistribution">The TimeSpanDistribution that specifies how long each object is held.</param>
 /// <param name="capacity">The capacity of this server to hold service objects (i.e. how many it can hold)</param>
 public MultiChannelDelayServer(IModel model, string name, Guid guid, TimeSpanDistribution timeSpanDistribution, int capacity)
     : this(model, name, guid)
 {
     m_timeSpanDistribution = timeSpanDistribution;
     m_capacity             = capacity;
 }