Пример #1
0
 public void SetLableOfALLWork(ref Panel panel1, ref WorkCollection workList, Point p)
 {
     SetLableOfWork(ref panel1, ref workList, "先来先服务FCFS: ", ref p);
     SetLableOfWork(ref panel1, ref workList, "最短进程优先SPN:", ref p);
     SetLableOfWork(ref panel1, ref workList, "最短剩余时间SRT:", ref p);
     SetLableOfWork(ref panel1, ref workList, "最高响应比HRRN:", ref p);
 }
Пример #2
0
        /// <summary>
        /// 绑定DataGridView控件
        /// </summary>
        /// <param name="wcFCFS"></param>
        /// <param name="mydataGridView"></param>
        private void BindDataGridView(ref WorkCollection workColl, ref DataGridView mydataGridView)
        {
            BindingSource bs = new BindingSource();

            foreach (object item in workColl)
            {
                bs.Add(item);
            }
            mydataGridView.AutoGenerateColumns = true;
            mydataGridView.DataSource          = bs;
            mydataGridView.AutoGenerateColumns = false;//一定要加这句,要不然没法移除列
            mydataGridView.Columns.Remove("isSetup");
            mydataGridView.Columns.Remove("isWaiting");
            mydataGridView.Columns.Remove("isRunning");
            mydataGridView.Columns.Remove("isEnd");
            mydataGridView.Columns.Remove("HaveRunTime");

            mydataGridView.Columns[0].ReadOnly   = true;
            mydataGridView.Columns[1].HeaderText = "作业名称";
            mydataGridView.Columns[2].HeaderText = "到达时间";
            mydataGridView.Columns[3].HeaderText = "服务时间";
            mydataGridView.Columns[4].HeaderText = "开始时间";
            mydataGridView.Columns[5].HeaderText = "结束时间";
            mydataGridView.Columns[6].HeaderText = "周转时间";
            mydataGridView.Columns[7].HeaderText = "带权周转时间";

            mydataGridView.Columns[7].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
        }
Пример #3
0
        /// <summary>
        /// 最短进程优先SPN,选出未运行的作业的最短进程
        /// </summary>
        /// <param name="workList"></param>
        /// <returns></returns>
        public WorkObject FecthWorkForSPN(ref WorkCollection workList)
        {
            if (workList.Count == 0)
            {
                return(null);
            }
            WorkObject minwork = new WorkObject();

            foreach (WorkObject work in workList)
            {
                if (!work.isEnd)
                {
                    minwork = work;//找到第一个未完成的作业
                    break;
                }
            }
            foreach (WorkObject work in workList)
            {
                if (!work.isEnd && work.ServerTime < minwork.ServerTime)
                {
                    minwork = work;
                }
            }

            return(minwork);
        }
Пример #4
0
        /// <summary>
        /// 初始化各作业的Lable并摆放在每一行的开始位置,返回下一组的其实坐标
        /// 如:FCFS: A..........
        ///           B..........
        ///           C..........
        ///     SRT:  A..........
        /// </summary>
        /// <param name="pane1">控件容器</param>
        /// <param name="workList">作业集合</param>
        /// <param name="headstring">标题,如FCFS\SRT\SPN等</param>
        /// <param name="p">起始坐标</param>
        private void SetLableOfWork(ref Panel pane1, ref WorkCollection workList, string headstring, ref Point p)
        {
            Label HeadLable = new Label();

            HeadLable.Text     = headstring;
            HeadLable.AutoSize = true;
            pane1.Controls.Add(HeadLable);
            HeadLable.Location = p;
            //摆放各作业的Lable
            int i = 0;
            int x = p.X + HeadLable.Width + 5;
            int y = p.Y;

            foreach (WorkObject work in workList)
            {
                Label myLable = new Label();
                myLable.Name     = "myLable" + i.ToString();
                myLable.Text     = work.Name;
                myLable.AutoSize = true;
                pane1.Controls.Add(myLable);
                myLable.Location = new Point(x, y);
                y += 25;
                i++;
            }
            p.X = x - HeadLable.Width - 5;
            p.Y = y;
        }
