软件工程-电梯调度算法分析与实现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