Beispiel #1
0
        /// <summary>
        /// 设置作业参数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            //如果演示已经运行中,停止他
            if (toolStripButton2.Text == "暂停" || isPause == true)
            {
                timer1.Stop();
                toolStripButton2.Image = Properties.Resources.setup;
                toolStripButton2.Text  = "启动";
                toolStripLabel2.Text   = Convert.ToString(0);
                setupTime    = 0;
                countOfTime1 = 0;
                workCount    = 0;
                CurrentWork  = null;
                isPause      = false;
                wcRuning.dataList.Clear();
            }
            Form form2 = new Form2(ref workList);

            form2.ShowDialog();
            if (form2.DialogResult == DialogResult.OK)
            {
                this.panel1.Controls.Clear();
                //timer1 = new Timer();
                //timer1.Interval = 100;
                //timer1.Tick += new EventHandler(timer1_Tick);
                uiDisplay.SetLableOfALLWork(ref panel1, ref workList, new Point(5, 20));
            }
        }
Beispiel #2
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);
        }
Beispiel #3
0
 /// <summary>
 /// 最短剩余时间优先,作业运行的相关操作
 /// 此方法没有设置起始时间,只有当作业第一次启动时才设其实时间
 /// 当isSetup为false时表示还没有启动过,之后isSetup为true
 /// </summary>
 /// <param name="growthButton"></param>
 public void WorkRunForSPT(ref WorkObject CurrentWork, int setupTime)
 {
     //运行任务
     CurrentWork.isSetup   = true;
     CurrentWork.isRunning = true;
     CurrentWork.isWaiting = false;
 }
Beispiel #4
0
 /// <summary>
 /// 作业结束时执行
 /// </summary>
 public void workEnd(ref WorkObject CurrentWork, int setupTime)
 {
     CurrentWork.isRunning = false;
     CurrentWork.isEnd     = true;
     CurrentWork.EndTime   = setupTime;
     CurrentWork.ZhouZhuan = setupTime - CurrentWork.ArrivalTime;
     CurrentWork.BiLi      = CurrentWork.ZhouZhuan / CurrentWork.ServerTime;
     CurrentWork           = (WorkObject)null;
 }
Beispiel #5
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;
 }
Beispiel #6
0
        /// <summary>
        /// 从队列中取最先到达的任务
        /// </summary>
        /// <param name="q"></param>
        /// <returns></returns>
        public WorkObject FecthWork(ref Queue q)
        {
            WorkObject work = (WorkObject)null;

            if (q.Count != 0)
            {
                work           = (WorkObject)q.Dequeue();
                work.isSetup   = false;
                work.isWaiting = true;
            }
            return(work);
        }
Beispiel #7
0
 //最短进程优先
 private void SPN()
 {
     if (countOfTime1 == 1)
     {
         tabControl1.SelectedIndex = 1;
     }
     if (countOfTime1 % 10 == 0 || countOfTime1 == 1)
     {
         foreach (WorkObject work in wcSPN)
         {
             if (work.ArrivalTime == setupTime)//有任务到达
             {
                 wcRuning.dataList.Add(work);
             }
         }
     }
     //取任务
     if (CurrentWork == null && wcRuning.Count != 0)//如果当前任务为空而且队列中还有任务,执行下面
     {
         CurrentWork = sdule.FecthWorkForSPN(ref wcRuning);
     }
     //运行任务
     if (CurrentWork != null)
     {
         //运行任务
         if (!CurrentWork.isSetup)
         {
             //运行任务
             sdule.WorkRun(ref CurrentWork, setupTime);
             //设置显示效果
             uiDisplay.AddButton(ref panel1,
                                 ref growthButton,
                                 new Point(200 + 5 * countOfTime1, 20 + 25 * CurrentWork.ID + workList.Count * 25 * which));
         }
         growthButton.Width += 5;
         //结束任务
         if (setupTime - CurrentWork.BeginTime >= CurrentWork.ServerTime)
         {
             sdule.workEnd(ref CurrentWork, setupTime);
             workCount++;//已经完成的作业计数器
         }
     }
     if (workCount == workList.Count)                                                                                                                        //所有作业都完成了
     {
         AllWorkEnd(2);                                                                                                                                      //重置条件
         tabControl1.TabPages[1].Controls[tabControl1.TabPages[1].Controls.IndexOfKey("myTextBox11")].Text = sdule.averageOfZhouZhuan(ref wcSPN).ToString(); //求平均周转
         tabControl1.TabPages[1].Controls[tabControl1.TabPages[1].Controls.IndexOfKey("myTextBox21")].Text = sdule.averageOfZhouZhuan1(ref wcSPN).ToString();
     }
     dataGridView2.Refresh();
 }
