zoukankan      html  css  js  c++  java
  • 电梯调度系统

    运行截图:

    组员/时间安 排

    董芳健 吕盼举
    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;
            }
    
        }
    }
    复制代码
  • 相关阅读:
    如何安装Tomcat服务器
    浅谈数据库中的锁机制
    彻底理解js中this的指向
    Javascript模块化编程的写法
    滚屏加载--无刷新动态加载数据技术的应用
    JavaScript正则表达式
    CSS:水平居中与垂直居中
    Linux常用命令大全
    HTML的元素嵌套规则
    clearfix清除浮动进化史
  • 原文地址:https://www.cnblogs.com/dongfangjian/p/3623466.html
Copyright © 2011-2022 走看看