trooped Members: Li Baoquan & Huang Yifan
Li Baoquan's Blog home: http://www.cnblogs.com/libaoquan/
Cooding Link: https://coding.net/u/2013040101159/p/4elevator/git
4-Way Elevator scheduling algorithm show:http://ele.libq.ren/
Pair programming Topic: Elevator Scheduling
Existing new office building, a total of 21 floors, a total of four elevators, all elevators basic parameters are shown in the following table:
Elevator number |
Service Floors available |
Maximum number of passengers |
Maximum Load weight |
1 |
All floors |
10 |
800KG |
2 |
Single layer |
10 |
800KG |
3 |
Double |
20 |
1600KG |
4 |
All floors |
20 |
2000KG |
The terms of use are as follows:
1, the floor number is 0~20, of which No. 0 is the basement layer;
2. Elevators with floor restrictions are not docked in the response floor, such as a single double layer;
3, all elevators with unified button control
Please design and implement an elevator control program according to the above requirements, if there is a graphical display is better.
Demand analysis
- Four elevators are controlled using a unified external button.
- Elevator Internal Button press event priority is higher than the external button.
- Single-storey elevators are docked only on a single floor, not in double-decker. The double-decker elevators are only double-decker, including 0 floors (basement level).
- When the elevator is idle, the elevator stops at the last movement to the floor.
- Reasonable dispatch of the elevator on the downstream and internal and external message response.
- Use the graphical interface to display the program.
We describe the reasonable elevator scheduling behavior as follows:
- The elevator first responds to internal button events.
- For external events, only the external events that respond to the elevator motion direction are responded to at a time. When the elevator is on the line, in response to an external event on top of the elevator floor, the elevator down, in response to the external events under the elevator floor.
- In response to internal events, priority responds to internal events in the direction of elevator motion. When the elevator is on the line, in response to the elevator on the floor of the internal events, the elevator down, in response to the elevator in the internal events under the layer.
- The same external event can have multiple elevators responding at the same time, or it can be a single elevator to the corresponding. This is determined by the specific motion state of the current 4 elevators.
Algorithm design
- Each elevator runs independently and uses Message Queuing inreqlist to store the elevator's docking messages. Message queues for each elevator are independent of each other.
- When the elevator interior button is pressed, the message is placed in the Inreqlist queue queue for this elevator. Since the floor where the internal button is pressed is the floor where the elevator must dock, each time you find the most suitable floor from the inreqlist queue and dock.
- When the elevator external button is pressed, the incoming message is placed in each inreqlist queue. Since the floor of the external button press is not necessarily the floor where each elevator is to be docked, it is necessary to respond to this external event according to the specific inreqlist queue of this elevator to find the appropriate time.
First from the single elevator in the scheduling process to start the discussion, the initial state of the elevator is idle state, in response to the external button event wake elevator, elevator start movement, scheduling diagram as follows:
When scheduling multiple elevators, because each elevator's internal events are independent of each other, only the response rules for external events need to be modified.
- When the external button is pressed, the message property of the 4 elevators is traversed, and if there is an internal message at this level, the write is discarded; otherwise, an external message is written at this level.
- When the elevator stops, clear the message on the floor of the elevator, then traverse the message properties of the other elevators, and if the other elevators are external properties, clear the message; otherwise, no processing is done.
In this way, the core of the elevator scheduling problem is how to find the most suitable floor in the message queue. This problem is easy to solve:
Because the elevator floor is fixed to 21 layers, you can save an elevator message queue with one-dimensional array inreqlist[21]. When the array value is inreqlist[i]=0, there is no docking message on layer I, the elevator does not need to stop at this level; When the array value is inreqlist[i]=1, there is an internal button press message on the level I, the elevator needs to be docked at this level; When the array value is inreqlist[i]= 2 o'clock, indicates that layer I has an external button press the message, the elevator needs to stop at this level;
- If the current floor is Now_floor, when the elevator line, from the inreqlist array of now_floor+1 items to the 20th item, the first value is not 0 of the item, its array subscript value is the most appropriate floor value in the message queue.
- If the current floor is Now_floor, the elevator down, from the No. 0 item in the Inreqlist array to the NOW_FLOOR-1 item, the first value is not 0, and its array subscript value is the most appropriate floor value in the message queue.
- When a row is up, the message queue above this layer is empty, and the queue is not empty, the elevator motion state is changed to a downward line. The downside is the reverse.
- When the message queue is empty, the elevator is idle.
The requirement analysis and algorithm design of the implementation and test of the elevator scheduling algorithm for the pair operation