예제 #1
0
 public process(string str, int at, int bt, int pri) {
     next = null;
     processName = str;
     aT = at;
     bT = bt;
     priority = pri;
     timePassed = 0;
     bTimePassed = 0;
     }
예제 #2
0
 public void Add(string str,int aT,int bT,int priority)
 {
     process nw = new process(str, aT, bT, priority);
     if (isEmpty()){ head = nw; }
     else{
         process tmp=head;
         head = nw;
         head.set_next(tmp);
     }
 }
예제 #3
0
 int[] allEle() {
     process tmp = head;
     int s = size();
     int[] arr = new int[s];
     for(int i = 0; i < s; i++)
     {
         arr[i] = tmp.get_aT();
         tmp = tmp.get_next();
     }
     return arr;
 }
예제 #4
0
 public int size()
 {
     if (isEmpty()) return 0;
     int i = 1;
     process tmp = head.get_next();
     while (tmp!=null) {
         i++;
         tmp=tmp.get_next();
     }
     return i;
 }
예제 #5
0
 public int check(int x,process p)
 {
     int i = 0;
     process tmp=p;
     while (tmp != null)
     {
         if (tmp.get_aT()-tmp.get_timePassed() == x) 
             i++;
         tmp=tmp.get_next();
     }
     return i;
 }
예제 #6
0
 public int tBT()
 {
     if (isEmpty()) return 0;
     process tmp = head;
     int i = 0;
     while (tmp != null)
     {
         i = i + tmp.get_bT();
         tmp = tmp.get_next();
     }
     return i;
 }
예제 #7
0
 public void restPassedT()
 {
     if (isEmpty()) return;
     head.set_timePassed(0);
     head.set_bTimePassed(0);
     process tmp = head.get_next();
     while (tmp != null)
     {
         tmp.set_timePassed(0);
         tmp.set_bTimePassed(0);
         tmp = tmp.get_next();
     }
 }
예제 #8
0
        public void elmiTDeff(int bbT,process p) {
            process tmp = p;
            while (tmp != null) {
                int at = tmp.get_aT();
                int tbbT = bbT + tmp.get_timePassed();
                if (at- tmp.get_timePassed() != 0) {

                    if (at > tbbT)
                        tmp.set_timePassed(tbbT);
                    else
                        tmp.set_timePassed(at);
                    
                }
                tmp = tmp.get_next();
            }
        }
예제 #9
0
        public int check(process p)
        {
            int loop = 1;

            if (p.get_next() != null)
            {
                int ctp = p.get_timePassed();
                int ntp = p.get_next().get_timePassed();
                int c   = p.get_aT() - ctp;
                int n   = p.get_next().get_aT() - ntp;
                if (c == n)
                {
                    loop = ls.check(c, p);
                }
            }
            return(loop);
        }
예제 #10
0
        public void sort(int sel, int siz, process p)
        {
            process tmp = p;
            int n = siz;
            int x, y;
            for (x = 0; x < n; x++)
            {
                process tmp2 = tmp.get_next();
                for (y = 0; y < n-x- 1; y++)
                {
                    if (sel == 0) {
                        int c = tmp.get_aT()-tmp.get_timePassed();
                        int nn = tmp2.get_aT()-tmp.get_timePassed();
                        if (c > nn)
                        {
                            swap(tmp, tmp2);
                        }
                    }
                    else if (sel == 1)
                    {
                        
                        int c = tmp.get_bT()-tmp.get_bTimePassed();
                        int nn = tmp2.get_bT()-tmp2.get_bTimePassed();
                        if (c > nn)
                        {
                            swap(tmp, tmp2);
                        }
                    }
                    else if (sel == 2)
                    {

                        int c = tmp.get_priority();
                        int nn = tmp2.get_priority();
                        if (c > nn)
                        {
                            swap(tmp, tmp2);
                        }
                    }
                    tmp2 =tmp2.get_next();
                }
                tmp=tmp.get_next();
            }
        }
