当前位置: 首页 > 编程日记 > 正文

结对项目开发电梯调度 - 整体设计

一、系统介绍

1. 功能描述

本电梯系统用来控制一台运行于一个具有16层的大楼电梯,它具有上升、下降、开门、关门、载客的基本功能。

大楼的每一层都有:

(1) 两个指示灯:  这两个指示灯分别用于指示当前所在的层数和电梯的当前状态(上行、下行或停止);

(2)按钮:  除了第一层和顶层,每一层都有两个按钮(上行、下行),乘客可以呼叫上楼或下楼,顶楼只有一个下楼按钮,而第一层只有一个上楼按钮。

2. 电梯里面具有:  标示从“1”到“16”的16个楼层按钮,用于让乘客选择所要的层数;

注:1-8层不停

二、关键实现方法描述

用两个队列来实现电梯的调度,电梯根据这两个队列发送来的楼层号作为目的地进行运行。在上行队列中保存了所有的上行请求的楼层号(包括楼层的呼叫和电梯里的楼层按钮请求),即保存电梯上行时需要停的楼层号。

队列排列规则是:高于或等于电梯当前所地楼层的上行请求的楼层号从小到大排在队列的前部分,低于电梯当前所地楼层的上行请求的楼层号从小到大排在队列后部分。如果新请求的楼层号被插在队列头时同时将这个楼层号发送给电梯作为它的目的地。在下行队列中保存了所有的下行请求的楼层号(包括楼层的呼叫和电梯里楼层按钮请求),即保存电梯下行时需要停的楼层号。

三、电梯具体设计

本次设计用的语言是.net,用的环境是VS 2010开发工具,

该系统用了3个.cs文件,一个主类class ElevatorController,主要定义了函数用来调度电梯。一个class Elevator,标明电梯状态;一个class Form1,设计布局,线程控制;

1. 电梯设置: 电梯分为三种状态:静止,上升,下降。

2 乘客分析: 乘客的需求分为“上”和“下”两种。

3 电梯需要初始化,其中状态为静止state=0,层数floor_lift设置为1。目标层数数组需要初始化。

  程序源代码:

    1.Elevator.CS

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace ElevatorManager
 7 {
 8     class Elevator
 9     {
10         public int floor;
11         public bool[] panel;//电梯内面板状态
12         public int direction;//up,down
13         public int gatestatus;//open,close
14         public bool isrun;
15 
16 
17         const int UP = 0;
18         const int DOWN = 1;
19 
20         const int CLOSE = 0;
21         const int OPEN = 1;
22 
23         public Elevator()
24         {
25             floor = 0;
26             panel = new bool[10];
27             for (int i = 0; i < 10; ++i)
28             {
29                 panel[i] = false;
30             }
31             direction = UP;
32             gatestatus = CLOSE;
33             isrun = false;
34         }
35 
36         public void setPanel(int i)
37         {
38             panel[i] = true;
39         }
40         
41     }
42 }
View Code

