Example #1
0
        private void fillchartpresjf()
        {
            List <Process> sortedList = processes.OrderBy(a => a.getBurst()).ToList();
            int            totalBurst = 0;

            for (int i = 0; i < sortedList.Count; i++)
            {
                totalBurst += sortedList[i].getBurst();
            }
            int     var         = processes.Count;
            int     waitingTime = 0;
            Process old         = sortedList[0];

            foreach (var item in sortedList)
            {
                if (item.getArrival() < old.getArrival())
                {
                    old = item;
                }
            }
            int    initialTime = old.getArrival();
            Random r           = new Random();

            for (int i = 0; i < processes.Count; i++)
            {
                chart1.Series.Add(processes[i].getName());
                chart1.Series[i].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.RangeBar;
                //chart1.Series[i].Color = Color.FromArgb(i * 10, i * 20, i *30);
                chart1.Series[i].Color = Color.FromArgb(r.Next(256), r.Next(256), r.Next(256));
                //chart1.Series[i].Color = Color.Yellow;
                //chart1.Series[i].MarkerColor = Color.White;
            }
            for (int time = initialTime; time < (totalBurst + initialTime); time++)
            {
                sortedList = sortedList.OrderBy(b => (b.getBurst() - b.getExec())).ToList();
                for (int j = 0; j < var; j++)
                {
                    if (sortedList[j].getArrival() <= time)
                    {
                        if (old != sortedList[j])
                        {
                            waitingTime = waitingTime + (time - sortedList[j].getDeparture());
                            old.setDeparture(time);
                            old = sortedList[j];
                        }
                        chart1.Series[sortedList[j].getName()].Points.AddXY(sortedList[j].getName(), time + 1, time);
                        sortedList[j].setExec((sortedList[j].getExec()) + 1);
                        if (sortedList[j].getBurst() == sortedList[j].getExec())
                        {
                            sortedList.RemoveAt(j);
                            var--;
                        }
                        break;
                    }
                }
            }
            waitingT.Text = ((double)waitingTime / processes.Count).ToString();
        }
Example #2
0
        private void fillchartRR(int Q)
        {
            int            totalBurst = 0;
            List <Process> sortedList = processes.OrderBy(a => a.getArrival()).ToList();

            for (int i = 0; i < sortedList.Count; i++)
            {
                totalBurst += sortedList[i].getBurst();
            }
            Random r = new Random();

            for (int i = 0; i < processes.Count; i++)
            {
                chart1.Series.Add(processes[i].getName());
                chart1.Series[i].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.RangeBar;
                chart1.Series[i].Color     = Color.FromArgb(r.Next(256), r.Next(256), r.Next(256));
            }
            int            currentlyExecuted = 0;
            int            time             = sortedList[0].getArrival();
            int            totalJobs        = processes.Count;
            int            waitingTimeround = 0;
            int            currentJob       = 0;
            List <Process> final            = new List <Process>();

            while (currentlyExecuted < totalBurst)
            {
                Process current = sortedList.ElementAt(currentJob);
                if (current.getArrival() <= time)
                {
                    if ((current.getBurst() - current.getExec()) > 0)
                    {
                        if ((current.getBurst() - current.getExec()) >= Q)
                        {
                            current.setExec(current.getExec() + Q);
                            chart1.Series[current.getName()].Points.AddXY(current.getName(), time + Q, time);
                            waitingTimeround   = waitingTimeround + (time - current.getDeparture());
                            time               = time + Q;
                            currentlyExecuted += Q;
                            current.setDeparture(time);
                        }
                        else
                        {
                            chart1.Series[current.getName()].Points.AddXY(current.getName(), time + current.getBurst() - current.getExec(), time);

                            waitingTimeround   = waitingTimeround + (time - current.getDeparture());
                            time               = time + (current.getBurst() - current.getExec());
                            currentlyExecuted += (current.getBurst() - current.getExec());
                            current.setExec(current.getBurst());
                            current.setDeparture(time);
                        }
                    }
                }
                currentJob = (++currentJob) % totalJobs;
            }
            waitingT.Text = (waitingTimeround / totalJobs).ToString();
        }