예제 #11
0
        public void swap(process tmp,process tmp2) {
            string tmpStr = tmp2.get_processName();
            int tmpAT = tmp2.get_aT();
            int tmpBT = tmp2.get_bT();
            int tmpPir = tmp2.get_priority();
            int tmpatp = tmp2.get_timePassed();
            int tmpbtp = tmp2.get_bTimePassed();
            tmp2.set_aT(tmp.get_aT());
            tmp2.set_bT(tmp.get_bT());
            tmp2.set_processName(tmp.get_processName());
            tmp2.set_priority(tmp.get_priority());
            tmp2.set_timePassed(tmp.get_timePassed());
            tmp2.set_bTimePassed(tmp.get_bTimePassed());
            tmp.set_aT(tmpAT);
            tmp.set_bT(tmpBT);
            tmp.set_processName(tmpStr);
            tmp.set_priority(tmpPir);
            tmp.set_timePassed(tmpatp);
            tmp.set_bTimePassed(tmpbtp);

        }
예제 #12
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                Form2 m = new Form2();
                m.Show();
                return;
            }
            ls.Add(textBox1.Text,
                   (int)numericUpDown1.Value,
                   (int)numericUpDown2.Value,
                   (int)numericUpDown3.Value);

            lsrr.Add(textBox1.Text,
                     (int)numericUpDown1.Value,
                     (int)numericUpDown2.Value,
                     (int)numericUpDown3.Value);
            process p = ls.get_process();

            listBox1.Items.Add(p.get_processName() + "\t" +
                               p.get_aT() + "\t" + p.get_bT() + "\t" + p.get_priority());
            pi++;
            textBox1.Text = "p" + pi;
        }