2.ElevatorManager.CS

  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using System.Threading;
  6 
  7 namespace ElevatorManager
  8 {
  9     class ElevatorController
 10     {
 11         public Elevator ele_1;
 12         public Elevator ele_2;
 13         public bool[] uppanel;
 14         public bool[] downpanel;
 15 
 16         #region 状态常量定义
 17         //电梯内
 18         const int UP = 0;
 19         const int DOWN = 1;
 20 
 21         const int CLOSE = 0;
 22         const int OPEN = 1;
 23         const int WAIT = 2;
 24 
 25         //电梯外
 26         const int EXTERIOR = 0;
 27         const int INTERIOR = 1;
 28 
 29         //任务
 30         const int MOVEUP = 0;
 31         const int MOVEDOWN = 1;
 32         const int NONE = -1;
 33 
 34         //type判断
 35         const int ELE1 = 0;
 36         const int ELE2 = 1;
 37         
 38 
 39         #endregion
 40 
 41         public ElevatorController()
 42         {
 43             ele_1 = new Elevator();
 44             ele_2 = new Elevator();
 45             uppanel = new bool[10];//电梯外 上按钮状态
 46             downpanel = new bool[10];//电梯外 下按钮状态
 47             for (int i = 0; i < 10; ++i)
 48             {
 49                 uppanel[i] = false;
 50             }
 51             for (int i = 0; i < 10; ++i)
 52             {
 53                 downpanel[i] = false;
 54             }
 55         }
 56 
 57         public void operate(int IorE, int type, int select)//操作
 58         {
 59             //操作判断
 60             if (IorE == INTERIOR)//外层IorE判断
 61             {
 62                 if (type == ELE1)//内层type判断
 63                 {
 64                     ele_1.setPanel(select);
 65                 }
 66                 else if (type == ELE2)
 67                 {
 68                     ele_2.setPanel(select);
 69                 }
 70                 else
 71                 {
 72                     Exception ex = new Exception("INTERIOR type 错误");
 73                     throw ex;
 74                 }
 75             }
 76             else if (IorE == EXTERIOR)
 77             {
 78                 if (type == UP)
 79                 {
 80                     uppanel[select] = true;
 81                 }
 82                 else if (type == DOWN)
 83                 {
 84                     downpanel[select] = true;
 85                 }
 86                 else
 87                 {
 88                     Exception ex = new Exception("EXTERIOR type 错误");
 89                     throw ex;
 90                 }
 91             }
 92             else
 93             {
 94                 Exception ex=new Exception("IorE错误");
 95                 throw ex;
 96             }
 97             
 98             //电梯是否在执行任务
 99             if (!ele_1.isrun)
100             {
101                 ele_1.isrun = true;
102                 Thread th1 = new Thread(new ThreadStart(run_ele1));
103                 th1.IsBackground = true;
104                 th1.Start();
105             }
106             if (!ele_2.isrun)
107             {
108                 ele_2.isrun = true;
109                 Thread th2 = new Thread(new ThreadStart(run_ele2));
110                 th2.IsBackground = true;
111                 th2.Start();
112             }
113         }
114 
115         public void run_ele1()
116         {
117             try
118             {
119                 run(ele_1);
120             }
121             catch (Exception ex)
122             {
123                 throw ex;
124             }
125         }
126 
127         public void run_ele2()
128         {
129             try
130             {
131                 run(ele_2);
132             }
133             catch (Exception ex)
134             {
135                 throw ex;
136             }
137         }
138 
139         public void run(Elevator ele)//运行
140         {
141             for (; isGoOn(ele); )
142             {
143                 for (operaGate(ele); ele.gatestatus == OPEN; operaGate(ele))
144                 {
145                     Thread.Sleep(5000);
146                     ele.gatestatus = CLOSE;
147                 }
148                 int task = NONE;
149                 task = gettask(ele);
150                 if (task == MOVEUP)
151                 {
152                     ele.floor += 1;
153                     if (!floorJudge(ele))
154                     {
155                         Exception ex = new Exception("楼层错误");
156                         throw ex;
157                     }
158                     Thread.Sleep(1000);
159                 }
160                 else if (task == MOVEDOWN)
161                 {
162                     ele.floor -= 1;
163                     if (!floorJudge(ele))
164                     {
165                         Exception ex = new Exception("楼层错误");
166                         throw ex;
167                     }
168                     Thread.Sleep(1000);
169                 }
170                 else if (task == NONE)
171                 {
172                     //不操作
173                     if (!floorJudge(ele))
174                     {
175                         Exception ex = new Exception("楼层错误");
176                         throw ex;
177                     }
178                 }
179                 else 
180                 {
181                     Exception ex = new Exception("获取的任务出错");
182                     throw ex;
183                 }
184             }
185             ele.isrun = false;
186         }
187 
188         public void operaGate(Elevator ele)//是否开门操作
189         {
190             if (ele.direction == UP)
191             {
192                 if(ele.panel[ele.floor]||uppanel[ele.floor])
193                 {
194                     ele.gatestatus = OPEN;
195                     //ele.direction = UP;
196                     ele.panel[ele.floor] = false;
197                     uppanel[ele.floor] = false;
198                     return;
199                 }
200                 if (!upAsk(ele))
201                 {
202                     if (downpanel[ele.floor])
203                     {
204                         ele.gatestatus = OPEN;
205                         ele.direction = DOWN;
206                         downpanel[ele.floor] = false;
207                         return;
208                     }
209                 }
210             }
211             else if (ele.direction == DOWN)
212             {
213                 if (ele.panel[ele.floor] || downpanel[ele.floor])
214                 {
215                     ele.gatestatus = OPEN;
216                     //ele.direction = DOWN;
217                     ele.panel[ele.floor] = false;
218                     downpanel[ele.floor] = false;
219                     return;
220                 }
221                 if (!downAsk(ele))
222                 {
223                     if (uppanel[ele.floor])
224                     {
225                         ele.gatestatus = OPEN;
226                         ele.direction = UP;
227                         uppanel[ele.floor] = false;
228                         return;
229                     }
230                 }
231             }
232             else
233             {
234                 Exception ex = new Exception("电梯状态出错");
235                 throw ex;
236             }
237         }
238 
239         public bool isGoOn(Elevator ele)//是否有任务判断
240         {
241             for (int i=0;i<10;++i)
242             {
243                 if (ele.panel[i])
244                 {
245                     return true;
246                 }
247                 if (uppanel[i])
248                 {
249                     return true;
250                 }
251                 if (downpanel[i])
252                 {
253                     return true; 
254                 }
255             }
256             return false;
257         }
258 
259         public int gettask(Elevator ele)//任务获取
260         {
261             if(ele.direction==UP)//方向上任务获取顺序
262             {
263                 if (upAsk(ele))
264                 {
265                     return MOVEUP;
266                 }
267                 if (downAsk(ele))
268                 {
269                     return MOVEDOWN;
270                 }
271             }
272             else if(ele.direction==DOWN)//方向下任务获取顺序
273             {
274                 if (downAsk(ele))
275                 {
276                     return MOVEDOWN;
277                 }
278                 if (upAsk(ele))
279                 {
280                     return MOVEUP;
281                 }
282             }
283             else
284             {
285                 Exception ex = new Exception("电梯状态出错");
286                 throw ex;
287             }
288             return NONE;
289         }
290 
291         public bool upAsk(Elevator ele)//上方查询
292         {
293             for (int i = ele.floor + 1; i < 10; ++i)
294             {
295                 if (ele.panel[i])
296                 {
297                     return true;
298                 }
299                 if (uppanel[i])
300                 {
301                     return true;
302                 }
303                 if (downpanel[i])
304                 {
305                     return true;
306                 }
307             }
308             return false;
309         }
310 
311         public bool downAsk(Elevator ele)//下方查询
312         {
313             for (int i = ele.floor - 1; i >= 0; --i)
314             {
315                 if (ele.panel[i])
316                 {
317                     return true;
318                 }
319                 if (uppanel[i])
320                 {
321                     return true;
322                 }
323                 if (downpanel[i])
324                 {
325                     return true;
326                 }
327             }
328             return false;
329         }
330 
331         public bool floorJudge(Elevator ele)
332         {
333             if (ele.floor>=0&&ele.floor<10)
334             { 
335                 return true;
336             }
337             return false;
338         }
339 
340     }
341 }
View Code

3.Form1.CS

  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Windows.Forms;
  9 using System.Threading;
 10 
 11 namespace ElevatorManager
 12 {
 13     public partial class Form1 : Form
 14     {
 15         const int UP = 0;
 16         const int DOWN = 1;
 17         const int EXTERIOR = 0;
 18         const int INTERIOR = 1;
 19         const int ELE1 = 0;
 20         const int ELE2 = 1;
 21 
 22         const int CLOSE = 0;
 23         const int OPEN = 1;
 24 
 25         List<Button> btnUpPanel;
 26         List<Button> btnDownPanel;
 27         List<Button> btnEle1;
 28         List<Button> btnEle2;
 29         Thread th_ui;
 30         ElevatorController myElevator;
 31         Image imgEleOpen;
 32         Image imgEleClose;
 33 
 34         public Form1()
 35         {
 36             InitializeComponent();
 37             System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
 38         }
 39 
 40         private void Form1_Load(object sender, EventArgs e)
 41         {
 42             try
 43             {
 44                 btnUpPanel = new List<Button>();
 45                 btnDownPanel = new List<Button>();
 46                 btnEle1 = new List<Button>();
 47                 btnEle2 = new List<Button>();
 48 
 49                 #region 控件获取
 50                 btnUpPanel.Add(btn_1_up);
 51                 btnUpPanel.Add(btn_2_up);
 52                 btnUpPanel.Add(btn_3_up);
 53                 btnUpPanel.Add(btn_4_up);
 54                 btnUpPanel.Add(btn_5_up);
 55                 btnUpPanel.Add(btn_6_up);
 56                 btnUpPanel.Add(btn_7_up);
 57                 btnUpPanel.Add(btn_8_up);
 58                 btnUpPanel.Add(btn_9_up);
 59                 btnUpPanel.Add(new Button());
 60 
 61                 btnDownPanel.Add(new Button());
 62                 btnDownPanel.Add(btn_2_down);
 63                 btnDownPanel.Add(btn_3_down);
 64                 btnDownPanel.Add(btn_4_down);
 65                 btnDownPanel.Add(btn_5_down);
 66                 btnDownPanel.Add(btn_6_down);
 67                 btnDownPanel.Add(btn_7_down);
 68                 btnDownPanel.Add(btn_8_down);
 69                 btnDownPanel.Add(btn_9_down);
 70                 btnDownPanel.Add(btn_10_down);
 71 
 72                 btnEle1.Add(btn_e1_f1);
 73                 btnEle1.Add(btn_e1_f2);
 74                 btnEle1.Add(btn_e1_f3);
 75                 btnEle1.Add(btn_e1_f4);
 76                 btnEle1.Add(btn_e1_f5);
 77                 btnEle1.Add(btn_e1_f6);
 78                 btnEle1.Add(btn_e1_f7);
 79                 btnEle1.Add(btn_e1_f8);
 80                 btnEle1.Add(btn_e1_f9);
 81                 btnEle1.Add(btn_e1_f10);
 82 
 83                 btnEle2.Add(btn_e2_f1);
 84                 btnEle2.Add(btn_e2_f2);
 85                 btnEle2.Add(btn_e2_f3);
 86                 btnEle2.Add(btn_e2_f4);
 87                 btnEle2.Add(btn_e2_f5);
 88                 btnEle2.Add(btn_e2_f6);
 89                 btnEle2.Add(btn_e2_f7);
 90                 btnEle2.Add(btn_e2_f8);
 91                 btnEle2.Add(btn_e2_f9);
 92                 btnEle2.Add(btn_e2_f10);
 93                 #endregion
 94 
 95                 imgEleOpen=new Bitmap(@".\elevator_open.jpg");
 96                 imgEleClose=new Bitmap(@".\elevator_close.jpg");
 97 
 98                 myElevator=new ElevatorController();
 99                 MessageBox.Show("初始化成功!!!");
100             }
101             catch(Exception ex)
102             {
103                 MessageBox.Show(ex.Message);
104             }
105             th_ui = new Thread(new ThreadStart(UIController));
106             th_ui.IsBackground=true;
107             th_ui.Start();
108         }
109 
110         public void UIController()//UI控制线程
111         {
112             try
113             {
114                 for (; true; )
115                 {
116                     #region 面板灯
117                     for (int i = 0; i < 10; ++i)
118                     {
119                         if (myElevator.uppanel[i])
120                         {
121                             btnUpPanel[i].BackColor = Color.Yellow;
122                         }
123                         if (!myElevator.uppanel[i])
124                         {
125                             btnUpPanel[i].BackColor = Color.White;
126                         }
127                         //
128                         if (myElevator.downpanel[i])
129                         {
130                             btnDownPanel[i].BackColor = Color.Yellow;
131                         }
132                         if (!myElevator.downpanel[i])
133                         {
134                             btnDownPanel[i].BackColor = Color.White;
135                         }
136                         //
137                         if (myElevator.ele_1.panel[i])
138                         {
139                             btnEle1[i].BackColor = Color.Yellow;
140                         }
141                         if (!myElevator.ele_1.panel[i])
142                         {
143                             btnEle1[i].BackColor = Color.White;
144                         }
145                         //
146                         if (myElevator.ele_2.panel[i])
147                         {
148                             btnEle2[i].BackColor = Color.Yellow;
149                         }
150                         if (!myElevator.ele_2.panel[i])
151                         {
152                             btnEle2[i].BackColor = Color.White;
153                         }
154                     }
155                     #endregion
156 
157                     label_ele1.Text = "Ele1.floor:" + (myElevator.ele_1.floor + 1).ToString();
158                     label_ele2.Text = "Ele2.floor:" + (myElevator.ele_2.floor + 1).ToString();
159 
160                     picture_ele1.Location = new Point(picture_ele1.Location.X, 500 - (50 * myElevator.ele_1.floor));
161                     picture_ele2.Location = new Point(picture_ele2.Location.X, 500 - (50 * myElevator.ele_2.floor));
162                     
163                     if (myElevator.ele_1.gatestatus == CLOSE)
164                     {
165                         picture_ele1.Image = imgEleClose;
166                     }
167                     if (myElevator.ele_1.gatestatus == OPEN)
168                     {
169                         picture_ele1.Image = imgEleOpen;
170                     }
171                     if (myElevator.ele_2.gatestatus == CLOSE)
172                     {
173                         picture_ele2.Image = imgEleClose;
174                     }
175                     if (myElevator.ele_2.gatestatus == OPEN)
176                     {
177                         picture_ele2.Image = imgEleOpen;
178                     }
179 
180                     Thread.Sleep(100);
181                 }
182             }
183             catch (Exception ex)
184             {
185                 MessageBox.Show(ex.Message);
186             }
187         }
188 
189         private void btn_1_up_Click(object sender, EventArgs e)
190         {
191             try
192             {
193                 myElevator.operate(EXTERIOR, UP, 0);
194             }
195             catch (Exception ex)
196             {
197                 MessageBox.Show(ex.Message);
198             }
199         }
200 
201         private void btn_2_down_Click(object sender, EventArgs e)
202         {
203             try
204             {
205                 myElevator.operate(EXTERIOR, DOWN, 1);
206             }
207             catch (Exception ex)
208             {
209                 MessageBox.Show(ex.Message);
210             }
211         }
212 
213         private void btn_2_up_Click(object sender, EventArgs e)
214         {
215             try
216             {
217                 myElevator.operate(EXTERIOR, UP, 1);
218             }
219             catch (Exception ex)
220             {
221                 MessageBox.Show(ex.Message);
222             }
223         }
224 
225         private void btn_3_down_Click(object sender, EventArgs e)
226         {
227             try
228             {
229                 myElevator.operate(EXTERIOR, DOWN, 2);
230             }
231             catch (Exception ex)
232             {
233                 MessageBox.Show(ex.Message);
234             }
235         }
236 
237         private void btn_3_up_Click(object sender, EventArgs e)
238         {
239             try
240             {
241                 myElevator.operate(EXTERIOR, UP, 2);
242             }
243             catch (Exception ex)
244             {
245                 MessageBox.Show(ex.Message);
246             }
247         }
248 
249         private void btn_4_down_Click(object sender, EventArgs e)
250         {
251             try
252             {
253                 myElevator.operate(EXTERIOR, DOWN, 3);
254             }
255             catch (Exception ex)
256             {
257                 MessageBox.Show(ex.Message);
258             }
259         }
260 
261         private void btn_4_up_Click(object sender, EventArgs e)
262         {
263             try
264             {
265                 myElevator.operate(EXTERIOR, UP, 3);
266             }
267             catch (Exception ex)
268             {
269                 MessageBox.Show(ex.Message);
270             }
271         }
272 
273         private void btn_5_down_Click(object sender, EventArgs e)
274         {
275             try
276             {
277                 myElevator.operate(EXTERIOR, DOWN, 4);
278             }
279             catch (Exception ex)
280             {
281                 MessageBox.Show(ex.Message);
282             }
283         }
284 
285         private void btn_5_up_Click(object sender, EventArgs e)
286         {
287             try
288             {
289                 myElevator.operate(EXTERIOR, UP, 4);
290             }
291             catch (Exception ex)
292             {
293                 MessageBox.Show(ex.Message);
294             }
295         }
296 
297         private void btn_6_down_Click(object sender, EventArgs e)
298         {
299             try
300             {
301                 myElevator.operate(EXTERIOR, DOWN, 5);
302             }
303             catch (Exception ex)
304             {
305                 MessageBox.Show(ex.Message);
306             }
307         }
308 
309         private void btn_6_up_Click(object sender, EventArgs e)
310         {
311             try
312             {
313                 myElevator.operate(EXTERIOR, UP, 5);
314             }
315             catch (Exception ex)
316             {
317                 MessageBox.Show(ex.Message);
318             }
319         }
320 
321         private void btn_7_down_Click(object sender, EventArgs e)
322         {
323             try
324             {
325                 myElevator.operate(EXTERIOR, DOWN, 6);
326             }
327             catch (Exception ex)
328             {
329                 MessageBox.Show(ex.Message);
330             }
331         }
332 
333         private void btn_7_up_Click(object sender, EventArgs e)
334         {
335             try
336             {
337                 myElevator.operate(EXTERIOR, UP, 6);
338             }
339             catch (Exception ex)
340             {
341                 MessageBox.Show(ex.Message);
342             }
343         }
344 
345         private void btn_8_down_Click(object sender, EventArgs e)
346         {
347             try
348             {
349                 myElevator.operate(EXTERIOR, DOWN, 7);
350             }
351             catch (Exception ex)
352             {
353                 MessageBox.Show(ex.Message);
354             }
355         }
356 
357         private void btn_8_up_Click(object sender, EventArgs e)
358         {
359             try
360             {
361                 myElevator.operate(EXTERIOR, UP, 7);
362             }
363             catch (Exception ex)
364             {
365                 MessageBox.Show(ex.Message);
366             }
367         }
368 
369         private void btn_9_down_Click(object sender, EventArgs e)
370         {
371             try
372             {
373                 myElevator.operate(EXTERIOR, DOWN, 8);
374             }
375             catch (Exception ex)
376             {
377                 MessageBox.Show(ex.Message);
378             }
379         }
380 
381         private void btn_9_up_Click(object sender, EventArgs e)
382         {
383             try
384             {
385                 myElevator.operate(EXTERIOR, UP, 8);
386             }
387             catch (Exception ex)
388             {
389                 MessageBox.Show(ex.Message);
390             }
391         }
392 
393         private void btn_10_down_Click(object sender, EventArgs e)
394         {
395             try
396             {
397                 myElevator.operate(EXTERIOR, DOWN, 9);
398             }
399             catch (Exception ex)
400             {
401                 MessageBox.Show(ex.Message);
402             }
403         }
404 
405         private void btn_e1_f1_Click(object sender, EventArgs e)
406         {
407             try
408             {
409                 myElevator.operate(INTERIOR, ELE1, 0);
410             }
411             catch (Exception ex)
412             {
413                 MessageBox.Show(ex.Message);
414             }
415         }
416 
417         private void btn_e1_f2_Click(object sender, EventArgs e)
418         {
419             try
420             {
421                 myElevator.operate(INTERIOR, ELE1, 1);
422             }
423             catch (Exception ex)
424             {
425                 MessageBox.Show(ex.Message);
426             }
427         }
428 
429         private void btn_e1_f3_Click(object sender, EventArgs e)
430         {
431             try
432             {
433                 myElevator.operate(INTERIOR, ELE1, 2);
434             }
435             catch (Exception ex)
436             {
437                 MessageBox.Show(ex.Message);
438             }
439         }
440 
441         private void btn_e1_f4_Click(object sender, EventArgs e)
442         {
443             try
444             {
445                 myElevator.operate(INTERIOR, ELE1, 3);
446             }
447             catch (Exception ex)
448             {
449                 MessageBox.Show(ex.Message);
450             }
451         }
452 
453         private void btn_e1_f5_Click(object sender, EventArgs e)
454         {
455             try
456             {
457                 myElevator.operate(INTERIOR, ELE1, 4);
458             }
459             catch (Exception ex)
460             {
461                 MessageBox.Show(ex.Message);
462             }
463         }
464 
465         private void btn_e1_f6_Click(object sender, EventArgs e)
466         {
467             try
468             {
469                 myElevator.operate(INTERIOR, ELE1, 5);
470             }
471             catch (Exception ex)
472             {
473                 MessageBox.Show(ex.Message);
474             }
475         }
476 
477         private void btn_e1_f7_Click(object sender, EventArgs e)
478         {
479             try
480             {
481                 myElevator.operate(INTERIOR, ELE1, 6);
482             }
483             catch (Exception ex)
484             {
485                 MessageBox.Show(ex.Message);
486             }
487         }
488 
489         private void btn_e1_f8_Click(object sender, EventArgs e)
490         {
491             try
492             {
493                 myElevator.operate(INTERIOR, ELE1, 7);
494             }
495             catch (Exception ex)
496             {
497                 MessageBox.Show(ex.Message);
498             }
499         }
500 
501         private void btn_e1_f9_Click(object sender, EventArgs e)
502         {
503             try
504             {
505                 myElevator.operate(INTERIOR, ELE1, 8);
506             }
507             catch (Exception ex)
508             {
509                 MessageBox.Show(ex.Message);
510             }
511         }
512 
513         private void btn_e1_f10_Click(object sender, EventArgs e)
514         {
515             try
516             {
517                 myElevator.operate(INTERIOR, ELE1, 9);
518             }
519             catch (Exception ex)
520             {
521                 MessageBox.Show(ex.Message);
522             }
523         }
524 
525         private void btn_e2_f1_Click(object sender, EventArgs e)
526         {
527             try
528             {
529                 myElevator.operate(INTERIOR, ELE2, 0);
530             }
531             catch (Exception ex)
532             {
533                 MessageBox.Show(ex.Message);
534             }
535         }
536 
537         private void btn_e2_f2_Click(object sender, EventArgs e)
538         {
539             try
540             {
541                 myElevator.operate(INTERIOR, ELE2, 1);
542             }
543             catch (Exception ex)
544             {
545                 MessageBox.Show(ex.Message);
546             }
547         }
548 
549         private void btn_e2_f3_Click(object sender, EventArgs e)
550         {
551             try
552             {
553                 myElevator.operate(INTERIOR, ELE2, 2);
554             }
555             catch (Exception ex)
556             {
557                 MessageBox.Show(ex.Message);
558             }
559         }
560 
561         private void btn_e2_f4_Click(object sender, EventArgs e)
562         {
563             try
564             {
565                 myElevator.operate(INTERIOR, ELE2, 3);
566             }
567             catch (Exception ex)
568             {
569                 MessageBox.Show(ex.Message);
570             }
571         }
572 
573         private void btn_e2_f5_Click(object sender, EventArgs e)
574         {
575             try
576             {
577                 myElevator.operate(INTERIOR, ELE2, 4);
578             }
579             catch (Exception ex)
580             {
581                 MessageBox.Show(ex.Message);
582             }
583         }
584 
585         private void btn_e2_f6_Click(object sender, EventArgs e)
586         {
587             try
588             {
589                 myElevator.operate(INTERIOR, ELE2, 5);
590             }
591             catch (Exception ex)
592             {
593                 MessageBox.Show(ex.Message);
594             }
595         }
596 
597         private void btn_e2_f7_Click(object sender, EventArgs e)
598         {
599             try
600             {
601                 myElevator.operate(INTERIOR, ELE2, 6);
602             }
603             catch (Exception ex)
604             {
605                 MessageBox.Show(ex.Message);
606             }
607         }
608 
609         private void btn_e2_f8_Click(object sender, EventArgs e)
610         {
611             try
612             {
613                 myElevator.operate(INTERIOR, ELE2, 7);
614             }
615             catch (Exception ex)
616             {
617                 MessageBox.Show(ex.Message);
618             }
619         }
620 
621         private void btn_e2_f9_Click(object sender, EventArgs e)
622         {
623             try
624             {
625                 myElevator.operate(INTERIOR, ELE2, 8);
626             }
627             catch (Exception ex)
628             {
629                 MessageBox.Show(ex.Message);
630             }
631         }
632 
633         private void btn_e2_f10_Click(object sender, EventArgs e)
634         {
635             try
636             {
637                 myElevator.operate(INTERIOR, ELE2, 9);
638             }
639             catch (Exception ex)
640             {
641                 MessageBox.Show(ex.Message);
642             }
643         }
644     }
645 }
View Code

