Beispiel #1
0
        void FCFS(Scheduler s)
        {
            createWaiting();
            createTimeline();
            Scheduler temp = new Scheduler();

            temp = s.sort("arrival");
            node   p       = temp.getProcesses().getChain();
            double i       = p.getData().getArrival();
            int    counter = 0;
            double average = 0;
            Series idle    = new Series();

            createSeries(idle, i);
            while (p != null)
            {
                Series barSeries = new Series();
                barSeries.ChartType  = SeriesChartType.StackedBar;
                barSeries.XValueType = ChartValueType.String;
                barSeries.Points.AddXY("timeline", p.getData().getDuration());
                barSeries.Label = p.getData().getName();
                timeline.Series.Add(barSeries);
                average = average + i - p.getData().getArrival();
                i       = i + p.getData().getDuration();
                counter++;
                p = p.getNext();
            }
            waiting.Text = " Average Waiting Time = " + average.ToString() + " / " + counter.ToString() + " = " + (average / counter).ToString();
            cpu.clear();
        }
Beispiel #2
0
        public Scheduler sort(string type)
        {
            if (processes.getChain() == processes.getTail())
            {
                return(this);
            }
            Scheduler left   = new Scheduler();
            Scheduler right  = new Scheduler();
            Scheduler result = new Scheduler();
            node      p      = processes.getChain();
            node      t      = processes.getTail();

            while (p != t && p.getNext() != t)
            {
                left.processes.addtoEnd(p.getData());
                right.processes.add(t.getData());
                p = p.getNext();
                t = t.getPrevious();
            }
            if (p == t)
            {
                right.processes.add(t.getData());
            }
            else if (p.getNext() == t)
            {
                left.processes.addtoEnd(p.getData());
                right.processes.add(t.getData());
            }
            return(merge(left.sort(type), right.sort(type), type));
        }
Beispiel #3
0
        void RoundRobin(Scheduler s, double q)
        {
            createWaiting();
            createTimeline();
            Scheduler temp = new Scheduler();

            temp = s.sort("arrival");
            node   p       = temp.getProcesses().getChain();
            double first   = p.getData().getArrival();
            double i       = p.getData().getArrival();
            double j       = 0;
            int    counter = 0;
            double average = 0;
            double working = 0;
            double arrival = 0;
            Series idle    = new Series();

            createSeries(idle, i);
            node p1 = temp.getProcesses().getChain();

            while (p1 != null)
            {
                arrival = arrival + p1.getData().getArrival();
                p1      = p1.getNext();
            }
            while (temp.getProcesses().getChain() != null)
            {
                j = (temp.getProcesses().getChain().getData().getDuration() <= q)? temp.getProcesses().getChain().getData().getDuration(): q;
                Series barSeries = new Series();
                barSeries.ChartType  = SeriesChartType.StackedBar;
                barSeries.XValueType = ChartValueType.String;
                barSeries.Points.AddXY("timeline", j);
                barSeries.Color = temp.getProcesses().getChain().getData().getColor();
                barSeries.Label = temp.getProcesses().getChain().getData().getName();
                timeline.Series.Add(barSeries);
                if (temp.getProcesses().getChain().getData().getDuration() <= q)
                {
                    average = average + i;
                    i       = i + temp.getProcesses().getChain().getData().getDuration();
                    counter++;
                }
                else
                {
                    i       = i + q;
                    working = working + q;
                    temp.getProcesses().getChain().getData().setDuration(temp.getProcesses().getChain().getData().getDuration() - q);
                    temp.getProcesses().getChain().getData().setArrival(i);
                    temp.add(temp.getProcesses().getChain().getData());
                }
                temp.remove(temp.getProcesses().getChain().getData().getName());
                temp = temp.sort("arrival");
            }
            waiting.Text = " Average Waiting Time = ( " + (average - arrival).ToString() + " - " + working.ToString() + " ) / " + counter.ToString() + " = " + ((average - working) / counter).ToString();
            cpu.clear();
        }
