首页 > 其他 > 详细

电梯调度《二》

时间:2014-03-18 12:19:51      阅读:527      评论:0      收藏:0      [点我收藏+]

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

     我们的设计目的就是综合调度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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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; }
             }
          
 
 
         }

  

电梯调度《二》,布布扣,bubuko.com

电梯调度《二》

原文:http://www.cnblogs.com/yangshichao/p/3605991.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!