四、测试结果  

结过几周的不断编写和调试,最后程序得已成功运行,期间查看了不少的资料和信息,特别 是对于画布的设计效果,还有就是对于电梯开关时的音效.

下面是测试效果:

1.开始界面,初使是默认在第一层:

2.进入乘客,分别对两台电梯进行操作:

3.15层要下行,两个电梯同时出发,当电梯2到达后,响应,电梯1不再调度。

4. 这是在进入电梯后,电梯1点击了13;电梯2中点击了8,9,10楼后的效果,分别在8,9,10楼电梯都停止,电梯门打开,等待一段时间后继续响应。

五、心得体会

回首本次实验历程,最初这个关于电梯调度的大工程,我们很是头疼,由于涉及到了图形界面,一开始我和雪青我们准备用java来实现,但是由于在图形界面这方面遇到的困难颇多,又因为上学期刚学了.net,最终选择了较为熟悉的.net开发;后来就是在电梯调度算法的选择上面出现了问题,虽然有小小的分歧,但是最终我们选择了一种容易实现并且易懂的算法,不得不说,在这个问题上,没少让我们学习有关操作系统各种调度算法的知识。这个电梯调度有个特点就是涉及到两个电梯,所以就更要求要有一个好的调度方法,来实现资源的利用最大化,涉及到并行,线程控制显得略为重要。

