private void DoSimulation(int m, int a, int R0, double pi1, double pi2) { Generator gen = new Generator(a, m, R0); int taskCount = 0, doneTaskCount = 0, deletedTaskCount = 0; int inputStatus = 2, queueStatus = 0, channel1Status = 0, channel2Status = 0; int k1 = 0, k2 = 0, x = 0, n = 0; int queueLengthSum = 0; for (var i = 1; i <= ticksCount; i++) { if (channel1Status == 1) // if channel #2 has a task { // then check k1++; if (gen.GetNext() <= (1 - pi1)) // if event will happen { // if happens then channel1Status = 0; // and make channel free doneTaskCount++; } } if (channel2Status == 1) // if channel #2 has a task { // then check k2++; if (gen.GetNext() <= (1 - pi2)) // if event will happen { channel2Status = 0; // if happens then doneTaskCount++; // increase done task counter // and make channel free } } if (queueStatus > 0) { if (channel1Status == 0) { channel1Status = 1; queueStatus--; } } if (queueStatus > 0) { if (channel2Status == 0) { channel2Status = 1; queueStatus--; } } if (inputStatus == 1) { taskCount++; if (channel1Status == 0) { channel1Status = 1; } else if (channel2Status == 0) { channel2Status = 1; } else { if (queueStatus < 2) { queueStatus++; } else { deletedTaskCount++; } } } queueLengthSum += queueStatus; // Console.WriteLine(queueLengthSum); if (inputStatus == 2) { inputStatus = 1; } else { inputStatus = 2; } } LLabel.Text = (((double)queueLengthSum / ticksCount)).ToString("0.####"); ALabel.Text = (((double)doneTaskCount / ticksCount)).ToString("0.####"); Console.WriteLine(n - x); Console.WriteLine((double)(n - x) / ticksCount); WLabel.Text = (((double)queueLengthSum / (double)ticksCount) / ((double)doneTaskCount / (double)ticksCount)).ToString("0.####"); }
private void DoSimulation(int m, int a, int R0, double pi1, double pi2) { Generator gen = new Generator(a, m, R0); int taskCount = 0, doneTaskCount = 0, deletedTaskCount = 0; int inputStatus = 2, queueStatus = 0, channel1Status = 0, channel2Status = 0; int queueLengthSum = 0; for (var i = 1; i <= ticksCount; i++) { if (channel2Status == 1) // if channel #2 has a task { // then check if (gen.GetNext() <= pi2) // if event will happen { // if happens then doneTaskCount++; // increase done task counter channel2Status = 0; // and make channel free } } if (channel1Status == 1) // if channel #2 has a task { // then check if (gen.GetNext() <= pi1) // if event will happen { // if happens then channel1Status = 0; // and make channel free if (channel2Status == 0) //check if channel #2 is free { // if it's free channel2Status = 1; // put task in channel #2 and make it busy } else // if channel #2 is busy { deletedTaskCount++; // then delete task and increase deleted task counter } } } if (queueStatus > 0) { if (channel1Status == 0) { channel1Status = 1; queueStatus--; } } if (inputStatus == 1) { taskCount++; if (channel1Status == 0) { channel1Status = 1; } else { if (queueStatus < 2) { queueStatus++; } else { deletedTaskCount++; } } } queueLengthSum += queueStatus; if (inputStatus == 2) { inputStatus = 1; } else { inputStatus = 2; } } PLabel.Text = ((double)deletedTaskCount / (deletedTaskCount + doneTaskCount)).ToString(); ALabel.Text = ((double)doneTaskCount / ticksCount).ToString(); LLabel.Text = ((double)queueLengthSum / ticksCount).ToString(); }