Ejemplo n.º 1
0
 public void setPrevious(node n)
 {
     previous = n;
 }
Ejemplo n.º 2
0
 public node(Process d)
 {
     data = d; next = null;
 }
Ejemplo n.º 3
0
 public void setNext(node n)
 {
     next = n;
 }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
0
 public node()
 {
     next = null;
 }
Ejemplo n.º 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);
            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();
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
0
 public void setTail(node n)
 {
     tail = n;
 }
Ejemplo n.º 9
0
 public void setChain(node n)
 {
     chain = n;
 }
Ejemplo n.º 10
0
 public linkedlist()
 {
     chain = null; tail = null;
 }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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();
        }