通过我们两个人精诚合作,最终实现了作为电梯调度的基本功能,虽然依旧没有完美的解决电梯调度中出现的问题,但是过程是十分重要的,我们学习到了许多知识,涉及多个学科,巩固了基础,提高了能力,也提高了结对开发的乐趣和效率,收获颇丰。

转载于:https://www.cnblogs.com/luyu2783/p/4575483.html

相关文章:

3.分支结构与循环结构

1 程序结构 程序结构分为顺序结构、分支结构、循环结构。分支结构有&#xff1a;if结构&#xff0c;if....else结构&#xff0c;if...else if....else &#xff0c;if...else结构&#xff0c;switch结构&#xff1b;循环结构有&#xff1a;while循环&#xff0c;do....while循环…

微信小程序 实现复制到剪贴版功能

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 实现API&#xff1a; wx.setClipboardData(Object object) API说明&#xff1a;设置系统剪贴板的内容 属性类型默认值是否必填说明支持版本datastring 是剪贴板的内容 successfunction 否接口调用成功…

数据结构面试题编程题_您下次编程面试时应该了解的顶级数据结构

数据结构面试题编程题by Fahim ul Haq通过Fahim ul Haq Niklaus Wirth, a Swiss computer scientist, wrote a book in 1976 titled Algorithms Data Structures Programs.瑞士计算机科学家Niklaus Wirth在1976年写了一本书&#xff0c;名为《 算法数据结构程序》。 40 yea…