Beispiel #8
0
 /// <summary>
 /// 保存作业信息到WordCollection对象集合中去,然后关闭设置参数的子窗体
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button2_Click(object sender, EventArgs e)
 {
     //save process to the object of WorkCollection
     workListLocal.dataList.Clear();
     for (int i = 0; i < dataGridView1.RowCount - 1; i++)
     {
         WorkObject wo = new WorkObject(Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value),
                                        dataGridView1.Rows[i].Cells[2].Value.ToString(),
                                        Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value),
                                        Convert.ToInt32(dataGridView1.Rows[i].Cells[4].Value));
         workListLocal.dataList.Add(wo);
     }
     //Close form2
     this.Close();
 }
Beispiel #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);
        }
Beispiel #10
0
 private void FCFS()
 {
     //每秒判断一次是否有任务到达
     if (countOfTime1 % 10 == 0 || countOfTime1 == 1)
     {
         foreach (WorkObject work in wcFCFS)
         {
             if (work.ArrivalTime == setupTime)
             {
                 q.Enqueue(work);
             }
         }
     }
     //取任务
     if (CurrentWork == null && q.Count != 0)//如果当前任务为空而且队列中还有任务,执行下面
     {
         CurrentWork = sdule.FecthWork(ref q);
     }
     if (CurrentWork != null)
     {
         if (!CurrentWork.isSetup)
         {
             //运行任务
             sdule.WorkRun(ref CurrentWork, setupTime);
             //设置显示效果
             uiDisplay.AddButton(ref panel1,
                                 ref growthButton,
                                 new Point(200 + 5 * countOfTime1, 20 + 25 * CurrentWork.ID + workList.Count * 25 * which));
         }
         growthButton.Width += 5;
         //结束任务
         if (setupTime - CurrentWork.BeginTime >= CurrentWork.ServerTime)
         {
             sdule.workEnd(ref CurrentWork, setupTime);
             workCount++;//已经完成的作业计数器
         }
     }
     if (workCount == wcFCFS.Count)                                                                                                                           //FCFS所有作业都完成了
     {
         AllWorkEnd(1);                                                                                                                                       //重置条件
         tabControl1.TabPages[0].Controls[tabControl1.TabPages[0].Controls.IndexOfKey("myTextBox10")].Text = sdule.averageOfZhouZhuan(ref wcFCFS).ToString(); //求平均周转
         tabControl1.TabPages[0].Controls[tabControl1.TabPages[0].Controls.IndexOfKey("myTextBox20")].Text = sdule.averageOfZhouZhuan1(ref wcFCFS).ToString();
     }
     dataGridView1.Refresh();
 }
Beispiel #11
0
 //停止演示
 private void toolStripButton1_Click(object sender, EventArgs e)
 {
     //如果演示已经运行中,停止他
     if (toolStripButton2.Text == "暂停" || isPause == true)
     {
         timer1.Stop();
         which = 0;
         toolStripButton2.Image = Properties.Resources.setup;
         toolStripButton2.Text  = "启动";
         toolStripLabel2.Text   = Convert.ToString(0);
         setupTime    = 0;
         countOfTime1 = 0;
         workCount    = 0;
         CurrentWork  = null;
         isPause      = false;
         wcRuning.dataList.Clear();
         panel1.Controls.Remove(growthButton);
     }
 }
Beispiel #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);
        }
