Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace samm2
- {
- class QueuingSystem
- {
- private double _lambda, _mu;
- private Random _random;
- private double tempTimeInput = 0;
- private double tempTimeFirst = 0;
- private double tempTimeSecond = 0;
- private Calculator calculator = new Calculator();
- private double inputTime = 0;
- private double outputTime = 0;
- private double firstStageTime = 0;
- private double secondStageTime = 0;
- private double tempMuGl = 0;
- private List<double> times = new List<double>();
- private int[] t = new int[3];
- private int inputStep = 1;
- private int outputStep = 0;
- private int queueCounter = 0;
- public QueuingSystem(double lambda, double mu)
- {
- _lambda = lambda;
- _mu = 2 * mu;
- _random = new Random();
- inputTime = getTime(_lambda);
- outputTime = getTime(_mu);
- }
- public double Lambda { get => _lambda; }
- public double Mu { get => _mu; }
- public string Imitate(int numberTacts)
- {
- calculator.Clear();
- for (double i = 0; i < numberTacts; i += 0.01)
- {
- GetNextState(i);
- }
- var a = calculator.getA(numberTacts);
- var l = calculator.getL(numberTacts);
- return "A = " + a.ToString() + ";\r\n Lоч = " + l.ToString() + ";";
- }
- private double getTime(double intensity)
- {
- return (double)((-1 / intensity) * Math.Log(_random.NextDouble()));
- }
- private void GetNextState(double currentTime)
- {
- if (inputTime <= currentTime)
- {
- inputTime = getTime(_lambda) + currentTime;
- if (inputStep == 4)
- {
- inputStep = 1;
- if (outputStep == 0) // not processes
- {
- outputStep = 1;
- outputTime = getTime(_mu) + currentTime;
- }
- else
- {
- queueCounter++;
- }
- }
- else // inputStep = 1..3
- {
- inputStep++;
- }
- }
- if (outputTime <= currentTime && outputStep != 0)
- {
- if (outputStep == 3)
- {
- if (queueCounter > 0)
- {
- outputTime = getTime(_mu) + currentTime;
- outputStep = 1;
- queueCounter--;
- }
- else
- {
- outputStep = 0;
- }
- }
- else // outputStep = 1..2
- {
- outputTime = getTime(_mu) + currentTime;
- outputStep++;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment