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
}
评论