Beispiel #4
0
        public Process searchByName(string name)
        {
            if (processes.getChain() == processes.getTail())
            {
                if (processes.getChain().getData().getName() == name)
                {
                    return(processes.getChain().getData());
                }
                else
                {
                    Process empty = new Process();
                    empty.setDuration(-1);
                    return(empty);
                }
            }
            Scheduler p1 = new Scheduler();

            p1 = this.sort("name");
            Scheduler left  = new Scheduler();
            Scheduler right = new Scheduler();
            node      p     = p1.processes.getChain();
            node      t     = p1.processes.getTail();

            while (p != t && p.getNext() != t)
            {
                left.processes.addtoEnd(p.getData());
                right.processes.add(t.getData());
                p = p.getNext();
                t = t.getPrevious();
            }
            if (p == t)
            {
                right.processes.add(t.getData());
            }
            else if (p.getNext() == t)
            {
                left.processes.addtoEnd(p.getData());
                right.add(t.getData());
            }
            if (right.processes.getChain().getData().getName() == name)
            {
                return(right.processes.getChain().getData());
            }
            else if (string.Compare(right.processes.getChain().getData().getName(), name) > 0)
            {
                return(left.searchByName(name));
            }
            else
            {
                return(right.searchByName(name));
            }
        }
Beispiel #5
0
        public void remove(string name)
        {
            if (processes.getChain() != null && processes.getChain().getData().getName() == name)
            {
                node temp = processes.getChain();
                processes.setChain(processes.getChain().getNext());
                temp = new node();
                if (processes.getChain() == null)
                {
                    processes.setTail(null);
                }
                return;
            }
            node p1 = processes.getChain();
            node p2 = processes.getChain().getNext();
            node p3 = new node();

            if (p2.getNext() != null)
            {
                p3 = p2.getNext();
            }
            while (p2 != null)
            {
                if (p2.getData().getName() == name)
                {
                    p1.setNext(p2.getNext());
                    p3.setPrevious(p2.getPrevious());
                    p2 = new node();
                    break;
                }
                p1 = p1.getNext();
                p2 = p2.getNext();
            }
        }
Beispiel #6
0
        void Priority_NPrem(Scheduler s)
        {
            createWaiting();
            createTimeline();
            Scheduler temp = new Scheduler();

            temp = s.sort("arrival");
            double first   = temp.getProcesses().getChain().getData().getArrival();
            double i       = temp.getProcesses().getChain().getData().getArrival();
            int    counter = 0;
            double average = 0;
            Series idle    = new Series();

            createSeries(idle, i);
            while (temp.getProcesses().getChain() != null)
            {
                Scheduler temp2 = new Scheduler();
                while (temp.getProcesses().getChain() != null && temp.getProcesses().getChain().getData().getArrival() <= first)
                {
                    temp2.add(temp.getProcesses().getChain().getData());
                    temp.remove(temp.getProcesses().getChain().getData().getName());
                }
                temp2 = temp2.sort("priority");
                node p2 = temp2.getProcesses().getChain();
                while (p2 != null)
                {
                    Series barSeries = new Series();
                    barSeries.ChartType  = SeriesChartType.StackedBar;
                    barSeries.XValueType = ChartValueType.String;
                    barSeries.Points.AddXY("timeline", p2.getData().getDuration());
                    barSeries.Label = p2.getData().getName();
                    timeline.Series.Add(barSeries);
                    average = average + i - p2.getData().getArrival();
                    i       = i + p2.getData().getDuration();
                    counter++;
                    p2 = p2.getNext();
                }
                first = i;
                temp2.clear();
            }
            waiting.Text = " Average Waiting Time = " + average.ToString() + " / " + counter.ToString() + " = " + (average / counter).ToString();
            temp.clear();
            cpu.clear();
        }
