Exemplo n.º 1
0
 private void createRow(DataGridView dgv, cProcess pr)
 {
     DataGridViewRow row = new DataGridViewRow();
     row.Cells.Add(new DataGridViewTextBoxCell { Value = pr.ID });
     row.Cells.Add(new DataGridViewTextBoxCell { Value = Math.Round(1.0*pr.Progress/pr.TBurst*100, 4).ToString() + "%" });
     dgv.Rows.Add(row);
 }
Exemplo n.º 2
0
        private void FCFSAlgorithm()
        {
            foreach (cProcess pr in processList)
            {
                if (i == pr.TArrival)
                {
                    readyProcessList.Add(pr);
                    setProgressDGViews(dgvProgress);

                    createRow(dgvProgress, pr);
                }
            }
            if (i == 0)
            {
                if(readyProcessList.Count!=0) executing = readyProcessList[0];
                firstTime("FCFS");
            }
            else if (readyProcessList.Count == 0 && i > 0)
            {
                addNewCell("(" + i.ToString() + "-" + (i + 1).ToString() + ")" + "s", Color.Black);
            }
            else if (readyProcessList.Count != 0)
            {
                executing=readyProcessList[0]; 
                addNewCell(executing.ID + "\n\n\n\n\n" + "(" + i.ToString() + "-" + (i + 1).ToString() + ")" + "s", executing.ProcessColor);

                executing.Progress++;
                dgvProgress.Rows[0].Cells[1].Value = Math.Round(1.0 * executing.Progress / executing.TBurst*100, 4).ToString() + "%";

                processDone("FCFS");
            }
            i++;
            if (dgvDone.Rows.Count==dgvProcesses.Rows.Count) timer1.Stop();
            dgvTimeline.ClearSelection();
        }
Exemplo n.º 3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (rbPS.Checked)
            {
                using (AddProcess fAdd = new AddProcess(true))
                {
                    if (fAdd.ShowDialog() == DialogResult.OK)
                    {
                        cProcess proc = new cProcess(fAdd.id, fAdd.tArrival, fAdd.tBurst, fAdd.Priority, fAdd.c);
                        if(processList.Count==0) setDataGridView(proc.Priority);
                        createDataGridViewRow(proc);
                        processList.Add(proc);
                        cProcess proc2 = new cProcess(fAdd.id, fAdd.tArrival, fAdd.tBurst, fAdd.Priority, fAdd.c);
                        tempProcessList.Add(proc2);
                    }

                }
            }
            else
            using (AddProcess fAdd = new AddProcess(false))
            {
                    if (fAdd.ShowDialog() == DialogResult.OK)
                    {
                        cProcess proc = new cProcess(fAdd.id, fAdd.tArrival, fAdd.tBurst, fAdd.Priority, fAdd.c);
                        if (processList.Count == 0)  setDataGridView(proc.Priority);
                        createDataGridViewRow(proc);
                        processList.Add(proc);
                        cProcess proc2 = new cProcess(fAdd.id, fAdd.tArrival, fAdd.tBurst, fAdd.Priority, fAdd.c);
                        tempProcessList.Add(proc2);
                    }
            }
        }
Exemplo n.º 4
0
        private void RoundRobinAlgorithm()
        {
            updateReadyProcessList();
            if (readyProcessList.Count != 0)
            {
                dgvProgress.Rows.Clear();
                setProgressDGViews(dgvProgress);
                foreach(cProcess pr in readyProcessList)
                {
                    createRow(dgvProgress, pr);
                }
                if (i == 0)
                {
                    executing = readyProcessList[0];
                    quant++;
                    firstTime("RR");
                }
                else if (quant % Convert.ToInt32(cbTQ.SelectedItem) != 0  && quant!=0 || quant==0)
                {
                    if (executing == null) executing = readyProcessList[0];
                    quant++;
                }
                else if (quant % Convert.ToInt32(cbTQ.SelectedItem) == 0 && quant != 0)
                {
                    quant = 0;
                    readyProcessList.Add(executing);
                    readyProcessList.RemoveAt(0);
                    dgvProgress.Rows.Clear();
                    setProgressDGViews(dgvProgress);
                    foreach (cProcess pr in readyProcessList)
                    {
                        createRow(dgvProgress, pr);
                    }
                    executing = readyProcessList[0];
                    quant++;
                }
            }
            else if (i == 0)
            {
                setProgressDGViews(dgvProgress);
                firstTime("SRTN");
            }
            if (executing == null && i > 0)
            {
                addNewCell("("+i.ToString()+"-"+(i+1).ToString()+")" + "s", Color.Black);
            }
            else if (executing != null && i > 0)
            {
                addNewCell(executing.ID + "\n\n\n\n\n" + "(" + i.ToString() + "-" + (i + 1).ToString() + ")" + "s", executing.ProcessColor);

                executing.Progress++; executing.ProgressLeft--;
                dgvProgress.Rows[0].Cells[1].Value = Math.Round(1.0 * executing.Progress / executing.TBurst * 100, 4).ToString() + "%";

                processDone("RR");
            }
            i++;
            if (dgvDone.Rows.Count == dgvProcesses.Rows.Count) timer1.Stop();
            dgvTimeline.ClearSelection();
        }
