Ejemplo n.º 1
0
        public void sets()
        {
            int e = 0, z = 0, w = 0;

            flag    = new string[number]; // sorted processes
            waiting = new int[number];    // sorted processes
            pp      = new process[number];
            while (j < number)
            {
                pp[j] = new process();
                pp[j].setArrival_time(arrival[j]);
                pp[j].setDuration(dur[j]);
                d.Add(dur[j]);
                j++;
            }
            Array.Sort(arrival);

            for (int k = 0; (k < number) && (z != number);)
            {
                if (pp[k].getArrival_time() == arrival[e])
                {
                    flag[e] = "p" + k;
                    dur[e]  = d[k];
                    if (e == 0)
                    {
                        w += (dur[k] + pp[k].getArrival_time());
                    }
                    else
                    {
                        w += dur[e];
                    }
                    waiting[e] = w - pp[k].getArrival_time() - pp[k].getDuration();
                    e++;
                    k = 0;
                    z++;
                }
                else
                {
                    k++;
                }
            }
            for (int k = 0; k < number; k++)
            {
                waiting_time += waiting[k];
            }
            avr_time = waiting_time / number;
        }
Ejemplo n.º 2
0
        public void sets()
        {
            pp = new process[number];
            while (i < number)
            {
                pp[i] = new process();
                pp[i].setArrival_time(arrival[i]);
                pp[i].setDuration(Dur[i]);
                d.Add(Dur[i]);
                i++;
            }
            Array.Sort(arrival);
            int e = 0, ee = 0;

            int[] ww;
            ww = new int[100];
            for (int k = 0; (k < number) && (z != number);)
            {
                if (e != 0)
                {
                    for (int s = 0; s < e; s++)
                    {
                        if (k == ww[s])
                        {
                            k++;
                        }
                    }
                }
                if (pp[k].getArrival_time() == arrival[e])
                {
                    Dur[e] = d[k];
                    process_no.Add(k);
                    ww[e] = k;
                    ee++;
                    k = 0;
                    e++;
                    z++;
                }

                else
                {
                    k++;
                }
            }
            int t = 0;

            waiting = new int[number];    // sorted processes
            int time = arrival[0];
            int x    = Dur.Count;

            w = arrival[0];
            while (x != 0)
            {
                if (q < Dur[j])
                {
                    plot.Add(q);
                    time += q;
                    flag.Add("p" + process_no[j]);
                    if (j < number - 1)
                    {
                        if (arrival[j + 1] <= time)
                        {
                            Dur.Add(Dur[j] - q); process_no.Add(process_no[j]); j++;
                        }
                        else
                        {
                            Dur[j] = Dur[j] - q;
                        }
                    }
                    else
                    {
                        Dur.Add(Dur[j] - q);
                        process_no.Add(process_no[j]);
                        j++;
                    }
                    w += q;
                }
                else
                {
                    plot.Add(Dur[j]);
                    flag.Add("p" + process_no[j]);
                    time      += Dur[j];
                    w         += Dur[j];
                    waiting[t] = w - pp[process_no[j]].getDuration() - pp[process_no[j]].getArrival_time();
                    x--;
                    t++;
                    j++;
                }
            }
            for (int k = 0; k < number; k++)
            {
                waiting_time += waiting[k];
            }
            avr_time = waiting_time / number;
        }