| Код | Класс Process: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing;
namespace WindowsFormsApplication2 { public class Process { public static Random k = new Random(); public string name; public int tStart, tProc; public float Pr0, Pri; public bool isRun = false, isEnd = false; public int ki = k.Next(1, 100); public void culcPriority(int t) { Pri = Pr0 + ki; } } }
Form1: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;
namespace WindowsFormsApplication2 { public partial class Form1 : Form { int count = 0; public Form1() { InitializeComponent(); label8.Text = "Введите процесс " + (count + 1); } Process[] proceses; public int N, Del; public Graphics g; private void button1_Click(object sender, EventArgs e)//ввод количества проц и дельта { N = int.Parse(textBox1.Text); proceses=new Process[N]; Del = int.Parse(textBox2.Text); button1.Enabled = false; textBox1.Enabled = false; textBox2.Enabled = false; }
private void button2_Click(object sender, EventArgs e) { if (count < N) // вод параметров процессов { proceses[count] = new Process(); proceses[count].name = textBox3.Text.ToString(); proceses[count].tStart = Convert.ToInt32(textBox4.Text); proceses[count].tProc = Convert.ToInt32(textBox5.Text); proceses[count].Pr0 = Convert.ToSingle(textBox6.Text); textBox3.Clear(); textBox4.Clear(); textBox5.Clear(); textBox6.Clear(); count++; label8.Text = "Введите процесс " + (count + 1); if (count == N) { button2.Text = "Рассчитать!"; textBox3.Enabled = false; textBox4.Enabled = false; textBox5.Enabled = false; textBox6.Enabled = false; label8.Text = "Нажмите кнопку"; } } else //запуск агоритма { bool end = false; for (int t = 0; end == false; t++) { for (int i = 0; i < N; i++) { if (proceses[i].tStart == t) { proceses[i].isRun = true; //переход в готовность }
if (proceses[i].tProc == 0) //проверка на законченность { proceses[i].isRun = false; proceses[i].isEnd = true; } if ((t % Del == 0 && proceses[i].isRun == true) || t == 0) proceses[i].culcPriority(t); }
//Сортировка Process buf = new Process(); for (int y = 0; y < N; y++) { for (int x = 0; x < N-1; x++) { if ((proceses[x].Pri < proceses[x + 1].Pri && proceses[x + 1].isRun == true) || (proceses[x + 1].isRun == true && proceses[x].isRun == false)) { buf=proceses[x]; proceses[x] = proceses[x + 1]; proceses[x + 1]= buf; } } } if(proceses[0].isRun==true) proceses[0].tProc--; //отрисовка g = pictureBox1.CreateGraphics(); //g.Clear(Color.White); g.DrawLine(new Pen(new SolidBrush(Color.Red)), 50, 5, 50, 80); g.DrawLine(new Pen(new SolidBrush(Color.Red)), 20, 40, 900, 40); float x0 = 50 + 20f * t; float y0 = 20f; for (int i = 0; i < N; i++) { if (proceses[i].isRun == true) { g.FillRectangle(new SolidBrush(Color.Gray), x0, y0 + 20 * i, 20, 20); g.DrawLine(new Pen(new SolidBrush(Color.Red)), x0, 20, x0, 40); Font fon = new Font("Colobri", 8.0f); g.DrawString(proceses[i].name, fon, new SolidBrush(Color.Black), x0 + 2, y0 + (20 * i) + 1); } } // конец отрисовки int z = 0; for (int i = 0;i < N;i++) { if (proceses[i].isEnd == true) z++; } if (z == N) { end = true; button2.Enabled = false; label8.Text = "Готово!!!"; } }
} }
private void textBox1_TextChanged(object sender, EventArgs e) {
}
private void label5_Click(object sender, EventArgs e) {
}
private void label7_Click(object sender, EventArgs e) {
}
private void label3_Click(object sender, EventArgs e) {
}
private void label8_Click(object sender, EventArgs e) {
}
} }
Program: using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms;
namespace WindowsFormsApplication2 { static class Program { /// <summary> /// Главная точка входа для приложения. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }
|
Диспетчер на основе дисциплины с динамическими приоритетами, изменяющимися по формуле Pri=Pr0i+ki., где ki – случайное число. Помогите исправить на Диспетчер на основе дисциплины с динамическими приоритетами, изменяющимися по формуле Pri=Pr0i+ai*log(t).где Pr0i – начальное значение приоритета i-ой задачи, ai – задаваемый коэффициент i-ой задачи, i =1..n, n – число задач. Это сообщение отредактировал(а) amanda7 - 10.5.2014, 21:49
|