zoukankan      html  css  js  c++  java
  • 电梯调度《二》

        经过几天的奋斗,电梯终于能运转了,我和李夏蕾分工如下:3-13我负责查阅调度算法,李夏蕾负责界面设计;3-15我们实现了单个电梯的上下移动;3-16我们共同用多线程控制4个电梯。

         我们的设计目的就是综合调度4个电梯,核心思想是响应的层数与4个电梯所在层数进行比较,从而得出用哪一个电梯最合适。

      核心算法:

       

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
     private void diaodu(int[] a)//判断用哪一个电梯
            {
                int i, j, x, y, q = 1, L, sub, small;
                int[] d=new int[5];
                
                               
                      for (i = 0; i < f - 1; i++) //排序
                      {
                          for (j = 0; j < f - 1 - i; j++)
                          {
                              if (a[j] > a[j + 1])
                              { x = a[j]; a[j] = a[j + 1]; a[j + 1] = x; }
                          }
                      }
                     
                        
                              y = this.label1.Location.Y;
                               Console.WriteLine("第一层");
    
                              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; }
                              }
    
    
    
                   //选择最佳电梯. 
                              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)
                              {
                                  dianti1 = flag;//电梯所在层。
                                  th1 = a[0];
                                  if (th1 >= dianti1)
                                  { k1 = th1 - dianti1; }
                                  else
                                  { k1 = dianti1 - th1; }
                                  this.timer1.Interval = 500;
                                  this.timer1.Enabled = true; 
                              }
                              if (L == 2)
                              {
                                  dianti2 = flag;
                                  th2 = a[0];
                                  if (th2 >= dianti2)
                                  { k2 = th2 - dianti2; }
                                  else
                                  { k2 = dianti2 - th2; }
                                  this.timer2.Interval = 500;
                                  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 = 500;
                                  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 = 500;
                                  this.timer4.Enabled = true;
                              }
                  
              }
              public void start1()//电梯1
              {
              
                  int  step = 21;
                  if ((th1 - dianti1) > 0)
                  {
                     this.label1.Location = new Point(this.label1.Location.X, this.label1.Location.Y - step);
                      k1--;
                      if(k1==0)  {    this.timer1.Enabled =false; }
                  }
    
                  else
                  {
                                    
                     this.label1.Location = new Point(this.label1.Location.X, this.label1.Location.Y + step);
                     k1--;
                     if (k1 == 0) { this.timer1.Enabled = false; }  
                   }
              
    
              }
                      
    
              public void start2()//电梯2
              {
                  int step = 21;
                  if ((th2 - dianti2) > 0)
                  {
                      this.label3.Location = new Point(this.label3.Location.X, this.label3.Location.Y - step);
                      k2--;
                      if (k2 == 0) { this.timer2.Enabled = false; }
                  }
    
                  else
                  {
    
                      this.label3.Location = new Point(this.label3.Location.X, this.label3.Location.Y + step);
                      k2--;
                      if (k2 == 0) { this.timer2.Enabled = false; }
                  }
              
    
              }
    
              public void start3()//电梯3
              {
                  int step = 21;
                  if ((th3 - dianti3) > 0)
                  {
                      this.label4.Location = new Point(this.label4.Location.X, this.label4.Location.Y - step);
                      k3--;
                      if (k3 == 0) { this.timer3.Enabled = false; }
                  }
    
                  else
                  {
    
                      this.label4.Location = new Point(this.label4.Location.X, this.label4.Location.Y + step);
                      k3--;
                      if (k3 == 0) { this.timer3.Enabled = false; }
                  }
              
    
              }
    
    
              public void start4()//电梯4
              {
                  int step = 21;
                  if ((th4 - dianti4) > 0)
                  {
                      this.label5.Location = new Point(this.label5.Location.X, this.label5.Location.Y - step);
                      k4--;
                      if (k4 == 0) { this.timer4.Enabled = false; }
                  }
    
                  else
                  {
    
                      this.label5.Location = new Point(this.label5.Location.X, this.label5.Location.Y + step);
                      k4--;
                      if (k4 == 0) { this.timer4.Enabled = false; }
                  }
              
    
    
              }
    

      

  • 相关阅读:
    [No0000159]C# 7 中的模范和实践
    [No0000158]思维模型1-20
    [No000014B]Office-PPT设置默认打开视图
    [No000014C]让大脑高效运转的24个技巧
    [No000014A]Linux简介与shell编程
    [No000014D]chrome console 调试 引入 jquery等外部库
    [No0000157].net core项目中拼音,excel,pdf处理库
    [No0000156]天干地支-狗年我懂,戊戌二字怎么来的?
    [No0000155]为什么32位机器最大只能用到4GB内存
    [No0000154]详解为什么32位系统只能用4G内存.
  • 原文地址:https://www.cnblogs.com/yangshichao/p/3605991.html
Copyright © 2011-2022 走看看