oracle使用小技巧

批量禁用触发器 SELECT ALTER TRIGGER || trigger_name || DISABLE; FROM all_triggers; 这样就生成了一个禁用语句列表&#xff0c;复制到sql脚本执行界面&#xff0c;批量执行即可&#xff0c;类似的&#xff0c;可以用all_tables来批量删除表。 转载于:https://www.cnblogs…

if for switch语句

顺序语句&#xff1a;一行行执行条件语句:选择分支if语句 1、 if&#xff08;....&#xff09;//括号内是判断条件 { //程序代码&#xff0c;运算等等 } 2、 if&#xff08;....&#xff09;//括号内是判断条件 { //程序代码&#xff0c;运算等等 } else//如果不满足条件则执…

Apache Unable to find the wrapper https - did you forget to enable it when you configured PHP?

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 Apache Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? 问题解决办法&#xff1a; 打开配置文件 php.ini &#xff0c; 如图&#xff1a; …

文件魔术数字_如何使用魔术脚手架自动创建文件并节省时间

文件魔术数字Before we begin: This article uses JavaScript / Node.js example code, but you can port these concepts to any language using the right tools.开始之前&#xff1a;本文使用JavaScript / Node.js示例代码&#xff0c;但是您可以使用正确的工具将这些概念移…

Sql Server统计报表案例

