当前位置:编程学习 > 网站相关 >>

北京邮电大学 程序设计课程设计 电梯项目 文件输入版本 代码(未调试)


模拟电梯系统:

 


•电梯说明:
–电梯服务楼层为1-9层。
–电梯有空闲、上行、下行、停靠的运行状态。
–电梯内有目标楼层按钮和开关门按钮。
–各楼层有上行和下行呼叫按钮。
–电梯的启动和停靠最短间隔是一个楼层,因此电梯离开X层上行时,X+1层按呼叫钮,不能停靠。同理,电梯下行离开Y层时,Y-1层按呼叫钮,不能停靠
–电梯运行速度要稳定,每层5秒-8秒。


•电梯的运行控制策略


             –先来先服务策略(链表实现)
n            将所有呼叫和目标按到达时间排队,然后一一完成。
             –顺便服务策略
n            一次将一个方向上的所有呼叫和目标全部完成。然后掉转运行方向完成另外一个方向上的所有呼叫和目标

PS:要求实现先来先服务和顺便服务两种策略,要求在电梯运行过程中可以更改策略


•电梯的运行控制策略


–两部电梯联动策略(选作)


n有新的呼叫请求时,将其分配给能够最快响应的电梯。

 

本次仅仅仅仅实现了文件输入和先来先服务策略,鉴于时间过紧,需要睡眠,调试工作暂缓,本程序bug无数,使用需谨慎!
放代码:

//Author :Chenxingman

//Time :2013_4_10_19:40
//file_input_output
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <string.h>
#include <malloc.h>


#define STOPTIME 2.0
#define LOCAL
#define UP_RUN 1
#define DOWN_RUN 2
#define UP_STOP 3
#define DOWN_STOP 4
#define IDLE 5
#define RUNAFLOOR 1.0
#define BREAKTIME 0.1


int debug=0;
float timecount=0;


struct _cmd
{
    float Time;//指令呼叫时间
    char state[60];//state表示指令
    _cmd *next;
};
typedef struct _cmd cmd; //链表存储待处理业务
typedef struct
{
    /*
    State=<电梯状态>,
    NowF=<电梯当前楼层>,
    GoalF=<电梯目标楼层>,
    WaitF=<未响应的楼层请求>
    StopT=<停靠时间>,
    pointer_top=<指向队列最前端>
    pointer_rare=<指向队列最尾端>
    */
    float NowF;
    int State;
    int GoalF;
    float StopT;
    int top;
    int rare;
    char Waitf[60];
}run_state;


run_state lift;


cmd * creat()
{
    printf("enter cmd:\n");
cmd *head;
cmd *p1,*p2;
    head=(cmd *)malloc(sizeof(cmd));
    if(scanf("T=%f,",&head->Time)!=EOF)
    {
    scanf("CallF=");
    char temp='a';
    int pt=0;
    memset(head->state,'\0',sizeof(head->state));
       while(temp!='\n')
       {
      head->state[pt++]=getchar();
      head->state[pt++]=getchar();
      temp=getchar();
     }
     printf("debug #%d:finished\n",debug++);
     p2=head;
     float temptime;
     while(scanf("T=%f,",&temptime)!=EOF)
     {
         printf("while loop:\n");
      p1=(cmd *)malloc(sizeof(cmd));
      temp='a';
      pt=0;
      p1->Time=temptime;
    scanf("CallF=");
    memset(p1->state,'\0',sizeof(p1->state));
    printf("debug #%d:finished\n",debug++);
    while(temp!='\n'&&temp!=-1)
           {
         p1->state[pt++]=getchar();
         p1->state[pt++]=getchar();
         temp=getchar();
         printf("temp=%d",temp);
         printf("debug #%d:finished\n",debug++);
            }
            p2->next=p1;
            p2=p1;
    }
    p1->next=NULL;
    }
    printf("debug #%d:finished\n",debug++);
    return head;
}
void print(cmd *head)
{
cmd *p;
p=head;
while(p!=NULL)
{
printf("time=%f,state:%s\n",p->Time,p->state);
p=p->next;
}
}
void addup(char input[])
{
    ++lift.top;
    int i=lift.top;
int j=0;
for(;j<strlen(input);i++,j++)
{
lift.top=lift.top%60;
lift.Waitf[lift.top]=input[j];
lift.top++;
}
lift.top--;
}
int EqualZero(float t)
{
    if(t>-10e-6&&t<10e-6)
        return 1;
    return 0;
}
void changestate()
{
lift.GoalF=lift.Waitf[lift.rare]-'0';//可以考虑换个地方
//How to do
switch(lift.State)
    {
        case IDLE:
            if(lift.GoalF>lift.NowF)
            {
            lift.State=UP_RUN;
            lift.NowF+=1.0/RUNAFLOOR;
                if(floor(lift.NowF)==lift.GoalF)
                {
               lift.State=UP_STOP;
                }
            }
            else if(lift.GoalF<lift.NowF)
            {
            lift.State=DOWN_RUN;
            lift.NowF-=1.0/RUNAFLOOR;
                if(floor(lift.NowF)==lift.GoalF)
         &n

补充:综合编程 , 其他综合 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,