zoukankan      html  css  js  c++  java
  • 电梯调度问题《三》

    我们小组《杨世超  李夏蕾》已经基本实现了当初设计的电梯调度算法,电梯运行如下图:

    我们设计的电梯没弄限重和限制人数,我们实现了四部电梯的调度,核心代码如下:

       private void diaodu(int[] a)
            {
                int i, j, x, y, q = 1, L, sub, small=30;
                int[] d=new int[5]; 
                               
                    
                        
                              y = this.label1.Location.Y;
                              for (j = 0; j < 21; j++)
                              {
                                  if (((y - b[j]) < 5&&(y - b[j])>=0) || ((y - b[j]) > -5&&(y - b[j])<0) )
                                  {  d[1] = j; break; }
                             
                              }
                              y = this.label3.Location.Y;
                           //   Console.WriteLine(y);
                              for (j = 0; j < 21; j++)
                              {
                                  if (((y - b[j]) < 5 && (y - b[j]) >=0) || ((y - b[j]) > -5 && (y - b[j]) < 0))
                                  {  d[2] = j; break; }
                                  
                              }
                          
                              y = this.label4.Location.Y;
                              for (j = 0; j < 21; j++)
                              {
                                  if (((y - b[j]) < 5 && (y - b[j]) >= 0) || ((y - b[j]) > -5 && (y - b[j]) < 0))
                                  { d[3] = j; break; }
                              }
                              y = this.label5.Location.Y;
                              //  Console.WriteLine(y);
                              for (j = 0; j < 21; j++)
                              {
                                  if (((y - b[j]) < 5 && (y - b[j]) >= 0) || ((y - b[j]) > -5 && (y - b[j]) < 0))
                                  { d[4]= j; break; }
                              }
    
    
                              L = 1;
                   //选择最佳电梯. 
                            /*  flag =d[1]; L = 1;
                              if (d[1] - a[0] >=0)
                              { small = d[1] - a[0]; }
                              else
                              { small = a[0] - d[1]; }
                             */
                              for (i = 1; i < 5; i++)
                              {
                                  if (d[i] - a[0] >=0)
                                  { sub = d[i] - a[0]; }
                                  else
                                  {sub= a[0] - d[i]; }
    
                                   if (small >sub)
                                   { small = sub; flag = d[i]; L = i; }
                              }
    
                  
    
                              if (L==1)
                              {
                                  c1[k1++]=a[0];
    
                                  for (i = 0; i < k1 - 1; i++) //排序
                                  {
                                      for (j = 0; j < k1 - 1 - i; j++)
                                      {
                                          if (c1[j] > c1[j + 1])
                                          { x = c1[j]; c1[j] = c1[j + 1]; c1[j + 1] = x; }
                                      }
                                  }         
    
                                  
                                  this.timer1.Interval = 1000;
                                  this.timer1.Enabled = true; 
                              }
                              if (L == 2)
                              {
                                  c2[k2++] = a[0];
    
                                  for (i = 0; i < k1 - 1; i++) //排序
                                  {
                                      for (j = 0; j < k1 - 1 - i; j++)
                                      {
                                          if (c2[j] > c2[j + 1])
                                          { x = c2[j]; c2[j] = c2[j + 1]; c2[j + 1] = x; }
                                      }
                                  }         
                                  this.timer2.Interval = 1000;
                                  this.timer2.Enabled = true;
                              }
                              if (L == 3)
                              {
                                  dianti3 = flag;
                                  th3 = a[0];
                                  if (th3>= dianti3)
                                  { k3 = th3 - dianti3; }
                                  else
                                  { k3 = dianti3 - th3; }
                                  this.timer3.Interval = 1000;
                                  this.timer3.Enabled = true;
                              }
                              if (L == 4)
                              {
                                  dianti4 = flag;
                                  th4 = a[0];
                                  if (th4 >= dianti4)
                                  { k4 = th4 - dianti4; }
                                  else
                                  { k4 = dianti4 - th4; }
                                  this.timer4.Interval = 1000;
                                  this.timer4.Enabled = true;
                              }
                  
              }
      public void start1()
              {
                  this.timer1.Interval = 1000;
                  int i=0,j,y,dceng=0, step = 21;
                  y = this.label1.Location.Y;
                  for (j = 0; j < 21; j++)
                  {
                      if (((y - b[j]) < 5 && (y - b[j]) >= 0) || ((y - b[j]) > -5 && (y - b[j]) < 0))
                      { dceng= j; break; }
                  }
                 
                  if (dceng!= c1[k11])
                  {
                      
                      this.label1.Location = new Point(this.label1.Location.X, this.label1.Location.Y - step);
                  }
                  else
                  {
                      k11++; this.timer1.Interval = 3000;
                      if (k11 == k1)
                      { k11 = 0; k1 = 0; this.timer1.Enabled = false; }
                  
                  }
                       
    
              }
                      
    

      通过这几周的努力,最终实现了电梯的基本功能。在这几周中感觉收获很多,专业知识又提升了一些。其中遇到的难点是,怎样实现四部电梯的调度,经过搜索资料,我们组用timer空件来实现四部电梯能同时运行,并且互不影响。然后在设计算法,实现电梯的综合调度,离乘客最近的电梯先响应。

  • 相关阅读:
    Python基础09 面向对象的进一步拓展
    Python快速教程 (手册)
    Python基础03 序列
    Python基础04 运算
    Python基础08 面向对象的基本概念
    Python基础07 函数
    Python基础10 反过头来看看
    Python基础05 缩进和选择
    Python进阶02 文本文件的输入输出
    Python进阶01 词典
  • 原文地址:https://www.cnblogs.com/yangshichao/p/3616006.html
Copyright © 2011-2022 走看看