场景&#xff1a;查询人员指定年月工作量信息 USE [Test] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER procedure [dbo].[GetWorkLoadMain] year int, month int, UserId varchar(50) as begindeclare day varchar(50)set dayCAST(year as varchar)-RIGHT((00…

运行报表时提示输入用户名和密码

在AX2012运行报表是总是提示用户输入用户名和密码&#xff1a; 尝试输入登陆名和密码&#xff0c;点击查看报表&#xff0c;出现如下错误&#xff1a; 因为AX2012的报表使用的针对AX2012客制化的SSRS&#xff0c;而要求输入登录名和密码是SSRS报表的数据源设置导致的。在SSRS管…

CSS 文字,边框实现从左至右颜色渐变

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 1.文本从左至右颜色渐变 效果图&#xff1a; 2.边框从左至右颜色渐变 效果图&#xff1a; 实现代码&#xff1a; 1.文本从左至右颜色渐变实现代码&#xff1a; <!DOCTYPE html> <html>&l…

如何使用Create-React-App和自定义服务人员构建PWA

Note: This is not a primer on create-react-app or what a service worker is. This post assumes prior knowledge of both.注意&#xff1a;这不是create-react-app或服务工作者的入门。 这篇文章假定两者都有先验知识。 So, I recently had the opportunity to work on a…

inline-block空隙怎么解决

方法一&#xff1a;移除空格 元素间留白间距出现的原因就是标签段之间的空格&#xff0c;因此&#xff0c;去掉HTML中的空格&#xff0c;自然间距就木有了。考虑到代码可读性&#xff0c;显然连成一行的写法是不可取的&#xff0c;我们可以&#xff1a; <div class"spa…

php 网络请求 get请求和post请求

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 代码记录 <?php header(content-type:application:json;charsetutf8); header(Access-Control-Allow-Origin:*); //header(Access-Control-Allow-Methods:POST); header(Access-Control-Allow-He…

docker查看现有容器_如何使用Docker将现有应用程序推送到容器中

docker查看现有容器by Daniel Newton丹尼尔牛顿 如何使用Docker将现有应用程序推送到容器中 (How to shove an existing application into containers with Docker) I have finally got round to learning how to use Docker past the level of knowing what it is and does w…

巧妙使用Firebug插件,快速监控网站打开缓慢的原因