Пример #5
0
 public Form2(ref WorkCollection workList)
 {
     InitializeComponent();
     workListLocal = workList; //将父窗体传过来的对象引用在本地创建副本
     InitGridViewData();       //Init dataGridView data which is save in txt file
     toolTip1.ToolTipTitle = "提示";
     toolTip1.SetToolTip(this.button2, "如果要保存数据作为下次运行的默认数据,请点击保存默认按钮\n如果不想保存数据,直接按确认按钮");
     toolTip1.SetToolTip(this.button1, "保存数据可作为下次运行的默认数据");
 }
Пример #6
0
        /// <summary>
        /// 求平均带权周转时间
        /// </summary>
        /// <param name="wc"></param>
        /// <returns></returns>
        public float averageOfZhouZhuan1(ref WorkCollection wc)
        {
            float total = 0;

            foreach (WorkObject work in wc)
            {
                total += work.BiLi;
            }
            return(total / wc.Count);
        }
Пример #7
0
        public WorkCollection Clone()
        {
            WorkCollection wc = new WorkCollection();

            for (int i = 0; i < this.dataList.Count; i++)
            {
                wc.dataList.Add(((WorkObject)this.dataList[i]).Copy());
            }
            return(wc);
        }
Пример #8
0
 public void workEndForHRRN(ref WorkCollection wcRunning, ref WorkObject CurrentWork, int setupTime)
 {
     CurrentWork.isRunning = false;
     CurrentWork.isWaiting = false;
     CurrentWork.isEnd     = true;
     CurrentWork.EndTime   = setupTime;
     CurrentWork.ZhouZhuan = CurrentWork.EndTime - CurrentWork.ArrivalTime;
     CurrentWork.BiLi      = CurrentWork.ZhouZhuan / CurrentWork.ServerTime;
     wcRunning.dataList.Remove(CurrentWork);
     CurrentWork = (WorkObject)null;
 }
Пример #9
0
        public WorkObject FecthWorkForSPT(ref WorkCollection workList)
        {
            if (workList.Count == 0)
            {
                return(null);
            }
            WorkObject minwork = workList[0];

            foreach (WorkObject work in workList)
            {
                if ((work.ServerTime - work.HaveRunTime) < (minwork.ServerTime - minwork.HaveRunTime))
                {
                    minwork = work;
                }
            }
            return(minwork);
        }
Пример #10
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //读取默认的数据
            ReadAndWriteTXT rw = new ReadAndWriteTXT(path, System.IO.FileMode.OpenOrCreate);

            workList = rw.ReadTXT();//return a Object of workCollection
            UiDisplay uiDisplay = new UiDisplay();

            this.panel1.Controls.Clear();
            uiDisplay.SetLableOfALLWork(ref panel1, ref workList, new Point(5, 20));
            for (int i = 0; i < tabControl1.TabCount; i++)
            {
                myLabel      = new Label();
                myLabel.Name = "myLabel1" + i.ToString();
                myLabel.Text = "平均周转时间:";
                tabControl1.TabPages[i].Controls.Add(myLabel);
                myLabel.Location = new Point(Width - 180, 0);
                myLabel.Anchor   = AnchorStyles.Top & AnchorStyles.Bottom & AnchorStyles.Left;

                myTextBox           = new TextBox();
                myTextBox.Name      = "myTextBox1" + i.ToString();
                myTextBox.Text      = "0";
                myTextBox.ForeColor = Color.Red;
                tabControl1.TabPages[i].Controls.Add(myTextBox);
                myTextBox.Anchor   = AnchorStyles.Top & AnchorStyles.Right & AnchorStyles.Bottom & AnchorStyles.Left;
                myTextBox.Location = new Point(Width - 180, 28);


                myLabel          = new Label();
                myLabel.Text     = "平均带权周转时间:";
                myLabel.AutoSize = true;
                myLabel.Name     = "myLabel2" + i.ToString();
                tabControl1.TabPages[i].Controls.Add(myLabel);
                myLabel.Location = new Point(Width - 180, 66);
                myLabel.Anchor   = AnchorStyles.Top & AnchorStyles.Right & AnchorStyles.Bottom & AnchorStyles.Left;

                myTextBox           = new TextBox();
                myTextBox.Name      = "myTextBox2" + i.ToString();
                myTextBox.Text      = "0";
                myTextBox.ForeColor = Color.Red;
                tabControl1.TabPages[i].Controls.Add(myTextBox);
                myTextBox.Location = new Point(Width - 180, 94);
                myTextBox.Anchor   = AnchorStyles.Top & AnchorStyles.Right & AnchorStyles.Bottom & AnchorStyles.Left;
            }
        }
