コード例 #1
0
ファイル: StatForm.cs プロジェクト: khoavnguyen/cs333
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Visible == true)
            {
                if (textBox1.Text == "")
                {
                    MessageBox.Show("Please enter quantum for Round Robin algorithm.");
                    return;
                }
                try
                {
                    int x = Int32.Parse(textBox1.Text);
                    if (x <= 0)
                    {
                        MessageBox.Show("Quantum must be positive.");
                        return;
                    }
                    if (x > 20)
                    {
                        MessageBox.Show("Quantum must be less than 20.");
                        return;
                    }
                }
                catch
                {
                    MessageBox.Show("Quantum must be an integer.");
                    return;
                }
            }

            Algorithm[] algos = { new FCFS(), new SJF(), new SRTF(), new RR() };
            for (int i = 0; i < algos.Length; i++)
            {
                float avgWT = 0, avgTT = 0;
                if (algos[i].GetType() != algo.GetType())
                {
                    string fileName = algo.FileName;
                    algos[i].loadProcesses(fileName);
                    algos[i].Overhead = algo.Overhead;
                    if (algos[i] is RR)
                    {
                        RR r = (RR)algos[i];
                        r.Quantum = Int32.Parse(textBox1.Text);
                    }
                    DisplayForm x = new DisplayForm(algos[i]);
                    while (x.step()) ;
                    avgWT = x.waitingTime();
                    avgTT = x.turnaroundTime();
                }
                else
                {
                    int n = listView2.Items.Count - 1;
                    avgWT = float.Parse(listView2.Items[n].SubItems[1].Text);
                    avgTT = float.Parse(listView2.Items[n].SubItems[2].Text);
                }
                if (listView1.Items[0].SubItems.Count == 5)
                {
                    listView1.Items[0].SubItems[i + 1].Text = avgWT.ToString();
                    listView1.Items[1].SubItems[i + 1].Text = avgTT.ToString();
                }
                else
                {
                    listView1.Items[0].SubItems.Add(avgWT.ToString());
                    listView1.Items[1].SubItems.Add(avgTT.ToString());
                }
                listView1.Visible = true;
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: khoavnguyen/cs333
        private void button2_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("You must select an input file first.");
                return;
            }
            if (comboBox2.SelectedIndex == -1)
            {
                MessageBox.Show("You must select a scheduling strategy first.");
                return;
            }
            int fileIndex = comboBox1.SelectedIndex;
            int algoIndex = comboBox2.SelectedIndex;
            InputForm i = new InputForm((String)files[fileIndex]);
            if (!i.checkFormat())
            {
                MessageBox.Show("The file you selected has a wrong format. Please edit it first.");
                i.External = false;
                i.ShowDialog();
                InputForm j = new InputForm((String)files[fileIndex]);
                if (!j.checkFormat())
                {
                    MessageBox.Show("Please choose another input file.");
                    return;
                }
            }
            if (textBox1.Text == "")
            {
                MessageBox.Show("Please choose an overhead for switching processes.");
                return;
            }
            try
            {
                int k = Int32.Parse(textBox1.Text);
                if (k <= 0)
                {
                    MessageBox.Show("Overhead must be positive.");
                    return;
                }
                if (k > 20)
                {
                    MessageBox.Show("Overhead should not exceed 20.");
                    return;
                }
            }
            catch
            {
                MessageBox.Show("Overhead must be an integer.");
                return;
            }

            Algorithm algorithm = newAlgorithm(algoIndex);
            algorithm.loadProcesses((String)files[fileIndex]);
            algorithm.Overhead = Int32.Parse(textBox1.Text);

            
            String text = "";
            switch (algoIndex)
            {
                case 0:
                    text = "First come first serve strategy";
                    break;
                case 1:
                    text = "Shortest job first strategy";
                    break;
                case 2:
                    text = "Shortest remaining time strategy";
                    break;
                case 3:
                    text = "Round robin strategy";
                    break;
                default:
                    text = "";
                    break;
            }
            DisplayForm x = new DisplayForm(algorithm);
            x.Text = text;
            x.Show();
        }