private tientrinh tinhThoiGianHT(int timeSlice, tientrinh x)
 {
     tientrinh max = new tientrinh();
     List<tientrinh> gant = xuLy(timeSlice);
     for (int i = 0; i < gant.Count; i++)
         if (gant[i].TenTienTrinh.Equals(x.TenTienTrinh) == true)
             max = gant[i];
     max.ThoiGianXuLy -= max.ThoiGianDen;
     return max;
 }
        public List<tientrinh> xuLy(int timeSlice)
        {
            tientrinhf.Clear();
            them();
            if (tientrinhf.Count == 0)
                return null;
            Queue<tientrinh> tam = new Queue<tientrinh>();
            List<tientrinh> gant = new List<tientrinh>();
            int c = 0;

            tientrinh a = tientrinhf.Peek();
            if (timeSlice >= a.ThoiGianXuLy)
                gant.Add(new tientrinh(a.TenTienTrinh, a.ThoiGianDen, a.ThoiGianDen, a.ThoiGianDen + a.ThoiGianXuLy));
            else
            {
                gant.Add(new tientrinh(a.TenTienTrinh, a.ThoiGianDen, a.ThoiGianDen, timeSlice + a.ThoiGianDen));
                c = 1;
            }
            tientrinh x;
            x = tientrinhf.Dequeue();
            while (tientrinhf.Count != 0 && tientrinhf.Peek().ThoiGianDen < gant[gant.Count - 1].ThoiGianXuLy)
            {
                tientrinh y;
                y = tientrinhf.Dequeue();
                tam.Enqueue(y);
            }
            if (c == 1)
                tam.Enqueue(new tientrinh(x.TenTienTrinh, timeSlice, x.ThoiGianDen, x.ThoiGianXuLy - timeSlice));
            while (tam.Count != 0)
            {
                c = 0;
                if (timeSlice >= tam.Peek().ThoiGianXuLy)
                    gant.Add(new tientrinh(tam.Peek().TenTienTrinh, gant[gant.Count - 1].ThoiGianXuLy, tam.Peek().ThoiGianDen, tam.Peek().ThoiGianXuLy + gant[gant.Count - 1].ThoiGianXuLy));
                else
                {
                    gant.Add(new tientrinh(tam.Peek().TenTienTrinh, gant[gant.Count - 1].ThoiGianXuLy, tam.Peek().ThoiGianDen, timeSlice + gant[gant.Count - 1].ThoiGianXuLy));
                    c = 1;
                }
                while (tientrinhf.Count != 0 && tientrinhf.Peek().ThoiGianDen < gant[gant.Count - 1].ThoiGianXuLy)
                {
                    tientrinh y = tientrinhf.Dequeue();
                    tam.Enqueue(y);
                }
                tientrinh t = tam.Dequeue();
                if (c == 1)
                    tam.Enqueue(new tientrinh(t.TenTienTrinh, timeSlice, t.ThoiGianDen, t.ThoiGianXuLy - timeSlice));

            }
            return gant;
        }
 private int tinhThoiGianCho(int timeSlice, tientrinh x)
 {
     tientrinh q = new tientrinh();
     List<tientrinh> gant = xuLy(timeSlice);
     int vt = -1;
     for (int i = 0; i < gant.Count; i++)
         if (x.TenTienTrinh.Equals(gant[i].TenTienTrinh) == true)
         {
             vt = i;
             q = gant[i]; break;
         }
     int tongCho = q.ThoiGianCho - q.ThoiGianDen;
     for (int i = vt; i < gant.Count; i++)
         if (x.TenTienTrinh.Equals(gant[i].TenTienTrinh) == true)
             for (int t = i + 1; t < gant.Count; t++)
                 if (x.TenTienTrinh.Equals(gant[t].TenTienTrinh) == true)
                 { tongCho += gant[t].ThoiGianCho - gant[i].ThoiGianXuLy; break; }
     return tongCho;
 }
Example #4
0
        public List <tientrinh> xuLyGant()
        {
            hangdoi.Clear();

            if (tam.Count == 0)
            {
                return(null);
            }
            them();
            tientrinh a = hangdoi.Dequeue();

            gant.Clear();
            gant.Add(new tientrinh(a.TenTienTrinh, a.ThoiGianDen, a.ThoiGianDen, a.ThoiGianXuLy + a.ThoiGianDen));
            while (hangdoi.Count != 0)
            {
                a = hangdoi.Dequeue();
                gant.Add(new tientrinh(a.TenTienTrinh, gant[gant.Count - 1].ThoiGianXuLy, a.ThoiGianDen, gant[gant.Count - 1].ThoiGianXuLy + a.ThoiGianXuLy));
            }
            return(gant);
        }
Example #5
0
        public List <tientrinh> xuLyGant()
        {
            Gant.Clear();
            ganTam.Clear();
            if (tam.Count == 0)
            {
                return(null);
            }
            them();
            tientrinh a = ganTam.Dequeue();

            Gant.Add(new tientrinh(a.TenTienTrinh, a.ThoiGianDen, a.ThoiGianDen, a.ThoiGianXuLy + a.ThoiGianDen));
            if (ganTam.Count == 0)
            {
                return(Gant);
            }
            List <tientrinh> hangdoiTam = new List <tientrinh>();

            hangdoiTam.Clear();
            while (ganTam.Count != 0 && ganTam.Peek().ThoiGianDen <= gant[gant.Count - 1].ThoiGianXuLy)
            {
                hangdoiTam.Add(ganTam.Dequeue());
            }
            hangdoiTam = hangdoiTam.OrderBy(t => t.ThoiGianXuLy).ToList();
            while (hangdoiTam.Count != 0)
            {
                Gant.Add(new tientrinh(hangdoiTam[0].TenTienTrinh, Gant[Gant.Count - 1].ThoiGianXuLy, hangdoiTam[0].ThoiGianDen, Gant[Gant.Count - 1].ThoiGianXuLy + hangdoiTam[0].ThoiGianXuLy));
                hangdoiTam.RemoveAt(0);
                while (ganTam.Count != 0 && ganTam.Peek().ThoiGianDen <= gant[gant.Count - 1].ThoiGianXuLy)
                {
                    hangdoiTam.Add(ganTam.Dequeue());
                }
                hangdoiTam = hangdoiTam.OrderBy(t => t.ThoiGianXuLy).ToList();
            }
            return(Gant);
        }
 public void add(string ten1, int tgden1, int tgxuly1)
 {
     tientrinh a = new tientrinh(ten1, tgden1, tgxuly1);
     tam.Add(a);
 }
Example #7
0
        public void add(string ten, int tgden, int tgxuLy)
        {
            tientrinh a = new tientrinh(ten, tgden, tgxuLy);

            tam.Add(a);
        }