Beispiel #13
0
 /// <summary>
 /// 最短剩余时间优先
 /// </summary>
 private void SPT()
 {
     if (countOfTime1 == 1)
     {
         tabControl1.SelectedIndex = 2;
     }
     if (countOfTime1 % 10 == 0 || countOfTime1 == 1)
     {
         foreach (WorkObject work in wcSRT)
         {
             if (work.ArrivalTime == setupTime)//有任务到达
             {
                 wcRuning.dataList.Add(work);
                 if (CurrentWork == null)
                 {
                     CurrentWork = sdule.FecthWorkForSPT(ref wcRuning);
                     if (CurrentWork != null)
                     {
                         CurrentWork.isWaiting = true;
                     }
                 }
                 else//新加的作业是否比当前作业剩余时间短
                 {
                     if (work.ServerTime < (CurrentWork.ServerTime - CurrentWork.HaveRunTime))
                     {
                         //对于立马要结束的作业执行多一次,防止立马完成的任务,没有正常结束
                         if (CurrentWork.HaveRunTime == CurrentWork.ServerTime - 1)//判断是否是要结束的任务
                         {
                             growthButton.Width += 5;
                             CurrentWork.HaveRunTime++;
                             //结束任务
                             sdule.WorkEndForSPT(ref wcRuning, ref CurrentWork, setupTime);
                             workCount++;//已经完成的作业计数器
                         }
                         else//如果不是,保存
                         {
                             growthButton.Width += 5;
                             CurrentWork.HaveRunTime++;
                             sdule.SaveCurrentWorkForSPT(ref CurrentWork); //保存当前作业
                         }
                         CurrentWork           = work;                     //抢占
                         CurrentWork.isWaiting = true;
                     }
                 }
             }
         }
     }
     if (CurrentWork == null && wcRuning.Count != 0)//执行完一个作业,但是又没有新作业到达时执行
     {
         CurrentWork = sdule.FecthWorkForSPT(ref wcRuning);
         if (CurrentWork != null)
         {
             CurrentWork.isWaiting = true;
         }
     }
     if (CurrentWork != null)
     {
         //运行任务
         if (!CurrentWork.isSetup)              //作业第一次启动
         {
             CurrentWork.BeginTime = setupTime; //设置起始时间
         }
         if (CurrentWork.isWaiting)
         {
             sdule.WorkRunForSPT(ref CurrentWork, setupTime);
             //设置显示效果
             uiDisplay.AddButton(ref panel1,
                                 ref growthButton,
                                 new Point(200 + 5 * countOfTime1,
                                           20 + 25 * CurrentWork.ID + workList.Count * 25 * which));
             beginTime = setupTime;//标识此次运行的起始时间
         }
         growthButton.Width += 5;
         if (countOfTime1 % 10 == 0 && setupTime > beginTime)//每秒钟到来
         {
             CurrentWork.HaveRunTime++;
         }
         //结束任务
         if (CurrentWork.HaveRunTime == CurrentWork.ServerTime)
         {
             sdule.WorkEndForSPT(ref wcRuning, ref CurrentWork, setupTime); //这里还将已经完成的作业移除
             workCount++;                                                   //已经完成的作业计数器
         }
     }
     if (workCount == workList.Count)                                                                                                                        //所有作业都完成了
     {
         AllWorkEnd(3);                                                                                                                                      //重置条件
         tabControl1.TabPages[2].Controls[tabControl1.TabPages[2].Controls.IndexOfKey("myTextBox12")].Text = sdule.averageOfZhouZhuan(ref wcSRT).ToString(); //求平均周转
         tabControl1.TabPages[2].Controls[tabControl1.TabPages[2].Controls.IndexOfKey("myTextBox22")].Text = sdule.averageOfZhouZhuan1(ref wcSRT).ToString();
     }
     dataGridView3.Refresh();
 }
Beispiel #14
0
 /// <summary>
 /// 最短剩余时间优先,作业被抢占时保存当前作业的相关操作
 /// </summary>
 /// <param name="CurrentWork"></param>
 /// <param name="setupTime"></param>
 /// <param name="setupTime">此次运行的开始时间</param>
 public void SaveCurrentWorkForSPT(ref WorkObject CurrentWork)
 {
     CurrentWork.isRunning = false;
     CurrentWork.isWaiting = true;
 }