Пример #1
0
        private async void CalculateQueues()
        {
            // Read inputs
            int    hours                 = (int)udHours.Value;
            int    requestsPerHour       = (int)udRequestsPerHour.Value;
            double avgRequestProcessTime = (double)udRequestProcessTime.Value;
            double requestWorth          = (double)udRequestWorth.Value;
            double channelFee            = (double)udChannelFee.Value;
            double queueFee              = (double)udQueueFee.Value;

            int channels  = (int)udChannels.Value;
            int queueSize = (int)udQueueSize.Value;

            // Create system
            MassServiceSystem mSS = new MassServiceSystem(hours, requestsPerHour, avgRequestProcessTime,
                                                          requestWorth, channelFee, channels, queueSize, queueFee);

            // Profits from systems with different queue sizes
            List <double> profit = new List <double>();

            // Calc profits and display them
            while (mSS.QueueSize > 0)
            {
                await Task.Factory.StartNew(() => mSS.Start());

                OutputBox.Text += $"QueueSize:{mSS.QueueSize,3} | {mSS.PureProfit,6:F2} y.e.\n";
                profit.Add(mSS.PureProfit);
                mSS.QueueSize--;
            }

            BuildQueuesPlot(profit);
        }
Пример #2
0
        private async void CalculateCustom()
        {
            // Read inputs
            int    hours                 = (int)udHours.Value;
            int    requestsPerHour       = (int)udRequestsPerHour.Value;
            double avgRequestProcessTime = (double)udRequestProcessTime.Value;
            double requestWorth          = (double)udRequestWorth.Value;
            double channelFee            = (double)udChannelFee.Value;
            double queueFee              = (double)udQueueFee.Value;

            int channels  = (int)udChannels.Value;
            int queueSize = (int)udQueueSize.Value;

            // Create system
            MassServiceSystem mSS = new MassServiceSystem(hours, requestsPerHour, avgRequestProcessTime,
                                                          requestWorth, channelFee, channels, queueSize, queueFee);

            // Run system
            await Task.Factory.StartNew(() => mSS.Start());

            // Display results
            OutputBox.Text         += $"Profit: {mSS.PureProfit,6:F2} y.e.\n";
            RequestsGrid.DataSource = mSS.Requests;
        }
Пример #3
0
        private async void CalculateTotal()
        {
            // Read inputs
            int    hours                 = (int)udHours.Value;
            int    requestsPerHour       = (int)udRequestsPerHour.Value;
            double avgRequestProcessTime = (double)udRequestProcessTime.Value;
            double requestWorth          = (double)udRequestWorth.Value;
            double channelFee            = (double)udChannelFee.Value;
            double queueFee              = (double)udQueueFee.Value;

            // Init values
            double profit2Channel = 0;
            double profit3Channel = 0;
            double queueProfit    = 0;
            int    queueSize      = 0;

            // Run 2 channel system
            Task task2Channel = Task.Factory.StartNew(() =>
            {
                MassServiceSystem mSS = new MassServiceSystem(hours, requestsPerHour, avgRequestProcessTime,
                                                              requestWorth, channelFee, 2);
                mSS.Start();
                profit2Channel = mSS.PureProfit;
            });

            // Run 3 channel system
            Task task3Channel = Task.Factory.StartNew(() =>
            {
                MassServiceSystem mSS = new MassServiceSystem(hours, requestsPerHour, avgRequestProcessTime,
                                                              requestWorth, channelFee, 3);
                mSS.Start();
                profit3Channel = mSS.PureProfit;
            });

            // Run system with queue [1..20] and 2 channels
            Task taskQueue = Task.Factory.StartNew(() =>
            {
                MassServiceSystem mSS = new MassServiceSystem(hours, requestsPerHour, avgRequestProcessTime,
                                                              requestWorth, channelFee, 2, 1, queueFee);

                // [1..20] - queue's sizes for testing
                for (int i = 1; i < 21; i++)
                {
                    mSS.QueueSize = i;
                    mSS.Start();

                    if (queueProfit < mSS.PureProfit)
                    {
                        // get queue size with max profit
                        queueProfit = mSS.PureProfit;
                        queueSize   = mSS.QueueSize;
                    }
                }
            });

            // Wait for task complition and display results
            await Task.WhenAll(new[] { task2Channel, task3Channel, taskQueue });

            // Display results
            OutputBox.Text += $"2 Channels profit | {profit2Channel,6:F2} y.e.\n";
            OutputBox.Text += $"3 Channels profit | {profit3Channel,6:F2} y.e.\n";
            OutputBox.Text += $"QueueSize: {queueSize} | {queueProfit,6:F2} y.e.\n";

            BuildTotalPlot(new [] { profit2Channel, profit3Channel, Math.Round(queueProfit) }, queueSize);
        }