Пример #11
0
 /// <summary>
 /// 启动或暂停演示
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void toolStripButton2_Click(object sender, EventArgs e)
 {
     if (toolStripButton2.Text == "启动")
     {
         //设置图片
         toolStripButton2.Image = Properties.Resources.stop;
         toolStripButton2.Text  = "暂停";
         if (!isPause)//第一次启动运行,不是被暂停的
         {
             isPause = false;
             //先来先服务,准备队列,并准备显示列表
             wcFCFS = workList.Clone();//进行了深拷贝
             BindDataGridView(ref wcFCFS, ref dataGridView1);
             //最短作业优先
             wcSPN = workList.Clone();
             BindDataGridView(ref wcSPN, ref dataGridView2);
             //最短剩余时间优先
             wcSRT = workList.Clone();
             BindDataGridView(ref wcSRT, ref dataGridView3);
             //最高响应比
             wcHRRN = workList.Clone();
             BindDataGridView(ref wcHRRN, ref dataGridView4);
             //作业开始计时工作
             timer1          = new Timer();
             timer1.Interval = 100;
             timer1.Tick    += new EventHandler(timer1_Tick);
             timer1.Start();
         }
         else//演示已经开始了,只是被暂停了,恢复运行
         {
             timer1.Start();
         }
     }
     else
     {
         isPause = true;
         toolStripButton2.Image = Properties.Resources.setup;
         toolStripButton2.Text  = "启动";
         timer1.Stop();
     }
 }
Пример #12
0
        public WorkObject FecthWorkForHRRN(ref WorkCollection wcRunning, int setupTime)
        {
            if (wcRunning.Count == 0)
            {
                return(null);
            }
            WorkObject maxwork = wcRunning[0];
            //响应比=(等待时间+服务时间)/服务时间
            float R = (setupTime - maxwork.ArrivalTime + maxwork.ServerTime) / maxwork.ServerTime;
            float each;

            foreach (WorkObject work in wcRunning)
            {
                each = (setupTime - work.ArrivalTime + work.ServerTime) / work.ServerTime;
                if (each > R)
                {
                    maxwork = work;
                }
            }
            return(maxwork);
        }
Пример #13
0
        public WorkCollection ReadTXT()
        {
            WorkCollection workColl = new WorkCollection();

            using (StreamReader sr = new StreamReader(fs, System.Text.Encoding.GetEncoding("UTF-8")))
            {
                string[] temp;
                string   eachLine;//保存数据
                int      i = 0;
                while ((eachLine = sr.ReadLine()) != null)
                {
                    temp = eachLine.Split('-');
                    int    id   = int.Parse(temp[0]);
                    string name = temp[1];
                    int    at   = int.Parse(temp[2]);
                    int    st   = int.Parse(temp[3]);
                    //workColl[i] = new WorkObject(id, name, at, st);
                    workColl.dataList.Add(new WorkObject(id, name, at, st));
                    i++;
                }
            }
            return(workColl);
        }