巧妙使用Firebug插件&#xff0c;快速监控网站打开缓慢的原因 原文 巧妙使用Firebug插件&#xff0c;快速监控网站打开缓慢的原因 很多用户会问&#xff0c;我的网站首页才50KB&#xff0c;打开网页用了近60秒才打开&#xff1f;如何解释&#xff1f; 用户抱怨服务器运行缓…

第二阶段第三次站立会议

昨天做了什么&#xff1a;写了部分购物车的功能 今天要干什么&#xff1a;修改后台代码的错误 遇到的困难&#xff1a;没有困难转载于:https://www.cnblogs.com/jingxiaopu/p/7109774.html

微信小程序生成小程序二维码 php 直接可以用

微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 小程序需要先上线才能生成二维码 HTTP请求的效果图&#xff1a; 小程序展示的效果图&#xff1a; 小程序展示二维码源码&#xff1a; 请求二维码图片base64路径&#xff0c;点击预览图片 onLoad: func…

vue和react相同点_我在React和Vue中创建了相同的应用程序。 这是区别。

vue和react相同点by Sunil Sandhu由Sunil Sandhu 我在React和Vue中创建了相同的应用程序。 这是区别。 (I created the same app in React and Vue. Here are the differences.) Having used Vue at my current workplace, I had a fairly solid understanding of how it all …

Filter(过滤器)

一、Filter过滤器(重要)     Javaweb中的过滤器可以拦截所有访问web资源的请求或响应操作。 1、Filter快速入门     1.1、步骤:      1. 创建一个类实现Filter接口      2. 重写接口中方法 doFilter方法是真正过滤的。      3. 在web.xml文件中配置 …

css3实现3D立体翻转效果

1、在IE下无法显示翻转效果&#xff0c;火狐和谷歌可以 1 /*样式css*/2 3 .nav-menu li {4 display: inline;5 }6 .nav-menu li a {7 color: #fff;8 display: block;9 text-decoration: none;10 overflow: visible;11 line-height: 40px;12 font-…

Ant Design 入门-参照官方文档使用组件

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 先来一个按钮组件使用的对比,官方文档的(不能直接用)和实际能用的。 官网demo: import { Table, Divider, Tag } from antd;const columns = [{title: Name,dataIndex: name,key: name,render: text =…

如何用JavaScript的回调函数做出承诺

by Adham El Banhawy由Adham El Banhawy 如何用JavaScript的回调函数做出承诺 (How to make a Promise out of a Callback function in JavaScript) Back-end developers run into challenges all the time while building applications or testing code. As a developer who …

VMware里的linux系统里的命令行里会有bee的声音,要如何关掉

VMware里的linux系统里的命令行里会有bee的声音&#xff0c;要如何关掉 取消bell报警声的方法&#xff1a;登陆linux系统vi /etc/inputrc找到set bell-style none 将前面的&#xff03;去掉&#xff0c;之后重启系统即可解决声音问题若不见效可以通过下面的方式解决下bell-styl…

React-Todos

最近学完React的最基本概念&#xff0c;闲下来的时候就自己写了一个Todo-List的小应用。这里做个简略的说明&#xff0c;给想好好学React的新手看。 React-Todo 学习前提 这里我用了webpackb做了babel和JSX预处理和模块打包。所以对React和一些ES2015&#xff08;ES6&#xff0…

Ant Design 入门-引用自己命名的组件

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 自己创建的组件:代码 import { Table, Divider, Tag } from antd; import React, { Component } from react; export default class My_Table extends Component {render() {const columns = [{title: …

迷宫出路代码_如何在软件开发的迷宫中找到自己的出路

迷宫出路代码by Tim Kleier蒂姆克莱尔(Tim Kleier) 如何在软件开发的迷宫中找到自己的出路 (How to find your way through the corn maze of software development) The corn maze is one of my favorite challenges to tackle. It’s an unnerving experience, especially w…

打包 React 项目并在服务器运行。

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 1.找到项目根目录的package.json文件&#xff1a;如图&#xff1a; 2.打开cmd执行&#xff1a;npm run build 3.生成DIST文件夹。 4.把DIST文件放到服务器phpStudty根目录&#xff0c;访问index.html。…

一些有用的Python问题

1. 修改IDLE工作路径&#xff0c;在命令交互模式下输入如下指令&#xff1a; >>> import os >>> os.getcwd() #查看当前的工作路径 >>> os.chdir(E:\\Python\\Demo) #修改当前的工作路径 2.Python中 ImportError: cannot import name NUMPY_MKL 的…

Python核心编程笔记---- print

在仅用变量名时&#xff0c;输出的字符串是用单引号括起来的。这个是为了让非字符串对象也可能以字符的形式显示在屏幕上。 而print 函数打印出来的是变量的值。 print 调用的是str()方法。而仅用变量名时调用的是repr()方法。 证明&#xff1a;------------------------------…

latex 插图解释_大O符号-只需插图和视频即可解释

latex 插图解释Big O notation is used to communicate how fast an algorithm is. This can be important when evaluating other people’s algorithms, and when evaluating your own! In this article, I’ll explain what Big O notation is and give you a list of the m…