Exemplo n.º 5
0
 private void processDone(string algorithm)
 {
     if (executing.Progress == executing.TBurst)
     {
         dgvProgress.Rows.Clear();
         setProgressDGViews(dgvDone);
         createRow(dgvDone, executing);
         if (algorithm == "FCFS")
         {
             readyProcessList.RemoveAt(0);
             if (readyProcessList.Count > 0) executing = readyProcessList[0];
             foreach (cProcess pr in readyProcessList)
             {
                 createRow(dgvProgress, pr);
             }
         }
         else if (algorithm == "RR")
         {
             readyProcessList.RemoveAt(0);
             quant = 0;
             executing = null;
             foreach (cProcess pr in readyProcessList)
             {
                 createRow(dgvProgress, pr);
             }
         }
         else if( algorithm == "PS")
         {
             readyProcessList.RemoveAt(0);
             quant = 0;
             executing = null;
             readyProcessList = readyProcessList.OrderBy(o => o.Priority).ToList();
             foreach (cProcess pr in readyProcessList)
             {
                 createRow(dgvProgress, pr);
             }
         }
         else if (algorithm == "SJF")
         {
             executing = null;
             foreach (cProcess pr in readyProcessList)
             {
                 createRow(dgvProgress, pr);
             }
         }
         else if (algorithm == "SRTN")
         {
             readyProcessList.RemoveAt(0);
             readyProcessList = readyProcessList.OrderBy(o => o.ProgressLeft).ToList();
             executing = null;
             foreach (cProcess pr in readyProcessList)
             {
                 createRow(dgvProgress, pr);
             }
         }
     }
 }
Exemplo n.º 6
0
        private void SJFAlgorithm()
        {
            updateReadyProcessList();
            if (readyProcessList.Count != 0)
            {
                readyProcessList = readyProcessList.OrderBy(o => o.TBurst).ToList();
                dgvProgress.Rows.Clear();
                setProgressDGViews(dgvProgress);
                if (executing != null) createRow(dgvProgress, executing);
                foreach (cProcess pr in readyProcessList)
                {
                    createRow(dgvProgress, pr);
                }
                if (executing == null)
                {
                    executing = readyProcessList[0];
                    readyProcessList.RemoveAt(0);

                }
                if (i == 0) firstTime("SJF");
                else processDone("SJF");
            }
            else if (i == 0) firstTime("SJF"); 
            if (executing==null && i > 0)
            {
                addNewCell("(" + i.ToString() + "-" + (i + 1).ToString() + ")" + "s", Color.Black);
                
            }
            else if (executing != null && i>0 )
            {
                addNewCell(executing.ID + "\n\n\n\n\n" + "(" + i.ToString() + "-" + (i + 1).ToString() + ")" + "s", executing.ProcessColor);
               
                executing.Progress++;
                dgvProgress.Rows[0].Cells[1].Value = Math.Round(1.0 * executing.Progress / executing.TBurst * 100, 4).ToString() + "%";

                processDone("SJF");
            }
            i++;
            if (dgvDone.Rows.Count == dgvProcesses.Rows.Count) timer1.Stop();
            dgvTimeline.ClearSelection();
        }
Exemplo n.º 7
0
        private void createDataGridViewRow(cProcess proc)
        {
            DataGridViewRow row = new DataGridViewRow();
            row.Cells.Add(new DataGridViewTextBoxCell { Value = proc.ID });
            row.Cells.Add(new DataGridViewTextBoxCell { Value = proc.TArrival.ToString() });
            row.Cells.Add(new DataGridViewTextBoxCell { Value = proc.TBurst.ToString() });
            if (dgvProcesses.ColumnCount == 5)
            {
                row.Cells.Add(new DataGridViewTextBoxCell { Value = proc.Priority.ToString() });
                row.Cells.Add(new DataGridViewTextBoxCell { Value = "" });
                row.Cells[4].Style.BackColor = proc.ProcessColor;
            }
            else
            {
                row.Cells.Add(new DataGridViewTextBoxCell { Value = "" });
                row.Cells[3].Style.BackColor = proc.ProcessColor;
            }

            dgvProcesses.Rows.Add(row);

        }
Exemplo n.º 8
0
 private void btnReset_Click(object sender, EventArgs e)
 {
     processList.Clear();
     executing = null;
     foreach(cProcess pr in tempProcessList) {
         pr.Progress = 0;
         processList.Add(pr);
     }
     readyProcessList.Clear();
     dgvDone.Columns.Clear();
     dgvProgress.Columns.Clear();
     setProgressDGViews(dgvProgress);
     dgvTimeline.Columns.Clear();
     btnStart.Enabled = true;
     i = 0;
     rbFCFS.Enabled = true;
     rbPS.Enabled = true;
     rbRR.Enabled = true;
     rbSJF.Enabled = true;
     rbSRTN.Enabled = true;
    // Application.Restart();
 }
Exemplo n.º 9
0
        private void btnAddRnd_Click(object sender, EventArgs e)
        {
            cProcess proc = new cProcess();

            Random randomGen = new Random();
            proc.ProcessColor = Color.FromArgb(randomGen.Next(0,255),randomGen.Next(0,255),randomGen.Next(0,255));
            proc.ID = "Pr" + dgvProcesses.Rows.Count;
            proc.TArrival = randomGen.Next(0, 30);
            proc.TBurst = randomGen.Next(1, 20);
            proc.ProgressLeft = proc.TBurst;
            if (rbRR.Checked || rbPS.Checked)
            {
                proc.Priority = randomGen.Next(1, 10);
            }

            if (dgvProcesses.ColumnCount < 4) setDataGridView(proc.Priority);
            createDataGridViewRow(proc);

            processList.Add(proc);
            cProcess proc2 = new cProcess(proc.ID, proc.TArrival, proc.TBurst, proc.Priority, proc.ProcessColor);
            proc2.ProgressLeft = proc2.TBurst;
            tempProcessList.Add(proc2);
        }