예제 #13
0
        private void button2_Click(object sender, EventArgs e)
        {
            int size = ls.size();

            if (size == 0)
            {
                Form2 m = new Form2();
                m.Show();
                return;
            }
            listBox2.Items.Clear();
            float  waiting = 0;
            float  turna   = 0;
            string gantt   = "";

            if (comboBox1.Text == "FCFS")
            {
                ls.sort(0, size, ls.get_process());
                process p     = ls.get_process();
                int     begin = p.get_aT();
                for (int i = 0; i < ls.size(); i++)
                {
                    if (i == 0)
                    {
                        listBox2.Items.Add(p.get_processName() + " "
                                           + "waiting=0" + " " + "Departure=" + (p.get_aT() + p.get_bT()));
                        gantt = gantt + "| " + p.get_processName() + " |";
                        begin = p.get_bT() + p.get_aT();
                    }

                    else
                    {
                        p = p.get_next();
                        int d;
                        if (begin >= p.get_aT())
                        {
                            d       = (begin + p.get_bT());
                            waiting = waiting + (begin - p.get_aT());
                            listBox2.Items.Add(p.get_processName() + " "
                                               + "waiting=" + (begin - p.get_aT()) + " " + "Departure=" + d);
                            gantt = gantt + " " + p.get_processName() + " |";
                        }
                        else
                        {
                            d = (p.get_aT() + p.get_bT());
                            listBox2.Items.Add(p.get_processName() + " "
                                               + "waiting=0" + " " + "Departure=" + d);
                            gantt = gantt + " " + "| " + p.get_processName() + " |";
                        }
                        begin = d;
                    }
                }
            }
            else if (comboBox1.Text == "SJF")
            {
                bool first = true;
                if (radioButton2.Checked)
                {
                    ls.sort(0, size, ls.get_process());
                    process p     = ls.get_process();
                    int     begin = p.get_aT();
                    while (p != null)
                    {
                        if (p.get_next() != null)
                        {
                            int ctp  = p.get_timePassed();
                            int ntp  = p.get_next().get_timePassed();
                            int c    = p.get_aT() - ctp;
                            int n    = p.get_next().get_aT() - ntp;
                            int loop = 1;
                            if (c == n)
                            {
                                loop = ls.check(c, p);
                            }
                            if (loop > 1)
                            {
                                ls.sort(1, loop, p);
                            }
                        }
                        int b = p.get_bT();
                        int d;
                        if (begin >= p.get_aT() && !first)
                        {
                            d       = begin + b;
                            waiting = waiting + (begin - p.get_aT());
                            listBox2.Items.Add(p.get_processName() + " "
                                               + "waiting=" + (begin - p.get_aT()) + " Departure=" + d);
                            gantt = gantt + " " + p.get_processName() + " |";
                        }
                        else
                        {
                            d = p.get_aT() + b;
                            listBox2.Items.Add(p.get_processName() + " "
                                               + "waiting=0" + " Departure=" + d);
                            gantt = gantt + " " + "| " + p.get_processName() + " |";
                            first = false;
                        }
                        begin = d;
                        p     = p.get_next();
                        ls.elmiTDeff(b, p);
                    }
                    ls.restPassedT();
                }
                else
                {
                    ls.sort(0, size, ls.get_process());
                    process p     = ls.get_process();
                    int     begin = p.get_aT();
                    while (begin < ls.tBT())
                    {
                        if (p == null)
                        {
                            p = ls.get_process();
                        }
                        if (p.get_next() != null)
                        {
                            int ctp  = p.get_timePassed();
                            int ntp  = p.get_next().get_timePassed();
                            int c    = p.get_aT() - ctp;
                            int n    = p.get_next().get_aT() - ntp;
                            int loop = 1;
                            if (c == n)
                            {
                                loop = ls.check(c, p);
                            }
                            if (loop > 1)
                            {
                                ls.sort(1, loop, p);
                            }
                        }

                        int bt  = p.get_bT();
                        int btP = p.get_bTimePassed();

                        while (p != null)
                        {
                            if (bt == btP)
                            {
                                p   = p.get_next();
                                bt  = p.get_bT();
                                btP = p.get_bTimePassed();
                            }

                            else
                            {
                                break;
                            }
                        }


                        bt  = p.get_bT();
                        btP = p.get_bTimePassed();
                        if (bt != btP)
                        {
                            if (bt - btP > 1)
                            {
                                p.set_bTimePassed(btP + 1);
                                begin++;
                            }
                            else
                            {
                                int b = p.get_bT();
                                begin++;
                                waiting = waiting + (begin - (p.get_aT() + b));
                                listBox2.Items.Add(p.get_processName() + " "
                                                   + "waiting=" + (begin - (p.get_aT() + b)) + " Departure=" + begin);
                                p.set_bTimePassed(btP + 1);
                            }
                            if (!first)
                            {
                                gantt = gantt + " " + p.get_processName() + " |";
                            }
                            else
                            {
                                gantt = gantt + "| " + p.get_processName() + " |";
                                first = false;
                            }
                            ls.elmiTDeff(1, p);
                        }
                    }
                    ls.restPassedT();
                }
            }
            else if (comboBox1.Text == "Priority")
            {
                bool first = true;
                if (radioButton2.Checked)
                {
                    ls.sort(0, size, ls.get_process());
                    process p     = ls.get_process();
                    int     begin = 0;
                    while (p != null)
                    {
                        if (p.get_next() != null)
                        {
                            int ctp  = p.get_timePassed();
                            int ntp  = p.get_next().get_timePassed();
                            int c    = p.get_aT() - ctp;
                            int n    = p.get_next().get_aT() - ntp;
                            int loop = 1;
                            if (c == n)
                            {
                                loop = ls.check(c, p);
                            }
                            if (loop > 1)
                            {
                                ls.sort(2, loop, p);
                            }
                        }
                        int b = p.get_bT();
                        int d;
                        if (begin >= p.get_aT() && !first)
                        {
                            d       = begin + b;
                            waiting = waiting + (begin - p.get_aT());
                            listBox2.Items.Add(p.get_processName() + " "
                                               + "waiting=" + (begin - p.get_aT()) + " Departure=" + d);
                            gantt = gantt + " " + p.get_processName() + " |";
                            begin = d;
                        }
                        else
                        {
                            d = p.get_aT() + b;
                            listBox2.Items.Add(p.get_processName() + " "
                                               + "waiting=0" + " Departure=" + d);
                            gantt = gantt + " " + "| " + p.get_processName() + " |";
                            first = false;
                            begin = d;
                        }
                        p = p.get_next();
                        ls.elmiTDeff(b, p);
                    }
                    ls.restPassedT();
                }
                else
                {
                    ls.sort(0, size, ls.get_process());
                    process p     = ls.get_process();
                    int     begin = p.get_aT();
                    while (begin < ls.tBT())
                    {
                        if (p == null)
                        {
                            p = ls.get_process();
                        }
                        if (p.get_next() != null)
                        {
                            int ctp  = p.get_timePassed();
                            int ntp  = p.get_next().get_timePassed();
                            int c    = p.get_aT() - ctp;
                            int n    = p.get_next().get_aT() - ntp;
                            int loop = 1;
                            if (c == n)
                            {
                                loop = ls.check(c, p);
                            }
                            if (loop > 1)
                            {
                                ls.sort(2, loop, p);
                            }
                        }

                        int bt  = p.get_bT();
                        int btP = p.get_bTimePassed();

                        while (p != null)
                        {
                            if (bt == btP)
                            {
                                p   = p.get_next();
                                bt  = p.get_bT();
                                btP = p.get_bTimePassed();
                            }

                            else
                            {
                                break;
                            }
                        }


                        bt  = p.get_bT();
                        btP = p.get_bTimePassed();
                        if (bt != btP)
                        {
                            if (bt - btP > 1)
                            {
                                p.set_bTimePassed(btP + 1);
                                begin++;
                            }
                            else
                            {
                                int b = p.get_bT();
                                waiting = waiting + (begin - (p.get_aT() + b));
                                begin++;
                                listBox2.Items.Add(p.get_processName() + " "
                                                   + "waiting=" + (begin - (p.get_aT() + b)) + " Departure=" + begin);
                                p.set_bTimePassed(btP + 1);
                            }
                            if (!first)
                            {
                                gantt = gantt + " " + p.get_processName() + " |";
                            }
                            else
                            {
                                gantt = gantt + "| " + p.get_processName() + " |";
                                first = false;
                            }
                            ls.elmiTDeff(1, p);
                        }
                    }
                    ls.restPassedT();
                }
            }
            else if (comboBox1.Text == "Round Roben")
            {
                bool first = true;
                int  q     = (int)numericUpDown4.Value;
                lsrr.sort(0, size, lsrr.get_process());
                process p     = lsrr.get_process();
                int     begin = p.get_aT();
                while (begin < lsrr.tBT())
                {
                    if (p == null)
                    {
                        p = lsrr.get_process();
                    }

                    int loop = check(p);

                    for (int i = 0; i < loop; i++)
                    {
                        int cpbt = p.get_bTimePassed();
                        int bt   = p.get_bT();
                        if (cpbt != bt)
                        {
                            if (bt - cpbt > q)
                            {
                                p.set_bTimePassed(cpbt + q);
                                begin = begin + q;
                            }
                            else
                            {
                                p.set_bTimePassed(bt);
                                begin   = begin + (bt - cpbt);
                                waiting = waiting + (begin - (p.get_bT() + p.get_aT()));
                                listBox2.Items.Add(p.get_processName() + " "
                                                   + "waiting=" + (begin - (p.get_bT() + p.get_aT())) + " Departure=" + begin);
                            }
                            if (!first)
                            {
                                gantt = gantt + " " + p.get_processName() + " |";
                            }
                            else
                            {
                                gantt = gantt + "| " + p.get_processName() + " |";
                                first = false;
                            }
                            lsrr.elmiTDeff(q, p);
                            check(p);
                        }
                        if (p.get_next() != null)
                        {
                            if (p.get_next().get_aT() == p.get_next().get_timePassed())
                            {
                                p = p.get_next();
                            }
                        }
                        else
                        {
                            p = null;
                        }
                    }
                }
            }
            label7.Text = "" + (waiting / size);
            listBox3.Items.Clear();
            listBox3.Items.Add(gantt);
            lsrr.restPassedT();
        }
예제 #14
0
 public LinkedList() {
     head = null;
 }
예제 #15
0
 public void set_next(process p) { next = p; }