基本信息
源码名称:电梯程序(knuthElevator.go)
源码大小:0.03M
文件格式:.go
开发语言:Go
更新时间:2021-03-27
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍
电梯程序


import (
"fmt"
"math/rand"
"time"
)

const (
// The Mathematics building has five floors: sub-basement, basement, first,
// second, and third. There is a single elevator, which has automatic controls
// and can stop at each floor. For convenience we will renumber the floors 0, 1,
// 2, 3, and 4.
floorSubbasement = 0
floorBasement    = 1
floorFirst       = 2
floorSecond      = 3
floorThird       = 4

floorHome = floorFirst

floors = 5

// The elevator is in one of three states: GOINGUP, GOINGDOWN, or NEUTRAL.
// (The current state is indicated to passengers by lighted arrows inside the
// elevator.) If it is in NEUTRAL state and not on floor 2, the machine will close
// its doors and (if no command is given by the time its doors are shut) it will
// change to GOINGUP or GOINGDOWN, heading for floor 2. (This is the “home floor,”
// since most passengers get in there.) On floor 2 in NEUTRAL state, the doors will
// eventually close and the machine will wait silently for another command. The first
// command received for another floor sets the machine GOINGUP or GOINGDOWN as
// appropriate; it stays in this state until there are no commands waiting in the
// same direction, and then it switches direction or switches to NEUTRAL just before
// opening the doors, depending on what other commands are in the CALL variables. The
// elevator takes a certain amount of time to open and close its doors, to accelerate
// and decelerate, and to get from one floor to another.
stateGoingUp = iota
stateGoingDown
stateNeutral

// E1--E9
stepWaitForCall          = 1
stepChangeOfState        = 2
stepOpenDoors            = 3
stepLetPeopleOutIn       = 4
stepCloseDoors           = 5
stepPrepareToMove        = 6
stepGoUpAFloor           = 7
stepGoDownAFloor         = 8
stepSetInactionIndicator = 9

minGiveUpTime = 30 * 10     // 30 seconds
maxGiveUpTime = 2 * 60 * 10 // 2 minutes

minInterTime = 1 * 10  // 1 seconds
maxInterTime = 90 * 10 // 90 seconds

maxTime = 1000 * 10 // stop simulation after 1000 seconds
)

type node struct {
info  interface{}
llink *node
rlink *node
}