Пример #1
0
		private void pushProcesses()
		{
			this.NumberOfProcess = this.dtgvInput.RowCount - 1;
			this.list = new LinkedList();

			try
			{
				for (int i = 0; i < this.NumberOfProcess; i++)
				{
					Node newNode = new Node
					{
						Name = this.dtgvInput.Rows[i].Cells[0].Value.ToString(),
						ArrivalTime = int.Parse(this.dtgvInput.Rows[i].Cells[1].Value.ToString()),
						CPUBurstTime = int.Parse(this.dtgvInput.Rows[i].Cells[2].Value.ToString())
					};

					this.list.addNodeAtTheEnd(newNode);
				}

				this.list.quickSort();
				this.list.Numbering();
			}
			catch (System.Exception ex)
			{
				MessageBox.Show("Không thể tính toán được.\n\rHãy nhập dữ liệu trước", "Lỗi",
								 MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}
Пример #2
0
        /* Hàm tạo */
		public Algorithm(LinkedList processesList)
		{
			this.NumberOfProcess = processesList.Length();
			this.Processed = new bool[this.NumberOfProcess];

			for (int i = 0; i <= this.NumberOfProcess - 1; i++)
			{
                this.Processed[i] = false;      // tất cả các tiến trình chưa chạy
			}

			this.RemainingTime = new int[this.NumberOfProcess];
			Node head = processesList.Head;

			while (head != processesList.Tail)
			{
				this.RemainingTime[head.Number] = head.CPUBurstTime;
				head = head.Next;
			}
			this.RemainingTime[head.Number] = head.CPUBurstTime;
			this.ready = new LinkedList();
			this.arrangedProcesses = new LinkedList();
			this.Process_List = processesList;
			this.TimeLine = new int[300];
			this.ProcessingTime = 0;
			this.TotalTime = 0;
			this.gantt = new Gantt();
		}
Пример #3
0
        /* Vẽ biểu đồ Gantt, ghi kết quả lên DataGridView Output và Textbox */
        public void DrawGantt(LinkedList processesList,     // danh sách các tiến trình đã hoàn thành
                              int[] timeLine,               // 
                              LinkedList arrangedProcesses, // danh sách các tiến trình đã được sắp xếp
                              PictureBox pic,               // picture box để show ảnh
                              DataGridView dtgv,            // Datagridview Output
                              TextBox tbx                   // textbox thời gian chờ trung bình
                             )
		{
			for (int i = 1; i < dtgv.RowCount; i++)
			{
				dtgv.Rows.Clear();  // làm sạch DataGridView dtgvOuput
			}

            int index = arrangedProcesses.Length(); // số tiến trình đã được sắp xếp
            int p_num = processesList.Length();      // số lượng tiến trình đầu vào
            int[] numArray = new int[p_num];        // thời gian chờ của các tiến trình
			int width = ((int)(timeLine[index] * this.Coefficient)) + 30;
			int height = pic.Height;
			// tạo ảnh bitmap
			Bitmap image = new Bitmap(width, height, PixelFormat.Format32bppPArgb);
			// tạo font chữ
			Font font = new Font("Tahoma", 13, FontStyle.Regular, GraphicsUnit.Point, 0);
			Graphics graphics = Graphics.FromImage(image);

			// vẽ các viền trên và dưới
			graphics.DrawLine(new Pen(Brushes.Black, 1.5f), new Point(0, this.Top), new Point(width, this.Top));
			graphics.DrawLine(new Pen(Brushes.Black, 1.5f), new Point(0, this.Bottom), new Point(width, this.Bottom));
			graphics.DrawLine(new Pen(Brushes.Black, 1.5f), new Point(0, this.Top), new Point(0, this.Bottom));

			// vẽ trục thời gian
			for (int j = 0; j <= index; j++)
			{
				graphics.DrawLine(new Pen(Brushes.Black, 1.5f), new Point((int)(this.Coefficient * timeLine[j]), this.Top), 
								  new Point((int)(this.Coefficient * timeLine[j]), this.Bottom));
				// ghi các mốc thời gian
				graphics.DrawString(timeLine[j].ToString(), font, Brushes.Black, 
									(PointF)new Point((int)((this.Coefficient * timeLine[j]) - 3), this.Bottom + 2));
			}
			
            Node head = new Node();
			head = processesList.Head;	   
			Node next = new Node();
			next = arrangedProcesses.Head;
            int row_num = 0;                   // số hàng datagridview
            Point point = new Point();      // điểm nhằm ghi tên các tiến trình

            while (next != arrangedProcesses.Tail)  // chừng nào danh sách đã sắp xếp chưa hết
			{
				point = new Point((int)(this.Coefficient * (timeLine[row_num] + ((timeLine[row_num + 1] - timeLine[row_num]) / 4))), 
								   this.Top + ((-this.Top + this.Bottom) / 4));
                // ghi tên các tiến trình lên ảnh
				graphics.DrawString(next.Name.ToString(), font, Brushes.Red, (PointF)point);
				// ghi kết quả lên datagridviewOutput
				dtgv.Rows.Add();
				dtgv.Rows[row_num].Cells[0].Value = next.Name.ToString();
				dtgv.Rows[row_num].Cells[1].Value = timeLine[row_num].ToString() + " -> " + timeLine[row_num + 1].ToString();
				next = next.Next;
				row_num++;
			}

			// tiến trình cuối cùng
			point = new Point((int)(this.Coefficient * (timeLine[row_num] + ((timeLine[row_num + 1] - timeLine[row_num]) / 4))),
								   this.Top + ((-this.Top + this.Bottom) / 4));
			graphics.DrawString(next.Name.ToString(), font, Brushes.Red, (PointF)point);
			
            /* ghi kết quả lên datagridviewOutput */
			dtgv.Rows.Add();
			dtgv.Rows[row_num].Cells[0].Value = next.Name.ToString();
			dtgv.Rows[row_num].Cells[1].Value = timeLine[row_num].ToString() + " -> " + timeLine[row_num + 1].ToString();

            int arrivalTime = 0;        // thời gian tới
            int arv_num = 0;            // thời gian tới
            int total_num = 0;          // tổng thời gian chờ
			string str = null;
			
			for (int k = 0; k < p_num; k++)
			{
				row_num = 0;
				Node node1 = processesList.Head;
				while (row_num != p_num)
				{
					if (node1.Number == k)
					{
						arrivalTime = node1.ArrivalTime;
						arv_num = arrivalTime;
						break;
					}
					node1 = node1.Next;
					row_num++;
				}

                // ghi lên text box thời gian chờ trung bình
				row_num = 0;
				numArray[k] = 0;
				Node node2 = arrangedProcesses.Head;

				while (node2 != arrangedProcesses.Tail)
				{
					if (node2.Number == k)
					{
						arv_num = timeLine[row_num];
						numArray[k] += arv_num - arrivalTime;
						arrivalTime = timeLine[row_num + 1];
					}
					node2 = node2.Next;
					row_num++;
				}
				if (node2.Number == k)
				{
					arv_num = timeLine[row_num];
					numArray[k] += arv_num - arrivalTime;
				}
				str = str + numArray[k].ToString() + " + ";
				total_num += numArray[k];
			}

			// ghi kết quả lên textbox kết quả (thời gian chờ trung bình)

			str = str.Remove(str.Length - 3);
			string str2 = "(" + str;
			string[] strArray = new string[] { str2, ")/", p_num.ToString(), " = ", (((double)total_num) / ((double)p_num)).ToString() };
			str = string.Concat(strArray);
			pic.Width = width + 10;
			pic.Image = image;
			tbx.Text = str;
		}
Пример #4
0
		// Sắp xếp
		public void quickSort()
		{
			if (this.Head != this.Tail)
			{
				Node node;
				LinkedList list = new LinkedList();
				LinkedList list2 = new LinkedList();
				node = this.Head;
				Node p = new Node();

				this.GetNodeP(ref node);

				while (this.Head != null)
				{
					p = this.Head;
					this.GetNodeP(ref p);
					if (p.ArrivalTime < node.ArrivalTime)
					{
						list.addNodeAtTheEnd(p);
					}
					else
					{
						list2.addNodeAtTheEnd(p);
					}
				}

				list.quickSort();
				list2.quickSort();

				if (list.Head == null)
				{
					this.Head = node;
				}
				else
				{
					this.Head = list.Head;
					list.Tail.Next = node;
					node.Next = list2.Head;
				}
				if (list2.Head == null)
				{
					this.Tail = node;
				}
				else
				{
					this.Tail = list2.Tail;
					node.Next = list2.Head;
				}
				this.Tail.Next = this.Head;
			}
		}
Пример #5
0
		public MainForm()
		{
			InitializeComponent();
			this.list = new LinkedList();
			this.components = null;
		}
Пример #6
0
		// xóa dữ liệu
		private void button3_Click(object sender, EventArgs e)
		{

			if (MessageBox.Show("Bạn muốn xóa dữ liệu vừa tính toán ?", "Chú ý",
								MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
			{
				dtgvInput.Rows.Clear();
				dtgvFCFS.Rows.Clear();
                dtgvSJF.Rows.Clear();
                dtgvSRTF.Rows.Clear();
                dtgvRR.Rows.Clear();
				this.NumberOfProcess = 0;
				this.list = null;
                this.FCFSTbx.Text = "";
                this.SJFTbx.Text = "";
                this.SRTFTbx.Text = "";
                this.RRTbx.Text = "";
                pictureBox1.Image = null;
                pictureBox2.Image = null;
                pictureBox3.Image = null;
                pictureBox4.Image = null;

				MessageBox.Show("Xóa dữ liệu thành công. \r\nHãy nhập vào dữ liệu mới", "Xóa thành công",
							MessageBoxButtons.OK, MessageBoxIcon.Information);
			}
		}