Beispiel #7
0
 private void Button_Click_new(object sender, EventArgs e)
 {
     try
     {
         timeline = new Chart();
         waiting  = new Label();
         Process Pn = new Process();
         Pn.setName(newname.Text);
         Pn.setArrival(Convert.ToDouble(interrupt.Text));
         if (Pn.getArrival() <= 0)
         {
             throw new System.Exception("Process " + "[ " + Pn.getName().ToString() + " ]" + " Arrival time must be positive integer");
         }
         Pn.setDuration(Convert.ToDouble(newburst.Text));
         if (Pn.getDuration() <= 0)
         {
             throw new System.Exception("Process " + "[ " + Pn.getName().ToString() + " ]" + " Burst time must be positive integer");
         }
         Random rnd = new Random(18 * System.Environment.TickCount);
         Pn.setColor(System.Drawing.Color.FromArgb(255, rnd.Next(255), rnd.Next(255), rnd.Next(255)));
         if (type == "Priority (P)" || type == "Priority (NP)")
         {
             Pn.setPriority(Int32.Parse(newpriority.Text));
             if (Pn.getPriority() <= 0)
             {
                 throw new System.Exception("Process " + "[ " + Pn.getName().ToString() + " ]" + " Priority must be positive integer");
             }
         }
         fillScheduler();
         node p = new node();
         p = newProcesses.getProcesses().getChain();
         while (p != null)
         {
             cpu.add(p.getData());
             p = p.getNext();
         }
         cpu.add(Pn);
         newProcesses.add(Pn);
         while (objects.Count > 0)
         {
             this.Controls.Remove(objects.Pop());
         }
         objects.Clear();
         scheduleCPU();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #8
0
        void FCFS(Scheduler s)
        {
            createWaiting();
            createTimeline();
            Scheduler temp = new Scheduler();

            temp = s.sort("arrival");
            node   p = temp.getProcesses().getChain();
            double i = p.getData().getArrival();
            int    counter = 0;
            double average = 0;
            double increment = p.getData().getArrival(), AvgTime = 0, TurnAround = 0;
            Series idle = new Series();

            createSeries(idle, i);
            while (p != null)
            {
                Series barSeries = new Series();
                barSeries.ChartType  = SeriesChartType.StackedBar;
                barSeries.XValueType = ChartValueType.String;
                barSeries.Points.AddXY("timeline", p.getData().getDuration());

                barSeries.Label = p.getData().getName();
                timeline.Series.Add(barSeries);
                increment += p.getData().getDuration();
                average    = average + i - p.getData().getArrival();
                i          = i + p.getData().getDuration();

                TurnAround += (increment - p.getData().getArrival());
                if (i < numberOfProcesses - 1)
                {
                    AvgTime += (increment - p.getNext().getData().getArrival());
                }
                counter++;
                p = p.getNext();
            }

            waiting.Top   = (numberOfProcesses * 30) + 165;
            waiting.Left  = 10;
            waiting.Size  = new System.Drawing.Size(500, 50);
            waiting.Text  = "Average Waiting Time = " + average.ToString() + " / " + counter.ToString() + " = " + (average / counter).ToString();
            waiting.Text += "\nAverage TurnAround Time = " + TurnAround.ToString() + " / " + counter.ToString() + " = " + (TurnAround / counter).ToString();

            cpu.clear();
        }
Beispiel #9
0
        void RoundRobin(Scheduler s, double q)
        {
            createWaiting();
            createTimeline();
            Scheduler temp = new Scheduler();

            temp = s.sort("arrival");
            node   p       = temp.getProcesses().getChain();
            double first   = p.getData().getArrival();
            double i       = p.getData().getArrival();
            double j       = 0;
            int    counter = 0;
            double average = 0;
            double working = 0;
            double arrival = 0;
            Series idle    = new Series();

            createSeries(idle, i);
            node                     p1     = temp.getProcesses().getChain();
            List <Process>           pro    = new List <Process>();
            Dictionary <string, int> flags  = new Dictionary <string, int>();
            double                   bursts = 0;

            while (p1 != null)
            {
                Process t = p1.getData();
                pro.Add(t);
                arrival = arrival + p1.getData().getArrival();
                bursts += p1.getData().getDuration();
                p1      = p1.getNext();
            }
            for (var k = 0; k < pro.Count(); k++)
            {
                flags.Add(pro[k].getName(), 0);
            }
            while (pro.Count() != 0)
            {
                flags[pro[0].getName()] = 1;
                j = (pro[0].getDuration() <= q) ? pro[0].getDuration() : q;
                Series barSeries = new Series();
                barSeries.ChartType  = SeriesChartType.StackedBar;
                barSeries.XValueType = ChartValueType.String;
                barSeries.Points.AddXY("timeline", j);
                barSeries.Color = pro[0].getColor();
                barSeries.Label = pro[0].getName();
                timeline.Series.Add(barSeries);
                if (pro[0].getDuration() <= q)
                {
                    average = average + i;
                    i       = i + pro[0].getDuration();
                    counter++;
                }
                else
                {
                    i       = i + q;
                    working = working + q;
                    pro[0].setDuration(pro[0].getDuration() - q);
                    pro[0].setArrival(i);
                    pro.Add(pro[0]);
                }

                pro.Remove(pro[0]);


                for (var k = 0; k < pro.Count() - 1; k++)
                {
                    for (var l = 0; l < pro.Count() - 1 - k; l++)
                    {
                        if (pro[l].getArrival() > pro[l + 1].getArrival())
                        {
                            Process tmp = pro[l];
                            pro[l]     = pro[l + 1];
                            pro[l + 1] = tmp;
                        }

                        /* else if(pro[l].getArrival() <= i && flags[pro[l].getName()] == 0)
                         * {
                         *   if((flags[pro[l+1].getName()] == 0&& pro[l].getArrival() > pro[l + 1].getArrival())|| (flags[pro[l + 1].getName()] == 1)) {
                         *       Process tmp = pro[l];
                         *       pro[l] = pro[l + 1];
                         *       pro[l + 1] = tmp;
                         *
                         *   }
                         * }*/
                    }
                }


                List <Process> t     = new List <Process>();
                int            index = 0;
                int            flag  = 0;
                for (var k = 0; k < pro.Count(); k++)
                {
                    if (!(pro[k].getArrival() <= i && flags[pro[k].getName()] == 0))
                    {
                        t.Add(pro[k]);
                        pro.Remove(pro[k]);
                        k--;
                        index = k;
                        flag  = 1;
                    }
                }
                for (var k = 0; k < pro.Count() - 1; k++)
                {
                    for (var l = 0; l < pro.Count() - 1 - k; l++)
                    {
                        if (pro[l].getArrival() > pro[l + 1].getArrival())
                        {
                            Process tmp = pro[l];
                            pro[l]     = pro[l + 1];
                            pro[l + 1] = tmp;
                        }
                    }
                }
                pro.AddRange(t);

                /* if (flag == 1)
                 * {
                 * for(var k = index; k >= 1; k--)
                 * {
                 * pro[k] = pro[k - 1];
                 * }
                 * pro[0] = t;
                 * }*/
            }
            waiting.Top   = (numberOfProcesses * 30) + 165;
            waiting.Left  = 10;
            waiting.Size  = new System.Drawing.Size(500, 50);
            waiting.Text  = "Average Waiting Time = ( " + (average - arrival).ToString() + " - " + working.ToString() + " ) / " + counter.ToString() + " = " + ((average - arrival - working) / counter).ToString();
            waiting.Text += "\nAverage TurnAround Time = " + (average - arrival - working + bursts).ToString() + " / " + counter.ToString() + " = " + ((average - arrival - working + bursts) / counter).ToString();
            cpu.clear();
        }
Beispiel #10
0
        void Priority_Prem(Scheduler s)
        {
            createWaiting();
            createTimeline();
            Scheduler temp = new Scheduler();

            temp = s.sort("arrival");
            double i       = temp.getProcesses().getChain().getData().getArrival();
            int    counter = 0;
            int    flag    = 0;
            double average = 0;
            double working = 0;
            Series idle    = new Series();

            createSeries(idle, i);
            List <Process>           pro       = new List <Process>();
            List <Process>           departure = new List <Process>();
            List <double>            depart    = new List <double>();
            Dictionary <string, int> flags     = new Dictionary <string, int>();
            node   pp         = temp.getProcesses().getChain();
            double bursttimes = 0;

            while (pp != null)
            {
                Process t = pp.getData();
                pro.Add(t);
                pp          = pp.getNext();
                bursttimes += t.getDuration();
            }
            for (var k = 0; k < pro.Count(); k++)
            {
                flags.Add(pro[k].getName(), 0);
            }

            while (pro.Count() != 0)
            {
                Scheduler temp2 = new Scheduler();

                node           p1   = temp.getProcesses().getChain();
                List <Process> pro2 = new List <Process>();



                double first  = temp.getProcesses().getChain().getData().getArrival();
                double first2 = pro[0].getArrival();
                for (var j = 0; j < pro.Count(); j++)
                {
                    if (pro[j].getArrival() <= i)
                    {
                        pro2.Add(pro[j]);
                        pro.Remove(pro[j]);
                        j--;
                    }
                }
                for (var k = 0; k < pro2.Count() - 1; k++)
                {
                    for (var j = 0; j < pro2.Count() - 1 - k; j++)
                    {
                        if (pro2[j].getPriority() > pro2[j + 1].getPriority() || (pro2[j].getPriority() == pro2[j + 1].getPriority() && pro2[j].getArrival() > pro2[j + 1].getArrival()))
                        {
                            Process tmp = pro2[j];
                            pro2[j]     = pro2[j + 1];
                            pro2[j + 1] = tmp;
                        }
                    }
                }

                for (var k = 0; k < pro2.Count(); k++)
                {
                    if (pro.Count() != 0 && pro2[k].getDuration() + pro2[k].getArrival() > i &&
                        true)
                    {
                        flags[pro2[k].getName()] = 1;
                        Series barSeries = new Series();
                        barSeries.ChartType  = SeriesChartType.StackedBar;
                        barSeries.XValueType = ChartValueType.String;
                        if (pro[0].getArrival() - pro2[k].getArrival() < pro2[k].getDuration())
                        {
                            barSeries.Points.AddXY("timeline", pro[0].getArrival() - pro2[k].getArrival());
                        }
                        else
                        {
                            barSeries.Points.AddXY("timeline", pro2[k].getDuration());
                        }


                        barSeries.Color = pro2[k].getColor();
                        barSeries.Label = pro2[k].getName();
                        timeline.Series.Add(barSeries);
                        double dur = pro2[k].getDuration();
                        if (pro[0].getArrival() - pro2[k].getArrival() < pro2[k].getDuration())
                        {
                            pro2[k].setDuration(pro2[k].getDuration() + pro2[k].getArrival() - pro[0].getArrival());
                        }
                        else
                        {
                            pro2[k].setDuration(pro2[k].getDuration() - pro2[k].getDuration());
                        }
                        pro.Add(pro2[k]);



                        if (pro[0].getArrival() - pro2[k].getArrival() < pro2[k].getDuration())
                        {
                            i       = pro[0].getArrival();
                            working = working + pro[0].getArrival() - pro2[k].getArrival();
                            depart.Add(i);
                            departure.Add(pro2[k]);
                        }
                        else
                        {
                            working = working + pro2[k].getDuration();
                            i       = i + pro2[k].getDuration();
                            depart.Add(i);
                            departure.Add(pro2[k]);
                        }

                        flag = 1;
                        break;
                    }
                    else
                    {
                        Series barSeries = new Series();
                        barSeries.ChartType  = SeriesChartType.StackedBar;
                        barSeries.XValueType = ChartValueType.String;
                        barSeries.Points.AddXY("timeline", pro2[k].getDuration());
                        barSeries.Color = pro2[k].getColor();
                        barSeries.Label = pro2[k].getName();
                        timeline.Series.Add(barSeries);
                        average = average + i - pro2[k].getArrival();

                        i = i + pro2[k].getDuration();

                        depart.Add(i);
                        departure.Add(pro2[k]);
                        counter++;
                        flag = 1;
                        break;
                    }
                }

                if (pro2.Count() > 1 && flag == 1)
                {
                    for (var l = 1; l < pro2.Count(); l++)
                    {
                        if (pro2[l].getDuration() > 0)
                        {
                            pro.Add(pro2[l]);
                        }
                    }
                    flag = 0;
                }
                pro2.Clear();
            }

            waiting.Top   = (numberOfProcesses * 30) + 165;
            waiting.Left  = 10;
            waiting.Size  = new System.Drawing.Size(500, 50);
            waiting.Text  = "Average Waiting Time = " + (average - working).ToString() + " / " + counter.ToString() + " = " + ((average - working) / counter).ToString();
            waiting.Text += "\nAverage TurnAround Time = " + (average - working + bursttimes).ToString() + " / " + counter.ToString() + " = " + ((average - working + bursttimes) / counter).ToString();
            temp.clear();
            cpu.clear();
        }
Beispiel #11
0
        void Priority_NPrem(Scheduler s)
        {
            createWaiting();
            createTimeline();
            Scheduler temp = new Scheduler();

            temp = s.sort("arrival");
            double first   = temp.getProcesses().getChain().getData().getArrival();
            double i       = temp.getProcesses().getChain().getData().getArrival();
            int    counter = 0;
            double average = 0;
            Series idle    = new Series();

            createSeries(idle, i);
            double bursttimes = 0;
            int    flag       = 0;
            node   pro        = temp.getProcesses().getChain();

            while (pro != null)
            {
                bursttimes += pro.getData().getDuration();
                pro         = pro.getNext();
            }
            while (temp.getProcesses().getChain() != null)
            {
                Scheduler temp2 = new Scheduler();
                while (temp.getProcesses().getChain() != null && temp.getProcesses().getChain().getData().getArrival() <= first)
                {
                    temp2.add(temp.getProcesses().getChain().getData());
                    temp.remove(temp.getProcesses().getChain().getData().getName());
                }
                temp2 = temp2.sort("priority");
                node p3 = temp2.getProcesses().getChain();
                while (p3 != null)
                {
                    Console.Write(p3.getData().getName() + "has piority" + p3.getData().getPriority() + "\n");
                    p3 = p3.getNext();
                }
                Console.Write("first is" + first + "\n");
                Console.Write("***************\n");
                node p2 = temp2.getProcesses().getChain();
                while (p2 != null)
                {
                    Series barSeries = new Series();
                    barSeries.ChartType  = SeriesChartType.StackedBar;
                    barSeries.XValueType = ChartValueType.String;
                    barSeries.Points.AddXY("timeline", p2.getData().getDuration());
                    barSeries.Label = p2.getData().getName();
                    timeline.Series.Add(barSeries);
                    average = average + i - p2.getData().getArrival();
                    i       = i + p2.getData().getDuration();
                    counter++;
                    if (temp.getProcesses().getChain() != null)
                    {
                        temp2.remove(p2.getData().getName());
                        flag = 1;
                        p2   = p2.getNext();

                        break;
                    }
                    p2 = p2.getNext();
                }
                first = i;
                if (flag == 1)
                {
                    while (p2 != null)
                    {
                        temp.add(p2.getData());
                        p2 = p2.getNext();
                    }
                    flag = 0;
                }
                temp2.clear();
            }
            waiting.Top   = (numberOfProcesses * 30) + 165;
            waiting.Left  = 10;
            waiting.Size  = new System.Drawing.Size(500, 50);
            waiting.Text  = "Average Waiting Time = " + average.ToString() + " / " + counter.ToString() + " = " + (average / counter).ToString();
            waiting.Text += "\nAverage TurnAround Time = " + (average + bursttimes).ToString() + " / " + counter.ToString() + " = " + ((average + bursttimes) / counter).ToString();
            temp.clear();
            cpu.clear();
        }
Beispiel #12
0
        public Scheduler merge(Scheduler l1, Scheduler l2, string type)
        {
            Scheduler merged = new Scheduler();
            node      p1     = l1.processes.getChain();
            node      p2     = l2.processes.getChain();

            if (type == "arrival")
            {
                while (p1 != null && p2 != null)
                {
                    if (p1.getData().getArrival() <= p2.getData().getArrival())
                    {
                        merged.processes.addtoEnd(p1.getData());
                        p1 = p1.getNext();
                    }
                    else
                    {
                        merged.processes.addtoEnd(p2.getData());
                        p2 = p2.getNext();
                    }
                }
            }
            else if (type == "duration")
            {
                while (p1 != null && p2 != null)
                {
                    if (p1.getData().getDuration() <= p2.getData().getDuration())
                    {
                        merged.processes.addtoEnd(p1.getData());
                        p1 = p1.getNext();
                    }
                    else
                    {
                        merged.processes.addtoEnd(p2.getData());
                        p2 = p2.getNext();
                    }
                }
            }
            else if (type == "priority")
            {
                while (p1 != null && p2 != null)
                {
                    if (p1.getData().getPriority() <= p2.getData().getPriority())
                    {
                        merged.processes.addtoEnd(p1.getData());
                        p1 = p1.getNext();
                    }
                    else
                    {
                        merged.processes.addtoEnd(p2.getData());
                        p2 = p2.getNext();
                    }
                }
            }
            if (p1 != null)
            {
                while (p1 != null)
                {
                    merged.processes.addtoEnd(p1.getData());
                    p1 = p1.getNext();
                }
            }
            if (p2 != null)
            {
                while (p2 != null)
                {
                    merged.processes.addtoEnd(p2.getData());
                    p2 = p2.getNext();
                }
            }
            return(merged);
        }
Beispiel #13
0
        void SJF_Prem(Scheduler s)
        {
            createWaiting();
            createTimeline();
            Scheduler temp = new Scheduler();

            temp = s.sort("arrival");
            double i       = temp.getProcesses().getChain().getData().getArrival();
            int    counter = 0;
            double average = 0;
            double working = 0;
            Series idle    = new Series();

            createSeries(idle, i);
            while (temp.getProcesses().getChain() != null)
            {
                Scheduler temp2 = new Scheduler();
                double    first = temp.getProcesses().getChain().getData().getArrival();
                while (temp.getProcesses().getChain() != null && temp.getProcesses().getChain().getData().getArrival() <= first)
                {
                    temp2.add(temp.getProcesses().getChain().getData());
                    temp.remove(temp.getProcesses().getChain().getData().getName());
                }
                temp2 = temp2.sort("duration");
                node p2 = temp2.getProcesses().getChain();
                while (p2 != null)
                {
                    if (temp.getProcesses().getChain() != null && p2.getData().getDuration() + p2.getData().getArrival() > temp.getProcesses().getChain().getData().getArrival())
                    {
                        Series barSeries = new Series();
                        barSeries.ChartType  = SeriesChartType.StackedBar;
                        barSeries.XValueType = ChartValueType.String;
                        barSeries.Points.AddXY("timeline", temp.getProcesses().getChain().getData().getArrival() - p2.getData().getArrival());
                        barSeries.Color = p2.getData().getColor();
                        barSeries.Label = p2.getData().getName();
                        timeline.Series.Add(barSeries);
                        p2.getData().setDuration(p2.getData().getDuration() + p2.getData().getArrival() - temp.getProcesses().getChain().getData().getArrival());
                        temp.add(p2.getData());
                        i       = temp.getProcesses().getChain().getData().getArrival();
                        working = working + temp.getProcesses().getChain().getData().getArrival() - p2.getData().getArrival();
                    }
                    else
                    {
                        Series barSeries = new Series();
                        barSeries.ChartType  = SeriesChartType.StackedBar;
                        barSeries.XValueType = ChartValueType.String;
                        barSeries.Points.AddXY("timeline", p2.getData().getDuration());
                        barSeries.Color = p2.getData().getColor();
                        barSeries.Label = p2.getData().getName();
                        timeline.Series.Add(barSeries);
                        average = average + i - p2.getData().getArrival();
                        i       = i + p2.getData().getDuration();
                        counter++;
                    }
                    p2 = p2.getNext();
                }
                temp2.clear();
            }
            waiting.Text = " Average Waiting Time = " + (average - working).ToString() + " / " + counter.ToString() + " = " + ((average - working) / counter).ToString();
            temp.clear();
            cpu.clear();
        }