軟件工程-電梯調度算法分析與實現3


組員/時間安 排

董芳健 呂盼舉
3月6日 到春暉樓體驗了一下電梯是怎樣調度的 到春暉樓體驗了一下電梯是怎樣調度的
3月7日 分析題目,確定使用的語言及環境 分析題目,確定使用的語言及環境
3月8日 8:00——11:00,討論該使用什么方法, 確定電梯聯合調度和獨立調度的算法,上行、下行的優先級
3月9日 14:00——17:20,設計界面 14:00——17:20構建類成員和具體方法

3月10—

3月14日

這段時間要上課,有了大概的思路之后就有點懶了, 具體的實現還需要反復的確認,想好每一個細節,學習要使用的工具和方法,這幾天基本沒寫。

 3月15日

 9:00——11:40,協助完成界面與代碼的連接,進行測試運行   9:00——11:40,對類和方法進行具體實現

 3月16日

 9:00——11:00,電梯調度程序經過修改,運行通過   9:00——11:00,此時功能還很單一,提交一個可運行版

 3月17——3月20日

 完善調度算法,設計顯示系統時間的功能,顯示電梯人數和載重  增加聯合調度算法,實現四個電梯聯合起來,實現最快響應

 3月21日

 9:30,確認電梯可以可以運行無誤, 9:30,發布較為滿意的一版程序,包含代碼

 核心思想:電梯響應離他所在的當前層最近的樓層的請求,

               響應完所有上行請求后才開始響應下行請求,反之亦然;

                每一個電梯運行函數都對應一個線程,獨立運行,

                每一個電梯都有一個檢測函數,不斷地將適合的電梯層加入電梯的停靠隊列。

主要代碼:

電梯類:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.IO;
using System.Threading;

namespace WindowsFormsApplication2
{
    class dianti
    {
        public int number;
        public int wight;
        public int sx;//電梯上行下行或停止標志 0、1、2標識
        public int maxnumber;
        public int maxwight;
        public int dqlc;//電梯當前層
       // private int i;
       // private int j;
        public dianti(int a, int b,int c,int d)
        {
            this.maxnumber = a;
            this.maxwight = b;
            this.dqlc = c;
            this.sx = d;
        }

        public void diaodu(ref ArrayList da,ref dianti dta) { if (da==null) { dta.sx = 2; return; } i = 21; if (dta.sx == 1) { foreach (chengke o in da) { if (o.sxt == dta.sx) {                             dta.sx = 1; break; } dta.sx = 0; } } else if (dta.sx == 0) {                     foreach (chengke o in da) { if (o.sxt == dta.sx) { dta.sx = 0; break; } dta.sx = 1; } } else                { dta.sx = 1; foreach (chengke o in da) { if (o.sxt == dta.sx) { dta.sx = 1; break; } dta.sx = 0; } } if (dta.sx == 1)//電梯A向上走 foreach (chengke o in da)//尋找離電梯最近的請求點 {                        if (o.sxt == dta.sx) { if (o.f == 0 && o.newfloor >= dta.dqlc)//未上電梯 if (i > o.newfloor - dta.dqlc) { i = o.newfloor - dta.dqlc; j = o.newfloor; } if (o.f == 0 && o.newfloor < dta.dqlc) if (i > dta.dqlc - o.newfloor) { i = dta.dqlc - o.newfloor; j = o.newfloor; } if (o.f == 1 && o.goalfloor >= dta.dqlc)//已上電梯 if (i > o.goalfloor - dta.dqlc) {                           i = o.goalfloor - dta.dqlc; j = o.goalfloor; } } } if (dta.sx == 0) foreach (chengke o in da) { if (o.sxt == dta.sx) { if (o.f == 0 && o.newfloor <= dta.dqlc) if (i > dta.dqlc - o.newfloor) { i = dta.dqlc - o.newfloor; j = o.newfloor; } if (o.f == 0 && o.newfloor > dta.dqlc) if (i > o.newfloor - dta.dqlc) { i = o.newfloor - dta.dqlc;
                             j = o.newfloor; } if (o.f == 1 && o.goalfloor <= dta.dqlc) if (i > dta.dqlc - o.goalfloor) { i = dta.dqlc - o.goalfloor; j = o.goalfloor; } } } } public void dtyuxinga( ref ArrayList da, ref dianti dta, ref Label label11, ref Button button1, ref Button button2) { 
 while (true) { if (da!=null) { if (dta.sx == 1) { while (dta.dqlc < j) { dta.dqlc++; label11.Text = dta.dqlc.ToString(); Thread.Sleep(2000); } while (dta.dqlc > j) { dta.dqlc--; label11.Text = dta.dqlc.ToString(); Thread.Sleep(2000); } if (dta.dqlc == j)                         {
                 dta.Opendoora(button1,button2); dta.jiancea(da,dta); Thread.Sleep(5000); dta.closedoora(button1, button2); } } if (dta.sx == 0) { while (dta.dqlc > j) { dta.dqlc--; label11.Text = dta.dqlc.ToString(); Thread.Sleep(2000); } while (dta.dqlc < j) { dta.dqlc++; label11.Text = dta.dqlc.ToString(); Thread.Sleep(2000);                         }
                 if (dta.dqlc == j) { dta.Opendoora(button1, button2); dta.jiancea(da,dta); Thread.Sleep(5000); dta.closedoora(button1, button2); } } } } } public void Opendoora(Button button1,Button button2) { while (button1.Width > 5 && button2.Width > 5) { button1.Width--; button2.Width--; button2.Location = new Point(button2.Location.X + 1, button2.Location.Y); Thread.Sleep(100);             }
     } public void closedoora(Button button1, Button button2) { while (button1.Width < 48 && button2.Width < 48) { button1.Width++; button2.Width++; button2.Location = new Point(button2.Location.X - 1, button2.Location.Y); Thread.Sleep(100); } } public void jiancea(ArrayList da,dianti dta) { for (int g = 0; g <da.Count; g++) {             chengke ck = (chengke)da[g]; if (ck.goalfloor == dta.dqlc && ck.f == 1) { dta.wight = dta.wight - ck.tzhong; dta.number = dta.number - 1; da.Remove(da[g]); } } foreach (chengke o in da) { if (o.newfloor == dta.dqlc && o.f == 0) { dta.wight = dta.wight + o.tzhong; dta.number = dta.number + 1; if (dta.number <= dta.maxnumber && dta.wight <= dta.maxwight) o.f = 1; else                { dta.wight = dta.wight - o.tzhong; dta.number = dta.number - 1; } } } }
    }
}
乘客類:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication2
{
    class chengke
    {
        public int tzhong;
        public int newfloor;
        public int goalfloor;
        public int f;//記錄是否進入電梯0沒進1進入
        public int sxt;//記錄上行下行
        public chengke(int f)
        {
            Random ranNum = new Random();
            this.tzhong = ranNum.Next(45, 120);
            this.f = f;
        }

    }
}
 

 

 
        

 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM